Bug 1527827 - Add ShutdownPhase::ShutdownCycleCollector triggered after the CycleCollector shutdown, r=froydnj
authorHonza Bambas <honzab.moz@firemni.cz>
Wed, 27 Feb 2019 12:57:11 +0000
changeset 519345 fd5c4700d912e9ced215e800d66c73cf7ee23325
parent 519344 280ab3f61c87b43e18be462606866a3a669e8b5a
child 519346 a2c753e0e87199ffbfb0f3754f9f951010051dfe
push id10862
push userffxbld-merge
push dateMon, 11 Mar 2019 13:01:11 +0000
treeherdermozilla-beta@a2e7f5c935da [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersfroydnj
bugs1527827
milestone67.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 1527827 - Add ShutdownPhase::ShutdownCycleCollector triggered after the CycleCollector shutdown, r=froydnj Differential Revision: https://phabricator.services.mozilla.com/D21047
netwerk/protocol/http/nsHttpHandler.cpp
xpcom/base/ClearOnShutdown.h
xpcom/build/XPCOMInit.cpp
--- a/netwerk/protocol/http/nsHttpHandler.cpp
+++ b/netwerk/protocol/http/nsHttpHandler.cpp
@@ -179,17 +179,20 @@ static nsCString GetDeviceModelId() {
 
 StaticRefPtr<nsHttpHandler> gHttpHandler;
 
 /* static */ already_AddRefed<nsHttpHandler> nsHttpHandler::GetInstance() {
   if (!gHttpHandler) {
     gHttpHandler = new nsHttpHandler();
     DebugOnly<nsresult> rv = gHttpHandler->Init();
     MOZ_ASSERT(NS_SUCCEEDED(rv));
-    ClearOnShutdown(&gHttpHandler);
+    // There is code that may be executed during the final cycle collection
+    // shutdown and still referencing gHttpHandler.
+    ClearOnShutdown(&gHttpHandler,
+                    ShutdownPhase::ShutdownPostLastCycleCollection);
   }
   RefPtr<nsHttpHandler> httpHandler = gHttpHandler;
   return httpHandler.forget();
 }
 
 nsHttpHandler::nsHttpHandler()
     : mHttpVersion(HttpVersion::v1_1),
       mProxyHttpVersion(HttpVersion::v1_1),
--- a/xpcom/base/ClearOnShutdown.h
+++ b/xpcom/base/ClearOnShutdown.h
@@ -45,16 +45,17 @@ namespace mozilla {
 // Must be contiguous starting at 0
 enum class ShutdownPhase {
   NotInShutdown = 0,
   WillShutdown,
   Shutdown,
   ShutdownThreads,
   ShutdownLoaders,
   ShutdownFinal,
+  ShutdownPostLastCycleCollection,
   ShutdownPhase_Length,  // never pass this value
   First = WillShutdown,  // for iteration
   Last = ShutdownFinal
 };
 
 namespace ClearOnShutdown_Internal {
 
 class ShutdownObserver : public LinkedListElement<ShutdownObserver> {
--- a/xpcom/build/XPCOMInit.cpp
+++ b/xpcom/build/XPCOMInit.cpp
@@ -727,16 +727,20 @@ nsresult ShutdownXPCOM(nsIServiceManager
   bool shutdownCollect;
 #ifdef NS_FREE_PERMANENT_DATA
   shutdownCollect = true;
 #else
   shutdownCollect = !!PR_GetEnv("MOZ_CC_RUN_DURING_SHUTDOWN");
 #endif
   nsCycleCollector_shutdown(shutdownCollect);
 
+  // There can be code trying to refer to global objects during the final cc
+  // shutdown. This is the phase for such global objects to correctly release.
+  mozilla::KillClearOnShutdown(ShutdownPhase::ShutdownPostLastCycleCollection);
+
   PROFILER_ADD_MARKER("Shutdown xpcom", OTHER);
   // If we are doing any shutdown checks, poison writes.
   if (gShutdownChecks != SCM_NOTHING) {
 #ifdef XP_MACOSX
     mozilla::OnlyReportDirtyWrites();
 #endif /* XP_MACOSX */
     mozilla::BeginLateWriteChecks();
   }