MCPcopy Create free account
hub / github.com/Snapchat/Valdi / dumpHeap

Method dumpHeap

valdi/src/valdi/quickjs/QuickJSJavaScriptContext.cpp:1190–1216  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1188#pragma clang diagnostic pop
1189
1190void QuickJSJavaScriptContext::dumpHeap(Valdi::JavaScriptHeapDumpBuilder& heapDumpBuilder) {
1191 auto guard = _threadAccessChecker.guard();
1192 auto* oldOpaque = JS_GetRuntimeOpaque(_runtime);
1193
1194 // We shove the heap dump builder as an opaque so that we can retrieve it while visiting
1195 // the heap.
1196 JS_SetRuntimeOpaque(_runtime, reinterpret_cast<Valdi::JavaScriptHeapDumpBuilder*>(&heapDumpBuilder));
1197 JS_VisitAllGCObjects(_runtime, &onObjectBegin, &onObjectEdgeProperty, &onObjectEdge);
1198
1199 auto stashedJSValues = getAllStashedJSValues();
1200 // Emit the stashed JS values as a separate node
1201 heapDumpBuilder.beginNode(Valdi::JavaScriptHeapDumpNodeType::HIDDEN,
1202 STRING_LITERAL("System / ExportedReferences"),
1203 this,
1204 sizeof(JSValue) * stashedJSValues.size());
1205
1206 size_t index = 0;
1207 for (const auto& jsValue : stashedJSValues) {
1208 auto indexStr = std::to_string(index);
1209 JS_VisitObjectEdge(
1210 _runtime, fromValdiJSValue(jsValue), indexStr.c_str(), JS_EDGE_TYPE_ELEMENT, &onObjectEdgeProperty);
1211 index++;
1212 }
1213
1214 // Restore old opaque
1215 JS_SetRuntimeOpaque(_runtime, oldOpaque);
1216}
1217
1218JSContext* QuickJSJavaScriptContext::getContext() const {
1219 return _context;

Callers

nothing calls this directly

Calls 5

guardMethod · 0.80
beginNodeMethod · 0.80
fromValdiJSValueFunction · 0.70
to_stringFunction · 0.50
sizeMethod · 0.45

Tested by

no test coverage detected