Bug 1277260, part 2 - Add and use method to annotate CC crashes with a class name. r=rweiss+418169,smaug
authorAndrew McCreight <continuation@gmail.com>
Fri, 15 Sep 2017 13:00:17 -0700
changeset 383684 e331b951c34705c1bfd940e3d00249bb3c3a9760
parent 383683 36de9e91851fe85b73574686174490a573c7884b
child 383685 a49d2fffbeb7c6a719d934c39c07870aad45c331
push id95615
push userarchaeopteryx@coole-files.de
push dateFri, 29 Sep 2017 11:32:50 +0000
treeherdermozilla-inbound@64949972673f [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersrweiss
bugs1277260, 418169
milestone58.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 1277260, part 2 - Add and use method to annotate CC crashes with a class name. r=rweiss+418169,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
@@ -2367,18 +2388,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);
   }
 
@@ -3199,27 +3222,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