summaryrefslogtreecommitdiff
path: root/xpcom/base/nsCycleCollector.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'xpcom/base/nsCycleCollector.cpp')
-rw-r--r--xpcom/base/nsCycleCollector.cpp38
1 files changed, 31 insertions, 7 deletions
diff --git a/xpcom/base/nsCycleCollector.cpp b/xpcom/base/nsCycleCollector.cpp
index 8df3c3a6bc..2e5804929e 100644
--- a/xpcom/base/nsCycleCollector.cpp
+++ b/xpcom/base/nsCycleCollector.cpp
@@ -337,7 +337,7 @@ public:
// Base types
////////////////////////////////////////////////////////////////////////
-struct PtrInfo;
+class PtrInfo;
class EdgePool
{
@@ -533,13 +533,15 @@ enum NodeColor { black, white, grey };
// hundreds of thousands of them to be allocated and touched
// repeatedly during each cycle collection.
-struct PtrInfo
+class PtrInfo final
{
+public:
void* mPointer;
nsCycleCollectionParticipant* mParticipant;
uint32_t mColor : 2;
uint32_t mInternalRefs : 30;
uint32_t mRefCount;
+
private:
EdgePool::Iterator mFirstChild;
@@ -609,8 +611,29 @@ public:
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.
@@ -2294,8 +2317,10 @@ CCGraphBuilder::NoteNativeRoot(void* aRoot,
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++;
@@ -3109,9 +3134,8 @@ nsCycleCollector::ScanWhiteNodes(bool aFullySynchGraphBuild)
continue;
}
- if (pi->mInternalRefs > pi->mRefCount) {
- 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.
}