Bug 790338 - Split up xpconnect finalization callback r=billm

--HG--
extra : rebase_source : 2b70376622af8104d829c23b0014cbd7d8d73a87
This commit is contained in:
Jon Coppeard 2012-10-12 10:45:30 +01:00
parent ffbe886600
commit cd78b635df
4 changed files with 53 additions and 11 deletions

View File

@ -30,7 +30,7 @@ struct StringWrapper
void
FinalizeCallback(JSFreeOp *fop, JSFinalizeStatus status, JSBool isCompartmentGC)
{
if (status == JSFINALIZE_START)
if (status == JSFINALIZE_GROUP_START)
sw.strOk = !JS_IsAboutToBeFinalized(sw.str);
}

View File

@ -1862,8 +1862,25 @@ typedef void
(* JSGCCallback)(JSRuntime *rt, JSGCStatus status);
typedef enum JSFinalizeStatus {
JSFINALIZE_START,
JSFINALIZE_END
/*
* Called when preparing to sweep a group of compartments, before anything
* has been swept. The collector will not yield to the mutator before
* calling the callback with JSFINALIZE_GROUP_END status.
*/
JSFINALIZE_GROUP_START,
/*
* Called when preparing to sweep a group of compartments. Weak references
* to unmarked things have been removed and things that are not swept
* incrementally have been finalized at this point. The collector may yield
* to the mutator after this point.
*/
JSFINALIZE_GROUP_END,
/*
* Called at the end of collection when everything has been swept.
*/
JSFINALIZE_COLLECTION_END
} JSFinalizeStatus;
typedef void

View File

@ -3830,7 +3830,7 @@ BeginSweepPhase(JSRuntime *rt)
{
gcstats::AutoPhase ap(rt->gcStats, gcstats::PHASE_FINALIZE_START);
if (rt->gcFinalizeCallback)
rt->gcFinalizeCallback(&fop, JSFINALIZE_START, !isFull);
rt->gcFinalizeCallback(&fop, JSFINALIZE_GROUP_START, !isFull);
}
/* Finalize unreachable (key,value) pairs in all weak maps. */
@ -3910,7 +3910,7 @@ BeginSweepPhase(JSRuntime *rt)
{
gcstats::AutoPhase ap(rt->gcStats, gcstats::PHASE_FINALIZE_END);
if (rt->gcFinalizeCallback)
rt->gcFinalizeCallback(&fop, JSFINALIZE_END, !isFull);
rt->gcFinalizeCallback(&fop, JSFINALIZE_GROUP_END, !isFull);
}
}
@ -4026,6 +4026,12 @@ EndSweepPhase(JSRuntime *rt, JSGCInvocationKind gckind, bool lastGC)
}
}
{
gcstats::AutoPhase ap(rt->gcStats, gcstats::PHASE_FINALIZE_END);
if (rt->gcFinalizeCallback)
rt->gcFinalizeCallback(&fop, JSFINALIZE_COLLECTION_END, !rt->gcIsFull);
}
/*
* Reset the list of arenas marked as being allocated during sweep phase.
*/

View File

@ -732,7 +732,7 @@ XPCJSRuntime::FinalizeCallback(JSFreeOp *fop, JSFinalizeStatus status, JSBool is
return;
switch (status) {
case JSFINALIZE_START:
case JSFINALIZE_GROUP_START:
{
NS_ASSERTION(!self->mDoingFinalization, "bad state");
@ -760,7 +760,7 @@ XPCJSRuntime::FinalizeCallback(JSFreeOp *fop, JSFinalizeStatus status, JSBool is
self->mDoingFinalization = true;
break;
}
case JSFINALIZE_END:
case JSFINALIZE_GROUP_END:
{
NS_ASSERTION(self->mDoingFinalization, "bad state");
self->mDoingFinalization = false;
@ -769,6 +769,29 @@ XPCJSRuntime::FinalizeCallback(JSFreeOp *fop, JSFinalizeStatus status, JSBool is
// to be dead.
DoDeferredRelease(self->mWrappedJSToReleaseArray);
// Sweep scopes needing cleanup
XPCWrappedNativeScope::FinishedFinalizationPhaseOfGC();
// mThreadRunningGC indicates that GC is running.
// Clear it and notify waiters.
{ // scoped lock
XPCAutoLock lock(self->GetMapLock());
NS_ASSERTION(self->mThreadRunningGC == PR_GetCurrentThread(), "bad state");
self->mThreadRunningGC = nullptr;
xpc_NotifyAll(self->GetMapLock());
}
break;
}
case JSFINALIZE_COLLECTION_END:
{
// mThreadRunningGC indicates that GC is running
{ // scoped lock
XPCAutoLock lock(self->GetMapLock());
NS_ASSERTION(!self->mThreadRunningGC, "bad state");
self->mThreadRunningGC = PR_GetCurrentThread();
}
#ifdef XPC_REPORT_NATIVE_INTERFACE_AND_SET_FLUSHING
printf("--------------------------------------------------------------\n");
int setsBefore = (int) self->mNativeSetMap->Count();
@ -869,9 +892,6 @@ XPCJSRuntime::FinalizeCallback(JSFreeOp *fop, JSFinalizeStatus status, JSBool is
printf("--------------------------------------------------------------\n");
#endif
// Sweep scopes needing cleanup
XPCWrappedNativeScope::FinishedFinalizationPhaseOfGC();
// Now we are going to recycle any unused WrappedNativeTearoffs.
// We do this by iterating all the live callcontexts
// and marking the tearoffs in use. And then we
@ -925,7 +945,6 @@ XPCJSRuntime::FinalizeCallback(JSFreeOp *fop, JSFinalizeStatus status, JSBool is
self->mDyingWrappedNativeProtoMap->
Enumerate(DyingProtoKiller, nullptr);
// mThreadRunningGC indicates that GC is running.
// Clear it and notify waiters.
{ // scoped lock