Bug 1559659 - 3. Get rid of per-thread jscontext instantiation and use the global pool instead r=jandem

Got rid of the per-thread JSContext created at the start of each thread. Tasks that require JSContext (ParseTasks, IonBuilder, Wasm tier 2 generators, GCParallel) now request an unused context to set to their thread. Tasks which do not use JSContext will not request one.

Differential Revision: https://phabricator.services.mozilla.com/D37495

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Kristen Wright 2019-07-16 13:21:52 +00:00
Родитель a42c715a83
Коммит 794b917537
3 изменённых файлов: 9 добавлений и 17 удалений

Просмотреть файл

@ -1127,6 +1127,7 @@ AbortReasonOr<Ok> IonBuilder::buildInline(IonBuilder* callerBuilder,
void IonBuilder::runTask() { void IonBuilder::runTask() {
// This is the entry point when ion compiles are run offthread. // This is the entry point when ion compiles are run offthread.
JSRuntime* rt = script()->runtimeFromAnyThread(); JSRuntime* rt = script()->runtimeFromAnyThread();
AutoSetHelperThreadContext usesContext;
TraceLoggerThread* logger = TraceLoggerForCurrentThread(); TraceLoggerThread* logger = TraceLoggerForCurrentThread();
TraceLoggerEvent event(TraceLogger_AnnotateScripts, script()); TraceLoggerEvent event(TraceLogger_AnnotateScripts, script());

Просмотреть файл

@ -542,11 +542,14 @@ size_t ParseTask::sizeOfExcludingThis(
} }
void ParseTask::runTask() { void ParseTask::runTask() {
AutoSetHelperThreadContext usesContext;
JSContext* cx = TlsContext.get(); JSContext* cx = TlsContext.get();
JSRuntime* runtime = parseGlobal->runtimeFromAnyThread(); JSRuntime* runtime = parseGlobal->runtimeFromAnyThread();
AutoSetContextRuntime ascr(runtime); AutoSetContextRuntime ascr(runtime);
AutoSetContextParse parsetask(this); AutoSetContextParse parsetask(this);
gc::AutoSuppressNurseryCellAlloc noNurseryAlloc(cx);
Zone* zone = parseGlobal->zoneFromAnyThread(); Zone* zone = parseGlobal->zoneFromAnyThread();
zone->setHelperThreadOwnerContext(cx); zone->setHelperThreadOwnerContext(cx);
@ -1764,11 +1767,12 @@ void js::GCParallelTask::runFromMainThread(JSRuntime* rt) {
void js::GCParallelTask::runFromHelperThread(AutoLockHelperThreadState& lock) { void js::GCParallelTask::runFromHelperThread(AutoLockHelperThreadState& lock) {
MOZ_ASSERT(isDispatched(lock)); MOZ_ASSERT(isDispatched(lock));
AutoSetContextRuntime ascr(runtime());
gc::AutoSetThreadIsPerformingGC performingGC;
{ {
AutoUnlockHelperThreadState parallelSection(lock); AutoUnlockHelperThreadState parallelSection(lock);
AutoSetHelperThreadContext usesContext;
AutoSetContextRuntime ascr(runtime());
gc::AutoSetThreadIsPerformingGC performingGC;
TimeStamp timeStart = ReallyNow(); TimeStamp timeStart = ReallyNow();
runTask(); runTask();
duration_ = TimeSince(timeStart); duration_ = TimeSince(timeStart);
@ -2172,7 +2176,6 @@ void HelperThread::handleIonWorkload(AutoLockHelperThreadState& locked) {
{ {
AutoUnlockHelperThreadState unlock(locked); AutoUnlockHelperThreadState unlock(locked);
AutoSetContextRuntime ascr(rt);
builder->runTask(); builder->runTask();
} }
@ -2540,22 +2543,9 @@ void HelperThread::threadLoop() {
ensureRegisteredWithProfiler(); ensureRegisteredWithProfiler();
JSContext cx(nullptr, JS::ContextOptions());
{
AutoEnterOOMUnsafeRegion oomUnsafe;
cx.setThread();
if (!cx.init(ContextKind::HelperThread)) {
oomUnsafe.crash("HelperThread cx.init()");
}
}
gc::AutoSuppressNurseryCellAlloc noNurseryAlloc(&cx);
JS_SetNativeStackQuota(&cx, HELPER_STACK_QUOTA);
while (!terminate) { while (!terminate) {
MOZ_ASSERT(idle()); MOZ_ASSERT(idle());
maybeFreeUnusedMemory(&cx);
// The selectors may depend on the HelperThreadState not changing // The selectors may depend on the HelperThreadState not changing
// between task selection and task execution, in particular, on new // between task selection and task execution, in particular, on new
// tasks not being added (because of the lifo structure of the work // tasks not being added (because of the lifo structure of the work

Просмотреть файл

@ -62,6 +62,7 @@ class Module::Tier2GeneratorTaskImpl : public Tier2GeneratorTask {
void cancel() override { cancelled_ = true; } void cancel() override { cancelled_ = true; }
void runTask() override { void runTask() override {
AutoSetHelperThreadContext usesContext;
CompileTier2(*compileArgs_, bytecode_->bytes, *module_, &cancelled_); CompileTier2(*compileArgs_, bytecode_->bytes, *module_, &cancelled_);
} }
ThreadType threadType() override { ThreadType threadType() override {