diff options
-rw-r--r-- | src/mongo/scripting/mozjs/implscope.cpp | 28 |
1 files changed, 24 insertions, 4 deletions
diff --git a/src/mongo/scripting/mozjs/implscope.cpp b/src/mongo/scripting/mozjs/implscope.cpp index 6c90fd85505..69296c9a5bb 100644 --- a/src/mongo/scripting/mozjs/implscope.cpp +++ b/src/mongo/scripting/mozjs/implscope.cpp @@ -313,10 +313,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*)>>( @@ -325,6 +321,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) @@ -333,6 +338,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) @@ -343,6 +357,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())); |