Changes between Version 1 and Version 2 of Inspecting the GC heap

Aug 23, 2018 9:31:47 PM (4 years ago)
Simon Fraser



  • Inspecting the GC heap

    v1 v2  
    1313The primary reason to inspect the GC heap is to get information about why an object is not being destroyed when you think it should be. Often, we see that Document objects stick around longer than we expect (see [ bug 186214] for more on this). If we capture a GC heap dump at the point where we expect the Document should have been destroyed, we can inspect the output to see what objects reference that Document, thus keeping it alive. We'll work through an example below.
     15== An example ==
     17[ Bug 188728] is a good example; in this case, after running IndexedDB tests, we notice that the Document for the main page is never released. A bit of investigation shows that this can be replicated in MiniBrowser by making a small test change to navigate as soon as the test is complete (see the [ small test patch]). Reproducing in MiniBrowser just makes it a little easier to debug.
     19Here's how we confirm that we are actually seeing a real problem:
     201. We start the test server so that the web-platform-test actually works: {{{./Tools/Scripts/run-webkit-httpd}}}
     212. Now run MiniBrowser and load the test, using the localhost url [http://localhost:8800/IndexedDB/value.htm]
     223. The test automatically navigates to about:blank now, but the previous page may still be in the page cache (and referenced by other cached things), so we need to trigger a low memory warning, which will clear those caches. On Apple platforms, we can do that via the {{{notifyutil}}} utility: {{{notifyutil -p org.WebKit.lowMemory}}}. That clears caches, and triggers a GC.
     234. Now we can see what Documents are still live, again using notifyutil: {{{notifyutil -p}}}. This will dump to the system log (and your Terminal or Xcode, wherever you ran MiniBrowser from). You'll see something like:
     251 live pages:
     26Page 0x1168fe000 with main document 0x1161bf000 file:///Volumes/Data/Development/apple/webkit/testcontent/simple/A.html
     272 live documents:
     28Document 0x11615e000 http://localhost:8800/IndexedDB/value.htm
     29Document 0x1161bf000 about:blank
     31  So that shows us that value.htm is still around, which is bad.
     335. Now we can dump the GC heap, again with notifyutil: {{{notifyutil -p}}}. This will log something like: {{{Dumped GC heap to /var/folders/bh/34x83y_n4mn5n_nv0v_rdmh80000gn/T/org.webkit.MiniBrowser/GCHeapOayHEu}}}.
     34  That's your JSON output, so copy the file somewhere to keep it:
     35  {{{mv Dumped GC heap to /var/folders/bh/34x83y_n4mn5n_nv0v_rdmh80000gn/T/org.webkit.MiniBrowser/GCHeapOayHEu ~/Desktop/values-heap.json}}}
     376. The heap viewer is located in {{{Tools/GCHeapInspector}}}. I usually fire up a local server to use it:
     39cd Tools/GCHeapInspector
     40python -m SimpleHTTServer 8999
     42  (port 8999 to avoid conflicting with the webkit test localhost ports)
     437. Now in the browser navigate to []. You'll see the GC heap inspector banner. Now drag your {{{~/Desktop/values-heap.json}}} file onto the badge in the top right.