Bug 1277260, part 2 - Add and use method to annotate CC crashes with a class name. r=smaug draft
authorAndrew McCreight <continuation@gmail.com>
Fri, 15 Sep 2017 13:00:17 -0700
changeset 666359 6db139aa76584cdf2810f7860783321898cbec87
parent 666358 0b53a48b1f865511a0363ae896396719078dc718
child 666360 9ce83c87e2fd1394277213c0cfc439f28f739bdc
push id80381
push userbmo:continuation@gmail.com
push dateMon, 18 Sep 2017 17:12:47 +0000
reviewerssmaug
bugs1277260
milestone57.0a1
Bug 1277260, part 2 - Add and use method to annotate CC crashes with a class name. r=smaug MozReview-Commit-ID: JweRzAC89NS
xpcom/base/nsCycleCollector.cpp
--- a/xpcom/base/nsCycleCollector.cpp
+++ b/xpcom/base/nsCycleCollector.cpp
@@ -652,18 +652,39 @@ public:
   }
 
   // this PtrInfo must be part of a NodePool
   void SetLastChild(EdgePool::Iterator aLastChild)
   {
     CC_GRAPH_ASSERT(aLastChild.Initialized());
     (this + 1)->mFirstChild = aLastChild;
   }
+
+  void AnnotatedReleaseAssert(bool aCondition, const char* aMessage);
 };
 
+void
+PtrInfo::AnnotatedReleaseAssert(bool aCondition, const char* aMessage)
+{
+  if (aCondition) {
+    return;
+  }
+
+#ifdef MOZ_CRASHREPORTER
+  const char* piName = "Unknown";
+  if (mParticipant) {
+    piName = mParticipant->ClassName();
+  }
+  nsPrintfCString msg("%s, for class %s", aMessage, piName);
+  CrashReporter::AnnotateCrashReport(NS_LITERAL_CSTRING("CycleCollector"), msg);
+#endif
+
+  MOZ_CRASH();
+}
+
 /**
  * A structure designed to be used like a linked list of PtrInfo, except
  * it allocates many PtrInfos at a time.
  */
 class NodePool
 {
 private:
   // The -2 allows us to use |NodeBlockSize + 1| for |mEntries|, and fit
@@ -2368,18 +2389,20 @@ CCGraphBuilder::NoteNativeRoot(void* aRo
                                nsCycleCollectionParticipant* aParticipant)
 {
   NoteRoot(aRoot, aParticipant);
 }
 
 NS_IMETHODIMP_(void)
 CCGraphBuilder::DescribeRefCountedNode(nsrefcnt aRefCount, const char* aObjName)
 {
-  MOZ_RELEASE_ASSERT(aRefCount != 0, "CCed refcounted object has zero refcount");
-  MOZ_RELEASE_ASSERT(aRefCount != UINT32_MAX, "CCed refcounted object has overflowing refcount");
+  mCurrPi->AnnotatedReleaseAssert(aRefCount != 0,
+                                  "CCed refcounted object has zero refcount");
+  mCurrPi->AnnotatedReleaseAssert(aRefCount != UINT32_MAX,
+                                  "CCed refcounted object has overflowing refcount");
 
   mResults.mVisitedRefCounted++;
 
   if (mLogger) {
     mLogger->NoteRefCountedObject((uint64_t)mCurrPi->mPointer, aRefCount,
                                   aObjName);
   }
 
@@ -3200,27 +3223,18 @@ nsCycleCollector::ScanWhiteNodes(bool aF
     }
 
     if (pi->mInternalRefs == pi->mRefCount || pi->IsGrayJS()) {
       pi->mColor = white;
       ++mWhiteNodeCount;
       continue;
     }
 
-    if (pi->mInternalRefs > pi->mRefCount) {
-#ifdef MOZ_CRASHREPORTER
-      const char* piName = "Unknown";
-      if (pi->mParticipant) {
-        piName = pi->mParticipant->ClassName();
-      }
-      nsPrintfCString msg("More references to an object than its refcount, for class %s", piName);
-      CrashReporter::AnnotateCrashReport(NS_LITERAL_CSTRING("CycleCollector"), msg);
-#endif
-      MOZ_CRASH();
-    }
+    pi->AnnotatedReleaseAssert(pi->mInternalRefs <= pi->mRefCount,
+                               "More references to an object than its refcount");
 
     // This node will get marked black in the next pass.
   }
 }
 
 // Any remaining grey nodes that haven't already been deleted must be alive,
 // so mark them and their children black. Any nodes that are black must have
 // already had their children marked black, so there's no need to look at them