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 665660 6a7daf1c4d07a5985e7f90f97243c5d039cd7018
parent 665659 6d6a195e4b721b557a52f06668058cd224308932
child 665661 7d56a7dd6a4f7ba685307e3a37e29c303bdc9698
push id80133
push userbmo:continuation@gmail.com
push dateFri, 15 Sep 2017 20:21:50 +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