Skip to content

Commit

Permalink
SERVER-66498 Disabled Baseline JIT for MozJS
Browse files Browse the repository at this point in the history
  • Loading branch information
mdashti authored and Evergreen Agent committed May 17, 2022
1 parent 3b4067a commit 13ec926
Showing 1 changed file with 24 additions and 4 deletions.
28 changes: 24 additions & 4 deletions src/mongo/scripting/mozjs/implscope.cpp
Expand Up @@ -315,10 +315,6 @@ MozJSImplScope::MozRuntime::MozRuntime(const MozJSScriptEngine* engine,
if (gFirstRuntimeCreated) {
// If we've already made a runtime, just proceed
lk.unlock();
} else {
// If this is the first one, hold the lock until after the first
// one's done
gFirstRuntimeCreated = true;
}

_context = std::unique_ptr<JSContext, std::function<void(JSContext*)>>(
Expand All @@ -327,6 +323,15 @@ MozJSImplScope::MozRuntime::MozRuntime(const MozJSScriptEngine* engine,

// We turn on a variety of optimizations if the jit is enabled
if (engine->isJITEnabled()) {
if (!gFirstRuntimeCreated) {
// The process-wide baseline JIT is enabled as part of creating the first JS
// runtime. If JIT is later disabled for a specific JS runtime, then the ION JIT
// engine gets disabled, but the baseline JIT is still enabled.
JS_SetGlobalJitCompilerOption(_context.get(), JSJITCOMPILER_BASELINE_ENABLE, 1);
JS_SetGlobalJitCompilerOption(
_context.get(), JSJITCOMPILER_BASELINE_INTERPRETER_ENABLE, 1);
JS_SetGlobalJitCompilerOption(_context.get(), JSJITCOMPILER_ION_ENABLE, 1);
}
JS::ContextOptionsRef(_context.get())
.setAsmJS(true)
.setThrowOnAsmJSValidationFailure(true)
Expand All @@ -335,6 +340,15 @@ MozJSImplScope::MozRuntime::MozRuntime(const MozJSScriptEngine* engine,
.setWasmIon(true)
.setAsyncStack(false);
} else {
if (!gFirstRuntimeCreated) {
// The process-wide baseline JIT is disabled as part of creating the first JS
// runtime. If JIT is later enabled for a specific JS runtime, then the ION JIT
// engine gets enabled.
JS_SetGlobalJitCompilerOption(_context.get(), JSJITCOMPILER_BASELINE_ENABLE, 0);
JS_SetGlobalJitCompilerOption(
_context.get(), JSJITCOMPILER_BASELINE_INTERPRETER_ENABLE, 0);
JS_SetGlobalJitCompilerOption(_context.get(), JSJITCOMPILER_ION_ENABLE, 0);
}
JS::ContextOptionsRef(_context.get())
.setAsmJS(false)
.setThrowOnAsmJSValidationFailure(false)
Expand All @@ -345,6 +359,12 @@ MozJSImplScope::MozRuntime::MozRuntime(const MozJSScriptEngine* engine,
.setAsyncStack(false);
}

if (!gFirstRuntimeCreated) {
// If this is the first one, hold the lock until after the first
// one's done
gFirstRuntimeCreated = true;
}

uassert(ErrorCodes::JSInterpreterFailure,
"UseInternalJobQueues",
js::UseInternalJobQueues(_context.get()));
Expand Down

0 comments on commit 13ec926

Please sign in to comment.