[gjs: 3/4] context: Collect nursery before heap dump




commit 247a4cdabb66eb234c7d66646bf33242027ac423
Author: Philip Chimento <philip chimento gmail com>
Date:   Sat Aug 10 22:29:44 2019 -0700

    context: Collect nursery before heap dump
    
    Until now, mostly we didn't care about the nursery because only plain JS
    objects are created there; objects with finalizers, which comprise all of
    our custom objects in GJS, are automatically promoted to the tenured heap
    in SpiderMonkey's implementation of generational garbage collection.
    
    However, with the taking-out-the-garbage patches we will create a lot more
    Proxies (GObject wrappers) and plain objects (GObject expando objects)
    which can be allocated in the nursery. This can result in them being
    missing from heap dumps when we use the IgnoreNurseryObjects flag to
    js::DumpHeap().
    
    The alternative is the CollectNurseryBeforeDump flag, which promotes any
    live objects in the nursery to the tenured heap. This way, we are
    certain to capture all of our wrappers and expando objects in the heap
    dump. The downside is that dumping the heap can now reduce performance.
    But it is something that should only be done for debugging, anyway.
    
    So here's this commit in advance of the taking-out-the-garbage branch, so
    that I don't have to keep rebasing it.
    
    See GNOME/gjs#217.

 gjs/context.cpp    | 5 +++--
 modules/system.cpp | 8 ++++++--
 2 files changed, 9 insertions(+), 4 deletions(-)
---
diff --git a/gjs/context.cpp b/gjs/context.cpp
index 9eab2939..59709572 100644
--- a/gjs/context.cpp
+++ b/gjs/context.cpp
@@ -143,7 +143,8 @@ static GjsAutoChar dump_heap_output;
 static unsigned dump_heap_idle_id = 0;
 
 #ifdef G_OS_UNIX
-/* Currently heap dumping is only supported on UNIX platforms! */
+// Currently heap dumping via SIGUSR1 is only supported on UNIX platforms!
+// This can reduce performance. See note in system.cpp on System.dumpHeap().
 static void
 gjs_context_dump_heaps(void)
 {
@@ -162,7 +163,7 @@ gjs_context_dump_heaps(void)
 
     for (GList *l = all_contexts; l; l = g_list_next(l)) {
         auto* gjs = static_cast<GjsContextPrivate*>(l->data);
-        js::DumpHeap(gjs->context(), fp, js::IgnoreNurseryObjects);
+        js::DumpHeap(gjs->context(), fp, js::CollectNurseryBeforeDump);
     }
 
     fclose(fp);
diff --git a/modules/system.cpp b/modules/system.cpp
index 8c321d45..f5e0340b 100644
--- a/modules/system.cpp
+++ b/modules/system.cpp
@@ -109,6 +109,10 @@ gjs_breakpoint(JSContext *context,
     return true;
 }
 
+// This can reduce performance, so should be used for debugging only.
+// js::CollectNurseryBeforeDump promotes any live objects in the nursery to the
+// tenured heap. This is slow, but this way, we are certain to get an accurate
+// picture of the heap.
 static bool
 gjs_dump_heap(JSContext *cx,
               unsigned   argc,
@@ -127,10 +131,10 @@ gjs_dump_heap(JSContext *cx,
                       strerror(errno));
             return false;
         }
-        js::DumpHeap(cx, fp, js::IgnoreNurseryObjects);
+        js::DumpHeap(cx, fp, js::CollectNurseryBeforeDump);
         fclose(fp);
     } else {
-        js::DumpHeap(cx, stdout, js::IgnoreNurseryObjects);
+        js::DumpHeap(cx, stdout, js::CollectNurseryBeforeDump);
     }
 
     gjs_debug(GJS_DEBUG_CONTEXT, "Heap dumped to %s",


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]