1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162
|
/*
* Copyright (C) 2012-2019 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 "JSCInlines.h"
#include "ObjectConstructor.h"
#include "ProfilerDatabase.h"
#include "ProfilerDumper.h"
#include <wtf/StringPrintStream.h>
namespace JSC { namespace Profiler {
Compilation::Compilation(Bytecodes* bytecodes, CompilationKind kind)
: m_kind(kind)
, m_bytecodes(bytecodes)
, m_numInlinedGetByIds(0)
, m_numInlinedPutByIds(0)
, m_numInlinedCalls(0)
, m_jettisonReason(NotJettisoned)
, m_uid(UID::generate())
{
}
Compilation::~Compilation() = default;
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 UncheckedKeyHashMap/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 = makeUnique<ExecutionCounter>();
return counter.get();
}
void Compilation::addOSRExitSite(const Vector<CodePtr<JSInternalPtrTag>>& 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();
}
void Compilation::dump(PrintStream& out) const
{
out.print("Comp", m_uid);
}
Ref<JSON::Value> Compilation::toJSON(Dumper& dumper) const
{
auto result = JSON::Object::create();
result->setDouble(dumper.keys().m_bytecodesID, m_bytecodes->id());
result->setString(dumper.keys().m_compilationKind, String::fromUTF8(toCString(m_kind).span()));
auto profiledBytecodes = JSON::Array::create();
for (const auto& bytecode : m_profiledBytecodes)
profiledBytecodes->pushValue(bytecode.toJSON(dumper));
result->setValue(dumper.keys().m_profiledBytecodes, WTFMove(profiledBytecodes));
auto descriptions = JSON::Array::create();
for (const auto& description : m_descriptions)
descriptions->pushValue(description.toJSON(dumper));
result->setValue(dumper.keys().m_descriptions, WTFMove(descriptions));
auto counters = JSON::Array::create();
for (const auto& [key, value] : m_counters) {
auto counterEntry = JSON::Object::create();
counterEntry->setValue(dumper.keys().m_origin, key.toJSON(dumper));
counterEntry->setDouble(dumper.keys().m_executionCount, value->count());
counters->pushValue(WTFMove(counterEntry));
}
result->setValue(dumper.keys().m_counters, WTFMove(counters));
auto exitSites = JSON::Array::create();
for (const auto& osrExitSite : m_osrExitSites)
exitSites->pushValue(osrExitSite.toJSON(dumper));
result->setValue(dumper.keys().m_osrExitSites, WTFMove(exitSites));
auto exits = JSON::Array::create();
for (unsigned i = 0; i < m_osrExits.size(); ++i)
exits->pushValue(m_osrExits[i].toJSON(dumper));
result->setValue(dumper.keys().m_osrExits, WTFMove(exits));
result->setDouble(dumper.keys().m_numInlinedGetByIds, m_numInlinedGetByIds);
result->setDouble(dumper.keys().m_numInlinedPutByIds, m_numInlinedPutByIds);
result->setDouble(dumper.keys().m_numInlinedCalls, m_numInlinedCalls);
result->setString(dumper.keys().m_jettisonReason, String::fromUTF8(toCString(m_jettisonReason).span()));
if (!m_additionalJettisonReason.isNull())
result->setString(dumper.keys().m_additionalJettisonReason, String::fromUTF8(m_additionalJettisonReason.span()));
result->setString(dumper.keys().m_uid, makeString(m_uid));
return result;
}
} } // namespace JSC::Profiler
|