From 483a33d0039e1e0f8aabc9986a94b5dcb47a5801 Mon Sep 17 00:00:00 2001 From: Andreas Gal Date: Thu, 15 Jul 2010 14:14:26 -0700 Subject: [PATCH] Backed out bug 573060. --- js/src/xpconnect/src/nsXPConnect.cpp | 59 ++++++++++++++++++++++++---- xpcom/base/nsCycleCollector.cpp | 2 - 2 files changed, 52 insertions(+), 9 deletions(-) diff --git a/js/src/xpconnect/src/nsXPConnect.cpp b/js/src/xpconnect/src/nsXPConnect.cpp index f3b26100a05..8e068c57c2d 100644 --- a/js/src/xpconnect/src/nsXPConnect.cpp +++ b/js/src/xpconnect/src/nsXPConnect.cpp @@ -334,6 +334,51 @@ nsXPConnect::GetInfoForName(const char * name, nsIInterfaceInfo** info) return FindInfo(NameTester, name, mInterfaceInfoManager, info); } +static JSGCCallback gOldJSGCCallback; +// Whether cycle collection was run. +static PRBool gDidCollection; +// Whether starting cycle collection was successful. +static PRBool gInCollection; +// Whether cycle collection collected anything. +static PRBool gCollected; + +static JSBool +XPCCycleCollectGCCallback(JSContext *cx, JSGCStatus status) +{ + // Launch the cycle collector. + switch(status) + { + case JSGC_BEGIN: + nsXPConnect::GetRuntimeInstance()->ClearWeakRoots(); + break; + + case JSGC_MARK_END: + // This is the hook between marking and sweeping in the JS GC. Do cycle + // collection. + if(!gDidCollection) + { + NS_ASSERTION(!gInCollection, "Recursing?"); + + gDidCollection = PR_TRUE; + gInCollection = nsCycleCollector_beginCollection(); + } + break; + + case JSGC_END: + if(gInCollection) + { + gInCollection = PR_FALSE; + gCollected = nsCycleCollector_finishCollection(); + } + break; + + default: + break; + } + + return gOldJSGCCallback ? gOldJSGCCallback(cx, status) : JS_TRUE; +} + PRBool nsXPConnect::Collect() { @@ -385,10 +430,12 @@ nsXPConnect::Collect() mCycleCollecting = PR_TRUE; mCycleCollectionContext = &cycleCollectionContext; - - nsXPConnect::GetRuntimeInstance()->ClearWeakRoots(); + gDidCollection = PR_FALSE; + gInCollection = PR_FALSE; + gCollected = PR_FALSE; JSContext *cx = mCycleCollectionContext->GetJSContext(); + gOldJSGCCallback = JS_SetGCCallback(cx, XPCCycleCollectGCCallback); // We want to scan the current thread for GC roots only if it was in a // request prior to the Collect call to avoid false positives during the @@ -407,15 +454,13 @@ nsXPConnect::Collect() JS_GC(cx); JS_THREAD_DATA(cx)->conservativeGC.enable(); } - - // The JavaScript GC is done. Lets cycle collect. - PRBool ok = nsCycleCollector_beginCollection() && - nsCycleCollector_finishCollection(); + JS_SetGCCallback(cx, gOldJSGCCallback); + gOldJSGCCallback = nsnull; mCycleCollectionContext = nsnull; mCycleCollecting = PR_FALSE; - return ok; + return gCollected; } // JSTRACE_XML can recursively hold on to more JSTRACE_XML objects, adding it to diff --git a/xpcom/base/nsCycleCollector.cpp b/xpcom/base/nsCycleCollector.cpp index b2361700ee3..4ff9317d5eb 100644 --- a/xpcom/base/nsCycleCollector.cpp +++ b/xpcom/base/nsCycleCollector.cpp @@ -154,8 +154,6 @@ #include #endif -//#define COLLECT_TIME_DEBUG - #ifdef DEBUG_CC #define IF_DEBUG_CC_PARAM(_p) , _p #define IF_DEBUG_CC_ONLY_PARAM(_p) _p