Bug 1664182 - Add JS::SetUseOffThreadParseGlobal and js::UseOffThreadParseGlobal, replacing JS::ContextOptions::setUseOffThreadParseGlobal. r=tcampbell

Differential Revision: https://phabricator.services.mozilla.com/D89784
This commit is contained in:
Tooru Fujisawa 2020-09-10 16:05:39 +00:00
Родитель f7175553bb
Коммит 0a00eddff0
9 изменённых файлов: 49 добавлений и 31 удалений

Просмотреть файл

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

Просмотреть файл

@ -45,8 +45,7 @@ class JS_PUBLIC_API ContextOptions {
#endif
fuzzing_(false),
privateClassFields_(false),
privateClassMethods_(false),
useOffThreadParseGlobal_(true) {
privateClassMethods_(false) {
}
bool asmJS() const { return asmJS_; }
@ -154,12 +153,6 @@ 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_; }
@ -269,9 +262,6 @@ 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);

Просмотреть файл

@ -134,6 +134,17 @@ extern JS_PUBLIC_API bool FinishMultiOffThreadScriptsDecoder(
extern JS_PUBLIC_API void CancelMultiOffThreadScriptsDecoder(
JSContext* cx, OffThreadToken* token);
// Tell off-thread compilation to/not to use the parse global.
// The default value is true.
//
// If set to false, off-thread compilation will compile to stencil, and
// instantiate the stencil on main-thread.
extern JS_PUBLIC_API void SetUseOffThreadParseGlobal(bool value);
} // namespace JS
namespace js {
extern bool UseOffThreadParseGlobal();
} // namespace js
#endif /* js_OffThreadScriptCompilation_h */

Просмотреть файл

