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
This commit is contained in:
Ted Campbell 2021-03-15 22:20:42 +00:00
parent 6d75d587c0
commit bccaebc8f0
3 changed files with 62 additions and 26 deletions

View File

@ -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<nsIXULRuntime> 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);

View File

@ -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

View File

@ -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);