From f6aefae288d31b408ea0a073490507cbfc7af6b0 Mon Sep 17 00:00:00 2001 From: Olli Pettay Date: Tue, 12 Nov 2013 00:12:00 +0200 Subject: [PATCH] Bug 937303 - Make CC logger to pass information about compartments, r=mccr8 --HG-- extra : rebase_source : 48545d4c83d88f34773ca84e542aa13316ca38c6 --- xpcom/base/CycleCollectedJSRuntime.cpp | 4 ++- xpcom/base/nsCycleCollector.cpp | 32 +++++++++++++------ xpcom/base/nsICycleCollectorListener.idl | 10 +++--- .../glue/nsCycleCollectionTraversalCallback.h | 4 ++- 4 files changed, 34 insertions(+), 16 deletions(-) diff --git a/xpcom/base/CycleCollectedJSRuntime.cpp b/xpcom/base/CycleCollectedJSRuntime.cpp index 1956832e024..1358d4aa40d 100644 --- a/xpcom/base/CycleCollectedJSRuntime.cpp +++ b/xpcom/base/CycleCollectedJSRuntime.cpp @@ -518,8 +518,10 @@ CycleCollectedJSRuntime::DescribeGCThing(bool aIsMarked, void* aThing, } char name[72]; + uint64_t compartmentAddress = 0; if (aTraceKind == JSTRACE_OBJECT) { JSObject* obj = static_cast(aThing); + compartmentAddress = (uint64_t)js::GetObjectCompartment(obj); const js::Class* clasp = js::GetObjectClass(obj); // Give the subclass a chance to do something @@ -555,7 +557,7 @@ CycleCollectedJSRuntime::DescribeGCThing(bool aIsMarked, void* aThing, } // Disable printing global for objects while we figure out ObjShrink fallout. - aCb.DescribeGCedNode(aIsMarked, name); + aCb.DescribeGCedNode(aIsMarked, name, compartmentAddress); } void diff --git a/xpcom/base/nsCycleCollector.cpp b/xpcom/base/nsCycleCollector.cpp index 16073d487bc..9eacc50b854 100644 --- a/xpcom/base/nsCycleCollector.cpp +++ b/xpcom/base/nsCycleCollector.cpp @@ -1115,7 +1115,7 @@ GraphWalker::DoWalk(nsDeque &aQueue) struct CCGraphDescriber : public LinkedListElement { CCGraphDescriber() - : mAddress("0x"), mToAddress("0x"), mCnt(0), mType(eUnknown) {} + : mAddress("0x"), mCnt(0), mType(eUnknown) {} enum Type { @@ -1129,8 +1129,8 @@ struct CCGraphDescriber : public LinkedListElement }; nsCString mAddress; - nsCString mToAddress; nsCString mName; + nsCString mCompartmentOrToAddress; uint32_t mCnt; Type mType; }; @@ -1290,7 +1290,8 @@ public: return NS_OK; } NS_IMETHOD NoteGCedObject(uint64_t aAddress, bool aMarked, - const char *aObjectDescription) + const char *aObjectDescription, + uint64_t aCompartmentAddress) { if (!mDisableLog) { fprintf(mStream, "%p [gc%s] %s\n", (void*)aAddress, @@ -1305,6 +1306,12 @@ public: CCGraphDescriber::eGCedObject; d->mAddress = mCurrentAddress; d->mName.Append(aObjectDescription); + if (aCompartmentAddress) { + d->mCompartmentOrToAddress.AssignLiteral("0x"); + d->mCompartmentOrToAddress.AppendInt(aCompartmentAddress, 16); + } else { + d->mCompartmentOrToAddress.SetIsVoid(true); + } } return NS_OK; } @@ -1318,7 +1325,8 @@ public: mDescribers.insertBack(d); d->mType = CCGraphDescriber::eEdge; d->mAddress = mCurrentAddress; - d->mToAddress.AppendInt(aToAddress, 16); + d->mCompartmentOrToAddress.AssignLiteral("0x"); + d->mCompartmentOrToAddress.AppendInt(aToAddress, 16); d->mName.Append(aEdgeName); } return NS_OK; @@ -1421,11 +1429,12 @@ public: aHandler->NoteGCedObject(d->mAddress, d->mType == CCGraphDescriber::eGCMarkedObject, - d->mName); + d->mName, + d->mCompartmentOrToAddress); break; case CCGraphDescriber::eEdge: aHandler->NoteEdge(d->mAddress, - d->mToAddress, + d->mCompartmentOrToAddress, d->mName); break; case CCGraphDescriber::eRoot: @@ -1598,7 +1607,8 @@ public: // nsCycleCollectionTraversalCallback methods. NS_IMETHOD_(void) DescribeRefCountedNode(nsrefcnt refCount, const char *objName); - NS_IMETHOD_(void) DescribeGCedNode(bool isMarked, const char *objName); + NS_IMETHOD_(void) DescribeGCedNode(bool isMarked, const char *objName, + uint64_t aCompartmentAddress); NS_IMETHOD_(void) NoteXPCOMChild(nsISupports *child); NS_IMETHOD_(void) NoteJSChild(void *child); @@ -1782,14 +1792,15 @@ GCGraphBuilder::DescribeRefCountedNode(nsrefcnt refCount, const char *objName) } NS_IMETHODIMP_(void) -GCGraphBuilder::DescribeGCedNode(bool isMarked, const char *objName) +GCGraphBuilder::DescribeGCedNode(bool isMarked, const char *objName, + uint64_t aCompartmentAddress) { uint32_t refCount = isMarked ? UINT32_MAX : 0; mCollector->mVisitedGCed++; if (mListener) { mListener->NoteGCedObject((uint64_t)mCurrPi->mPointer, isMarked, - objName); + objName, aCompartmentAddress); } DescribeNode(refCount, objName); @@ -1923,7 +1934,8 @@ public: NS_IMETHOD_(void) DescribeRefCountedNode(nsrefcnt refcount, const char *objname) {} NS_IMETHOD_(void) DescribeGCedNode(bool ismarked, - const char *objname) {} + const char *objname, + uint64_t aCompartmentAddress) {} NS_IMETHOD_(void) NoteNextEdgeName(const char* name) {} bool MayHaveChild() { return mMayHaveChild; diff --git a/xpcom/base/nsICycleCollectorListener.idl b/xpcom/base/nsICycleCollectorListener.idl index 1ee71f8d495..91f15694da1 100644 --- a/xpcom/base/nsICycleCollectorListener.idl +++ b/xpcom/base/nsICycleCollectorListener.idl @@ -4,7 +4,7 @@ #include "nsISupports.idl" -[scriptable, uuid(0ef15f15-7783-4991-af68-4976d7ec2267)] +[scriptable, uuid(39a8f80e-7eee-4141-b9ef-6e2a7d6e466d)] interface nsICycleCollectorHandler : nsISupports { void noteRefCountedObject(in ACString aAddress, @@ -12,7 +12,8 @@ interface nsICycleCollectorHandler : nsISupports in ACString aObjectDescription); void noteGCedObject(in ACString aAddress, in boolean aMarked, - in ACString aObjectDescription); + in ACString aObjectDescription, + in ACString aCompartmentAddress); void noteEdge(in ACString aFromAddress, in ACString aToAddress, in ACString aEdgeName); @@ -34,7 +35,7 @@ interface nsICycleCollectorHandler : nsISupports * a call to end(). If begin() returns an error none of the other * functions will be called. */ -[scriptable, builtinclass, uuid(32a3ab19-82a3-4096-a12a-de37274f51c3)] +[scriptable, builtinclass, uuid(7096e77d-7834-4996-b52c-50564144d4be)] interface nsICycleCollectorListener : nsISupports { nsICycleCollectorListener allTraces(); @@ -55,7 +56,8 @@ interface nsICycleCollectorListener : nsISupports in string aObjectDescription); void noteGCedObject (in unsigned long long aAddress, in boolean aMarked, - in string aObjectDescription); + in string aObjectDescription, + in unsigned long long aCompartmentAddress); void noteEdge(in unsigned long long aToAddress, in string aEdgeName); void noteWeakMapEntry(in unsigned long long aMap, diff --git a/xpcom/glue/nsCycleCollectionTraversalCallback.h b/xpcom/glue/nsCycleCollectionTraversalCallback.h index 8bf7b41da8c..d90ba694a71 100644 --- a/xpcom/glue/nsCycleCollectionTraversalCallback.h +++ b/xpcom/glue/nsCycleCollectionTraversalCallback.h @@ -19,8 +19,10 @@ public: // WANT_DEBUG_INFO in mFlags. NS_IMETHOD_(void) DescribeRefCountedNode(nsrefcnt refcount, const char* objname) = 0; + // Note, aCompartmentAddress is 0 if it is unknown. NS_IMETHOD_(void) DescribeGCedNode(bool ismarked, - const char* objname) = 0; + const char* objname, + uint64_t aCompartmentAddress = 0) = 0; NS_IMETHOD_(void) NoteXPCOMChild(nsISupports *child) = 0; NS_IMETHOD_(void) NoteJSChild(void *child) = 0;