Bug 845545: Part 1 - Fix heap dumping to work off the main thread. r=mccr8
authorKyle Huey <khuey@kylehuey.com>
Sat, 03 Aug 2013 16:55:39 -0700
changeset 148888 efe4ad163c58374fb9d51969e9d25e54d744fb78
parent 148887 45cd37a5b83493b862ceee8080de86f34cc10056
child 148889 b7dbdc2a38f9679122cc299ee84713fac521a341
push idunknown
push userunknown
push dateunknown
reviewersmccr8
bugs845545
milestone25.0a1
Bug 845545: Part 1 - Fix heap dumping to work off the main thread. r=mccr8
js/xpconnect/src/nsXPConnect.cpp
js/xpconnect/src/xpcpublic.h
xpcom/base/CycleCollectedJSRuntime.cpp
xpcom/base/CycleCollectedJSRuntime.h
xpcom/base/nsCycleCollector.cpp
--- a/js/xpconnect/src/nsXPConnect.cpp
+++ b/js/xpconnect/src/nsXPConnect.cpp
@@ -1441,24 +1441,16 @@ Base64Decode(JSContext *cx, JS::Value va
     if (!str)
         return false;
 
     *out = STRING_TO_JSVAL(str);
     return true;
 }
 
 void
-DumpJSHeap(FILE* file)
-{
-    NS_ABORT_IF_FALSE(NS_IsMainThread(), "Must dump GC heap on main thread.");
-    nsXPConnect* xpc = nsXPConnect::XPConnect();
-    js::DumpHeapComplete(xpc->GetRuntime()->Runtime(), file);
-}
-
-void
 SetLocationForGlobal(JSObject *global, const nsACString& location)
 {
     MOZ_ASSERT(global);
     EnsureCompartmentPrivate(global)->SetLocation(location);
 }
 
 void
 SetLocationForGlobal(JSObject *global, nsIURI *locationURI)
--- a/js/xpconnect/src/xpcpublic.h
+++ b/js/xpconnect/src/xpcpublic.h
@@ -316,18 +316,16 @@ bool StringToJsval(JSContext* cx, mozill
     return NonVoidStringToJsval(cx, str, rval);
 }
 
 nsIPrincipal *GetCompartmentPrincipal(JSCompartment *compartment);
 nsIPrincipal *GetObjectPrincipal(JSObject *obj);
 
 bool IsXBLScope(JSCompartment *compartment);
 
-void DumpJSHeap(FILE* file);
-
 void SetLocationForGlobal(JSObject *global, const nsACString& location);
 void SetLocationForGlobal(JSObject *global, nsIURI *locationURI);
 
 /**
  * Define quick stubs on the given object, @a proto.
  *
  * @param cx
  *     A context.  Requires request.
--- a/xpcom/base/CycleCollectedJSRuntime.cpp
+++ b/xpcom/base/CycleCollectedJSRuntime.cpp
@@ -1027,16 +1027,23 @@ CycleCollectedJSRuntime::DeferredFinaliz
 }
 
 void
 CycleCollectedJSRuntime::DeferredFinalize(nsISupports* aSupports)
 {
   mDeferredSupports.AppendElement(aSupports);
 }
 
+void
+CycleCollectedJSRuntime::DumpJSHeap(FILE* file)
+{
+  js::DumpHeapComplete(Runtime(), file);
+}
+
+
 bool
 ReleaseSliceNow(uint32_t aSlice, void* aData)
 {
   MOZ_ASSERT(aSlice > 0, "nonsensical/useless call with slice == 0");
   nsTArray<nsISupports*>* items = static_cast<nsTArray<nsISupports*>*>(aData);
 
   uint32_t length = items->Length();
   aSlice = std::min(aSlice, length);
--- a/xpcom/base/CycleCollectedJSRuntime.h
+++ b/xpcom/base/CycleCollectedJSRuntime.h
@@ -191,16 +191,18 @@ public:
   virtual void PrepareForForgetSkippable() {}
   virtual void PrepareForCollection() {}
 
   void DeferredFinalize(DeferredFinalizeAppendFunction aAppendFunc,
                         DeferredFinalizeFunction aFunc,
                         void* aThing);
   void DeferredFinalize(nsISupports* aSupports);
 
+  void DumpJSHeap(FILE* aFile);
+
 private:
   JSGCThingParticipant mGCThingCycleCollectorGlobal;
 
   JSZoneParticipant mJSZoneCycleCollectorGlobal;
 
   JSRuntime* mJSRuntime;
 
   nsDataHashtable<nsPtrHashKey<void>, nsScriptObjectTracer*> mJSHolders;
--- a/xpcom/base/nsCycleCollector.cpp
+++ b/xpcom/base/nsCycleCollector.cpp
@@ -1442,17 +1442,19 @@ public:
         nsCOMPtr<nsIFile> gcLogFile = CreateTempFile("incomplete-gc-edges");
         NS_ENSURE_STATE(gcLogFile);
 
         // Dump the JS heap.
         FILE* gcLogANSIFile = nullptr;
         gcLogFile->OpenANSIFileDesc("w", &gcLogANSIFile);
         NS_ENSURE_STATE(gcLogANSIFile);
         MozillaRegisterDebugFILE(gcLogANSIFile);
-        xpc::DumpJSHeap(gcLogANSIFile);
+        CollectorData *data = sCollectorData.get();
+        if (data && data->mRuntime)
+            data->mRuntime->DumpJSHeap(gcLogANSIFile);
         MozillaUnRegisterDebugFILE(gcLogANSIFile);
         fclose(gcLogANSIFile);
 
         // Strip off "incomplete-".
         nsCOMPtr<nsIFile> gcLogFileFinalDestination =
             CreateTempFile("gc-edges");
         NS_ENSURE_STATE(gcLogFileFinalDestination);