|
29 | 29 | #include "JSCInlines.h" |
30 | 30 | #include "ObjectConstructor.h" |
31 | 31 | #include "ProfilerDatabase.h" |
32 | | -#include "ProfilerDumper.h" |
33 | 32 | #include <wtf/StringPrintStream.h> |
34 | 33 |
|
35 | 34 | namespace JSC { namespace Profiler { |
@@ -111,50 +110,76 @@ void Compilation::dump(PrintStream& out) const |
111 | 110 | out.print("Comp", m_uid); |
112 | 111 | } |
113 | 112 |
|
114 | | -Ref<JSON::Value> Compilation::toJSON(Dumper& dumper) const |
| 113 | +JSValue Compilation::toJS(JSGlobalObject* globalObject) const |
115 | 114 | { |
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, { }); |
136 | 163 | } |
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)))); |
153 | 178 | 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 | + |
158 | 183 | return result; |
159 | 184 | } |
160 | 185 |
|
|
0 commit comments