Ignore:
Timestamp:
Jan 17, 2019, 9:32:38 AM (6 years ago)
Author:
[email protected]
Message:

[JSC] Add generateHeapSnapshotForGCDebugging function to dump GCDebugging data
https://bugs.webkit.org/show_bug.cgi?id=193526

Reviewed by Michael Saboff.

This patch adds generateHeapSnapshotForGCDebugging to JSC shell to dump heap snapshot JSON string with GCDebugging option.
GCDebuggingSnapshot mode is slightly different from InspectorSnapshot in terms of both the output data and the behavior.
It always takes full snapshot, and it reports internal data too. This is useful to view the live heap objects after running
the code. Also, generateHeapSnapshotForGCDebugging returns String instead of parsing it to JSObject internally by calling
JSON.parse. If we convert the String to bunch of objects by using JSON.parse, it is difficult to call generateHeapSnapshotForGCDebugging
multiple times for debugging. Currently, it only generates a large string, which is easily distinguishable in the heap inspector tool.

  • jsc.cpp:

(GlobalObject::finishCreation):
(functionGenerateHeapSnapshotForGCDebugging):

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/JavaScriptCore/jsc.cpp

    r239981 r240113  
    329329static EncodedJSValue JSC_HOST_CALL functionPlatformSupportsSamplingProfiler(ExecState*);
    330330static EncodedJSValue JSC_HOST_CALL functionGenerateHeapSnapshot(ExecState*);
     331static EncodedJSValue JSC_HOST_CALL functionGenerateHeapSnapshotForGCDebugging(ExecState*);
    331332static EncodedJSValue JSC_HOST_CALL functionResetSuperSamplerState(ExecState*);
    332333static EncodedJSValue JSC_HOST_CALL functionEnsureArrayStorage(ExecState*);
     
    563564        addFunction(vm, "platformSupportsSamplingProfiler", functionPlatformSupportsSamplingProfiler, 0);
    564565        addFunction(vm, "generateHeapSnapshot", functionGenerateHeapSnapshot, 0);
     566        addFunction(vm, "generateHeapSnapshotForGCDebugging", functionGenerateHeapSnapshotForGCDebugging, 0);
    565567        addFunction(vm, "resetSuperSamplerState", functionResetSuperSamplerState, 0);
    566568        addFunction(vm, "ensureArrayStorage", functionEnsureArrayStorage, 0);
     
    21202122}
    21212123
     2124EncodedJSValue JSC_HOST_CALL functionGenerateHeapSnapshotForGCDebugging(ExecState* exec)
     2125{
     2126    VM& vm = exec->vm();
     2127    JSLockHolder lock(vm);
     2128    auto scope = DECLARE_THROW_SCOPE(vm);
     2129    String jsonString;
     2130    {
     2131        DeferGCForAWhile deferGC(vm.heap); // Prevent concurrent GC from interfering with the full GC that the snapshot does.
     2132
     2133        HeapSnapshotBuilder snapshotBuilder(vm.ensureHeapProfiler(), HeapSnapshotBuilder::SnapshotType::GCDebuggingSnapshot);
     2134        snapshotBuilder.buildSnapshot();
     2135
     2136        jsonString = snapshotBuilder.json();
     2137    }
     2138    scope.releaseAssertNoException();
     2139    return JSValue::encode(jsString(&vm, jsonString));
     2140}
     2141
    21222142EncodedJSValue JSC_HOST_CALL functionResetSuperSamplerState(ExecState*)
    21232143{
Note: See TracChangeset for help on using the changeset viewer.