Backed out changeset dcd8195681d7 (bug 1513542) for browser-chrome failures at build/src/xpcom/base/nsTraceRefcnt.cpp
authorCoroiu Cristina <ccoroiu@mozilla.com>
Wed, 19 Dec 2018 05:36:59 +0200
changeset 451271 7359f1ce3a65537fe5c7a2075c58e0cb11b358e3
parent 451270 6cfb1fdf1ddc001f75b304c219ddb8b3c13dcab7
child 451272 f69fb4fba54b564f2a20ea733663d96ccd2e0ef0
push id35232
push userebalazs@mozilla.com
push dateWed, 19 Dec 2018 15:45:00 +0000
treeherdermozilla-central@335cc6f2cbb1 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
bugs1513542
milestone66.0a1
backs outdcd8195681d70ee47bde2e80846fc62b1e63eb74
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
Backed out changeset dcd8195681d7 (bug 1513542) for browser-chrome failures at build/src/xpcom/base/nsTraceRefcnt.cpp
netwerk/base/nsStandardURL.cpp
--- a/netwerk/base/nsStandardURL.cpp
+++ b/netwerk/base/nsStandardURL.cpp
@@ -186,53 +186,18 @@ const nsACString &nsStandardURL::nsSegme
   return str;
 }
 
 //----------------------------------------------------------------------------
 // nsStandardURL <public>
 //----------------------------------------------------------------------------
 
 #ifdef DEBUG_DUMP_URLS_AT_SHUTDOWN
-class DumpLeakedURLs {
- public:
-  DumpLeakedURLs() : mMutex("DumpLeakedURLs::mMutex") {}
-
-  ~DumpLeakedURLs();
-
-  void add(nsStandardURL *aUrl) {
-    OffTheBooksMutexAutoLock lock(mMutex);
-    mURLs.insertBack(aUrl);
-  }
-
-  void remove(nsStandardURL *aUrl) {
-    OffTheBooksMutexAutoLock lock(mMutex);
-    if (aUrl->isInList()) {
-      aUrl->remove();
-    }
-  }
-
- private:
-  OffTheBooksMutex mMutex;
-  LinkedList<nsStandardURL> mURLs;
-};
-
-DumpLeakedURLs::~DumpLeakedURLs() {
-  MOZ_ASSERT(NS_IsMainThread());
-  OffTheBooksMutexAutoLock lock(mMutex);
-  if (!mURLs.isEmpty()) {
-    printf("Leaked URLs:\n");
-    for (auto url : mURLs) {
-      url->PrintSpec();
-    }
-    mURLs.clear();
-  }
-}
-
-static DumpLeakedURLs gLeakedURLDumper;
-
+static StaticMutex gAllURLsMutex;
+static LinkedList<nsStandardURL> gAllURLs;
 #endif
 
 nsStandardURL::nsStandardURL(bool aSupportsFileURL, bool aTrackURL)
     : mDefaultPort(-1),
       mPort(-1),
       mDisplayHost(nullptr),
       mURLType(URLTYPE_STANDARD),
       mSupportsFileURL(aSupportsFileURL),
@@ -245,30 +210,55 @@ nsStandardURL::nsStandardURL(bool aSuppo
   MOZ_ASSERT(gInitialized);
 
   // default parser in case nsIStandardURL::Init is never called
   mParser = net_GetStdURLParser();
 
 #ifdef DEBUG_DUMP_URLS_AT_SHUTDOWN
   if (NS_IsMainThread()) {
     if (aTrackURL) {
-      gLeakedURLDumper.add(this);
+      StaticMutexAutoLock lock(gAllURLsMutex);
+      gAllURLs.insertBack(this);
     }
   }
 #endif
 }
 
 nsStandardURL::~nsStandardURL() {
   LOG(("Destroying nsStandardURL @%p\n", this));
 
 #ifdef DEBUG_DUMP_URLS_AT_SHUTDOWN
-  gLeakedURLDumper.remove(this);
+  {
+    StaticMutexAutoLock lock(gAllURLsMutex);
+    if (isInList()) {
+      remove();
+    }
+  }
 #endif
 }
 
+#ifdef DEBUG_DUMP_URLS_AT_SHUTDOWN
+struct DumpLeakedURLs {
+  DumpLeakedURLs() = default;
+  ~DumpLeakedURLs();
+};
+
+DumpLeakedURLs::~DumpLeakedURLs() {
+  MOZ_ASSERT(NS_IsMainThread());
+  StaticMutexAutoLock lock(gAllURLsMutex);
+  if (!gAllURLs.isEmpty()) {
+    printf("Leaked URLs:\n");
+    for (auto url : gAllURLs) {
+      url->PrintSpec();
+    }
+    gAllURLs.clear();
+  }
+}
+#endif
+
 void nsStandardURL::InitGlobalObjects() {
   MOZ_DIAGNOSTIC_ASSERT(NS_IsMainThread());
 
   if (gInitialized) {
     return;
   }
 
   gInitialized = true;
@@ -285,16 +275,25 @@ void nsStandardURL::InitGlobalObjects() 
   nsCOMPtr<nsIURLParser> parser = net_GetStdURLParser();
   MOZ_DIAGNOSTIC_ASSERT(parser);
   Unused << parser;
 }
 
 void nsStandardURL::ShutdownGlobalObjects() {
   MOZ_DIAGNOSTIC_ASSERT(NS_IsMainThread());
   NS_IF_RELEASE(gIDN);
+
+#ifdef DEBUG_DUMP_URLS_AT_SHUTDOWN
+  if (gInitialized) {
+    // This instanciates a dummy class, and will trigger the class
+    // destructor when libxul is unloaded. This is equivalent to atexit(),
+    // but gracefully handles dlclose().
+    static DumpLeakedURLs d;
+  }
+#endif
 }
 
 //----------------------------------------------------------------------------
 // nsStandardURL <private>
 //----------------------------------------------------------------------------
 
 void nsStandardURL::Clear() {
   mSpec.Truncate();