Bug 1385474 - Avoid QIing for NoteXPCOMRoot. r=smaug
authorAndrew McCreight <continuation@gmail.com>
Fri, 28 Jul 2017 16:11:03 -0700
changeset 372175 8d09df72c2e9b923bb84fe9741a668988834c393
parent 372174 576d291d94492f2e47c9f38d129fddf3fb46562a
child 372176 51ffb9283f0c7c00e08eb8c39b33fbee218c370d
child 372208 5c312f2c6e58e87f3ec0504ace592ef9d71b9079
push id93228
push userarchaeopteryx@coole-files.de
push dateTue, 01 Aug 2017 09:26:48 +0000
treeherdermozilla-inbound@c893a197feb6 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssmaug
bugs1385474
milestone56.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 1385474 - Avoid QIing for NoteXPCOMRoot. r=smaug This callback is only used in very limited ways, so just require that the caller pass in the canonical supports pointer, plus the participant. This probably won't affect performance much. MozReview-Commit-ID: CsThzFsKyYx
js/xpconnect/src/XPCJSRuntime.cpp
xpcom/base/nsCycleCollectionNoteRootCallback.h
xpcom/base/nsCycleCollector.cpp
--- a/js/xpconnect/src/XPCJSRuntime.cpp
+++ b/js/xpconnect/src/XPCJSRuntime.cpp
@@ -653,21 +653,23 @@ XPCJSRuntime::TraverseAdditionalNativeRo
     for (XPCRootSetElem* e = mVariantRoots; e ; e = e->GetNextRoot()) {
         XPCTraceableVariant* v = static_cast<XPCTraceableVariant*>(e);
         if (nsCCUncollectableMarker::InGeneration(cb,
                                                   v->CCGeneration())) {
            JS::Value val = v->GetJSValPreserveColor();
            if (val.isObject() && !JS::ObjectIsMarkedGray(&val.toObject()))
                continue;
         }
-        cb.NoteXPCOMRoot(v);
+        cb.NoteXPCOMRoot(v,
+                         XPCTraceableVariant::NS_CYCLE_COLLECTION_INNERCLASS::GetParticipant());
     }
 
     for (XPCRootSetElem* e = mWrappedJSRoots; e ; e = e->GetNextRoot()) {
-        cb.NoteXPCOMRoot(ToSupports(static_cast<nsXPCWrappedJS*>(e)));
+        cb.NoteXPCOMRoot(ToSupports(static_cast<nsXPCWrappedJS*>(e)),
+                         nsXPCWrappedJS::NS_CYCLE_COLLECTION_INNERCLASS::GetParticipant());
     }
 }
 
 void
 XPCJSRuntime::UnmarkSkippableJSHolders()
 {
     CycleCollectedJSRuntime::UnmarkSkippableJSHolders();
 }
--- a/xpcom/base/nsCycleCollectionNoteRootCallback.h
+++ b/xpcom/base/nsCycleCollectionNoteRootCallback.h
@@ -8,17 +8,20 @@
 #define nsCycleCollectionNoteRootCallback_h__
 
 class nsCycleCollectionParticipant;
 class nsISupports;
 
 class nsCycleCollectionNoteRootCallback
 {
 public:
-  NS_IMETHOD_(void) NoteXPCOMRoot(nsISupports* aRoot) = 0;
+  // aRoot must be canonical (ie the result of QIing to nsCycleCollectionISupports).
+  NS_IMETHOD_(void) NoteXPCOMRoot(nsISupports* aRoot,
+                                  nsCycleCollectionParticipant* aParticipant) = 0;
+
   NS_IMETHOD_(void) NoteJSRoot(JSObject* aRoot) = 0;
   NS_IMETHOD_(void) NoteNativeRoot(void* aRoot,
                                    nsCycleCollectionParticipant* aParticipant) = 0;
 
   NS_IMETHOD_(void) NoteWeakMapping(JSObject* aMap, JS::GCCellPtr aKey,
                                     JSObject* aKeyDelegate, JS::GCCellPtr aVal) = 0;
 
   bool WantAllTraces() const { return mWantAllTraces; }
--- a/xpcom/base/nsCycleCollector.cpp
+++ b/xpcom/base/nsCycleCollector.cpp
@@ -2097,17 +2097,18 @@ private:
 
   void SetLastChild()
   {
     mCurrPi->SetLastChild(mEdgeBuilder.Mark());
   }
 
 public:
   // nsCycleCollectionNoteRootCallback methods.
-  NS_IMETHOD_(void) NoteXPCOMRoot(nsISupports* aRoot);
+  NS_IMETHOD_(void) NoteXPCOMRoot(nsISupports* aRoot,
+                                  nsCycleCollectionParticipant* aParticipant);
   NS_IMETHOD_(void) NoteJSRoot(JSObject* aRoot);
   NS_IMETHOD_(void) NoteNativeRoot(void* aRoot,
                                    nsCycleCollectionParticipant* aParticipant);
   NS_IMETHOD_(void) NoteWeakMapping(JSObject* aMap, JS::GCCellPtr aKey,
                                     JSObject* aKdelegate, JS::GCCellPtr aVal);
 
   // nsCycleCollectionTraversalCallback methods.
   NS_IMETHOD_(void) DescribeRefCountedNode(nsrefcnt aRefCount,
@@ -2290,26 +2291,28 @@ CCGraphBuilder::BuildGraph(SliceBudget& 
   }
 
   mCurrNode = nullptr;
 
   return true;
 }
 
 NS_IMETHODIMP_(void)
-CCGraphBuilder::NoteXPCOMRoot(nsISupports* aRoot)
+CCGraphBuilder::NoteXPCOMRoot(nsISupports* aRoot,
+                              nsCycleCollectionParticipant* aParticipant)
 {
-  aRoot = CanonicalizeXPCOMParticipant(aRoot);
-  NS_ASSERTION(aRoot,
-               "Don't add objects that don't participate in collection!");
-
+  MOZ_ASSERT(aRoot == CanonicalizeXPCOMParticipant(aRoot));
+
+#ifdef DEBUG
   nsXPCOMCycleCollectionParticipant* cp;
   ToParticipant(aRoot, &cp);
-
-  NoteRoot(aRoot, cp);
+  MOZ_ASSERT(aParticipant == cp);
+#endif
+
+  NoteRoot(aRoot, aParticipant);
 }
 
 NS_IMETHODIMP_(void)
 CCGraphBuilder::NoteJSRoot(JSObject* aRoot)
 {
   if (JS::Zone* zone = MergeZone(JS::GCCellPtr(aRoot))) {
     NoteRoot(zone, mJSZoneParticipant);
   } else {