Bug 718634 - Move CanSkip* to nsCycleCollectionParticipant, r=mccr8
authorOlli Pettay <Olli.Pettay@helsinki.fi>
Tue, 17 Jan 2012 18:32:19 +0200
changeset 84654 1cfc17f1bd13a7220b0b90c822b98a91d7fdb6bf
parent 84653 ff1bedd7d4637cbef5d354765623c210ef0d2b89
child 84655 4c7f169a47553c2491a284e6db055142fcc11bc9
child 84663 59ecf7d205344e3d0deaa2a43f04e9ec550ba039
push id21869
push useropettay@mozilla.com
push dateTue, 17 Jan 2012 17:48:33 +0000
treeherdermozilla-central@1cfc17f1bd13 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmccr8
bugs718634
milestone12.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 718634 - Move CanSkip* to nsCycleCollectionParticipant, r=mccr8
xpcom/base/nsCycleCollector.cpp
xpcom/glue/nsCycleCollectionParticipant.h
--- a/xpcom/base/nsCycleCollector.cpp
+++ b/xpcom/base/nsCycleCollector.cpp
@@ -1730,17 +1730,19 @@ GCGraphBuilder::NoteRoot(PRUint32 langID
 {
     NS_ASSERTION(root, "Don't add a null root!");
 
     if (langID > nsIProgrammingLanguage::MAX || !mRuntimes[langID]) {
         Fault("adding root for unregistered language", root);
         return;
     }
 
-    AddNode(root, participant, langID);
+    if (!participant->CanSkipThis(root)) {
+        AddNode(root, participant, langID);
+    }
 }
 
 NS_IMETHODIMP_(void)
 GCGraphBuilder::DescribeRefCountedNode(nsrefcnt refCount, size_t objSz,
                                        const char *objName)
 {
     if (refCount == 0)
         Fault("zero refcount", mCurrPi);
--- a/xpcom/glue/nsCycleCollectionParticipant.h
+++ b/xpcom/glue/nsCycleCollectionParticipant.h
@@ -129,60 +129,26 @@ protected:
     nsCycleCollectionTraversalCallback() : mFlags(0) {}
 
     PRUint32 mFlags;
 };
 
 class NS_NO_VTABLE nsCycleCollectionParticipant
 {
 public:
+    nsCycleCollectionParticipant() : mMightSkip(false) {}
+    nsCycleCollectionParticipant(bool aSkip) : mMightSkip(aSkip) {} 
+    
     NS_DECLARE_STATIC_IID_ACCESSOR(NS_CYCLECOLLECTIONPARTICIPANT_IID)
 
     NS_IMETHOD Traverse(void *p, nsCycleCollectionTraversalCallback &cb) = 0;
 
     NS_IMETHOD Root(void *p) = 0;
     NS_IMETHOD Unlink(void *p) = 0;
     NS_IMETHOD Unroot(void *p) = 0;
-};
-
-NS_DEFINE_STATIC_IID_ACCESSOR(nsCycleCollectionParticipant, 
-                              NS_CYCLECOLLECTIONPARTICIPANT_IID)
-
-#undef IMETHOD_VISIBILITY
-#define IMETHOD_VISIBILITY NS_COM_GLUE
-
-typedef void
-(* TraceCallback)(PRUint32 langID, void *p, const char *name, void *closure);
-
-class NS_NO_VTABLE nsScriptObjectTracer : public nsCycleCollectionParticipant
-{
-public:
-    NS_IMETHOD_(void) Trace(void *p, TraceCallback cb, void *closure) = 0;
-    void NS_COM_GLUE TraverseScriptObjects(void *p,
-                                        nsCycleCollectionTraversalCallback &cb);
-};
-
-class NS_COM_GLUE nsXPCOMCycleCollectionParticipant
-    : public nsScriptObjectTracer
-{
-public:
-    nsXPCOMCycleCollectionParticipant() : mMightSkip(false) {}
-    nsXPCOMCycleCollectionParticipant(bool aSkip) : mMightSkip(aSkip) {}
-
-    NS_IMETHOD Traverse(void *p, nsCycleCollectionTraversalCallback &cb);
-
-    NS_IMETHOD Root(void *p);
-    NS_IMETHOD Unlink(void *p);
-    NS_IMETHOD Unroot(void *p);
-
-    NS_IMETHOD_(void) Trace(void *p, TraceCallback cb, void *closure);
-
-    NS_IMETHOD_(void) UnmarkPurple(nsISupports *p);
-
-    bool CheckForRightISupports(nsISupports *s);
 
     // If CanSkip returns true, p is removed from the purple buffer during
     // a call to nsCycleCollector_forgetSkippable().
     // Note, calling CanSkip may remove objects from the purple buffer!
     bool CanSkip(void *p)
     {
         return mMightSkip ? CanSkipReal(p) : false;
     }
@@ -218,16 +184,58 @@ protected:
         NS_ASSERTION(false, "Forgot to implement CanSkipThisReal?");
         return false;
     }
 
 private:
     bool mMightSkip;
 };
 
+NS_DEFINE_STATIC_IID_ACCESSOR(nsCycleCollectionParticipant, 
+                              NS_CYCLECOLLECTIONPARTICIPANT_IID)
+
+#undef IMETHOD_VISIBILITY
+#define IMETHOD_VISIBILITY NS_COM_GLUE
+
+typedef void
+(* TraceCallback)(PRUint32 langID, void *p, const char *name, void *closure);
+
+class NS_NO_VTABLE nsScriptObjectTracer : public nsCycleCollectionParticipant
+{
+public:
+    nsScriptObjectTracer() : nsCycleCollectionParticipant(false) {}
+    nsScriptObjectTracer(bool aSkip) : nsCycleCollectionParticipant(aSkip) {}
+
+    NS_IMETHOD_(void) Trace(void *p, TraceCallback cb, void *closure) = 0;
+    void NS_COM_GLUE TraverseScriptObjects(void *p,
+                                        nsCycleCollectionTraversalCallback &cb);
+};
+
+class NS_COM_GLUE nsXPCOMCycleCollectionParticipant
+    : public nsScriptObjectTracer
+{
+public:
+    nsXPCOMCycleCollectionParticipant()
+    : nsScriptObjectTracer(false) {}
+    nsXPCOMCycleCollectionParticipant(bool aSkip)
+    : nsScriptObjectTracer(aSkip) {}
+
+    NS_IMETHOD Traverse(void *p, nsCycleCollectionTraversalCallback &cb);
+
+    NS_IMETHOD Root(void *p);
+    NS_IMETHOD Unlink(void *p);
+    NS_IMETHOD Unroot(void *p);
+
+    NS_IMETHOD_(void) Trace(void *p, TraceCallback cb, void *closure);
+
+    NS_IMETHOD_(void) UnmarkPurple(nsISupports *p);
+
+    bool CheckForRightISupports(nsISupports *s);
+};
+
 #undef IMETHOD_VISIBILITY
 #define IMETHOD_VISIBILITY NS_VISIBILITY_HIDDEN
 
 ///////////////////////////////////////////////////////////////////////////////
 // Helpers for implementing a QI to nsXPCOMCycleCollectionParticipant
 ///////////////////////////////////////////////////////////////////////////////
 
 #define NS_CYCLE_COLLECTION_INNERCLASS                                         \