Bug 744103, part 2 - Change NoteScriptChild to NoteJSChild. r=smaug

This commit is contained in:
Andrew McCreight 2012-05-03 12:28:10 -07:00
parent 8f2a67acb2
commit 38b851ba07
17 changed files with 75 additions and 101 deletions

View File

@ -6086,10 +6086,9 @@ public:
nsCycleCollectionParticipant* helper)
{
}
NS_IMETHOD_(void) NoteScriptChild(PRUint32 langID, void* child)
NS_IMETHOD_(void) NoteJSChild(void* child)
{
if (langID == nsIProgrammingLanguage::JAVASCRIPT &&
child == mWrapper) {
if (child == mWrapper) {
mFound = true;
}
}
@ -6116,12 +6115,11 @@ private:
};
static void
DebugWrapperTraceCallback(PRUint32 langID, void *p, const char *name,
void *closure)
DebugWrapperTraceCallback(void *p, const char *name, void *closure)
{
DebugWrapperTraversalCallback* callback =
static_cast<DebugWrapperTraversalCallback*>(closure);
callback->NoteScriptChild(langID, p);
callback->NoteJSChild(p);
}
// static
@ -6639,8 +6637,7 @@ nsContentUtils::TraceWrapper(nsWrapperCache* aCache, TraceCallback aCallback,
if (aCache->PreservingWrapper()) {
JSObject *wrapper = aCache->GetWrapperPreserveColor();
if (wrapper) {
aCallback(nsIProgrammingLanguage::JAVASCRIPT, wrapper,
"Preserved wrapper", aClosure);
aCallback(wrapper, "Preserved wrapper", aClosure);
}
}
}

View File

@ -494,12 +494,10 @@ NS_IMPL_CYCLE_COLLECTION_TRACE_BEGIN(nsXBLDocumentInfo)
NS_IMPL_CYCLE_COLLECTION_TRACE_END
static void
UnmarkXBLJSObject(PRUint32 aLangID, void* aP, const char* aName, void* aClosure)
UnmarkXBLJSObject(void* aP, const char* aName, void* aClosure)
{
if (aLangID == nsIProgrammingLanguage::JAVASCRIPT) {
xpc_UnmarkGrayObject(static_cast<JSObject*>(aP));
}
}
static bool
UnmarkProtos(nsHashKey* aKey, void* aData, void* aClosure)

View File

@ -263,7 +263,7 @@ void
nsXBLProtoImplMethod::Trace(TraceCallback aCallback, void *aClosure) const
{
if (IsCompiled() && mJSMethodObject) {
aCallback(nsIProgrammingLanguage::JAVASCRIPT, mJSMethodObject, "mJSMethodObject", aClosure);
aCallback(mJSMethodObject, "mJSMethodObject", aClosure);
}
}

View File

@ -344,13 +344,11 @@ void
nsXBLProtoImplProperty::Trace(TraceCallback aCallback, void *aClosure) const
{
if (mJSAttributes & JSPROP_GETTER) {
aCallback(nsIProgrammingLanguage::JAVASCRIPT, mJSGetterObject,
"mJSGetterObject", aClosure);
aCallback(mJSGetterObject, "mJSGetterObject", aClosure);
}
if (mJSAttributes & JSPROP_SETTER) {
aCallback(nsIProgrammingLanguage::JAVASCRIPT, mJSSetterObject,
"mJSSetterObject", aClosure);
aCallback(mJSSetterObject, "mJSSetterObject", aClosure);
}
}

View File

@ -1353,8 +1353,7 @@ static PLDHashOperator
TraceXBLHandlers(nsXBLPrototypeHandler* aKey, JSObject* aData, void* aClosure)
{
TraceData* data = static_cast<TraceData*>(aClosure);
data->callback(nsIProgrammingLanguage::JAVASCRIPT, aData,
"Cached XBL prototype handler", data->closure);
data->callback(aData, "Cached XBL prototype handler", data->closure);
return PL_DHASH_NEXT;
}

View File

@ -3946,8 +3946,7 @@ NS_IMPL_CYCLE_COLLECTION_TRACE_BEGIN(nsJSArgArray)
jsval *end;
for (end = argv + tmp->mArgc; argv < end; ++argv) {
if (JSVAL_IS_GCTHING(*argv))
NS_IMPL_CYCLE_COLLECTION_TRACE_CALLBACK(JAVASCRIPT,
JSVAL_TO_GCTHING(*argv),
NS_IMPL_CYCLE_COLLECTION_TRACE_JS_CALLBACK(JSVAL_TO_GCTHING(*argv),
"mArgv[i]")
}
}

