Bug 811212 - Make most cycle collector assertions fatal - r=mccr8
authorBenoit Jacob <bjacob@mozilla.com>
Thu, 15 Nov 2012 02:32:39 -0500
changeset 113360 7a4b00ee35b78178e6a3a8a3fa4f6487d03ad770
parent 113359 ed94525f58234b0db23925bd7eeb952146c39a3f
child 113361 6c9caeb3422baf2deb41953f9dce0c2acf2a06cd
push id23869
push useremorley@mozilla.com
push dateThu, 15 Nov 2012 16:18:16 +0000
treeherdermozilla-central@a37525d304d9 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmccr8
bugs811212
milestone19.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 811212 - Make most cycle collector assertions fatal - r=mccr8
xpcom/base/nsCycleCollector.cpp
xpcom/glue/nsCycleCollectionParticipant.h
--- a/xpcom/base/nsCycleCollector.cpp
+++ b/xpcom/base/nsCycleCollector.cpp
@@ -319,19 +319,19 @@ public:
     EdgePool()
     {
         mSentinelAndBlocks[0].block = nullptr;
         mSentinelAndBlocks[1].block = nullptr;
     }
 
     ~EdgePool()
     {
-        NS_ASSERTION(!mSentinelAndBlocks[0].block &&
-                     !mSentinelAndBlocks[1].block,
-                     "Didn't call Clear()?");
+        MOZ_ASSERT(!mSentinelAndBlocks[0].block &&
+                   !mSentinelAndBlocks[1].block,
+                   "Didn't call Clear()?");
     }
 
     void Clear()
     {
         Block *b = Blocks();
         while (b) {
             Block *next = b->Next();
             delete b;
@@ -543,17 +543,17 @@ public:
     NodePool()
         : mBlocks(nullptr),
           mLast(nullptr)
     {
     }
 
     ~NodePool()
     {
-        NS_ASSERTION(!mBlocks, "Didn't call Clear()?");
+        MOZ_ASSERT(!mBlocks, "Didn't call Clear()?");
     }
 
     void Clear()
     {
 #ifdef DEBUG_CC
         {
             Enumerator queue(*this);
             while (!queue.IsDone()) {
@@ -576,18 +576,18 @@ public:
     friend class Builder;
     class Builder {
     public:
         Builder(NodePool& aPool)
             : mNextBlock(&aPool.mBlocks),
               mNext(aPool.mLast),
               mBlockEnd(nullptr)
         {
-            NS_ASSERTION(aPool.mBlocks == nullptr && aPool.mLast == nullptr,
-                         "pool not empty");
+            MOZ_ASSERT(aPool.mBlocks == nullptr && aPool.mLast == nullptr,
+                       "pool not empty");
         }
         PtrInfo *Add(void *aPointer, nsCycleCollectionParticipant *aParticipant)
         {
             if (mNext == mBlockEnd) {
                 Block *block;
                 if (!(*mNextBlock = block =
                         static_cast<Block*>(NS_Alloc(sizeof(Block)))))
                     return nullptr;
@@ -624,17 +624,17 @@ public:
 
         bool AtBlockEnd() const
         {
             return mNext == mBlockEnd;
         }
 
         PtrInfo* GetNext()
         {
-            NS_ASSERTION(!IsDone(), "calling GetNext when done");
+            MOZ_ASSERT(!IsDone(), "calling GetNext when done");
             if (mNext == mBlockEnd) {
                 Block *nextBlock = mCurBlock ? mCurBlock->mNext : mFirstBlock;
                 mNext = nextBlock->mEntries;
                 mBlockEnd = mNext + BlockSize;
                 mCurBlock = nextBlock;
             }
             return mNext++;
         }
@@ -900,17 +900,17 @@ public:
         e->mNotPurple = false;
 
         // Caller is responsible for filling in result's mRefCnt.
         return e;
     }
 
     void Remove(nsPurpleBufferEntry *e)
     {
-        NS_ASSERTION(mCount != 0, "must have entries");
+        MOZ_ASSERT(mCount != 0, "must have entries");
 
 #ifdef DEBUG_CC
         mNormalObjects.RemoveEntry(e->mObject);
 #endif
 
         e->mNextInFreeList =
             (nsPurpleBufferEntry*)(uintptr_t(mFreeList) | uintptr_t(1));
         mFreeList = e;
@@ -1828,18 +1828,18 @@ GCGraphBuilder::AddNode(void *s, nsCycle
         result = mNodeBuilder.Add(s, aParticipant);
         if (!result) {
             PL_DHashTableRawRemove(&mPtrToNodeMap, e);
             return nullptr;
         }
         e->mNode = result;
     } else {
         result = e->mNode;
-        NS_ASSERTION(result->mParticipant == aParticipant,
-                     "nsCycleCollectionParticipant shouldn't change!");
+        MOZ_ASSERT(result->mParticipant == aParticipant,
+                   "nsCycleCollectionParticipant shouldn't change!");
     }
     return result;
 }
 
 MOZ_NEVER_INLINE void
 GCGraphBuilder::Traverse(PtrInfo* aPtrInfo)
 {
     mCurrPi = aPtrInfo;
@@ -1960,17 +1960,17 @@ GCGraphBuilder::NoteNativeChild(void *ch
     nsCString edgeName;
     if (WantDebugInfo()) {
         edgeName.Assign(mNextEdgeName);
         mNextEdgeName.Truncate();
     }
     if (!child)
         return;
 
-    NS_ASSERTION(participant, "Need a nsCycleCollectionParticipant!");
+    MOZ_ASSERT(participant, "Need a nsCycleCollectionParticipant!");
     NoteChild(child, participant, edgeName);
 }
 
 NS_IMETHODIMP_(void)
 GCGraphBuilder::NoteJSChild(void *child) 
 {
     if (!child) {
         return;
@@ -1997,17 +1997,17 @@ GCGraphBuilder::NoteNextEdgeName(const c
     if (WantDebugInfo()) {
         mNextEdgeName = name;
     }
 }
 
 PtrInfo*
 GCGraphBuilder::AddWeakMapNode(void *node)
 {
-    NS_ASSERTION(node, "Weak map node should be non-null.");
+    MOZ_ASSERT(node, "Weak map node should be non-null.");
 
     if (!xpc_GCThingIsGrayCCThing(node) && !WantAllTraces())
         return nullptr;
 
     if (JSCompartment *comp = MergeCompartment(node)) {
         return AddNode(comp, mJSCompParticipant);
     } else {
         return AddNode(node, mJSParticipant);
@@ -2227,18 +2227,18 @@ struct scanVisitor
         if (pi->mInternalRefs == pi->mRefCount || pi->mRefCount == 0) {
             pi->mColor = white;
             ++mWhiteNodeCount;
 #ifdef DEBUG_CC
             sCollector->mStats.mSetColorWhite++;
 #endif
         } else {
             GraphWalker<ScanBlackVisitor>(ScanBlackVisitor(mWhiteNodeCount)).Walk(pi);
-            NS_ASSERTION(pi->mColor == black,
-                         "Why didn't ScanBlackVisitor make pi black?");
+            MOZ_ASSERT(pi->mColor == black,
+                       "Why didn't ScanBlackVisitor make pi black?");
         }
     }
 
     uint32_t &mWhiteNodeCount;
 };
 
 // Iterate over the WeakMaps.  If we mark anything while iterating
 // over the WeakMaps, we must iterate over all of the WeakMaps again.
@@ -2325,18 +2325,18 @@ nsCycleCollector::CollectWhite(nsICycleC
     //
     //   - Root(whites), which should pin the whites in memory.
     //   - Unlink(whites), which drops outgoing links on each white.
     //   - Unroot(whites), which returns the whites to normal GC.
 
     nsresult rv;
     TimeLog timeLog;
 
-    NS_ASSERTION(mWhiteNodes->IsEmpty(),
-                 "FinishCollection wasn't called?");
+    MOZ_ASSERT(mWhiteNodes->IsEmpty(),
+               "FinishCollection wasn't called?");
 
     mWhiteNodes->SetCapacity(mWhiteNodeCount);
     uint32_t numWhiteGCed = 0;
 
     NodePool::Enumerator etor(mGraph.mNodes);
     while (!etor.IsDone())
     {
         PtrInfo *pinfo = etor.GetNext();
@@ -2348,18 +2348,18 @@ nsCycleCollector::CollectWhite(nsICycleC
             } else if (pinfo->mRefCount == 0) {
                 // only JS objects have a refcount of 0
                 ++numWhiteGCed;
             }
         }
     }
 
     uint32_t count = mWhiteNodes->Length();
-    NS_ASSERTION(numWhiteGCed <= count,
-                 "More freed GCed nodes than total freed nodes.");
+    MOZ_ASSERT(numWhiteGCed <= count,
+               "More freed GCed nodes than total freed nodes.");
     if (mResults) {
         mResults->mFreedRefCounted += count - numWhiteGCed;
         mResults->mFreedGCed += numWhiteGCed;
     }
 
     timeLog.Checkpoint("CollectWhite::Root");
 
     if (mBeforeUnlinkCB) {
@@ -2564,18 +2564,18 @@ nsCycleCollector::Suspect2(void *n, nsCy
 
     // Re-entering ::Suspect during collection used to be a fault, but
     // we are canonicalizing nsISupports pointers using QI, so we will
     // see some spurious refcount traffic here. 
 
     if (mScanInProgress)
         return nullptr;
 
-    NS_ASSERTION(nsCycleCollector_isScanSafe(n, cp),
-                 "suspected a non-scansafe pointer");
+    MOZ_ASSERT(nsCycleCollector_isScanSafe(n, cp),
+               "suspected a non-scansafe pointer");
 
     if (mParams.mDoNothing)
         return nullptr;
 
 #ifdef DEBUG_CC
     if (!LogPurpleAddition(n, cp))
         return nullptr;
 #endif
@@ -2670,18 +2670,18 @@ nsCycleCollector::LogPurpleRemoval(void*
 // were reachable only from XPConnect roots that might participate in
 // cycles. We ask the JS runtime whether we need to force a GC before
 // this CC. It returns true on startup (before the mark bits have been set),
 // and also when UnmarkGray has run out of stack.  We also force GCs on shut 
 // down to collect cycles involving both DOM and JS.
 void
 nsCycleCollector::GCIfNeeded(bool aForceGC)
 {
-    NS_ASSERTION(NS_IsMainThread(),
-                 "nsCycleCollector::GCIfNeeded() must be called on the main thread.");
+    MOZ_ASSERT(NS_IsMainThread(),
+               "nsCycleCollector::GCIfNeeded() must be called on the main thread.");
 
     if (mParams.mDoNothing)
         return;
 
     if (!mJSRuntime)
         return;
 
     if (!aForceGC) {
@@ -3181,18 +3181,18 @@ public:
         TlsSetValue(gTLSThreadIDIndex,
                     (void*) mozilla::threads::CycleCollector);
 #elif defined(NS_TLS)
         gTLSThreadID = mozilla::threads::CycleCollector;
 #else
         gCycleCollectorThread = PR_GetCurrentThread();
 #endif
 
-        NS_ASSERTION(NS_IsCycleCollectorThread() && !NS_IsMainThread(),
-                     "Wrong thread!");
+        MOZ_ASSERT(NS_IsCycleCollectorThread() && !NS_IsMainThread(),
+                   "Wrong thread!");
 
         MutexAutoLock autoLock(mLock);
 
         if (mShutdown)
             return NS_OK;
 
         mRunning = true;
 
@@ -3220,24 +3220,24 @@ public:
           mLock("cycle collector lock"),
           mRequest(mLock, "cycle collector request condvar"),
           mReply(mLock, "cycle collector reply condvar"),
           mRunning(false),
           mShutdown(false),
           mCollected(false),
           mMergeCompartments(false)
     {
-        NS_ASSERTION(NS_IsMainThread(), "Wrong thread!");
+        MOZ_ASSERT(NS_IsMainThread(), "Wrong thread!");
     }
 
     void Collect(bool aMergeCompartments,
                  nsCycleCollectorResults *aResults,
                  nsICycleCollectorListener *aListener)
     {
-        NS_ASSERTION(NS_IsMainThread(), "Wrong thread!");
+        MOZ_ASSERT(NS_IsMainThread(), "Wrong thread!");
 
         // On a WantAllTraces CC, force a synchronous global GC to prevent
         // hijinks from ForgetSkippable and compartmental GCs.
         bool wantAllTraces = false;
         if (aListener) {
             aListener->GetWantAllTraces(&wantAllTraces);
         }
         mCollector->GCIfNeeded(wantAllTraces);
@@ -3246,17 +3246,17 @@ public:
 
         if (!mRunning)
             return;
 
         nsAutoTArray<PtrInfo*, 4000> whiteNodes;
         if (!mCollector->PrepareForCollection(aResults, &whiteNodes))
             return;
 
-        NS_ASSERTION(!mListener, "Should have cleared this already!");
+        MOZ_ASSERT(!mListener, "Should have cleared this already!");
         if (aListener && NS_FAILED(aListener->Begin()))
             aListener = nullptr;
         mListener = aListener;
         mMergeCompartments = aMergeCompartments;
 
         if (mCollector->mJSRuntime->NotifyLeaveMainThread()) {
             mRequest.Notify();
             mReply.Wait();
@@ -3270,17 +3270,17 @@ public:
         if (mCollected) {
             mCollector->FinishCollection(aListener);
             mCollector->CleanupAfterCollection();
         }
     }
 
     void Shutdown()
     {
-        NS_ASSERTION(NS_IsMainThread(), "Wrong thread!");
+        MOZ_ASSERT(NS_IsMainThread(), "Wrong thread!");
 
         MutexAutoLock autoLock(mLock);
 
         mShutdown = true;
 
         if (!mRunning)
             return;
 
@@ -3294,18 +3294,18 @@ public:
 static nsCycleCollectorRunner* sCollectorRunner;
 
 // Holds a reference.
 static nsIThread* sCollectorThread;
 
 nsresult
 nsCycleCollector_startup()
 {
-    NS_ASSERTION(NS_IsMainThread(), "Wrong thread!");
-    NS_ASSERTION(!sCollector, "Forgot to call nsCycleCollector_shutdown?");
+    MOZ_ASSERT(NS_IsMainThread(), "Wrong thread!");
+    MOZ_ASSERT(!sCollector, "Forgot to call nsCycleCollector_shutdown?");
 
     sCollector = new nsCycleCollector();
 
     nsRefPtr<nsCycleCollectorRunner> runner =
         new nsCycleCollectorRunner(sCollector);
 
     nsCOMPtr<nsIThread> thread;
     nsresult rv = NS_NewThread(getter_AddRefs(thread), runner);
@@ -3344,53 +3344,53 @@ nsCycleCollector_forgetSkippable(bool aR
     }
 }
 
 void
 nsCycleCollector_collect(bool aMergeCompartments,
                          nsCycleCollectorResults *aResults,
                          nsICycleCollectorListener *aListener)
 {
-    NS_ASSERTION(NS_IsMainThread(), "Wrong thread!");
+    MOZ_ASSERT(NS_IsMainThread(), "Wrong thread!");
     SAMPLE_LABEL("CC", "nsCycleCollector_collect");
     nsCOMPtr<nsICycleCollectorListener> listener(aListener);
     if (!aListener && sCollector && sCollector->mParams.mLogGraphs) {
         listener = new nsCycleCollectorLogger();
     }
 
     if (sCollectorRunner) {
         sCollectorRunner->Collect(aMergeCompartments, aResults, listener);
     } else if (sCollector) {
         sCollector->Collect(aMergeCompartments, aResults, 1, listener);
     }
 }
 
 void
 nsCycleCollector_shutdownThreads()
 {
-    NS_ASSERTION(NS_IsMainThread(), "Wrong thread!");
+    MOZ_ASSERT(NS_IsMainThread(), "Wrong thread!");
     if (sCollectorRunner) {
         nsRefPtr<nsCycleCollectorRunner> runner;
         runner.swap(sCollectorRunner);
         runner->Shutdown();
     }
 
     if (sCollectorThread) {
         nsCOMPtr<nsIThread> thread;
         thread.swap(sCollectorThread);
         thread->Shutdown();
     }
 }
 
 void
 nsCycleCollector_shutdown()
 {
-    NS_ASSERTION(NS_IsMainThread(), "Wrong thread!");
-    NS_ASSERTION(!sCollectorRunner, "Should have finished before!");
-    NS_ASSERTION(!sCollectorThread, "Should have finished before!");
+    MOZ_ASSERT(NS_IsMainThread(), "Wrong thread!");
+    MOZ_ASSERT(!sCollectorRunner, "Should have finished before!");
+    MOZ_ASSERT(!sCollectorThread, "Should have finished before!");
 
     if (sCollector) {
         SAMPLE_LABEL("CC", "nsCycleCollector_shutdown");
         sCollector->Shutdown();
         delete sCollector;
         sCollector = nullptr;
     }
 }
--- a/xpcom/glue/nsCycleCollectionParticipant.h
+++ b/xpcom/glue/nsCycleCollectionParticipant.h
@@ -314,18 +314,18 @@ struct DowncastCCParticipantImpl
 
 // Specialization for XPCOM CC participants
 template <typename T>
 struct DowncastCCParticipantImpl<T, true>
 {
   static T* Run(void *p)
   {
     nsISupports *s = static_cast<nsISupports*>(p);
-    NS_ASSERTION(NS_CYCLE_COLLECTION_CLASSNAME(T)::CheckForRightISupports(s),
-                 "not the nsISupports pointer we expect");
+    MOZ_ASSERT(NS_CYCLE_COLLECTION_CLASSNAME(T)::CheckForRightISupports(s),
+               "not the nsISupports pointer we expect");
     return NS_CYCLE_COLLECTION_CLASSNAME(T)::Downcast(s);
   }
 };
 
 // Specialization for native CC participants
 template <typename T>
 struct DowncastCCParticipantImpl<T, false>
 {
@@ -413,18 +413,18 @@ T* DowncastCCParticipant(void *p)
     (void)tmp;                                                                 \
     return NS_OK;                                                              \
   }
 
 #define NS_IMPL_CYCLE_COLLECTION_UNLINK_0(_class)                              \
   NS_METHOD                                                                    \
   NS_CYCLE_COLLECTION_CLASSNAME(_class)::UnlinkImpl(void *p)                   \
   {                                                                            \
-    NS_ASSERTION(CheckForRightISupports(static_cast<nsISupports*>(p)),         \
-                 "not the nsISupports pointer we expect");                     \
+    MOZ_ASSERT(CheckForRightISupports(static_cast<nsISupports*>(p)),           \
+               "not the nsISupports pointer we expect");                       \
     return NS_OK;                                                              \
   }
 
 #define NS_IMPL_CYCLE_COLLECTION_UNLINK_NATIVE_0(_class)                       \
   NS_METHOD                                                                    \
   NS_CYCLE_COLLECTION_CLASSNAME(_class)::UnlinkImpl(void *p)                   \
   {                                                                            \
     return NS_OK;                                                              \