Bug 655647 - Allow per-process GC/CC from about:memory. r=dougt
authorJiten <jitenmt@gmail.com>
Tue, 13 Sep 2011 19:53:51 +0200
changeset 76917 a1268291394f18266d1f19510d5e71fc5f8b78b9
parent 76914 1ec4fc4006e04608968818eeab728c6fb23fbc32
child 76918 e3cfe5ae818ce4ab1e139a03809dc4fdffacceee
push id21156
push usermbrubeck@mozilla.com
push dateWed, 14 Sep 2011 13:45:18 +0000
treeherdermozilla-central@0a6d1368cd97 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersdougt
bugs655647
milestone9.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 655647 - Allow per-process GC/CC from about:memory. r=dougt
dom/ipc/ContentChild.cpp
dom/ipc/ContentChild.h
dom/ipc/ContentParent.cpp
dom/ipc/Makefile.in
dom/ipc/PContent.ipdl
toolkit/components/aboutmemory/content/aboutMemory.js
--- a/dom/ipc/ContentChild.cpp
+++ b/dom/ipc/ContentChild.cpp
@@ -68,16 +68,17 @@
 #include "nsTObserverArray.h"
 #include "nsIObserver.h"
 #include "nsIPrefService.h"
 #include "nsServiceManagerUtils.h"
 #include "nsXULAppAPI.h"
 #include "nsWeakReference.h"
 #include "nsIScriptError.h"
 #include "nsIConsoleService.h"
+#include "nsJSEnvironment.h"
 
 #include "History.h"
 #include "nsDocShellCID.h"
 #include "nsNetUtil.h"
 
 #include "base/message_loop.h"
 #include "base/task.h"
 
@@ -758,10 +759,25 @@ ContentChild::GetIndexedDBPath()
     if (!gIndexedDBPath) {
         gIndexedDBPath = new nsString(); // cleaned up in the destructor
         SendGetIndexedDBDirectory(gIndexedDBPath);
     }
 
     return *gIndexedDBPath;
 }
 
+bool
+ContentChild::RecvGarbageCollect()
+{
+    nsJSContext::GarbageCollectNow();
+    return true;
+}
+
+bool
+ContentChild::RecvCycleCollect()
+{
+    nsJSContext::GarbageCollectNow();
+    nsJSContext::CycleCollectNow();
+    return true;
+}
+
 } // namespace dom
 } // namespace mozilla
--- a/dom/ipc/ContentChild.h
+++ b/dom/ipc/ContentChild.h
@@ -143,16 +143,19 @@ public:
                                          const double& z);
 
     virtual bool RecvScreenSizeChanged(const gfxIntSize &size);
 
     virtual bool RecvFlushMemory(const nsString& reason);
 
     virtual bool RecvActivateA11y();
 
+    virtual bool RecvGarbageCollect();
+    virtual bool RecvCycleCollect();
+
 #ifdef ANDROID
     gfxIntSize GetScreenSize() { return mScreenSize; }
 #endif
 
     // Get the directory for IndexedDB files. We query the parent for this and
     // cache the value
     nsString &GetIndexedDBPath();
 