View File

@ -110,10 +110,8 @@ NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN(nsJSEventListener)
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
NS_IMPL_CYCLE_COLLECTION_TRACE_BEGIN(nsJSEventListener)
NS_IMPL_CYCLE_COLLECTION_TRACE_MEMBER_CALLBACK(nsIProgrammingLanguage::JAVASCRIPT,
mScopeObject)
NS_IMPL_CYCLE_COLLECTION_TRACE_MEMBER_CALLBACK(nsIProgrammingLanguage::JAVASCRIPT,
mHandler)
NS_IMPL_CYCLE_COLLECTION_TRACE_JS_MEMBER_CALLBACK(mScopeObject)
NS_IMPL_CYCLE_COLLECTION_TRACE_JS_MEMBER_CALLBACK(mHandler)
NS_IMPL_CYCLE_COLLECTION_TRACE_END
NS_IMPL_CYCLE_COLLECTION_CAN_SKIP_BEGIN(nsJSEventListener)

View File

@ -363,14 +363,11 @@ void XPCJSRuntime::TraceGrayJS(JSTracer* trc, void* data)
}
static void
TraceJSObject(PRUint32 aLangID, void *aScriptThing, const char *name,
void *aClosure)
TraceJSObject(void *aScriptThing, const char *name, void *aClosure)
{
if (aLangID == nsIProgrammingLanguage::JAVASCRIPT) {
JS_CALL_TRACER(static_cast<JSTracer*>(aClosure), aScriptThing,
js_GetGCThingTraceKind(aScriptThing), name);
}
}
static JSDHashOperator
TraceJSHolder(JSDHashTable *table, JSDHashEntryHdr *hdr, uint32_t number,
@ -441,16 +438,14 @@ struct Closure
};
static void
CheckParticipatesInCycleCollection(PRUint32 aLangID, void *aThing,
const char *name, void *aClosure)
CheckParticipatesInCycleCollection(void *aThing, const char *name, void *aClosure)
{
Closure *closure = static_cast<Closure*>(aClosure);
if (closure->cycleCollectionEnabled)
return;
if (aLangID == nsIProgrammingLanguage::JAVASCRIPT &&
AddToCCKind(js_GetGCThingTraceKind(aThing)) &&
if (AddToCCKind(js_GetGCThingTraceKind(aThing)) &&
xpc_IsGrayGCThing(aThing))
{
closure->cycleCollectionEnabled = true;

View File

@ -120,8 +120,7 @@ NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN(XPCVariant)
jsval val = tmp->GetJSValPreserveColor();
if (JSVAL_IS_OBJECT(val)) {
NS_CYCLE_COLLECTION_NOTE_EDGE_NAME(cb, "mJSVal");
cb.NoteScriptChild(nsIProgrammingLanguage::JAVASCRIPT,
JSVAL_TO_OBJECT(val));
cb.NoteJSChild(JSVAL_TO_OBJECT(val));
}
nsVariant::Traverse(tmp->mData, cb);

View File

@ -82,8 +82,7 @@ NS_CYCLE_COLLECTION_CLASSNAME(nsXPCWrappedJS)::Traverse
// nsXPCWrappedJS roots its mJSObj when its refcount is > 1, see
// the comment above nsXPCWrappedJS::AddRef.
NS_CYCLE_COLLECTION_NOTE_EDGE_NAME(cb, "mJSObj");
cb.NoteScriptChild(nsIProgrammingLanguage::JAVASCRIPT,
tmp->GetJSObjectPreserveColor());
cb.NoteJSChild(tmp->GetJSObjectPreserveColor());
}
nsXPCWrappedJS* root = tmp->GetRootWrapper();

View File

@ -119,7 +119,7 @@ NS_CYCLE_COLLECTION_CLASSNAME(XPCWrappedNative)::Traverse(void *p,
JSObject *obj = tmp->GetFlatJSObjectPreserveColor();
NS_CYCLE_COLLECTION_NOTE_EDGE_NAME(cb, "mFlatJSObject");
cb.NoteScriptChild(nsIProgrammingLanguage::JAVASCRIPT, obj);
cb.NoteJSChild(obj);
}
if (tmp->MightHaveExpandoObject()) {
@ -129,8 +129,7 @@ NS_CYCLE_COLLECTION_CLASSNAME(XPCWrappedNative)::Traverse(void *p,
xpc::CompartmentPrivate *priv = (xpc::CompartmentPrivate *)
JS_GetCompartmentPrivate(r.front());
NS_CYCLE_COLLECTION_NOTE_EDGE_NAME(cb, "XPCWrappedNative expando object");
cb.NoteScriptChild(nsIProgrammingLanguage::JAVASCRIPT,
priv->LookupExpandoObjectPreserveColor(tmp));
cb.NoteJSChild(priv->LookupExpandoObjectPreserveColor(tmp));
}
}

View File

@ -581,8 +581,12 @@ nsXPConnect::FinishTraverse()
nsCycleCollectionParticipant *
nsXPConnect::ToParticipant(void *p)
{
if (!AddToCCKind(js_GetGCThingTraceKind(p)))
return NULL;
return this;
}
nsCycleCollectionParticipant *
nsXPConnect::GetParticipant()
{
return this;
}
@ -746,7 +750,7 @@ NoteJSChild(JSTracer *trc, void **thingp, JSGCTraceKind kind)
}
}
#endif
tracer->cb.NoteScriptChild(nsIProgrammingLanguage::JAVASCRIPT, thing);
tracer->cb.NoteJSChild(thing);
} else if (kind == JSTRACE_SHAPE) {
JS_TraceShapeCycleCollectorChildren(trc, thing);
} else if (kind != JSTRACE_STRING) {
@ -962,7 +966,7 @@ public:
cb.DescribeRefCountedNode(refCount, js::SizeOfJSContext(), "JSContext");
if (JSObject *global = JS_GetGlobalObject(cx)) {
NS_CYCLE_COLLECTION_NOTE_EDGE_NAME(cb, "[global object]");
cb.NoteScriptChild(nsIProgrammingLanguage::JAVASCRIPT, global);
cb.NoteJSChild(global);
}
return NS_OK;

View File

@ -478,6 +478,7 @@ public:
virtual nsresult BeginCycleCollection(nsCycleCollectionTraversalCallback &cb);
virtual nsresult FinishTraverse();
virtual nsCycleCollectionParticipant *ToParticipant(void *p);
virtual nsCycleCollectionParticipant *GetParticipant();
virtual bool NeedCollect();
virtual void Collect(PRUint32 reason, PRUint32 kind);

View File

@ -538,6 +538,7 @@ public:
mLangID(aLangID)
#endif
{
MOZ_ASSERT(aParticipant);
}
#ifdef DEBUG_CC
@ -1671,12 +1672,14 @@ private:
PLDHashTable mPtrToNodeMap;
PtrInfo *mCurrPi;
nsCycleCollectionLanguageRuntime **mRuntimes; // weak, from nsCycleCollector
nsCycleCollectionParticipant *mJSParticipant;
nsCString mNextEdgeName;
nsICycleCollectorListener *mListener;
public:
GCGraphBuilder(GCGraph &aGraph,
nsCycleCollectionLanguageRuntime **aRuntimes,
nsCycleCollectionJSRuntime *aJSRuntime,
nsICycleCollectorListener *aListener);
~GCGraphBuilder();
bool Initialized();
@ -1720,10 +1723,12 @@ private:
const char *objName);
NS_IMETHOD_(void) NoteRoot(PRUint32 langID, void *child,
nsCycleCollectionParticipant* participant);
NS_IMETHOD_(void) NoteXPCOMChild(nsISupports *child);
NS_IMETHOD_(void) NoteJSChild(void *child);
NS_IMETHOD_(void) NoteNativeChild(void *child,
nsCycleCollectionParticipant *participant);
NS_IMETHOD_(void) NoteScriptChild(PRUint32 langID, void *child);
NS_IMETHOD_(void) NoteNextEdgeName(const char* name);
NS_IMETHOD_(void) NoteWeakMapping(void *map, void *key, void *val);
private:
@ -1743,17 +1748,23 @@ private:
GCGraphBuilder::GCGraphBuilder(GCGraph &aGraph,
nsCycleCollectionLanguageRuntime **aRuntimes,
nsCycleCollectionJSRuntime *aJSRuntime,
nsICycleCollectorListener *aListener)
: mNodeBuilder(aGraph.mNodes),
mEdgeBuilder(aGraph.mEdges),
mWeakMaps(aGraph.mWeakMaps),
mRuntimes(aRuntimes),
mJSParticipant(nsnull),
mListener(aListener)
{
if (!PL_DHashTableInit(&mPtrToNodeMap, &PtrNodeOps, nsnull,
sizeof(PtrToNodeEntry), 32768))
mPtrToNodeMap.ops = nsnull;
if (aJSRuntime) {
mJSParticipant = aJSRuntime->GetParticipant();
}
PRUint32 flags = 0;
#ifdef DEBUG_CC
flags = nsCycleCollectionTraversalCallback::WANT_DEBUG_INFO |
@ -1945,36 +1956,22 @@ GCGraphBuilder::NoteNativeChild(void *child,
}
NS_IMETHODIMP_(void)
GCGraphBuilder::NoteScriptChild(PRUint32 langID, void *child)
GCGraphBuilder::NoteJSChild(void *child)
{
if (!child) {
return;
}
nsCString edgeName;
if (WantDebugInfo()) {
if (NS_UNLIKELY(WantDebugInfo())) {
edgeName.Assign(mNextEdgeName);
mNextEdgeName.Truncate();
}
if (!child)
return;
if (langID > nsIProgrammingLanguage::MAX) {
Fault("traversing pointer for unknown language", child);
return;
if (xpc_GCThingIsGrayCCThing(child) || NS_UNLIKELY(WantAllTraces())) {
NoteChild(child, mJSParticipant, nsIProgrammingLanguage::JAVASCRIPT,
edgeName);
}
if (!mRuntimes[langID]) {
NS_WARNING("Not collecting cycles involving objects for scripting "
"languages that don't participate in cycle collection.");
return;
}
// skip over non-grey JS children
if (langID == nsIProgrammingLanguage::JAVASCRIPT &&
!xpc_GCThingIsGrayCCThing(child) && !WantAllTraces()) {
return;
}
nsCycleCollectionParticipant *cp = mRuntimes[langID]->ToParticipant(child);
if (cp)
NoteChild(child, cp, langID, edgeName);
}
NS_IMETHODIMP_(void)
@ -1988,15 +1985,12 @@ GCGraphBuilder::NoteNextEdgeName(const char* name)
PtrInfo*
GCGraphBuilder::AddWeakMapNode(void *node)
{
nsCycleCollectionParticipant *cp;
NS_ASSERTION(node, "Weak map node should be non-null.");
if (!xpc_GCThingIsGrayCCThing(node) && !WantAllTraces())
return nsnull;
cp = mRuntimes[nsIProgrammingLanguage::JAVASCRIPT]->ToParticipant(node);
NS_ASSERTION(cp, "Javascript runtime participant should be non-null.");
return AddNode(node, cp, nsIProgrammingLanguage::JAVASCRIPT);
return AddNode(node, mJSParticipant, nsIProgrammingLanguage::JAVASCRIPT);
}
NS_IMETHODIMP_(void)
@ -2025,7 +2019,7 @@ public:
NS_IMETHOD_(void) NoteXPCOMChild(nsISupports *child);
NS_IMETHOD_(void) NoteNativeChild(void *child,
nsCycleCollectionParticipant *helper);
NS_IMETHOD_(void) NoteScriptChild(PRUint32 langID, void *child);
NS_IMETHOD_(void) NoteJSChild(void *child);
NS_IMETHOD_(void) DescribeRefCountedNode(nsrefcnt refcount,
size_t objsz,
@ -2065,15 +2059,11 @@ ChildFinder::NoteNativeChild(void *child,
};
NS_IMETHODIMP_(void)
ChildFinder::NoteScriptChild(PRUint32 langID, void *child)
ChildFinder::NoteJSChild(void *child)
{
if (!child)
return;
if (langID == nsIProgrammingLanguage::JAVASCRIPT &&
!xpc_GCThingIsGrayCCThing(child)) {
return;
}
if (child && xpc_GCThingIsGrayCCThing(child)) {
mMayHaveChild = true;
}
};
static bool
@ -2726,7 +2716,7 @@ public:
NS_IMETHOD_(void) NoteRoot(PRUint32 langID, void *root,
nsCycleCollectionParticipant* participant) {};
NS_IMETHOD_(void) NoteXPCOMChild(nsISupports *child) {}
NS_IMETHOD_(void) NoteScriptChild(PRUint32 langID, void *child) {}
NS_IMETHOD_(void) NoteJSChild(void *child) {}
NS_IMETHOD_(void) NoteNativeChild(void *child,
nsCycleCollectionParticipant *participant) {}
NS_IMETHOD_(void) NoteNextEdgeName(const char* name) {}
@ -3096,7 +3086,7 @@ nsCycleCollector::BeginCollection(nsICycleCollectorListener *aListener)
if (mParams.mDoNothing)
return false;
GCGraphBuilder builder(mGraph, mRuntimes, aListener);
GCGraphBuilder builder(mGraph, mRuntimes, mJSRuntime, aListener);
if (!builder.Initialized())
return false;
@ -3254,7 +3244,7 @@ nsCycleCollector::Shutdown()
Collect(nsnull, SHUTDOWN_COLLECTIONS(mParams), listener);
#ifdef DEBUG_CC
GCGraphBuilder builder(mGraph, mRuntimes, nsnull);
GCGraphBuilder builder(mGraph, mRuntimes, mJSRuntime, nsnull);
mScanInProgress = true;
SelectPurple(builder);
mScanInProgress = false;

View File

@ -117,6 +117,11 @@ struct nsCycleCollectionJSRuntime : public nsCycleCollectionLanguageRuntime
* |kind| is a nsGCType from nsIXPConnect.idl.
*/
virtual void Collect(PRUint32 reason, PRUint32 kind) = 0;
/**
* Get the JS cycle collection participant.
*/
virtual nsCycleCollectionParticipant *GetParticipant() = 0;
};
#ifdef DEBUG

View File

@ -39,13 +39,12 @@
#include "nsCOMPtr.h"
static void
NoteChild(PRUint32 aLangID, void *aScriptThing, const char *name,
void *aClosure)
NoteChild(void *aScriptThing, const char *name, void *aClosure)
{
nsCycleCollectionTraversalCallback *cb =
static_cast<nsCycleCollectionTraversalCallback*>(aClosure);
NS_CYCLE_COLLECTION_NOTE_EDGE_NAME(*cb, name);
cb->NoteScriptChild(aLangID, aScriptThing);
cb->NoteJSChild(aScriptThing);
}
void

View File

@ -93,13 +93,14 @@ public:
NS_IMETHOD_(void) NoteXPCOMRoot(nsISupports *root) = 0;
NS_IMETHOD_(void) NoteRoot(PRUint32 langID, void *root,
nsCycleCollectionParticipant* helper) = 0;
NS_IMETHOD_(void) NoteScriptChild(PRUint32 langID, void *child) = 0;
NS_IMETHOD_(void) NoteXPCOMChild(nsISupports *child) = 0;
NS_IMETHOD_(void) NoteJSChild(void *child) = 0;
NS_IMETHOD_(void) NoteNativeChild(void *child,
nsCycleCollectionParticipant *helper) = 0;
// Give a name to the edge associated with the next call to
// NoteScriptChild, NoteXPCOMChild, or NoteNativeChild.
// NoteXPCOMChild, NoteJSChild, or NoteNativeChild.
// Callbacks who care about this should set WANT_DEBUG_INFO in the
// flags.
NS_IMETHOD_(void) NoteNextEdgeName(const char* name) = 0;
@ -192,7 +193,7 @@ NS_DEFINE_STATIC_IID_ACCESSOR(nsCycleCollectionParticipant,
#define IMETHOD_VISIBILITY NS_COM_GLUE
typedef void
(* TraceCallback)(PRUint32 langID, void *p, const char *name, void *closure);
(* TraceCallback)(void *p, const char *name, void *closure);
class NS_NO_VTABLE nsScriptObjectTracer : public nsCycleCollectionParticipant
{
@ -557,16 +558,9 @@ public:
{ \
_class *tmp = static_cast<_class*>(p);
#define NS_IMPL_CYCLE_COLLECTION_TRACE_CALLBACK(_langID, _object, _name) \
if (_object) \
aCallback(_langID, _object, _name, aClosure);
#define NS_IMPL_CYCLE_COLLECTION_TRACE_MEMBER_CALLBACK(_langID, _field) \
NS_IMPL_CYCLE_COLLECTION_TRACE_CALLBACK(_langID, tmp->_field, #_field)
#define NS_IMPL_CYCLE_COLLECTION_TRACE_JS_CALLBACK(_object, _name) \
NS_IMPL_CYCLE_COLLECTION_TRACE_CALLBACK(nsIProgrammingLanguage::JAVASCRIPT, \
_object, _name)
if (_object) \
aCallback(_object, _name, aClosure);
#define NS_IMPL_CYCLE_COLLECTION_TRACE_JS_MEMBER_CALLBACK(_field) \
NS_IMPL_CYCLE_COLLECTION_TRACE_JS_CALLBACK(tmp->_field, #_field)