Bug 1301796 - Remove racy code in nsCycleCollector::RegisterJSRuntime. r=smaug
authorAndrew McCreight <continuation@gmail.com>
Fri, 09 Sep 2016 15:14:15 -0700
changeset 313692 0f7f9fa31c4a2a37294c123a201d678080ce6cf5
parent 313691 51d254b8787c45ea15de620e4a71c053f70df011
child 313693 1f363e4553af0e2cb417e45c1dfc8dc3199888dd
push id32229
push useramccreight@mozilla.com
push dateTue, 13 Sep 2016 15:54:25 +0000
treeherderautoland@0f7f9fa31c4a [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssmaug
bugs1301796
milestone51.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 1301796 - Remove racy code in nsCycleCollector::RegisterJSRuntime. r=smaug MozReview-Commit-ID: 18MW4EYbaC8
xpcom/base/nsCycleCollector.cpp
--- a/xpcom/base/nsCycleCollector.cpp
+++ b/xpcom/base/nsCycleCollector.cpp
@@ -3430,24 +3430,24 @@ nsCycleCollector::~nsCycleCollector()
 }
 
 void
 nsCycleCollector::RegisterJSRuntime(CycleCollectedJSRuntime* aJSRuntime)
 {
   MOZ_RELEASE_ASSERT(!mJSRuntime, "Multiple registrations of JS runtime in cycle collector");
   mJSRuntime = aJSRuntime;
 
+  if (!NS_IsMainThread()) {
+    return;
+  }
+
   // We can't register as a reporter in nsCycleCollector() because that runs
   // before the memory reporter manager is initialized.  So we do it here
   // instead.
-  static bool registered = false;
-  if (!registered) {
-    RegisterWeakMemoryReporter(this);
-    registered = true;
-  }
+  RegisterWeakMemoryReporter(this);
 }
 
 void
 nsCycleCollector::ForgetJSRuntime()
 {
   MOZ_RELEASE_ASSERT(mJSRuntime, "Forgetting JS runtime in cycle collector before a JS runtime was registered");
   mJSRuntime = nullptr;
 }