From 810702a01eb52ad6dac2ca2ebbd702ac58ee6ee2 Mon Sep 17 00:00:00 2001 From: Peter Van der Beken Date: Sat, 24 Jan 2009 23:13:29 +0100 Subject: [PATCH] Back out changeset e919f0c1dfa9 (Fix for bug 464676 (Cycle collector sometimes unlinks live cycles). r=bent, sr=jst.) to try to fix red on leak tinderboxes. --- js/src/xpconnect/src/nsXPConnect.cpp | 57 +++---------------- .../xpconnect/src/xpcwrappednativescope.cpp | 3 +- 2 files changed, 9 insertions(+), 51 deletions(-) diff --git a/js/src/xpconnect/src/nsXPConnect.cpp b/js/src/xpconnect/src/nsXPConnect.cpp index 30e97d5ca46..86cecd52b5c 100644 --- a/js/src/xpconnect/src/nsXPConnect.cpp +++ b/js/src/xpconnect/src/nsXPConnect.cpp @@ -697,20 +697,6 @@ NoteJSChild(JSTracer *trc, void *thing, uint32 kind) } } -static JSBool -WrapperIsNotMainThreadOnly(XPCWrappedNative *wrapper) -{ - XPCWrappedNativeProto *proto = wrapper->GetProto(); - if(proto && proto->ClassIsMainThreadOnly()) - return PR_FALSE; - - // If the native participates in cycle collection then we know it can only - // be used on the main thread, in that case we assume the wrapped native - // can only be used on the main thread too. - nsXPCOMCycleCollectionParticipant* participant; - return NS_FAILED(CallQueryInterface(wrapper->Native(), &participant)); -} - NS_IMETHODIMP nsXPConnect::Traverse(void *p, nsCycleCollectionTraversalCallback &cb) { @@ -720,35 +706,6 @@ nsXPConnect::Traverse(void *p, nsCycleCollectionTraversalCallback &cb) JSContext *cx = mCycleCollectionContext->GetJSContext(); uint32 traceKind = js_GetGCThingTraceKind(p); - JSObject *obj; - JSClass *clazz; - - // We do not want to add wrappers to the cycle collector if they're not - // explicitly marked as main thread only, because the cycle collector isn't - // able to deal with objects that might be used off of the main thread. We - // do want to explicitly mark them for cycle collection if the wrapper has - // an external reference, because the wrapper would mark the JS object if - // we did add the wrapper to the cycle collector. - JSBool dontTraverse = PR_FALSE; - JSBool markJSObject = PR_FALSE; - if(traceKind == JSTRACE_OBJECT) - { - obj = static_cast(p); - clazz = OBJ_GET_CLASS(cx, obj); - - if(clazz == &XPC_WN_Tearoff_JSClass) - { - XPCWrappedNative *wrapper = - (XPCWrappedNative*)xpc_GetJSPrivate(STOBJ_GET_PARENT(obj)); - dontTraverse = WrapperIsNotMainThreadOnly(wrapper); - } - else if(IS_WRAPPER_CLASS(clazz)) - { - XPCWrappedNative *wrapper = (XPCWrappedNative*)xpc_GetJSPrivate(obj); - dontTraverse = WrapperIsNotMainThreadOnly(wrapper); - markJSObject = dontTraverse && wrapper->HasExternalReference(); - } - } CCNodeType type; @@ -769,14 +726,12 @@ 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; + type = PL_DHASH_ENTRY_IS_BUSY(entry) ? GCMarked : GCUnmarked; } else { // Normal codepath (matches non-DEBUG_CC codepath). - type = !markJSObject && JS_IsAboutToBeFinalized(cx, p) ? GCUnmarked : - GCMarked; + type = JS_IsAboutToBeFinalized(cx, p) ? GCUnmarked : GCMarked; } char name[72]; @@ -900,8 +855,7 @@ nsXPConnect::Traverse(void *p, nsCycleCollectionTraversalCallback &cb) } #else - type = !markJSObject && JS_IsAboutToBeFinalized(cx, p) ? GCUnmarked : - GCMarked; + type = JS_IsAboutToBeFinalized(cx, p) ? GCUnmarked : GCMarked; cb.DescribeNode(type, 0); #endif @@ -922,9 +876,12 @@ nsXPConnect::Traverse(void *p, nsCycleCollectionTraversalCallback &cb) JS_TRACER_INIT(&trc, cx, NoteJSChild); JS_TraceChildren(&trc, p, traceKind); - if(traceKind != JSTRACE_OBJECT || dontTraverse) + if(traceKind != JSTRACE_OBJECT) return NS_OK; + JSObject *obj = static_cast(p); + JSClass* clazz = OBJ_GET_CLASS(cx, obj); + if(clazz == &XPC_WN_Tearoff_JSClass) { // A tearoff holds a strong reference to its native object diff --git a/js/src/xpconnect/src/xpcwrappednativescope.cpp b/js/src/xpconnect/src/xpcwrappednativescope.cpp index 06494db548a..1c4d201e3c9 100644 --- a/js/src/xpconnect/src/xpcwrappednativescope.cpp +++ b/js/src/xpconnect/src/xpcwrappednativescope.cpp @@ -395,7 +395,8 @@ WrappedNativeSuspecter(JSDHashTable *table, JSDHashEntryHdr *hdr, { SuspectClosure* closure = static_cast(arg); XPCWrappedNative* wrapper = ((Native2WrappedNativeMap::Entry*)hdr)->value; - if(wrapper->IsValid()) + XPCWrappedNativeProto* proto = wrapper->GetProto(); + if(proto && proto->ClassIsMainThreadOnly() && wrapper->IsValid()) { NS_ASSERTION(NS_IsMainThread(), "Suspecting wrapped natives from non-main thread");