--- a/dom/ipc/ContentParent.cpp
+++ b/dom/ipc/ContentParent.cpp
@@ -195,16 +195,18 @@ void
 ContentParent::Init()
 {
     nsCOMPtr<nsIObserverService> obs = mozilla::services::GetObserverService();
     if (obs) {
         obs->AddObserver(this, "xpcom-shutdown", PR_FALSE);
         obs->AddObserver(this, NS_IPC_IOSERVICE_SET_OFFLINE_TOPIC, PR_FALSE);
         obs->AddObserver(this, "child-memory-reporter-request", PR_FALSE);
         obs->AddObserver(this, "memory-pressure", PR_FALSE);
+        obs->AddObserver(this, "child-gc-request", PR_FALSE);
+        obs->AddObserver(this, "child-cc-request", PR_FALSE);
 #ifdef ACCESSIBILITY
         obs->AddObserver(this, "a11y-init-or-shutdown", PR_FALSE);
 #endif
     }
     nsCOMPtr<nsIPrefBranch2> prefs(do_GetService(NS_PREFSERVICE_CONTRACTID));
     if (prefs) {
         prefs->AddObserver("", this, PR_FALSE);
     }
@@ -299,16 +301,18 @@ ContentParent::ActorDestroy(ActorDestroy
     nsCOMPtr<nsIThreadObserver>
         kungFuDeathGrip(static_cast<nsIThreadObserver*>(this));
     nsCOMPtr<nsIObserverService> obs = mozilla::services::GetObserverService();
     if (obs) {
         obs->RemoveObserver(static_cast<nsIObserver*>(this), "xpcom-shutdown");
         obs->RemoveObserver(static_cast<nsIObserver*>(this), "memory-pressure");
         obs->RemoveObserver(static_cast<nsIObserver*>(this), "child-memory-reporter-request");
         obs->RemoveObserver(static_cast<nsIObserver*>(this), NS_IPC_IOSERVICE_SET_OFFLINE_TOPIC);
+        obs->RemoveObserver(static_cast<nsIObserver*>(this), "child-gc-request");
+        obs->RemoveObserver(static_cast<nsIObserver*>(this), "child-cc-request");
 #ifdef ACCESSIBILITY
         obs->RemoveObserver(static_cast<nsIObserver*>(this), "a11y-init-or-shutdown");
 #endif
     }
 
     mMessageManager->Disconnect();
 
     // clear the child memory reporters
@@ -744,16 +748,22 @@ ContentParent::Observe(nsISupports* aSub
              !strcmp(aTopic, "alertclickcallback") ) {
         if (!SendNotifyAlertsObserver(nsDependentCString(aTopic),
                                       nsDependentString(aData)))
             return NS_ERROR_NOT_AVAILABLE;
     }
     else if (!strcmp(aTopic, "child-memory-reporter-request")) {
         SendPMemoryReportRequestConstructor();
     }
+    else if (!strcmp(aTopic, "child-gc-request")){
+        SendGarbageCollect();
+    }
+    else if (!strcmp(aTopic, "child-cc-request")){
+        SendCycleCollect();
+    }
 #ifdef ACCESSIBILITY
     // Make sure accessibility is running in content process when accessibility
     // gets initiated in chrome process.
     else if (aData && (*aData == '1') &&
              !strcmp(aTopic, "a11y-init-or-shutdown")) {
         SendActivateA11y();
     }
 #endif
--- a/dom/ipc/Makefile.in
+++ b/dom/ipc/Makefile.in
@@ -100,16 +100,17 @@ LOCAL_INCLUDES += \
 	-I$(topsrcdir)/chrome/src \
 	-I$(topsrcdir)/uriloader/exthandler \
 	-I$(srcdir)/../../netwerk/base/src \
 	-I$(srcdir)/../src/base \
 	-I$(srcdir)/../src/storage \
 	-I$(srcdir)/../../xpcom/base \
 	-I$(srcdir)/../indexedDB \
 	-I$(topsrcdir)/extensions/cookie \
+	-I$(topsrcdir)/dom/base \
 	$(NULL)
 
 DEFINES += -DBIN_SUFFIX='"$(BIN_SUFFIX)"'
 
 ifdef MOZ_PERMISSIONS
 DEFINES += -DMOZ_PERMISSIONS
 endif
 
--- a/dom/ipc/PContent.ipdl
+++ b/dom/ipc/PContent.ipdl
@@ -124,16 +124,19 @@ child:
     AddPermission(Permission permission);
 
     DeviceMotionChanged(long type, double x, double y, double z);
 
     ScreenSizeChanged(gfxIntSize size);
 
     FlushMemory(nsString reason);
 
+    GarbageCollect();
+    CycleCollect();
+    
     /**
      * Start accessibility engine in content process.
      */
     ActivateA11y();
 
 parent:
     PNecko();
     PCrashReporter();
--- a/toolkit/components/aboutmemory/content/aboutMemory.js
+++ b/toolkit/components/aboutmemory/content/aboutMemory.js
@@ -139,24 +139,30 @@ function ChildMemoryListener(aSubject, a
 function $(n)
 {
   return document.getElementById(n);
 }
 
 function doGlobalGC()
 {
   Cu.forceGC();
+  var os = Cc["@mozilla.org/observer-service;1"]
+            .getService(Ci.nsIObserverService);
+  os.notifyObservers(null, "child-gc-request", null);
   update();
 }
 
 function doCC()
 {
   window.QueryInterface(Ci.nsIInterfaceRequestor)
         .getInterface(Ci.nsIDOMWindowUtils)
         .cycleCollect();
+  var os = Cc["@mozilla.org/observer-service;1"]
+            .getService(Ci.nsIObserverService);
+  os.notifyObservers(null, "child-cc-request", null);
   update();
 }
 
 // For maximum effect, this returns to the event loop between each
 // notification.  See bug 610166 comment 12 for an explanation.
 // Ideally a single notification would be enough.
 function sendHeapMinNotifications()
 {