From bccaebc8f031904dc622ad7f0dbc18e4ce23b48e Mon Sep 17 00:00:00 2001 From: Ted Campbell Date: Mon, 15 Mar 2021 22:20:42 +0000 Subject: [PATCH] Bug 1697904 - Migrate JIT-enable prefs to StaticPrefs. r=jandem,KrisWright Mark these prefs as 'do_not_use_directly` to avoid confusion since they should only be snapshotted once in `LoadStartupJSPrefs`. We cannot use the `once` mirrors here since they are not available until after the EnterprisePolicies code has ran and that itself uses javascript. Differential Revision: https://phabricator.services.mozilla.com/D108104 --- js/xpconnect/src/XPCJSContext.cpp | 51 ++++++++++++++---------- modules/libpref/init/StaticPrefList.yaml | 33 +++++++++++++++ modules/libpref/init/all.js | 4 -- 3 files changed, 62 insertions(+), 26 deletions(-) diff --git a/js/xpconnect/src/XPCJSContext.cpp b/js/xpconnect/src/XPCJSContext.cpp index fee37f597f8a..bb5b61bf8438 100644 --- a/js/xpconnect/src/XPCJSContext.cpp +++ b/js/xpconnect/src/XPCJSContext.cpp @@ -833,12 +833,6 @@ static void LoadStartupJSPrefs(XPCJSContext* xpccx) { bool disableWasmHugeMemory = Preferences::GetBool( JS_OPTIONS_DOT_STR "wasm_disable_huge_memory", false); - bool useBaselineInterp = Preferences::GetBool(JS_OPTIONS_DOT_STR "blinterp"); - bool useBaselineJit = Preferences::GetBool(JS_OPTIONS_DOT_STR "baselinejit"); - bool useIon = Preferences::GetBool(JS_OPTIONS_DOT_STR "ion"); - bool useNativeRegExp = - Preferences::GetBool(JS_OPTIONS_DOT_STR "native_regexp"); - bool offthreadIonCompilation = Preferences::GetBool(JS_OPTIONS_DOT_STR "ion.offthread_compilation"); #ifdef DEBUG @@ -866,27 +860,40 @@ static void LoadStartupJSPrefs(XPCJSContext* xpccx) { bool spectreJitToCxxCalls = Preferences::GetBool(JS_OPTIONS_DOT_STR "spectre.jit_to_C++_calls"); + bool safeMode = false; nsCOMPtr xr = do_GetService("@mozilla.org/xre/runtime;1"); if (xr) { - bool safeMode = false; xr->GetInSafeMode(&safeMode); - if (safeMode) { - useBaselineJit = false; - useIon = false; - useJitForTrustedPrincipals = false; - useNativeRegExp = false; - } } - JS_SetGlobalJitCompilerOption(cx, JSJITCOMPILER_BASELINE_INTERPRETER_ENABLE, - useBaselineInterp); - JS_SetGlobalJitCompilerOption(cx, JSJITCOMPILER_BASELINE_ENABLE, - useBaselineJit); - JS_SetGlobalJitCompilerOption(cx, JSJITCOMPILER_ION_ENABLE, useIon); - JS_SetGlobalJitCompilerOption(cx, JSJITCOMPILER_JIT_TRUSTEDPRINCIPALS_ENABLE, - useJitForTrustedPrincipals); - JS_SetGlobalJitCompilerOption(cx, JSJITCOMPILER_NATIVE_REGEXP_ENABLE, - useNativeRegExp); + // NOTE: Baseline Interpreter is still used in safe-mode. This gives a big + // perf gain and is our simplest JIT so we make a tradeoff. + JS_SetGlobalJitCompilerOption( + cx, JSJITCOMPILER_BASELINE_INTERPRETER_ENABLE, + StaticPrefs::javascript_options_blinterp_DoNotUseDirectly()); + + // Disable most JITs in Safe-Mode. + if (safeMode) { + JS_SetGlobalJitCompilerOption(cx, JSJITCOMPILER_BASELINE_ENABLE, false); + JS_SetGlobalJitCompilerOption(cx, JSJITCOMPILER_ION_ENABLE, false); + JS_SetGlobalJitCompilerOption( + cx, JSJITCOMPILER_JIT_TRUSTEDPRINCIPALS_ENABLE, false); + JS_SetGlobalJitCompilerOption(cx, JSJITCOMPILER_NATIVE_REGEXP_ENABLE, + false); + } else { + JS_SetGlobalJitCompilerOption( + cx, JSJITCOMPILER_BASELINE_ENABLE, + StaticPrefs::javascript_options_baselinejit_DoNotUseDirectly()); + JS_SetGlobalJitCompilerOption( + cx, JSJITCOMPILER_ION_ENABLE, + StaticPrefs::javascript_options_ion_DoNotUseDirectly()); + JS_SetGlobalJitCompilerOption(cx, + JSJITCOMPILER_JIT_TRUSTEDPRINCIPALS_ENABLE, + useJitForTrustedPrincipals); + JS_SetGlobalJitCompilerOption( + cx, JSJITCOMPILER_NATIVE_REGEXP_ENABLE, + StaticPrefs::javascript_options_native_regexp_DoNotUseDirectly()); + } JS_SetOffthreadIonCompilationEnabled(cx, offthreadIonCompilation); diff --git a/modules/libpref/init/StaticPrefList.yaml b/modules/libpref/init/StaticPrefList.yaml index 4f9549d2540a..79d373c3622e 100644 --- a/modules/libpref/init/StaticPrefList.yaml +++ b/modules/libpref/init/StaticPrefList.yaml @@ -5304,8 +5304,41 @@ #--------------------------------------------------------------------------- # Prefs starting with "javascript." +# +# NOTE: SpiderMonkey starts up before `mirror: once` preferences are sealed and +# we cannot use them (Bug 1698311). Instead, we use `mirror: always` +# prefs but mark as `do_not_use_directly` and `LoadStartupJSPrefs` will +# mirror them into SpiderMonkey. #--------------------------------------------------------------------------- +# The JavaScript JIT compilers. These are read once on startup so a browser may +# need to be restarted if toggling them. In general each subsequent JIT depends +# on the ones before it being enabled. +- name: javascript.options.blinterp + type: bool + value: true + mirror: always # LoadStartupJSPrefs + do_not_use_directly: true + +- name: javascript.options.baselinejit + type: bool + value: true + mirror: always # LoadStartupJSPrefs + do_not_use_directly: true + +- name: javascript.options.ion + type: bool + value: true + mirror: always # LoadStartupJSPrefs + do_not_use_directly: true + +# The irregexp JIT for regex evaluation. +- name: javascript.options.native_regexp + type: bool + value: true + mirror: always # LoadStartupJSPrefs + do_not_use_directly: true + - name: javascript.options.compact_on_user_inactive type: bool value: true diff --git a/modules/libpref/init/all.js b/modules/libpref/init/all.js index b49b64a7a44c..a205aea9763e 100644 --- a/modules/libpref/init/all.js +++ b/modules/libpref/init/all.js @@ -1090,13 +1090,10 @@ pref("dom.event.contextmenu.enabled", true); pref("dom.event.coalesce_mouse_move", true); pref("javascript.enabled", true); -pref("javascript.options.blinterp", true); // Duplicated in JitOptions - ensure both match. pref("javascript.options.blinterp.threshold", 10); -pref("javascript.options.baselinejit", true); // Duplicated in JitOptions - ensure both match. pref("javascript.options.baselinejit.threshold", 100); -pref("javascript.options.ion", true); // Duplicated in JitOptions - ensure both match. pref("javascript.options.ion.threshold", 1500); // Duplicated in JitOptions - ensure both match. @@ -1114,7 +1111,6 @@ pref("javascript.options.wasm_baselinejit", true); #ifdef ENABLE_WASM_MULTI_VALUE pref("javascript.options.wasm_multi_value", true); #endif -pref("javascript.options.native_regexp", true); pref("javascript.options.parallel_parsing", true); pref("javascript.options.source_pragmas", true);