Issue #1691 - Part 10: Add and use method to annotate CC crashes with a class name. https://bugzilla.mozilla.org/show_bug.cgi?id=1277260 Make PtrInfo into a class and mark it final. Also fix an erroneous debug assert because mBaseURL not set in one code path.

(cherry picked from commit a1890054011adf0cf87be0d56047418c9f201420)
This commit is contained in:
Brian Smith 2023-04-21 19:10:43 -05:00 • committed by roytam1
commit 7e056a6f72
2 changed files with 33 additions and 9 deletions

View file

@ -1764,11 +1764,11 @@ ScriptLoader::ProcessScriptElement(nsIScriptElement *aElement)
MOZ_ASSERT_IF(!request->IsModuleRequest(), !aElement->GetScriptAsync()); MOZ_ASSERT_IF(!request->IsModuleRequest(), !aElement->GetScriptAsync());
request->SetScriptMode(false, aElement->GetScriptAsync()); request->SetScriptMode(false, aElement->GetScriptAsync());
request->mBaseURL = mDocument->GetDocBaseURI();
if (request->IsModuleRequest()) { if (request->IsModuleRequest()) {
ModuleLoadRequest* modReq = request->AsModuleRequest(); ModuleLoadRequest* modReq = request->AsModuleRequest();
request->mBaseURL = mDocument->GetDocBaseURI();
if (aElement->GetScriptAsync()) { if (aElement->GetScriptAsync()) {
AddAsyncRequest(modReq); AddAsyncRequest(modReq);
} else { } else {

View file

@ -337,7 +337,7 @@ public:
// Base types // Base types
//////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////
struct PtrInfo; class PtrInfo;
class EdgePool class EdgePool
{ {
@ -533,13 +533,15 @@ enum NodeColor { black, white, grey };
// hundreds of thousands of them to be allocated and touched // hundreds of thousands of them to be allocated and touched
// repeatedly during each cycle collection. // repeatedly during each cycle collection.
struct PtrInfo class PtrInfo final
{ {
public:
void* mPointer; void* mPointer;
nsCycleCollectionParticipant* mParticipant; nsCycleCollectionParticipant* mParticipant;
uint32_t mColor : 2; uint32_t mColor : 2;
uint32_t mInternalRefs : 30; uint32_t mInternalRefs : 30;
uint32_t mRefCount; uint32_t mRefCount;
private: private:
EdgePool::Iterator mFirstChild; EdgePool::Iterator mFirstChild;
@ -609,8 +611,29 @@ public:
CC_GRAPH_ASSERT(aLastChild.Initialized()); CC_GRAPH_ASSERT(aLastChild.Initialized());
(this + 1)->mFirstChild = aLastChild; (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 * A structure designed to be used like a linked list of PtrInfo, except
* it allocates many PtrInfos at a time. * it allocates many PtrInfos at a time.
@ -2297,8 +2320,10 @@ CCGraphBuilder::NoteNativeRoot(void* aRoot,
NS_IMETHODIMP_(void) NS_IMETHODIMP_(void)
CCGraphBuilder::DescribeRefCountedNode(nsrefcnt aRefCount, const char* aObjName) CCGraphBuilder::DescribeRefCountedNode(nsrefcnt aRefCount, const char* aObjName)
{ {
MOZ_RELEASE_ASSERT(aRefCount != 0, "CCed refcounted object has zero refcount"); mCurrPi->AnnotatedReleaseAssert(aRefCount != 0,
MOZ_RELEASE_ASSERT(aRefCount != UINT32_MAX, "CCed refcounted object has overflowing refcount"); "CCed refcounted object has zero refcount");
mCurrPi->AnnotatedReleaseAssert(aRefCount != UINT32_MAX,
"CCed refcounted object has overflowing refcount");
mResults.mVisitedRefCounted++; mResults.mVisitedRefCounted++;
@ -3112,9 +3137,8 @@ nsCycleCollector::ScanWhiteNodes(bool aFullySynchGraphBuild)
continue; continue;
} }
if (pi->mInternalRefs > pi->mRefCount) { pi->AnnotatedReleaseAssert(pi->mInternalRefs <= pi->mRefCount,
MOZ_CRASH(); "More references to an object than its refcount");
}
// This node will get marked black in the next pass. // This node will get marked black in the next pass.
} }