Bug 899367 - Only use JSOPTION_UNROOTED_GLOBAL for DOM JSContexts. r=mccr8

We don't cycle collect any other kind, so there's no difference between marking
them gray and letting the JS engine mark them black. This also gets rid of that
nasty code which reset the flag, which billm theorizes has to do with faulty
logic in ContextHolder when creating ephemeral sandbox cxes. The assertion in
this patch should catch us if anything goes wrong.
This commit is contained in:
Bobby Holley
2013-08-27 15:21:37 -07:00
parent 18a2f39c66
commit 4bc74a5aec
5 changed files with 11 additions and 33 deletions

View File

@@ -474,12 +474,10 @@ NoteJSChildGrayWrapperShim(void* aData, void* aThing)
static const JSZoneParticipant sJSZoneCycleCollectorGlobal;
CycleCollectedJSRuntime::CycleCollectedJSRuntime(uint32_t aMaxbytes,
JSUseHelperThreads aUseHelperThreads,
bool aExpectUnrootedGlobals)
JSUseHelperThreads aUseHelperThreads)
: mGCThingCycleCollectorGlobal(sGCThingCycleCollectorGlobal),
mJSZoneCycleCollectorGlobal(sJSZoneCycleCollectorGlobal),
mJSRuntime(nullptr),
mExpectUnrootedGlobals(aExpectUnrootedGlobals)
mJSRuntime(nullptr)
#ifdef DEBUG
, mObjectToUnlink(nullptr)
#endif
@@ -544,7 +542,10 @@ CycleCollectedJSRuntime::MaybeTraceGlobals(JSTracer* aTracer) const
{
JSContext* iter = nullptr;
while (JSContext* acx = JS_ContextIterator(Runtime(), &iter)) {
MOZ_ASSERT(js::HasUnrootedGlobal(acx) == mExpectUnrootedGlobals);
// DOM JSContexts are the only JSContexts that cycle-collect their default
// compartment object, so they're the only ones that we need to do the
// JSOPTION_UNROOTED_GLOBAL dance for. The other ones are just marked black.
MOZ_ASSERT(js::HasUnrootedGlobal(acx) == !!GetScriptContextFromJSContext(acx));
if (!js::HasUnrootedGlobal(acx)) {
continue;
}
@@ -1186,21 +1187,7 @@ CycleCollectedJSRuntime::OnGC(JSGCStatus aStatus)
{
switch (aStatus) {
case JSGC_BEGIN:
{
// XXXkhuey do we still need this?
// We seem to sometime lose the unrooted global flag. Restore it
// here. FIXME: bug 584495.
if (mExpectUnrootedGlobals){
JSContext* iter = nullptr;
while (JSContext* acx = JS_ContextIterator(Runtime(), &iter)) {
if (!js::HasUnrootedGlobal(acx)) {
JS_ToggleOptions(acx, JSOPTION_UNROOTED_GLOBAL);
}
}
}
break;
}
case JSGC_END:
{
/*
@@ -1229,11 +1216,5 @@ CycleCollectedJSRuntime::OnGC(JSGCStatus aStatus)
bool
CycleCollectedJSRuntime::OnContext(JSContext* aCx, unsigned aOperation)
{
if (mExpectUnrootedGlobals && aOperation == JSCONTEXT_NEW) {
// XXXkhuey bholley is going to make this go away, but for now XPConnect
// needs it.
JS_ToggleOptions(aCx, JSOPTION_UNROOTED_GLOBAL);
}
return CustomContextCallback(aCx, aOperation);
}