Bug 1452982 part 13 - Misc cleanup related to cooperative scheduling. r=jonco

This commit is contained in:
Jan de Mooij 2018-04-17 13:30:19 +02:00
parent 03b1aaefed
commit 43efd96cbe
8 changed files with 21 additions and 38 deletions

View File

@ -189,7 +189,7 @@ impl Runtime {
});
if use_internal_job_queue {
assert!(js::UseInternalJobQueues(js_context, false));
assert!(js::UseInternalJobQueues(js_context));
}
JS::InitSelfHostedCode(js_context);

View File

@ -431,7 +431,7 @@ ForgetSourceHook(JSContext* cx);
* right time(s), such as after evaluation of a script has run to completion.
*/
extern JS_FRIEND_API(bool)
UseInternalJobQueues(JSContext* cx, bool cooperative = false);
UseInternalJobQueues(JSContext* cx);
/**
* Enqueue |job| on the internal job queue.

View File

@ -3548,34 +3548,22 @@ WorkerMain(void* arg)
js_delete(input);
});
if (input->parentRuntime)
sc->isWorker = true;
sc->isWorker = true;
JS_SetContextPrivate(cx, sc);
SetWorkerContextOptions(cx);
JS::SetBuildIdOp(cx, ShellBuildId);
Maybe<EnvironmentPreparer> environmentPreparer;
if (input->parentRuntime) {
JS_SetFutexCanWait(cx);
JS::SetWarningReporter(cx, WarningReporter);
js::SetPreserveWrapperCallback(cx, DummyPreserveWrapperCallback);
JS_InitDestroyPrincipalsCallback(cx, ShellPrincipals::destroy);
JS_SetFutexCanWait(cx);
JS::SetWarningReporter(cx, WarningReporter);
js::SetPreserveWrapperCallback(cx, DummyPreserveWrapperCallback);
JS_InitDestroyPrincipalsCallback(cx, ShellPrincipals::destroy);
js::UseInternalJobQueues(cx);
js::UseInternalJobQueues(cx);
if (!JS::InitSelfHostedCode(cx))
return;
if (!JS::InitSelfHostedCode(cx))
return;
environmentPreparer.emplace(cx);
} else {
JS_AddInterruptCallback(cx, ShellInterruptCallback);
js::UseInternalJobQueues(cx, /* cooperative = */true);
// The Gecko Profiler requires that all cooperating contexts have
// profiling stacks installed.
MOZ_ALWAYS_TRUE(EnsureGeckoProfilingStackInstalled(cx, sc));
}
EnvironmentPreparer environmentPreparer(cx);
do {
JSAutoRequest ar(cx);

View File

@ -1071,11 +1071,11 @@ class MOZ_STACK_CLASS ReportExceptionClosure : public ScriptEnvironmentPreparer:
} // anonymous namespace
JS_FRIEND_API(bool)
js::UseInternalJobQueues(JSContext* cx, bool cooperative)
js::UseInternalJobQueues(JSContext* cx)
{
// Internal job queue handling must be set up very early. Self-hosting
// initialization is as good a marker for that as any.
MOZ_RELEASE_ASSERT(cooperative || !cx->runtime()->hasInitializedSelfHosting(),
MOZ_RELEASE_ASSERT(!cx->runtime()->hasInitializedSelfHosting(),
"js::UseInternalJobQueues must be called early during runtime startup.");
MOZ_ASSERT(!cx->jobQueue);
auto* queue = js_new<PersistentRooted<JobQueue>>(cx, JobQueue(SystemAllocPolicy()));
@ -1084,8 +1084,7 @@ js::UseInternalJobQueues(JSContext* cx, bool cooperative)
cx->jobQueue = queue;
if (!cooperative)
cx->runtime()->offThreadPromiseState.ref().initInternalDispatchQueue();
cx->runtime()->offThreadPromiseState.ref().initInternalDispatchQueue();
MOZ_ASSERT(cx->runtime()->offThreadPromiseState.ref().initialized());
JS::SetEnqueuePromiseJobCallback(cx, InternalEnqueuePromiseJobCallback);

View File

@ -18,7 +18,6 @@
_(TestMutex, 100) \
_(ShellContextWatchdog, 100) \
_(ShellWorkerThreads, 100) \
_(ShellThreadCooperation, 100) \
_(ShellArrayBufferMailbox, 100) \
\
_(RuntimeExclusiveAccess, 200) \

View File

@ -480,10 +480,7 @@ struct JSRuntime : public js::MallocProvider<JSRuntime>
bool activeThreadHasScriptDataAccess;
#endif
/*
* Number of zones which may be operated on by non-cooperating helper
* threads.
*/
// Number of zones which may be operated on by helper threads.
mozilla::Atomic<size_t> numActiveHelperThreadZones;
friend class js::AutoLockForExclusiveAccess;

View File

@ -869,7 +869,7 @@ TraceLoggerThreadState::init()
"\n"
"usage: TLOPTIONS=option,option,option,... where options can be:\n"
"\n"
" EnableActiveThread Start logging cooperating threads immediately.\n"
" EnableMainThread Start logging main threads immediately.\n"
" EnableOffThread Start logging helper threads immediately.\n"
" EnableGraph Enable spewing the tracelogging graph to a file.\n"
" Errors Report errors during tracing to stderr.\n"
@ -879,8 +879,8 @@ TraceLoggerThreadState::init()
/*NOTREACHED*/
}
if (strstr(options, "EnableActiveThread"))
cooperatingThreadEnabled = true;
if (strstr(options, "EnableMainThread"))
mainThreadEnabled = true;
if (strstr(options, "EnableOffThread"))
helperThreadEnabled = true;
if (strstr(options, "EnableGraph"))
@ -985,7 +985,7 @@ TraceLoggerThreadState::forCurrentThread(JSContext* maybecx)
if (graphSpewingEnabled)
logger->initGraph();
if (CurrentHelperThread() ? helperThreadEnabled : cooperatingThreadEnabled)
if (CurrentHelperThread() ? helperThreadEnabled : mainThreadEnabled)
logger->enable();
}

View File

@ -378,7 +378,7 @@ class TraceLoggerThreadState
#endif
bool enabledTextIds[TraceLogger_Last];
bool cooperatingThreadEnabled;
bool mainThreadEnabled;
bool helperThreadEnabled;
bool graphSpewingEnabled;
bool spewErrors;
@ -405,7 +405,7 @@ class TraceLoggerThreadState
#ifdef DEBUG
initialized(false),
#endif
cooperatingThreadEnabled(false),
mainThreadEnabled(false),
helperThreadEnabled(false),
graphSpewingEnabled(false),
spewErrors(false),