Bug 665564 - change DescribeNode to DescribeRefCountedNode to remove CCNodeType. r=bent

This commit is contained in:
Andrew McCreight 2011-06-23 14:10:52 -07:00
parent ef5097944c
commit 8795ae8744
10 changed files with 89 additions and 75 deletions

View File

@ -5362,10 +5362,14 @@ public:
mFlags = WANT_ALL_TRACES;
}
NS_IMETHOD_(void) DescribeNode(CCNodeType type,
nsrefcnt refcount,
size_t objsz,
const char* objname)
NS_IMETHOD_(void) DescribeRefCountedNode(nsrefcnt refCount,
size_t objSz,
const char *objName)
{
}
NS_IMETHOD_(void) DescribeGCedNode(PRBool isMarked,
size_t objSz,
const char *objName)
{
}
NS_IMETHOD_(void) NoteXPCOMRoot(nsISupports *root)

View File

@ -1808,11 +1808,10 @@ NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN_INTERNAL(nsDocument)
else {
PR_snprintf(name, sizeof(name), "nsDocument %s", uri.get());
}
cb.DescribeNode(RefCounted, tmp->mRefCnt.get(), sizeof(nsDocument), name);
cb.DescribeRefCountedNode(tmp->mRefCnt.get(), sizeof(nsDocument), name);
}
else {
cb.DescribeNode(RefCounted, tmp->mRefCnt.get(), sizeof(nsDocument),
"nsDocument");
NS_IMPL_CYCLE_COLLECTION_DESCRIBE(nsDocument, tmp->mRefCnt.get())
}
// Always need to traverse script objects, so do that before we check

View File

@ -4182,12 +4182,11 @@ NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN_INTERNAL(nsGenericElement)
else {
PR_snprintf(name, sizeof(name), "nsGenericElement %s", localName.get());
}
cb.DescribeNode(RefCounted, tmp->mRefCnt.get(), sizeof(nsGenericElement),
name);
cb.DescribeRefCountedNode(tmp->mRefCnt.get(), sizeof(nsGenericElement),
name);
}
else {
cb.DescribeNode(RefCounted, tmp->mRefCnt.get(), sizeof(nsGenericElement),
"nsGenericElement");
NS_IMPL_CYCLE_COLLECTION_DESCRIBE(nsGenericElement, tmp->mRefCnt.get())
}
// Always need to traverse script objects, so do that before we check

View File

@ -198,11 +198,10 @@ NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN_INTERNAL(nsNodeInfo)
PR_snprintf(name, sizeof(name), "nsNodeInfo %s", localName.get());
}
cb.DescribeNode(RefCounted, tmp->mRefCnt.get(), sizeof(nsNodeInfo), name);
cb.DescribeRefCountedNode(tmp->mRefCnt.get(), sizeof(nsNodeInfo), name);
}
else {
cb.DescribeNode(RefCounted, tmp->mRefCnt.get(), sizeof(nsNodeInfo),
"nsNodeInfo");
NS_IMPL_CYCLE_COLLECTION_DESCRIBE(nsNodeInfo, tmp->mRefCnt.get())
}
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NATIVE_MEMBER(mOwnerManager,

View File

@ -142,13 +142,12 @@ NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN_INTERNAL(nsJSScriptTimeoutHandler)
}
}
}
cb.DescribeNode(RefCounted, tmp->mRefCnt.get(),
sizeof(nsJSScriptTimeoutHandler), foo.get());
cb.DescribeRefCountedNode(tmp->mRefCnt.get(),
sizeof(nsJSScriptTimeoutHandler), foo.get());
}
else {
cb.DescribeNode(RefCounted, tmp->mRefCnt.get(),
sizeof(nsJSScriptTimeoutHandler),
"nsJSScriptTimeoutHandler");
NS_IMPL_CYCLE_COLLECTION_DESCRIBE(nsJSScriptTimeoutHandler,
tmp->mRefCnt.get())
}
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMPTR(mContext)

View File

