Skip to content

Commit 422ff29

Browse files
webkit-commit-queuekmiller68
authored andcommitted
Unreviewed, reverting 265586@main.
https://bugs.webkit.org/show_bug.cgi?id=258924 Introduced a memory regression Reverted changeset: "[JSC] Use JSONValues for Bytecode Profiler output instead of JSC's JSON" https://bugs.webkit.org/show_bug.cgi?id=258606 https://commits.webkit.org/265586@main Canonical link: https://commits.webkit.org/265800@main
1 parent 59f29ab commit 422ff29

36 files changed

Lines changed: 334 additions & 354 deletions

‎Source/JavaScriptCore/CMakeLists.txt‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -930,7 +930,6 @@ set(JavaScriptCore_PRIVATE_FRAMEWORK_HEADERS
930930
profiler/ProfilerCompilationKind.h
931931
profiler/ProfilerCompiledBytecode.h
932932
profiler/ProfilerDatabase.h
933-
profiler/ProfilerDumper.h
934933
profiler/ProfilerEvent.h
935934
profiler/ProfilerExecutionCounter.h
936935
profiler/ProfilerJettisonReason.h

‎Source/JavaScriptCore/JavaScriptCore.xcodeproj/project.pbxproj‎

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1941,7 +1941,6 @@
19411941
E3BFA5D021E853A1009C0EBA /* DFGDesiredGlobalProperty.h in Headers */ = {isa = PBXBuildFile; fileRef = E3BFA5CD21E853A1009C0EBA /* DFGDesiredGlobalProperty.h */; };
19421942
E3BFD0BC1DAF808E0065DEA2 /* AccessCaseSnippetParams.h in Headers */ = {isa = PBXBuildFile; fileRef = E3BFD0BA1DAF807C0065DEA2 /* AccessCaseSnippetParams.h */; };
19431943
E3C091E929B07D4C00CD6D97 /* WasmBBQJIT.cpp in Sources */ = {isa = PBXBuildFile; fileRef = FED5FA3329A0859C00798A7F /* WasmBBQJIT.cpp */; };
1944-
E3C0ECCA2A4C01E9002C9D2B /* ProfilerDumper.h in Headers */ = {isa = PBXBuildFile; fileRef = E3C0ECC92A4C01E8002C9D2B /* ProfilerDumper.h */; settings = {ATTRIBUTES = (Private, ); }; };
19451944
E3C295DD1ED2CBDA00D3016F /* ObjectPropertyChangeAdaptiveWatchpoint.h in Headers */ = {isa = PBXBuildFile; fileRef = E3C295DC1ED2CBAA00D3016F /* ObjectPropertyChangeAdaptiveWatchpoint.h */; };
19461945
E3C4131D289E08EA001150F8 /* SyntheticModuleRecord.h in Headers */ = {isa = PBXBuildFile; fileRef = E3C4131C289E08E5001150F8 /* SyntheticModuleRecord.h */; settings = {ATTRIBUTES = (Private, ); }; };
19471946
E3C694B323026877006FBE42 /* WasmOSREntryData.h in Headers */ = {isa = PBXBuildFile; fileRef = E3C694B123026873006FBE42 /* WasmOSREntryData.h */; settings = {ATTRIBUTES = (Private, ); }; };
@@ -5473,7 +5472,6 @@
54735472
E3BFA5CD21E853A1009C0EBA /* DFGDesiredGlobalProperty.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = DFGDesiredGlobalProperty.h; path = dfg/DFGDesiredGlobalProperty.h; sourceTree = "<group>"; };
54745473
E3BFD0B91DAF807C0065DEA2 /* AccessCaseSnippetParams.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = AccessCaseSnippetParams.cpp; sourceTree = "<group>"; };
54755474
E3BFD0BA1DAF807C0065DEA2 /* AccessCaseSnippetParams.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = AccessCaseSnippetParams.h; sourceTree = "<group>"; };
5476-
E3C0ECC92A4C01E8002C9D2B /* ProfilerDumper.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = ProfilerDumper.h; path = profiler/ProfilerDumper.h; sourceTree = "<group>"; };
54775475
E3C295DC1ED2CBAA00D3016F /* ObjectPropertyChangeAdaptiveWatchpoint.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ObjectPropertyChangeAdaptiveWatchpoint.h; sourceTree = "<group>"; };
54785476
E3C4131B289E08E5001150F8 /* SyntheticModuleRecord.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = SyntheticModuleRecord.cpp; sourceTree = "<group>"; };
54795477
E3C4131C289E08E5001150F8 /* SyntheticModuleRecord.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = SyntheticModuleRecord.h; sourceTree = "<group>"; };
@@ -8839,7 +8837,6 @@
88398837
0FF7299B166AD347000F5BA3 /* ProfilerCompiledBytecode.h */,
88408838
0FF7299C166AD347000F5BA3 /* ProfilerDatabase.cpp */,
88418839
0FF7299D166AD347000F5BA3 /* ProfilerDatabase.h */,
8842-
E3C0ECC92A4C01E8002C9D2B /* ProfilerDumper.h */,
88438840
DC605B591CE26E9800593718 /* ProfilerEvent.cpp */,
88448841
DC605B5A1CE26E9800593718 /* ProfilerEvent.h */,
88458842
0FF7299E166AD347000F5BA3 /* ProfilerExecutionCounter.h */,
@@ -10974,7 +10971,6 @@
1097410971
0FF729BB166AD360000F5BA3 /* ProfilerCompilationKind.h in Headers */,
1097510972
0FF729BC166AD360000F5BA3 /* ProfilerCompiledBytecode.h in Headers */,
1097610973
0FF729BD166AD360000F5BA3 /* ProfilerDatabase.h in Headers */,
10977-
E3C0ECCA2A4C01E9002C9D2B /* ProfilerDumper.h in Headers */,
1097810974
DC605B5E1CE26EA200593718 /* ProfilerEvent.h in Headers */,
1097910975
0FF729BE166AD360000F5BA3 /* ProfilerExecutionCounter.h in Headers */,
1098010976
0F190CAD189D82F6000AE5F0 /* ProfilerJettisonReason.h in Headers */,

‎Source/JavaScriptCore/bytecode/CodeBlock.cpp‎

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -140,11 +140,16 @@ CString CodeBlock::sourceCodeForTools() const
140140
{
141141
if (codeType() != FunctionCode)
142142
return ownerExecutable()->source().toUTF8();
143-
143+
144+
SourceProvider* provider = source().provider();
144145
FunctionExecutable* executable = jsCast<FunctionExecutable*>(ownerExecutable());
145-
return executable->source().provider()->getRange(
146-
executable->functionStart(),
147-
executable->parametersStartOffset() + executable->source().length()).utf8();
146+
UnlinkedFunctionExecutable* unlinked = executable->unlinkedExecutable();
147+
unsigned unlinkedStartOffset = unlinked->startOffset();
148+
unsigned linkedStartOffset = executable->source().startOffset();
149+
int delta = linkedStartOffset - unlinkedStartOffset;
150+
unsigned rangeStart = delta + unlinked->unlinkedFunctionStart();
151+
unsigned rangeEnd = delta + unlinked->startOffset() + unlinked->sourceLength();
152+
return provider->source().substring(rangeStart, rangeEnd - rangeStart).utf8();
148153
}
149154

150155
CString CodeBlock::sourceCodeOnOneLine() const

‎Source/JavaScriptCore/profiler/ProfilerBytecode.cpp‎

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,16 +29,16 @@
2929
#include "JSCInlines.h"
3030
#include "ObjectConstructor.h"
3131
#include "Opcode.h"
32-
#include "ProfilerDumper.h"
3332

3433
namespace JSC { namespace Profiler {
3534

36-
Ref<JSON::Value> Bytecode::toJSON(Dumper& dumper) const
35+
JSValue Bytecode::toJS(JSGlobalObject* globalObject) const
3736
{
38-
auto result = JSON::Object::create();
39-
result->setDouble(dumper.keys().m_bytecodeIndex, m_bytecodeIndex);
40-
result->setString(dumper.keys().m_opcode, String::fromUTF8(opcodeNames[m_opcodeID]));
41-
result->setString(dumper.keys().m_description, String::fromUTF8(m_description));
37+
VM& vm = globalObject->vm();
38+
JSObject* result = constructEmptyObject(globalObject);
39+
result->putDirect(vm, vm.propertyNames->bytecodeIndex, jsNumber(m_bytecodeIndex));
40+
result->putDirect(vm, vm.propertyNames->opcode, jsString(vm, String::fromUTF8(opcodeNames[m_opcodeID])));
41+
result->putDirect(vm, vm.propertyNames->description, jsString(vm, String::fromUTF8(m_description)));
4242
return result;
4343
}
4444

‎Source/JavaScriptCore/profiler/ProfilerBytecode.h‎

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@
2626
#pragma once
2727

2828
#include "JSCJSValue.h"
29-
#include <wtf/JSONValues.h>
3029
#include <wtf/text/CString.h>
3130

3231
namespace JSC {
@@ -35,8 +34,6 @@ enum OpcodeID : unsigned;
3534

3635
namespace Profiler {
3736

38-
class Dumper;
39-
4037
class Bytecode {
4138
public:
4239
Bytecode()
@@ -55,7 +52,7 @@ class Bytecode {
5552
OpcodeID opcodeID() const { return m_opcodeID; }
5653
const CString& description() const { return m_description; }
5754

58-
Ref<JSON::Value> toJSON(Dumper&) const;
55+
JSValue toJS(JSGlobalObject*) const;
5956
private:
6057
unsigned m_bytecodeIndex;
6158
OpcodeID m_opcodeID;

‎Source/JavaScriptCore/profiler/ProfilerBytecodeSequence.cpp‎

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -74,17 +74,25 @@ const Bytecode& BytecodeSequence::forBytecodeIndex(unsigned bytecodeIndex) const
7474
return at(indexForBytecodeIndex(bytecodeIndex));
7575
}
7676

77-
void BytecodeSequence::addSequenceProperties(Dumper& dumper, JSON::Object& result) const
77+
void BytecodeSequence::addSequenceProperties(JSGlobalObject* globalObject, JSObject* result) const
7878
{
79-
auto header = JSON::Array::create();
80-
for (unsigned i = 0; i < m_header.size(); ++i)
81-
header->pushString(String::fromUTF8(m_header[i]));
82-
result.setValue(dumper.keys().m_header, WTFMove(header));
83-
84-
auto sequence = JSON::Array::create();
85-
for (unsigned i = 0; i < m_sequence.size(); ++i)
86-
sequence->pushValue(m_sequence[i].toJSON(dumper));
87-
result.setValue(dumper.keys().m_bytecode, WTFMove(sequence));
79+
VM& vm = globalObject->vm();
80+
auto scope = DECLARE_THROW_SCOPE(vm);
81+
JSArray* header = constructEmptyArray(globalObject, nullptr);
82+
RETURN_IF_EXCEPTION(scope, void());
83+
for (unsigned i = 0; i < m_header.size(); ++i) {
84+
header->putDirectIndex(globalObject, i, jsString(vm, String::fromUTF8(m_header[i])));
85+
RETURN_IF_EXCEPTION(scope, void());
86+
}
87+
result->putDirect(vm, vm.propertyNames->header, header);
88+
89+
JSArray* sequence = constructEmptyArray(globalObject, nullptr);
90+
RETURN_IF_EXCEPTION(scope, void());
91+
for (unsigned i = 0; i < m_sequence.size(); ++i) {
92+
sequence->putDirectIndex(globalObject, i, m_sequence[i].toJS(globalObject));
93+
RETURN_IF_EXCEPTION(scope, void());
94+
}
95+
result->putDirect(vm, vm.propertyNames->bytecode, sequence);
8896
}
8997

9098
} } // namespace JSC::Profiler

‎Source/JavaScriptCore/profiler/ProfilerBytecodeSequence.h‎

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,6 @@ class CodeBlock;
3636

3737
namespace Profiler {
3838

39-
class Dumper;
40-
4139
class BytecodeSequence {
4240
public:
4341
BytecodeSequence(CodeBlock*);
@@ -51,7 +49,7 @@ class BytecodeSequence {
5149
const Bytecode& forBytecodeIndex(unsigned bytecodeIndex) const;
5250

5351
protected:
54-
void addSequenceProperties(Dumper&, JSON::Object&) const;
52+
void addSequenceProperties(JSGlobalObject*, JSObject*) const;
5553

5654
private:
5755
Vector<CString> m_header;

‎Source/JavaScriptCore/profiler/ProfilerBytecodes.cpp‎

Lines changed: 11 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,7 @@
2929
#include "CodeBlock.h"
3030
#include "JSCInlines.h"
3131
#include "ObjectConstructor.h"
32-
#include "ProfilerDumper.h"
3332
#include <wtf/StringPrintStream.h>
34-
#include <wtf/unicode/CharacterNames.h>
3533

3634
namespace JSC { namespace Profiler {
3735

@@ -52,23 +50,18 @@ void Bytecodes::dump(PrintStream& out) const
5250
out.print("#", m_hash, "(", m_id, ")");
5351
}
5452

55-
Ref<JSON::Value> Bytecodes::toJSON(Dumper& dumper) const
53+
JSValue Bytecodes::toJS(JSGlobalObject* globalObject) const
5654
{
57-
auto result = JSON::Object::create();
58-
59-
result->setDouble(dumper.keys().m_bytecodesID, m_id);
60-
result->setString(dumper.keys().m_inferredName, String::fromUTF8(m_inferredName));
61-
String sourceCode = String::fromUTF8(m_sourceCode);
62-
if (Options::abbreviateSourceCodeForProfiler()) {
63-
unsigned size = Options::abbreviateSourceCodeForProfiler();
64-
if (sourceCode.length() > size)
65-
sourceCode = makeString(StringView(sourceCode).left(size - 1), horizontalEllipsis);
66-
}
67-
result->setString(dumper.keys().m_sourceCode, WTFMove(sourceCode));
68-
result->setString(dumper.keys().m_hash, String::fromUTF8(toCString(m_hash)));
69-
result->setDouble(dumper.keys().m_instructionCount, m_instructionCount);
70-
addSequenceProperties(dumper, result.get());
71-
55+
VM& vm = globalObject->vm();
56+
JSObject* result = constructEmptyObject(globalObject);
57+
58+
result->putDirect(vm, vm.propertyNames->bytecodesID, jsNumber(m_id));
59+
result->putDirect(vm, vm.propertyNames->inferredName, jsString(vm, String::fromUTF8(m_inferredName)));
60+
result->putDirect(vm, vm.propertyNames->sourceCode, jsString(vm, String::fromUTF8(m_sourceCode)));
61+
result->putDirect(vm, vm.propertyNames->hash, jsString(vm, String::fromUTF8(toCString(m_hash))));
62+
result->putDirect(vm, vm.propertyNames->instructionCount, jsNumber(m_instructionCount));
63+
addSequenceProperties(globalObject, result);
64+
7265
return result;
7366
}
7467

‎Source/JavaScriptCore/profiler/ProfilerBytecodes.h‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ class Bytecodes : public BytecodeSequence {
4646

4747
void dump(PrintStream&) const;
4848

49-
Ref<JSON::Value> toJSON(Dumper&) const;
49+
JSValue toJS(JSGlobalObject*) const;
5050

5151
private:
5252
size_t m_id;

‎Source/JavaScriptCore/profiler/ProfilerCompilation.cpp‎

Lines changed: 67 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@
2929
#include "JSCInlines.h"
3030
#include "ObjectConstructor.h"
3131
#include "ProfilerDatabase.h"
32-
#include "ProfilerDumper.h"
3332
#include <wtf/StringPrintStream.h>
3433

3534
namespace JSC { namespace Profiler {
@@ -111,50 +110,76 @@ void Compilation::dump(PrintStream& out) const
111110
out.print("Comp", m_uid);
112111
}
113112

114-
Ref<JSON::Value> Compilation::toJSON(Dumper& dumper) const
113+
JSValue Compilation::toJS(JSGlobalObject* globalObject) const
115114
{
116-
auto result = JSON::Object::create();
117-
result->setDouble(dumper.keys().m_bytecodesID, m_bytecodes->id());
118-
result->setString(dumper.keys().m_compilationKind, String::fromUTF8(toCString(m_kind)));
119-
120-
auto profiledBytecodes = JSON::Array::create();
121-
for (const auto& bytecode : m_profiledBytecodes)
122-
profiledBytecodes->pushValue(bytecode.toJSON(dumper));
123-
result->setValue(dumper.keys().m_profiledBytecodes, WTFMove(profiledBytecodes));
124-
125-
auto descriptions = JSON::Array::create();
126-
for (const auto& description : m_descriptions)
127-
descriptions->pushValue(description.toJSON(dumper));
128-
result->setValue(dumper.keys().m_descriptions, WTFMove(descriptions));
129-
130-
auto counters = JSON::Array::create();
131-
for (const auto& [key, value] : m_counters) {
132-
auto counterEntry = JSON::Object::create();
133-
counterEntry->setValue(dumper.keys().m_origin, key.toJSON(dumper));
134-
counterEntry->setDouble(dumper.keys().m_executionCount, value->count());
135-
counters->pushValue(WTFMove(counterEntry));
115+
VM& vm = globalObject->vm();
116+
auto scope = DECLARE_THROW_SCOPE(vm);
117+
JSObject* result = constructEmptyObject(globalObject);
118+
RETURN_IF_EXCEPTION(scope, { });
119+
result->putDirect(vm, vm.propertyNames->bytecodesID, jsNumber(m_bytecodes->id()));
120+
result->putDirect(vm, vm.propertyNames->compilationKind, jsString(vm, String::fromUTF8(toCString(m_kind))));
121+
122+
JSArray* profiledBytecodes = constructEmptyArray(globalObject, nullptr);
123+
RETURN_IF_EXCEPTION(scope, { });
124+
for (unsigned i = 0; i < m_profiledBytecodes.size(); ++i) {
125+
auto value = m_profiledBytecodes[i].toJS(globalObject);
126+
RETURN_IF_EXCEPTION(scope, { });
127+
profiledBytecodes->putDirectIndex(globalObject, i, value);
128+
RETURN_IF_EXCEPTION(scope, { });
129+
}
130+
result->putDirect(vm, vm.propertyNames->profiledBytecodes, profiledBytecodes);
131+
132+
JSArray* descriptions = constructEmptyArray(globalObject, nullptr);
133+
RETURN_IF_EXCEPTION(scope, { });
134+
for (unsigned i = 0; i < m_descriptions.size(); ++i) {
135+
auto value = m_descriptions[i].toJS(globalObject);
136+
RETURN_IF_EXCEPTION(scope, { });
137+
descriptions->putDirectIndex(globalObject, i, value);
138+
RETURN_IF_EXCEPTION(scope, { });
139+
}
140+
result->putDirect(vm, vm.propertyNames->descriptions, descriptions);
141+
142+
JSArray* counters = constructEmptyArray(globalObject, nullptr);
143+
RETURN_IF_EXCEPTION(scope, { });
144+
for (auto it = m_counters.begin(), end = m_counters.end(); it != end; ++it) {
145+
JSObject* counterEntry = constructEmptyObject(globalObject);
146+
RETURN_IF_EXCEPTION(scope, { });
147+
auto value = it->key.toJS(globalObject);
148+
RETURN_IF_EXCEPTION(scope, { });
149+
counterEntry->putDirect(vm, vm.propertyNames->origin, value);
150+
counterEntry->putDirect(vm, vm.propertyNames->executionCount, jsNumber(it->value->count()));
151+
counters->push(globalObject, counterEntry);
152+
RETURN_IF_EXCEPTION(scope, { });
153+
}
154+
result->putDirect(vm, vm.propertyNames->counters, counters);
155+
156+
JSArray* exitSites = constructEmptyArray(globalObject, nullptr);
157+
RETURN_IF_EXCEPTION(scope, { });
158+
for (unsigned i = 0; i < m_osrExitSites.size(); ++i) {
159+
auto value = m_osrExitSites[i].toJS(globalObject);
160+
RETURN_IF_EXCEPTION(scope, { });
161+
exitSites->putDirectIndex(globalObject, i, value);
162+
RETURN_IF_EXCEPTION(scope, { });
136163
}
137-
result->setValue(dumper.keys().m_counters, WTFMove(counters));
138-
139-
auto exitSites = JSON::Array::create();
140-
for (const auto& osrExitSite : m_osrExitSites)
141-
exitSites->pushValue(osrExitSite.toJSON(dumper));
142-
result->setValue(dumper.keys().m_osrExitSites, WTFMove(exitSites));
143-
144-
auto exits = JSON::Array::create();
145-
for (unsigned i = 0; i < m_osrExits.size(); ++i)
146-
exits->pushValue(m_osrExits[i].toJSON(dumper));
147-
result->setValue(dumper.keys().m_osrExits, WTFMove(exits));
148-
149-
result->setDouble(dumper.keys().m_numInlinedGetByIds, m_numInlinedGetByIds);
150-
result->setDouble(dumper.keys().m_numInlinedPutByIds, m_numInlinedPutByIds);
151-
result->setDouble(dumper.keys().m_numInlinedCalls, m_numInlinedCalls);
152-
result->setString(dumper.keys().m_jettisonReason, String::fromUTF8(toCString(m_jettisonReason)));
164+
result->putDirect(vm, vm.propertyNames->osrExitSites, exitSites);
165+
166+
JSArray* exits = constructEmptyArray(globalObject, nullptr);
167+
RETURN_IF_EXCEPTION(scope, { });
168+
for (unsigned i = 0; i < m_osrExits.size(); ++i) {
169+
exits->putDirectIndex(globalObject, i, m_osrExits[i].toJS(globalObject));
170+
RETURN_IF_EXCEPTION(scope, { });
171+
}
172+
result->putDirect(vm, vm.propertyNames->osrExits, exits);
173+
174+
result->putDirect(vm, vm.propertyNames->numInlinedGetByIds, jsNumber(m_numInlinedGetByIds));
175+
result->putDirect(vm, vm.propertyNames->numInlinedPutByIds, jsNumber(m_numInlinedPutByIds));
176+
result->putDirect(vm, vm.propertyNames->numInlinedCalls, jsNumber(m_numInlinedCalls));
177+
result->putDirect(vm, vm.propertyNames->jettisonReason, jsString(vm, String::fromUTF8(toCString(m_jettisonReason))));
153178
if (!m_additionalJettisonReason.isNull())
154-
result->setString(dumper.keys().m_additionalJettisonReason, String::fromUTF8(m_additionalJettisonReason));
155-
156-
result->setValue(dumper.keys().m_uid, m_uid.toJSON(dumper));
157-
179+
result->putDirect(vm, vm.propertyNames->additionalJettisonReason, jsString(vm, String::fromUTF8(m_additionalJettisonReason)));
180+
181+
result->putDirect(vm, vm.propertyNames->uid, m_uid.toJS(globalObject));
182+
158183
return result;
159184
}
160185

0 commit comments

Comments
 (0)