summaryrefslogtreecommitdiff
path: root/Source/JavaScriptCore/profiler/ProfilerCompilation.cpp
diff options
context:
space:
mode:
authorLorry Tar Creator <lorry-tar-importer@lorry>2015-10-15 09:45:50 +0000
committerLorry Tar Creator <lorry-tar-importer@lorry>2015-10-15 09:45:50 +0000
commite15dd966d523731101f70ccf768bba12435a0208 (patch)
treeae9cb828a24ded2585a41af3f21411523b47897d /Source/JavaScriptCore/profiler/ProfilerCompilation.cpp
downloadWebKitGtk-tarball-e15dd966d523731101f70ccf768bba12435a0208.tar.gz
webkitgtk-2.10.2webkitgtk-2.10.2
Diffstat (limited to 'Source/JavaScriptCore/profiler/ProfilerCompilation.cpp')
-rw-r--r--Source/JavaScriptCore/profiler/ProfilerCompilation.cpp156
1 files changed, 156 insertions, 0 deletions
diff --git a/Source/JavaScriptCore/profiler/ProfilerCompilation.cpp b/Source/JavaScriptCore/profiler/ProfilerCompilation.cpp
new file mode 100644
index 000000000..488f563de
--- /dev/null
+++ b/Source/JavaScriptCore/profiler/ProfilerCompilation.cpp
@@ -0,0 +1,156 @@
+/*
+ * Copyright (C) 2012, 2013, 2014 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "config.h"
+#include "ProfilerCompilation.h"
+
+#include "JSGlobalObject.h"
+#include "ObjectConstructor.h"
+#include "JSCInlines.h"
+#include "ProfilerDatabase.h"
+#include "Watchpoint.h"
+#include <wtf/StringPrintStream.h>
+
+namespace JSC { namespace Profiler {
+
+Compilation::Compilation(Bytecodes* bytecodes, CompilationKind kind)
+ : m_bytecodes(bytecodes)
+ , m_kind(kind)
+ , m_jettisonReason(NotJettisoned)
+ , m_numInlinedGetByIds(0)
+ , m_numInlinedPutByIds(0)
+ , m_numInlinedCalls(0)
+{
+}
+
+Compilation::~Compilation() { }
+
+void Compilation::addProfiledBytecodes(Database& database, CodeBlock* profiledBlock)
+{
+ Bytecodes* bytecodes = database.ensureBytecodesFor(profiledBlock);
+
+ // First make sure that we haven't already added profiled bytecodes for this code
+ // block. We do this using an O(N) search because I suspect that this list will
+ // tend to be fairly small, and the additional space costs of having a HashMap/Set
+ // would be greater than the time cost of occasionally doing this search.
+
+ for (unsigned i = m_profiledBytecodes.size(); i--;) {
+ if (m_profiledBytecodes[i].bytecodes() == bytecodes)
+ return;
+ }
+
+ m_profiledBytecodes.append(ProfiledBytecodes(bytecodes, profiledBlock));
+}
+
+void Compilation::addDescription(const CompiledBytecode& compiledBytecode)
+{
+ m_descriptions.append(compiledBytecode);
+}
+
+void Compilation::addDescription(const OriginStack& stack, const CString& description)
+{
+ addDescription(CompiledBytecode(stack, description));
+}
+
+ExecutionCounter* Compilation::executionCounterFor(const OriginStack& origin)
+{
+ std::unique_ptr<ExecutionCounter>& counter = m_counters.add(origin, nullptr).iterator->value;
+ if (!counter)
+ counter = std::make_unique<ExecutionCounter>();
+
+ return counter.get();
+}
+
+void Compilation::addOSRExitSite(const Vector<const void*>& codeAddresses)
+{
+ m_osrExitSites.append(OSRExitSite(codeAddresses));
+}
+
+OSRExit* Compilation::addOSRExit(unsigned id, const OriginStack& originStack, ExitKind exitKind, bool isWatchpoint)
+{
+ m_osrExits.append(OSRExit(id, originStack, exitKind, isWatchpoint));
+ return &m_osrExits.last();
+}
+
+void Compilation::setJettisonReason(JettisonReason jettisonReason, const FireDetail* detail)
+{
+ if (m_jettisonReason != NotJettisoned)
+ return; // We only care about the original jettison reason.
+
+ m_jettisonReason = jettisonReason;
+ if (detail)
+ m_additionalJettisonReason = toCString(*detail);
+ else
+ m_additionalJettisonReason = CString();
+}
+
+JSValue Compilation::toJS(ExecState* exec) const
+{
+ JSObject* result = constructEmptyObject(exec);
+
+ result->putDirect(exec->vm(), exec->propertyNames().bytecodesID, jsNumber(m_bytecodes->id()));
+ result->putDirect(exec->vm(), exec->propertyNames().compilationKind, jsString(exec, String::fromUTF8(toCString(m_kind))));
+
+ JSArray* profiledBytecodes = constructEmptyArray(exec, 0);
+ for (unsigned i = 0; i < m_profiledBytecodes.size(); ++i)
+ profiledBytecodes->putDirectIndex(exec, i, m_profiledBytecodes[i].toJS(exec));
+ result->putDirect(exec->vm(), exec->propertyNames().profiledBytecodes, profiledBytecodes);
+
+ JSArray* descriptions = constructEmptyArray(exec, 0);
+ for (unsigned i = 0; i < m_descriptions.size(); ++i)
+ descriptions->putDirectIndex(exec, i, m_descriptions[i].toJS(exec));
+ result->putDirect(exec->vm(), exec->propertyNames().descriptions, descriptions);
+
+ JSArray* counters = constructEmptyArray(exec, 0);
+ for (auto it = m_counters.begin(), end = m_counters.end(); it != end; ++it) {
+ JSObject* counterEntry = constructEmptyObject(exec);
+ counterEntry->putDirect(exec->vm(), exec->propertyNames().origin, it->key.toJS(exec));
+ counterEntry->putDirect(exec->vm(), exec->propertyNames().executionCount, jsNumber(it->value->count()));
+ counters->push(exec, counterEntry);
+ }
+ result->putDirect(exec->vm(), exec->propertyNames().counters, counters);
+
+ JSArray* exitSites = constructEmptyArray(exec, 0);
+ for (unsigned i = 0; i < m_osrExitSites.size(); ++i)
+ exitSites->putDirectIndex(exec, i, m_osrExitSites[i].toJS(exec));
+ result->putDirect(exec->vm(), exec->propertyNames().osrExitSites, exitSites);
+
+ JSArray* exits = constructEmptyArray(exec, 0);
+ for (unsigned i = 0; i < m_osrExits.size(); ++i)
+ exits->putDirectIndex(exec, i, m_osrExits[i].toJS(exec));
+ result->putDirect(exec->vm(), exec->propertyNames().osrExits, exits);
+
+ result->putDirect(exec->vm(), exec->propertyNames().numInlinedGetByIds, jsNumber(m_numInlinedGetByIds));
+ result->putDirect(exec->vm(), exec->propertyNames().numInlinedPutByIds, jsNumber(m_numInlinedPutByIds));
+ result->putDirect(exec->vm(), exec->propertyNames().numInlinedCalls, jsNumber(m_numInlinedCalls));
+ result->putDirect(exec->vm(), exec->propertyNames().jettisonReason, jsString(exec, String::fromUTF8(toCString(m_jettisonReason))));
+ if (!m_additionalJettisonReason.isNull())
+ result->putDirect(exec->vm(), exec->propertyNames().additionalJettisonReason, jsString(exec, String::fromUTF8(m_additionalJettisonReason)));
+
+ return result;
+}
+
+} } // namespace JSC::Profiler
+