Bug 1662140 - Add javascript.options.off_thread_parse_global pref and --no-off-thread-parse-global shell option. r=tcampbell

This adds the preference, JS shell option, and {ContextOptions,CompileOptions} fields,
but the value isn't read and the code always acts as it's set to true.

Differential Revision: https://phabricator.services.mozilla.com/D88922
This commit is contained in:
Tooru Fujisawa 2020-08-31 23:32:14 +00:00
parent a7cd806311
commit 6eecdba324
9 changed files with 49 additions and 4 deletions

View File

@ -290,7 +290,9 @@ void LoadContextOptions(const char* aPrefName, void* /* aClosure */) {
.setPrivateClassFields(
GetWorkerPref<bool>("experimental.private_fields"_ns))
.setPrivateClassMethods(
GetWorkerPref<bool>("experimental.private_methods"_ns));
GetWorkerPref<bool>("experimental.private_methods"_ns))
.setUseOffThreadParseGlobal(
GetWorkerPref<bool>("off_thread_parse_global"_ns));
nsCOMPtr<nsIXULRuntime> xr = do_GetService("@mozilla.org/xre/runtime;1");
if (xr) {

View File

@ -133,6 +133,11 @@ class JS_PUBLIC_API TransitiveCompileOptions {
bool privateClassFields = false;
bool privateClassMethods = false;
// True if off-thread parsing should use a parse GlobalObject in order to
// directly allocate to the GC from a helper thread. If false, transfer the
// CompilationStencil back to main thread before allocating GC objects.
bool useOffThreadParseGlobal = true;
/**
* |introductionType| is a statically allocated C string: one of "eval",
* "Function", or "GeneratorFunction".

View File

@ -45,7 +45,8 @@ class JS_PUBLIC_API ContextOptions {
#endif
fuzzing_(false),
privateClassFields_(false),
privateClassMethods_(false) {
privateClassMethods_(false),
useOffThreadParseGlobal_(true) {
}
bool asmJS() const { return asmJS_; }
@ -153,6 +154,12 @@ class JS_PUBLIC_API ContextOptions {
return *this;
}
bool useOffThreadParseGlobal() const { return useOffThreadParseGlobal_; }
ContextOptions& setUseOffThreadParseGlobal(bool use) {
useOffThreadParseGlobal_ = use;
return *this;
}
// Override to allow disabling the eval restriction security checks for
// this context.
bool disableEvalSecurityChecks() const { return disableEvalSecurityChecks_; }
@ -262,6 +269,9 @@ class JS_PUBLIC_API ContextOptions {
bool fuzzing_ : 1;
bool privateClassFields_ : 1;
bool privateClassMethods_ : 1;
// See TransitiveCompileOptions.useOffThreadParseGlobal.
bool useOffThreadParseGlobal_ : 1;
};
JS_PUBLIC_API ContextOptions& ContextOptionsRef(JSContext* cx);

View File

@ -175,6 +175,13 @@ static bool GetRealmConfiguration(JSContext* cx, unsigned argc, Value* vp) {
return false;
}
bool offThreadParseGlobal = cx->options().useOffThreadParseGlobal();
if (!JS_SetProperty(
cx, info, "offThreadParseGlobal",
offThreadParseGlobal ? TrueHandleValue : FalseHandleValue)) {
return false;
}
args.rval().setObject(*info);
return true;
}

View File

@ -3466,6 +3466,7 @@ void JS::TransitiveCompileOptions::copyPODTransitiveOptions(
nonSyntacticScope = rhs.nonSyntacticScope;
privateClassFields = rhs.privateClassFields;
privateClassMethods = rhs.privateClassMethods;
useOffThreadParseGlobal = rhs.useOffThreadParseGlobal;
};
void JS::ReadOnlyCompileOptions::copyPODNonTransitiveOptions(
@ -3559,6 +3560,7 @@ JS::CompileOptions::CompileOptions(JSContext* cx)
cx->options().throwOnAsmJSValidationFailure();
privateClassFields = cx->options().privateClassFields();
privateClassMethods = cx->options().privateClassMethods();
useOffThreadParseGlobal = cx->options().useOffThreadParseGlobal();
sourcePragmas_ = cx->options().sourcePragmas();

View File

@ -521,6 +521,7 @@ bool shell::enablePropertyErrorMessageFix = false;
bool shell::enableIteratorHelpers = false;
bool shell::enablePrivateClassFields = false;
bool shell::enablePrivateClassMethods = false;
bool shell::useOffThreadParseGlobal = true;
#ifdef JS_GC_ZEAL
uint32_t shell::gZealBits = 0;
uint32_t shell::gZealFrequency = 0;
@ -10251,6 +10252,7 @@ static bool SetContextOptions(JSContext* cx, const OptionParser& op) {
enablePrivateClassFields = op.getBoolOption("enable-private-fields") ||
op.getBoolOption("enable-private-methods");
enablePrivateClassMethods = op.getBoolOption("enable-private-methods");
useOffThreadParseGlobal = !op.getBoolOption("no-off-thread-parse-global");
JS::ContextOptionsRef(cx)
.setAsmJS(enableAsmJS)
@ -10277,7 +10279,8 @@ static bool SetContextOptions(JSContext* cx, const OptionParser& op) {
.setAsyncStack(enableAsyncStacks)
.setAsyncStackCaptureDebuggeeOnly(enableAsyncStackCaptureDebuggeeOnly)
.setPrivateClassFields(enablePrivateClassFields)
.setPrivateClassMethods(enablePrivateClassMethods);
.setPrivateClassMethods(enablePrivateClassMethods)
.setUseOffThreadParseGlobal(useOffThreadParseGlobal);
if (op.getBoolOption("no-ion-for-main-context")) {
JS::ContextOptionsRef(cx).setDisableIon();
@ -11143,6 +11146,9 @@ int main(int argc, char** argv, char** envp) {
"Enable private class fields") ||
!op.addBoolOption('\0', "enable-private-methods",
"Enable private class methods") ||
!op.addBoolOption('\0', "no-off-thread-parse-global",
"Do not use parseGlobal in off-thread compilation and "
"instead instantiate stencil in main-thread") ||
!op.addStringOption('\0', "shared-memory", "on/off",
"SharedArrayBuffer and Atomics "
#if SHARED_MEMORY_DEFAULT

View File

@ -135,6 +135,7 @@ extern bool enableReadableStreamPipeTo;
extern bool enableWeakRefs;
extern bool enableToSource;
extern bool enablePropertyErrorMessageFix;
extern bool useOffThreadParseGlobal;
extern bool enableIteratorHelpers;
extern bool enablePrivateClassFields;
extern bool enablePrivateClassMethods;

View File

@ -974,6 +974,9 @@ static void ReloadPrefsCallback(const char* pref, void* aXpccx) {
Preferences::GetBool(JS_OPTIONS_DOT_STR "experimental.private_methods");
#endif
bool useOffThreadParseGlobal =
Preferences::GetBool(JS_OPTIONS_DOT_STR "off_thread_parse_global");
#ifdef JS_GC_ZEAL
int32_t zeal = Preferences::GetInt(JS_OPTIONS_DOT_STR "gczeal", -1);
int32_t zeal_frequency = Preferences::GetInt(
@ -1017,7 +1020,8 @@ static void ReloadPrefsCallback(const char* pref, void* aXpccx) {
.setThrowOnDebuggeeWouldRun(throwOnDebuggeeWouldRun)
.setDumpStackOnDebuggeeWouldRun(dumpStackOnDebuggeeWouldRun)
.setPrivateClassFields(privateFieldsEnabled)
.setPrivateClassMethods(privateMethodsEnabled);
.setPrivateClassMethods(privateMethodsEnabled)
.setUseOffThreadParseGlobal(useOffThreadParseGlobal);
nsCOMPtr<nsIXULRuntime> xr = do_GetService("@mozilla.org/xre/runtime;1");
if (xr) {

View File

@ -4995,6 +4995,14 @@
#endif
mirror: always
# True if off-thread parsing should use a parse GlobalObject in order to
# directly allocate to the GC from a helper thread. If false, transfer the
# CompilationStencil back to main thread before allocating GC objects.
- name: javascript.options.off_thread_parse_global
type: bool
value: true
mirror: once
#---------------------------------------------------------------------------
# Prefs starting with "layers."
#---------------------------------------------------------------------------