@ -747,7 +747,7 @@ nsXPConnect::Traverse(void *p, nsCycleCollectionTraversalCallback &cb)
}
}
CCNodeType type;
PRBool isMarked;
#ifdef DEBUG_CC
// Note that the conditions under which we specify GCMarked vs.
@ -765,14 +765,13 @@ nsXPConnect::Traverse(void *p, nsCycleCollectionTraversalCallback &cb)
// ExplainLiveExpectedGarbage codepath
PLDHashEntryHdr* entry =
PL_DHashTableOperate(&mJSRoots, p, PL_DHASH_LOOKUP);
type = markJSObject || PL_DHASH_ENTRY_IS_BUSY(entry) ? GCMarked :
GCUnmarked;
isMarked = markJSObject || PL_DHASH_ENTRY_IS_BUSY(entry);
}
else
#endif
{
// Normal codepath (matches non-DEBUG_CC codepath).
type = !markJSObject && xpc_IsGrayGCThing(p) ? GCUnmarked : GCMarked;
isMarked = markJSObject || !xpc_IsGrayGCThing(p);
}
if (cb.WantDebugInfo()) {
@ -845,19 +844,19 @@ nsXPConnect::Traverse(void *p, nsCycleCollectionTraversalCallback &cb)
char fullname[100];
JS_snprintf(fullname, sizeof(fullname),
"%s (global=%p)", name, global);
cb.DescribeNode(type, 0, sizeof(JSObject), fullname);
cb.DescribeGCedNode(isMarked, sizeof(JSObject), fullname);
} else {
cb.DescribeNode(type, 0, sizeof(JSObject), name);
cb.DescribeGCedNode(isMarked, sizeof(JSObject), name);
}
} else {
cb.DescribeNode(type, 0, sizeof(JSObject), "JS Object");
cb.DescribeGCedNode(isMarked, sizeof(JSObject), "JS Object");
}
// There's no need to trace objects that have already been marked by the JS
// GC. Any JS objects hanging from them will already be marked. Only do this
// if DEBUG_CC is not defined, else we do want to know about all JS objects
// to get better graphs and explanations.
if(!cb.WantAllTraces() && type == GCMarked)
if(!cb.WantAllTraces() && isMarked)
return NS_OK;
TraversalTracer trc(cb);
@ -932,8 +931,7 @@ public:
// edges will ensure that any cycles this context is in won't be
// collected.
unsigned refCount = nsXPConnect::GetXPConnect()->GetOutstandingRequests(cx) + 1;
cb.DescribeNode(RefCounted, refCount, sizeof(JSContext), "JSContext");
NS_IMPL_CYCLE_COLLECTION_DESCRIBE(JSContext, refCount)
NS_CYCLE_COLLECTION_NOTE_EDGE_NAME(cb, "[global object]");
if (cx->globalObject) {
cb.NoteScriptChild(nsIProgrammingLanguage::JAVASCRIPT,

View File

@ -67,10 +67,9 @@ NS_CYCLE_COLLECTION_CLASSNAME(nsXPCWrappedJS)::Traverse
tmp->GetClass()->GetInterfaceName());
else
JS_snprintf(name, sizeof(name), "nsXPCWrappedJS");
cb.DescribeNode(RefCounted, refcnt, sizeof(nsXPCWrappedJS), name);
cb.DescribeRefCountedNode(refcnt, sizeof(nsXPCWrappedJS), name);
} else {
cb.DescribeNode(RefCounted, refcnt, sizeof(nsXPCWrappedJS),
"nsXPCWrappedJS");
NS_IMPL_CYCLE_COLLECTION_DESCRIBE(nsXPCWrappedJS, refcnt)
}
// nsXPCWrappedJS keeps its own refcount artificially at or above 1, see the

View File

