Bug 1299934 - Run shutdown collection in workers in opt builds. r=smaug,froydnj draft
authorAndrew McCreight <continuation@gmail.com>
Thu, 08 Sep 2016 13:04:30 -0700
changeset 413111 2d57eb569c61d5f600d0b431d3316e7c8620e767
parent 412289 644b3de5d7a18b101d44a003bc27d50853dee4c9
child 531143 05921e2f2c136adf495dd137454d6c8fa4f1841b
push id29342
push userbmo:continuation@gmail.com
push dateTue, 13 Sep 2016 17:03:10 +0000
reviewerssmaug, froydnj
bugs1299934
milestone51.0a1
Bug 1299934 - Run shutdown collection in workers in opt builds. r=smaug,froydnj We skip running shutdown collection on the main thread, because we're exiting right after, but the process still continues when we shut down a worker, so we should always do collections there. MozReview-Commit-ID: IQZItm1qWXW
xpcom/base/nsCycleCollector.cpp
xpcom/base/nsCycleCollector.h
xpcom/build/XPCOMInit.cpp
--- a/xpcom/base/nsCycleCollector.cpp
+++ b/xpcom/base/nsCycleCollector.cpp
@@ -1325,17 +1325,17 @@ public:
 
   void PrepareForGarbageCollection();
   void FinishAnyCurrentCollection();
 
   bool Collect(ccType aCCType,
                SliceBudget& aBudget,
                nsICycleCollectorListener* aManualListener,
                bool aPreferShorterSlices = false);
-  void Shutdown();
+  void Shutdown(bool aDoCollect);
 
   bool IsIdle() const { return mIncrementalPhase == IdlePhase; }
 
   void SizeOfIncludingThis(mozilla::MallocSizeOf aMallocSizeOf,
                            size_t* aObjectSize,
                            size_t* aGraphSize,
                            size_t* aPurpleBufferSize) const;
 
@@ -3871,27 +3871,24 @@ nsCycleCollector::BeginCollection(ccType
 uint32_t
 nsCycleCollector::SuspectedCount()
 {
   CheckThreadSafety();
   return mPurpleBuf.Count();
 }
 
 void
-nsCycleCollector::Shutdown()
+nsCycleCollector::Shutdown(bool aDoCollect)
 {
   CheckThreadSafety();
 
   // Always delete snow white objects.
   FreeSnowWhite(true);
 
-#ifndef NS_FREE_PERMANENT_DATA
-  if (PR_GetEnv("MOZ_CC_RUN_DURING_SHUTDOWN"))
-#endif
-  {
+  if (aDoCollect) {
     ShutdownCollect();
   }
 }
 
 void
 nsCycleCollector::RemoveObjectFromGraph(void* aObj)
 {
   if (IsIdle()) {
@@ -4191,26 +4188,26 @@ nsCycleCollector_finishAnyCurrentCollect
   if (!data->mCollector) {
     return;
   }
 
   data->mCollector->FinishAnyCurrentCollection();
 }
 
 void
-nsCycleCollector_shutdown()
+nsCycleCollector_shutdown(bool aDoCollect)
 {
   CollectorData* data = sCollectorData.get();
 
   if (data) {
     MOZ_ASSERT(data->mCollector);
     PROFILER_LABEL("nsCycleCollector", "shutdown",
                    js::ProfileEntry::Category::CC);
 
-    data->mCollector->Shutdown();
+    data->mCollector->Shutdown(aDoCollect);
     data->mCollector = nullptr;
     if (data->mRuntime) {
       // Run any remaining tasks that may have been enqueued via
       // RunInStableState during the final cycle collection.
       data->mRuntime->ProcessStableStateQueue();
     }
     if (!data->mRuntime) {
       delete data;
--- a/xpcom/base/nsCycleCollector.h
+++ b/xpcom/base/nsCycleCollector.h
@@ -46,17 +46,20 @@ bool nsCycleCollector_doDeferredDeletion
 already_AddRefed<nsICycleCollectorLogSink> nsCycleCollector_createLogSink();
 
 void nsCycleCollector_collect(nsICycleCollectorListener* aManualListener);
 
 void nsCycleCollector_collectSlice(js::SliceBudget& budget,
                                    bool aPreferShorterSlices = false);
 
 uint32_t nsCycleCollector_suspectedCount();
-void nsCycleCollector_shutdown();
+
+// If aDoCollect is true, then run the GC and CC a few times before
+// shutting down the CC completely.
+void nsCycleCollector_shutdown(bool aDoCollect = true);
 
 // Helpers for interacting with JS
 void nsCycleCollector_registerJSRuntime(mozilla::CycleCollectedJSRuntime* aRt);
 void nsCycleCollector_forgetJSRuntime();
 
 #define NS_CYCLE_COLLECTOR_LOGGER_CID \
 { 0x58be81b4, 0x39d2, 0x437c, \
 { 0x94, 0xea, 0xae, 0xde, 0x2c, 0x62, 0x08, 0xd3 } }
--- a/xpcom/build/XPCOMInit.cpp
+++ b/xpcom/build/XPCOMInit.cpp
@@ -979,17 +979,23 @@ ShutdownXPCOM(nsIServiceManager* aServMg
       if (obs) {
         obs->Observe(nullptr, NS_XPCOM_SHUTDOWN_LOADERS_OBSERVER_ID, nullptr);
       }
     }
 
     moduleLoaders = nullptr;
   }
 
-  nsCycleCollector_shutdown();
+  bool shutdownCollect;
+#ifdef NS_FREE_PERMANENT_DATA
+  shutdownCollect = true;
+#else
+  shutdownCollect = !!PR_GetEnv("MOZ_CC_RUN_DURING_SHUTDOWN");
+#endif
+  nsCycleCollector_shutdown(shutdownCollect);
 
   PROFILER_MARKER("Shutdown xpcom");
   // If we are doing any shutdown checks, poison writes.
   if (gShutdownChecks != SCM_NOTHING) {
 #ifdef XP_MACOSX
     mozilla::OnlyReportDirtyWrites();
 #endif /* XP_MACOSX */
     mozilla::BeginLateWriteChecks();