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-09-04 14:06:54 -07:00
parent 2903ab3e4d
commit 59b924c116
5 changed files with 11 additions and 33 deletions

View File

@ -851,7 +851,8 @@ nsJSContext::nsJSContext(bool aGCOnDestruction,
++sContextCount;
mDefaultJSOptions = JSOPTION_PRIVATE_IS_NSISUPPORTS;
mDefaultJSOptions = JSOPTION_PRIVATE_IS_NSISUPPORTS |
JSOPTION_UNROOTED_GLOBAL;
mContext = ::JS_NewContext(sRuntime, gStackSize);
if (mContext) {

View File

@ -831,8 +831,7 @@ public:
// call to JS_SetGCParameter inside CreateJSContextForWorker.
WorkerJSRuntime(WorkerPrivate* aWorkerPrivate)
: CycleCollectedJSRuntime(WORKER_DEFAULT_RUNTIME_HEAPSIZE,
JS_NO_HELPER_THREADS,
false),
JS_NO_HELPER_THREADS),
mWorkerPrivate(aWorkerPrivate)
{
// We need to ensure that a JSContext outlives the cycle collector, and

View File

@ -2874,7 +2874,7 @@ SourceHook(JSContext *cx, JS::Handle<JSScript*> script, jschar **src,
}
XPCJSRuntime::XPCJSRuntime(nsXPConnect* aXPConnect)
: CycleCollectedJSRuntime(32L * 1024L * 1024L, JS_USE_HELPER_THREADS, true),
: CycleCollectedJSRuntime(32L * 1024L * 1024L, JS_USE_HELPER_THREADS),
mJSContextStack(new XPCJSContextStack()),
mCallContext(nullptr),
mAutoRoots(nullptr),

View File

@ -475,12 +475,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
@ -545,7 +543,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;
}
@ -1187,21 +1188,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:
{
/*
@ -1230,11 +1217,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);
}

View File

@ -83,8 +83,7 @@ class CycleCollectedJSRuntime
friend class IncrementalFinalizeRunnable;
protected:
CycleCollectedJSRuntime(uint32_t aMaxbytes,
JSUseHelperThreads aUseHelperThreads,
bool aExpectUnrootedGlobals);
JSUseHelperThreads aUseHelperThreads);
virtual ~CycleCollectedJSRuntime();
size_t SizeOfExcludingThis(mozilla::MallocSizeOf aMallocSizeOf) const;
@ -223,8 +222,6 @@ private:
nsRefPtr<IncrementalFinalizeRunnable> mFinalizeRunnable;
bool mExpectUnrootedGlobals;
#ifdef DEBUG
void* mObjectToUnlink;
#endif