log info about object compartments draft
authorAndrew McCreight <continuation@gmail.com>
Wed, 05 Apr 2017 13:49:17 -0700
changeset 560577 378741b73e4f155c866d98ca2899c5b482c61269
parent 560576 972c58459397f03826e557082f5fee10868f90c1
child 560578 db6c2593576ceaaa8532b526a118e74a436673ed
push id53458
push userbmo:continuation@gmail.com
push dateTue, 11 Apr 2017 16:27:38 +0000
milestone55.0a1
log info about object compartments MozReview-Commit-ID: 9jIlpxWrjn4
js/public/TracingAPI.h
js/src/gc/Tracer.cpp
js/src/jsfriendapi.cpp
--- a/js/public/TracingAPI.h
+++ b/js/public/TracingAPI.h
@@ -378,17 +378,18 @@ using CompartmentSet = js::HashSet<JSCom
  */
 extern JS_PUBLIC_API(void)
 TraceIncomingCCWs(JSTracer* trc, const JS::CompartmentSet& compartments);
 
 } // namespace JS
 
 extern JS_PUBLIC_API(void)
 JS_GetTraceThingInfo(char* buf, size_t bufsize, JSTracer* trc,
-                     void* thing, JS::TraceKind kind, bool includeDetails);
+                     void* thing, JS::TraceKind kind, bool includeDetails,
+                     JSCompartment** compartment);
 
 namespace js {
 
 // Trace an edge that is not a GC root and is not wrapped in a barriered
 // wrapper for some reason.
 //
 // This method does not check if |*edgep| is non-null before tracing through
 // it, so callers must check any nullable pointer before calling this method.
--- a/js/src/gc/Tracer.cpp
+++ b/js/src/gc/Tracer.cpp
@@ -317,28 +317,30 @@ StringKindHeader(JSString* str)
         return "dependent: ";
     if (str->isExternal())
         return "external: ";
     return "linear: ";
 }
 
 JS_PUBLIC_API(void)
 JS_GetTraceThingInfo(char* buf, size_t bufsize, JSTracer* trc, void* thing,
-                     JS::TraceKind kind, bool details)
+                     JS::TraceKind kind, bool details, JSCompartment** compartment)
 {
     const char* name = nullptr; /* silence uninitialized warning */
+    *compartment = nullptr;
     size_t n;
 
     if (bufsize == 0)
         return;
 
     switch (kind) {
       case JS::TraceKind::Object:
       {
         name = static_cast<JSObject*>(thing)->getClass()->name;
+        *compartment = static_cast<JSObject*>(thing)->compartment();
         break;
       }
 
       case JS::TraceKind::Script:
         name = "script";
         break;
 
       case JS::TraceKind::String:
--- a/js/src/jsfriendapi.cpp
+++ b/js/src/jsfriendapi.cpp
@@ -1129,17 +1129,17 @@ DumpHeapVisitCompartment(JSContext* cx, 
 {
     char name[1024];
     if (cx->runtime()->compartmentNameCallback)
         (*cx->runtime()->compartmentNameCallback)(cx, comp, name, sizeof(name));
     else
         strcpy(name, "<unknown>");
 
     DumpHeapTracer* dtrc = static_cast<DumpHeapTracer*>(data);
-    fprintf(dtrc->output, "# compartment 0x%" PRIxPTR "%s [in zone %p]\n",
+    fprintf(dtrc->output, "# compartment 0x%" PRIxPTR " %s [in zone %p]\n",
             uintptr_t(comp), name, (void*)comp->zone());
 }
 
 static void
 DumpHeapVisitArena(JSRuntime* rt, void* data, gc::Arena* arena,
                    JS::TraceKind traceKind, size_t thingSize)
 {
     DumpHeapTracer* dtrc = static_cast<DumpHeapTracer*>(data);
@@ -1148,18 +1148,20 @@ DumpHeapVisitArena(JSRuntime* rt, void* 
 }
 
 static void
 DumpHeapVisitCell(JSRuntime* rt, void* data, void* thing,
                   JS::TraceKind traceKind, size_t thingSize)
 {
     DumpHeapTracer* dtrc = static_cast<DumpHeapTracer*>(data);
     char cellDesc[1024 * 32];
-    JS_GetTraceThingInfo(cellDesc, sizeof(cellDesc), dtrc, thing, traceKind, true);
-    fprintf(dtrc->output, "%p %c %s\n", thing, MarkDescriptor(thing), cellDesc);
+    JSCompartment* comp;
+    JS_GetTraceThingInfo(cellDesc, sizeof(cellDesc), dtrc, thing, traceKind, true, &comp);
+    fprintf(dtrc->output, "%p %c 0x%" PRIxPTR " %s\n", thing,
+            MarkDescriptor(thing), uintptr_t(comp), cellDesc);
     js::TraceChildren(dtrc, thing, traceKind);
 }
 
 void
 DumpHeapTracer::onChild(const JS::GCCellPtr& thing)
 {
     if (gc::IsInsideNursery(thing.asCell()))
         return;