@ -115,11 +115,10 @@ NS_CYCLE_COLLECTION_CLASSNAME(XPCWrappedNative)::Traverse(void *p,
else
JS_snprintf(name, sizeof(name), "XPCWrappedNative");
cb.DescribeNode(RefCounted, tmp->mRefCnt.get(),
sizeof(XPCWrappedNative), name);
cb.DescribeRefCountedNode(tmp->mRefCnt.get(),
sizeof(XPCWrappedNative), name);
} else {
cb.DescribeNode(RefCounted, tmp->mRefCnt.get(),
sizeof(XPCWrappedNative), "XPCWrappedNative");
NS_IMPL_CYCLE_COLLECTION_DESCRIBE(XPCWrappedNative, tmp->mRefCnt.get())
}
if(tmp->mRefCnt.get() > 1) {

View File

@ -1461,8 +1461,30 @@ public:
NS_IMETHOD_(void) NoteXPCOMRoot(nsISupports *root);
private:
NS_IMETHOD_(void) DescribeNode(CCNodeType type, nsrefcnt refCount,
size_t objSz, const char *objName);
void DescribeNode(PRUint32 refCount,
size_t objSz,
const char *objName)
{
#ifdef DEBUG_CC
mCurrPi->mBytes = objSz;
mCurrPi->mName = PL_strdup(objName);
#endif
if (mListener) {
mListener->NoteObject((PRUint64)mCurrPi->mPointer, objName);
}
mCurrPi->mRefCount = refCount;
#ifdef DEBUG_CC
sCollector->mStats.mVisitedNode++;
#endif
}
NS_IMETHOD_(void) DescribeRefCountedNode(nsrefcnt refCount, size_t objSz,
const char *objName);
NS_IMETHOD_(void) DescribeGCedNode(PRBool isMarked, size_t objSz,
const char *objName);
NS_IMETHOD_(void) NoteRoot(PRUint32 langID, void *child,
nsCycleCollectionParticipant* participant);
NS_IMETHOD_(void) NoteXPCOMChild(nsISupports *child);
@ -1594,32 +1616,22 @@ GCGraphBuilder::NoteRoot(PRUint32 langID, void *root,
}
NS_IMETHODIMP_(void)
GCGraphBuilder::DescribeNode(CCNodeType type, nsrefcnt refCount,
size_t objSz, const char *objName)
GCGraphBuilder::DescribeRefCountedNode(nsrefcnt refCount, size_t objSz,
const char *objName)
{
#ifdef DEBUG_CC
mCurrPi->mBytes = objSz;
mCurrPi->mName = PL_strdup(objName);
#endif
if (refCount == 0)
Fault("zero refcount", mCurrPi);
if (refCount == PR_UINT32_MAX)
Fault("overflowing refcount", mCurrPi);
DescribeNode(refCount, objSz, objName);
}
if (mListener) {
mListener->NoteObject((PRUint64)mCurrPi->mPointer, objName);
}
if (type == RefCounted) {
if (refCount == 0)
Fault("zero refcount", mCurrPi);
if (refCount == PR_UINT32_MAX)
Fault("overflowing refcount", mCurrPi);
mCurrPi->mRefCount = refCount;
}
else {
mCurrPi->mRefCount = type == GCMarked ? PR_UINT32_MAX : 0;
}
#ifdef DEBUG_CC
sCollector->mStats.mVisitedNode++;
#endif
NS_IMETHODIMP_(void)
GCGraphBuilder::DescribeGCedNode(PRBool isMarked, size_t objSz,
const char *objName)
{
PRUint32 refCount = isMarked ? PR_UINT32_MAX : 0;
DescribeNode(refCount, objSz, objName);
}
NS_IMETHODIMP_(void)
@ -2279,8 +2291,14 @@ public:
return mSuppressThisNode;
}
NS_IMETHOD_(void) DescribeNode(CCNodeType type, nsrefcnt refCount,
size_t objSz, const char *objName)
NS_IMETHOD_(void) DescribeRefCountedNode(nsrefcnt refCount, size_t objSz,
const char *objName)
{
mSuppressThisNode = (PL_strstr(sSuppressionList, objName) != nsnull);
}
NS_IMETHOD_(void) DescribeGCedNode(PRBool isMarked, size_t objSz,
const char *objName)
{
mSuppressThisNode = (PL_strstr(sSuppressionList, objName) != nsnull);
}

View File

@ -81,20 +81,19 @@ NS_DEFINE_STATIC_IID_ACCESSOR(nsCycleCollectionISupports,
class nsCycleCollectionParticipant;
enum CCNodeType { RefCounted, GCMarked, GCUnmarked };
class NS_NO_VTABLE nsCycleCollectionTraversalCallback
{
public:
// If type is RefCounted you must call DescribeNode() with an accurate
// You must call DescribeRefCountedNode() with an accurate
// refcount, otherwise cycle collection will fail, and probably crash.
// If type is not refcounted then the refcount will be ignored.
// If the callback cares about objsz or objname, it should
// put WANT_DEBUG_INFO in mFlags.
NS_IMETHOD_(void) DescribeNode(CCNodeType type,
nsrefcnt refcount,
size_t objsz,
const char *objname) = 0;
NS_IMETHOD_(void) DescribeRefCountedNode(nsrefcnt refcount,
size_t objsz,
const char *objname) = 0;
NS_IMETHOD_(void) DescribeGCedNode(PRBool ismarked,
size_t objsz,
const char *objname) = 0;
NS_IMETHOD_(void) NoteXPCOMRoot(nsISupports *root) = 0;
NS_IMETHOD_(void) NoteRoot(PRUint32 langID, void *root,
nsCycleCollectionParticipant* helper) = 0;
@ -112,8 +111,9 @@ public:
enum {
// Values for flags:
// Caller should pass useful objsz and objname to DescribeNode
// and should call NoteNextEdgeName.
// Caller should pass useful objsz and objname to
// DescribeRefCountedNode and DescribeGCedNode and should call
// NoteNextEdgeName.
WANT_DEBUG_INFO = (1<<0),
// Caller should not skip objects that we know will be
@ -307,7 +307,7 @@ public:
///////////////////////////////////////////////////////////////////////////////
#define NS_IMPL_CYCLE_COLLECTION_DESCRIBE(_class, _refcnt) \
cb.DescribeNode(RefCounted, _refcnt, sizeof(_class), #_class);
cb.DescribeRefCountedNode(_refcnt, sizeof(_class), #_class);
#define NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN_INTERNAL(_class) \
NS_IMETHODIMP \