зеркало из https://github.com/mozilla/pjs.git
Move the cycle collector our of the GC callback (573060, r=peterv).
This commit is contained in:
Родитель
cc167964e9
Коммит
25178ec25d
|
@ -334,51 +334,6 @@ 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()
|
||||
{
|
||||
|
@ -430,12 +385,10 @@ nsXPConnect::Collect()
|
|||
|
||||
mCycleCollecting = PR_TRUE;
|
||||
mCycleCollectionContext = &cycleCollectionContext;
|
||||
gDidCollection = PR_FALSE;
|
||||
gInCollection = PR_FALSE;
|
||||
gCollected = PR_FALSE;
|
||||
|
||||
nsXPConnect::GetRuntimeInstance()->ClearWeakRoots();
|
||||
|
||||
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
|
||||
|
@ -454,13 +407,15 @@ nsXPConnect::Collect()
|
|||
JS_GC(cx);
|
||||
JS_THREAD_DATA(cx)->conservativeGC.enable();
|
||||
}
|
||||
JS_SetGCCallback(cx, gOldJSGCCallback);
|
||||
gOldJSGCCallback = nsnull;
|
||||
|
||||
// The JavaScript GC is done. Lets cycle collect.
|
||||
PRBool ok = nsCycleCollector_beginCollection() &&
|
||||
nsCycleCollector_finishCollection();
|
||||
|
||||
mCycleCollectionContext = nsnull;
|
||||
mCycleCollecting = PR_FALSE;
|
||||
|
||||
return gCollected;
|
||||
return ok;
|
||||
}
|
||||
|
||||
// JSTRACE_XML can recursively hold on to more JSTRACE_XML objects, adding it to
|
||||
|
|
|
@ -154,6 +154,8 @@
|
|||
#include <process.h>
|
||||
#endif
|
||||
|
||||
//#define COLLECT_TIME_DEBUG
|
||||
|
||||
#ifdef DEBUG_CC
|
||||
#define IF_DEBUG_CC_PARAM(_p) , _p
|
||||
#define IF_DEBUG_CC_ONLY_PARAM(_p) _p
|
||||
|
|
Загрузка…
Ссылка в новой задаче