@ -62,6 +62,7 @@
#include "js/friend/WindowProxy.h" // js::ToWindowProxyIfWindow
#include "js/HashTable.h"
#include "js/LocaleSensitive.h"
#include "js/OffThreadScriptCompilation.h" // js::UseOffThreadParseGlobal
#include "js/PropertySpec.h"
#include "js/RegExpFlags.h" // JS::RegExpFlag, JS::RegExpFlags
#include "js/SourceText.h"
@ -177,7 +178,7 @@ static bool GetRealmConfiguration(JSContext* cx, unsigned argc, Value* vp) {
return false;
}
bool offThreadParseGlobal = cx->options().useOffThreadParseGlobal();
bool offThreadParseGlobal = js::UseOffThreadParseGlobal();
if (!JS_SetProperty(
cx, info, "offThreadParseGlobal",
offThreadParseGlobal ? TrueHandleValue : FalseHandleValue)) {

Просмотреть файл

@ -61,7 +61,8 @@
#include "js/JSON.h"
#include "js/LocaleSensitive.h"
#include "js/MemoryFunctions.h"
#include "js/Object.h" // JS::SetPrivate
#include "js/Object.h" // JS::SetPrivate
#include "js/OffThreadScriptCompilation.h" // js::UseOffThreadParseGlobal
#include "js/PropertySpec.h"
#include "js/Proxy.h"
#include "js/SliceBudget.h"
@ -3545,7 +3546,7 @@ JS::CompileOptions::CompileOptions(JSContext* cx)
cx->options().throwOnAsmJSValidationFailure();
privateClassFields = cx->options().privateClassFields();
privateClassMethods = cx->options().privateClassMethods();
useOffThreadParseGlobal = cx->options().useOffThreadParseGlobal();
useOffThreadParseGlobal = UseOffThreadParseGlobal();
sourcePragmas_ = cx->options().sourcePragmas();

Просмотреть файл

@ -109,10 +109,10 @@
#include "js/Exception.h" // JS::StealPendingExceptionStack
#include "js/experimental/CodeCoverage.h" // js::EnableCodeCoverage
#include "js/experimental/JitInfo.h" // JSJit{Getter,Setter,Method}CallArgs, JSJitGetterInfo, JSJit{Getter,Setter}Op, JSJitInfo
#include "js/experimental/SourceHook.h" // js::{Set,Forget,}SourceHook
#include "js/experimental/TypedData.h" // JS_NewUint8Array
#include "js/friend/DumpFunctions.h" // JS::FormatStackDump
#include "js/friend/StackLimits.h" // js::CheckRecursionLimitConservative
#include "js/experimental/SourceHook.h" // js::{Set,Forget,}SourceHook
#include "js/experimental/TypedData.h" // JS_NewUint8Array
#include "js/friend/DumpFunctions.h" // JS::FormatStackDump
#include "js/friend/StackLimits.h" // js::CheckRecursionLimitConservative
#include "js/friend/WindowProxy.h" // js::IsWindowProxy, js::SetWindowProxyClass, js::ToWindowProxyIfWindow, js::ToWindowIfWindowProxy
#include "js/GCAPI.h" // JS::AutoCheckCannotGC
#include "js/GCVector.h"
@ -121,6 +121,7 @@
#include "js/MemoryFunctions.h"
#include "js/Modules.h" // JS::GetModulePrivate, JS::SetModule{DynamicImport,Metadata,Resolve}Hook, JS::SetModulePrivate
#include "js/Object.h" // JS::GetClass, JS::GetCompartment, JS::GetReservedSlot, JS::SetReservedSlot
#include "js/OffThreadScriptCompilation.h" // JS::SetUseOffThreadParseGlobal
#include "js/Printf.h"
#include "js/PropertySpec.h"
#include "js/Realm.h"
@ -10270,8 +10271,9 @@ static bool SetContextOptions(JSContext* cx, const OptionParser& op) {
.setAsyncStack(enableAsyncStacks)
.setAsyncStackCaptureDebuggeeOnly(enableAsyncStackCaptureDebuggeeOnly)
.setPrivateClassFields(enablePrivateClassFields)
.setPrivateClassMethods(enablePrivateClassMethods)
.setUseOffThreadParseGlobal(useOffThreadParseGlobal);
.setPrivateClassMethods(enablePrivateClassMethods);
JS::SetUseOffThreadParseGlobal(useOffThreadParseGlobal);
if (op.getBoolOption("no-ion-for-main-context")) {
JS::ContextOptionsRef(cx).setDisableIon();

Просмотреть файл

@ -17,8 +17,9 @@
#include "frontend/BytecodeCompilation.h"
#include "frontend/CompilationInfo.h" // frontend::CompilationInfo, frontend::CompilationGCOutput
#include "jit/IonCompileTask.h"
#include "js/ContextOptions.h" // JS::ContextOptions
#include "js/friend/StackLimits.h" // js::ReportOverRecursed
#include "js/ContextOptions.h" // JS::ContextOptions
#include "js/friend/StackLimits.h" // js::ReportOverRecursed
#include "js/OffThreadScriptCompilation.h" // js::UseOffThreadParseGlobal
#include "js/SourceText.h"
#include "js/UniquePtr.h"
#include "js/Utility.h"
@ -2072,7 +2073,9 @@ JSObject* GlobalHelperThreadState::finishModuleParseTask(
MOZ_ASSERT(script->isModule());
if (!cx->options().useOffThreadParseGlobal()) {
// NOTE: StartOffThreadParseTask alters CompileOption only for decode task.
// UseOffThreadParseGlobal() should match CompileOption here.
if (!UseOffThreadParseGlobal()) {
return script->module();
}

Просмотреть файл

@ -207,3 +207,13 @@ JS_PUBLIC_API void JS::CancelMultiOffThreadScriptsDecoder(
HelperThreadState().cancelParseTask(cx->runtime(),
ParseTaskKind::MultiScriptsDecode, token);
}
namespace js {
bool gUseOffThreadParseGlobal = true;
} // namespace js
JS_PUBLIC_API void JS::SetUseOffThreadParseGlobal(bool value) {
gUseOffThreadParseGlobal = value;
}
bool js::UseOffThreadParseGlobal() { return gUseOffThreadParseGlobal; }

Просмотреть файл

@ -40,6 +40,7 @@
#include "jsapi.h"
#include "js/ContextOptions.h"
#include "js/MemoryMetrics.h"
#include "js/OffThreadScriptCompilation.h"
#include "mozilla/dom/BindingUtils.h"
#include "mozilla/dom/ContentChild.h"
#include "mozilla/dom/Element.h"
@ -866,6 +867,9 @@ static void LoadStartupJSPrefs(XPCJSContext* xpccx) {
bool disableWasmHugeMemory =
Preferences::GetBool(JS_OPTIONS_DOT_STR "wasm_disable_huge_memory");
bool useOffThreadParseGlobal =
Preferences::GetBool(JS_OPTIONS_DOT_STR "off_thread_parse_global");
nsCOMPtr<nsIXULRuntime> xr = do_GetService("@mozilla.org/xre/runtime;1");
if (xr) {
bool safeMode = false;
@ -927,6 +931,8 @@ static void LoadStartupJSPrefs(XPCJSContext* xpccx) {
bool disabledHugeMemory = JS::DisableWasmHugeMemory();
MOZ_RELEASE_ASSERT(disabledHugeMemory);
}
JS::SetUseOffThreadParseGlobal(useOffThreadParseGlobal);
}
static void ReloadPrefsCallback(const char* pref, void* aXpccx) {
@ -1001,9 +1007,6 @@ 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(
@ -1047,8 +1050,7 @@ static void ReloadPrefsCallback(const char* pref, void* aXpccx) {
.setThrowOnDebuggeeWouldRun(throwOnDebuggeeWouldRun)
.setDumpStackOnDebuggeeWouldRun(dumpStackOnDebuggeeWouldRun)
.setPrivateClassFields(privateFieldsEnabled)
.setPrivateClassMethods(privateMethodsEnabled)
.setUseOffThreadParseGlobal(useOffThreadParseGlobal);
.setPrivateClassMethods(privateMethodsEnabled);
nsCOMPtr<nsIXULRuntime> xr = do_GetService("@mozilla.org/xre/runtime;1");
if (xr) {