Reverse the meaning of suspectCurrentCount and rename it to expectedGarbageCount. (Bug 488603) r+sr=peterv
authorL. David Baron <dbaron@dbaron.org>
Fri, 24 Apr 2009 15:45:34 -0700
changeset 27821 f7facb749df7c8df4c0486987e2a68af35975dfa
parent 27820 908a746fee8556ce625d4a65fec097a68c6cf4ed
child 27822 a00490016114a11bcdf9d16fc70251de257bf91f
push id6729
push userdbaron@mozilla.com
push dateFri, 24 Apr 2009 22:45:54 +0000
treeherdermozilla-central@cec9d9f355e8 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
bugs488603
milestone1.9.2a1pre
Reverse the meaning of suspectCurrentCount and rename it to expectedGarbageCount. (Bug 488603) r+sr=peterv
xpcom/base/nsCycleCollector.cpp
--- a/xpcom/base/nsCycleCollector.cpp
+++ b/xpcom/base/nsCycleCollector.cpp
@@ -2551,47 +2551,53 @@ nsCycleCollector::ExplainLiveExpectedGar
     }
 
     mCollectionInProgress = PR_TRUE;
     mScanInProgress = PR_TRUE;
 
     {
         GCGraphBuilder builder(mGraph, mRuntimes);
 
+        // Instead of adding roots from the purple buffer, we add them
+        // from the list of nodes we were expected to collect.
+        // Put the expected garbage in *before* calling
+        // BeginCycleCollection so that we can separate the expected
+        // garbage from the NoteRoot calls in such a way that something
+        // that's in both is considered expected garbage.
+        mExpectedGarbage.EnumerateEntries(&AddExpectedGarbage, &builder);
+
+        PRUint32 expectedGarbageCount = builder.Count();
+
         for (PRUint32 i = 0; i <= nsIProgrammingLanguage::MAX; ++i) {
             if (mRuntimes[i])
                 mRuntimes[i]->BeginCycleCollection(builder);
         }
 
-        // This might fail to explain expected garbage that's also in
-        // the set of roots added by the runtimes (what used to be
-        // called suspectCurrent), but that seems pretty unlikely.
-        PRUint32 suspectCurrentCount = builder.Count();
-
-        // Instead of adding roots from the purple buffer, we add them
-        // from the list of nodes we were expected to collect.
-        mExpectedGarbage.EnumerateEntries(&AddExpectedGarbage, &builder);
-
         MarkRoots(builder);
         ScanRoots();
 
         mScanInProgress = PR_FALSE;
 
         PRBool describeExtraRefcounts = PR_FALSE;
         PRBool findCycleRoots = PR_FALSE;
         {
             NodePool::Enumerator queue(mGraph.mNodes);
             PRUint32 i = 0;
             while (!queue.IsDone()) {
                 PtrInfo *pi = queue.GetNext();
                 if (pi->mColor == white) {
                     findCycleRoots = PR_TRUE;
                 }
 
-                if (pi->mInternalRefs != pi->mRefCount && i >= suspectCurrentCount) {
+                if (pi->mInternalRefs != pi->mRefCount &&
+                    (i < expectedGarbageCount || i >= mGraph.mRootCount)) {
+                    // This check isn't particularly useful anymore
+                    // given that we need to enter this part for i >=
+                    // mGraph.mRootCount and there are plenty of
+                    // NoteRoot roots.
                     describeExtraRefcounts = PR_TRUE;
                 }
                 ++i;
             }
         }
 
         if ((describeExtraRefcounts || findCycleRoots) &&
             CreateReversedEdges()) {
@@ -2609,17 +2615,17 @@ nsCycleCollector::ExplainLiveExpectedGar
                 PtrInfo *pi = etor_clear.GetNext();
                 pi->mSCCIndex = INDEX_UNREACHED;
             }
 
             nsDeque queue; // for breadth-first search
             NodePool::Enumerator etor_roots(mGraph.mNodes);
             for (PRUint32 i = 0; i < mGraph.mRootCount; ++i) {
                 PtrInfo *root_pi = etor_roots.GetNext();
-                if (i >= suspectCurrentCount) {
+                if (i < expectedGarbageCount) {
                     root_pi->mSCCIndex = INDEX_REACHED;
                     root_pi->mShortestPathToExpectedGarbage = root_pi;
                     queue.Push(root_pi);
                 }
             }
 
             while (queue.GetSize() > 0) {
                 PtrInfo *pi = (PtrInfo*)queue.PopFront();