diff --git a/js/public/OffThreadScriptCompilation.h b/js/public/OffThreadScriptCompilation.h index 85d48652e7fd..3ae3c9e45954 100644 --- a/js/public/OffThreadScriptCompilation.h +++ b/js/public/OffThreadScriptCompilation.h @@ -53,9 +53,6 @@ extern JS_PUBLIC_API bool CanDecodeOffThread(JSContext* cx, const DecodeOptions& options, size_t length); -extern JS_PUBLIC_API void CancelMultiOffThreadScriptsDecoder( - JSContext* cx, OffThreadToken* token); - } // namespace JS #endif /* js_OffThreadScriptCompilation_h */ diff --git a/js/public/Transcoding.h b/js/public/Transcoding.h index 2debb6277ac4..b993b7c5225e 100644 --- a/js/public/Transcoding.h +++ b/js/public/Transcoding.h @@ -110,7 +110,7 @@ extern JS_PUBLIC_API bool FinishIncrementalEncoding(JSContext* cx, // // JS::DecodeScript* and JS::DecodeOffThreadScript internally check this. // -// JS::DecodeMultiOffThreadStencils checks some options shared across multiple +// JS::DecodeMultiStencilsOffThread checks some options shared across multiple // scripts. Caller is responsible for checking each script with this API when // using the decoded script instead of compiling a new script wiht the given // options. diff --git a/js/public/experimental/JSStencil.h b/js/public/experimental/JSStencil.h index cb68b3f999e6..3adf702663c3 100644 --- a/js/public/experimental/JSStencil.h +++ b/js/public/experimental/JSStencil.h @@ -26,7 +26,7 @@ #include "js/CompileOptions.h" // JS::ReadOnlyCompileOptions, JS::InstantiateOptions, JS::DecodeOptions #include "js/OffThreadScriptCompilation.h" // JS::OffThreadCompileCallback #include "js/SourceText.h" // JS::SourceText -#include "js/Transcoding.h" // JS::TranscodeSource, JS::TranscodeBuffer, JS::TranscodeRange +#include "js/Transcoding.h" // JS::TranscodeSources, JS::TranscodeBuffer, JS::TranscodeRange #include "js/UniquePtr.h" // js::UniquePtr struct JS_PUBLIC_API JSContext; @@ -198,6 +198,10 @@ extern JS_PUBLIC_API OffThreadToken* DecodeStencilOffThread( JSContext* cx, const DecodeOptions& options, const TranscodeRange& range, OffThreadCompileCallback callback, void* callbackData); +extern JS_PUBLIC_API OffThreadToken* DecodeMultiStencilsOffThread( + JSContext* cx, const DecodeOptions& options, TranscodeSources& sources, + OffThreadCompileCallback callback, void* callbackData); + // Finish the off-thread task to compile the source text into a JS::Stencil, // started by JS::CompileToStencilOffThread, and return the result JS::Stencil. // @@ -216,6 +220,10 @@ extern JS_PUBLIC_API already_AddRefed FinishDecodeStencilOffThread( JSContext* cx, OffThreadToken* token, InstantiationStorage* storage = nullptr); +extern JS_PUBLIC_API bool FinishDecodeMultiStencilsOffThread( + JSContext* cx, OffThreadToken* token, + mozilla::Vector>* stencils); + extern JS_PUBLIC_API void CancelCompileToStencilOffThread( JSContext* cx, OffThreadToken* token); @@ -225,21 +233,15 @@ extern JS_PUBLIC_API void CancelCompileModuleToStencilOffThread( extern JS_PUBLIC_API void CancelDecodeStencilOffThread(JSContext* cx, OffThreadToken* token); +extern JS_PUBLIC_API void CancelDecodeMultiStencilsOffThread( + JSContext* cx, OffThreadToken* token); + // Register an encoder on its script source, such that all functions can be // encoded as they are parsed, in the same way as // JS::CompileAndStartIncrementalEncoding extern JS_PUBLIC_API bool StartIncrementalEncoding(JSContext* cx, RefPtr&& stencil); -extern JS_PUBLIC_API OffThreadToken* DecodeMultiOffThreadStencils( - JSContext* cx, const ReadOnlyCompileOptions& options, - mozilla::Vector& sources, - OffThreadCompileCallback callback, void* callbackData); - -extern JS_PUBLIC_API bool FinishMultiOffThreadStencilDecoder( - JSContext* cx, OffThreadToken* token, - mozilla::Vector>* stencils); - } // namespace JS namespace mozilla { diff --git a/js/src/vm/HelperThreadState.h b/js/src/vm/HelperThreadState.h index 743ab9e9ed32..a0b36a5aa30d 100644 --- a/js/src/vm/HelperThreadState.h +++ b/js/src/vm/HelperThreadState.h @@ -546,15 +546,6 @@ struct ParseTask : public mozilla::LinkedListElement, ThreadType threadType() override { return ThreadType::THREAD_TYPE_PARSE; } }; -struct MultiStencilsDecodeTask : public ParseTask { - JS::TranscodeSources* sources; - - MultiStencilsDecodeTask(JSContext* cx, JS::TranscodeSources& sources, - JS::OffThreadCompileCallback callback, - void* callbackData); - void parse(JSContext* cx) override; -}; - // It is not desirable to eagerly compress: if lazy functions that are tied to // the ScriptSource were to be executed relatively soon after parsing, they // would need to block on decompression, which hurts responsiveness. diff --git a/js/src/vm/HelperThreads.cpp b/js/src/vm/HelperThreads.cpp index 4b9eeb76e9dc..f5fa2665e789 100644 --- a/js/src/vm/HelperThreads.cpp +++ b/js/src/vm/HelperThreads.cpp @@ -655,6 +655,15 @@ struct DecodeStencilTask : public ParseTask { void parse(JSContext* cx) override; }; +struct MultiStencilsDecodeTask : public ParseTask { + JS::TranscodeSources* sources; + + MultiStencilsDecodeTask(JSContext* cx, JS::TranscodeSources& sources, + JS::OffThreadCompileCallback callback, + void* callbackData); + void parse(JSContext* cx) override; +}; + template CompileToStencilTask::CompileToStencilTask( JSContext* cx, JS::SourceText& srcBuf, @@ -995,7 +1004,7 @@ JS::OffThreadToken* js::StartOffThreadDecodeStencil( } JS::OffThreadToken* js::StartOffThreadDecodeMultiStencils( - JSContext* cx, const ReadOnlyCompileOptions& options, + JSContext* cx, const JS::DecodeOptions& options, JS::TranscodeSources& sources, JS::OffThreadCompileCallback callback, void* callbackData) { auto task = cx->make_unique(cx, sources, callback, @@ -1004,7 +1013,10 @@ JS::OffThreadToken* js::StartOffThreadDecodeMultiStencils( return nullptr; } - return StartOffThreadParseTask(cx, std::move(task), options); + JS::CompileOptions compileOptions(cx); + options.copyTo(compileOptions); + + return StartOffThreadParseTask(cx, std::move(task), compileOptions); } #ifdef DEBUG diff --git a/js/src/vm/HelperThreads.h b/js/src/vm/HelperThreads.h index dcb8f8dd87a6..86dde3ad59be 100644 --- a/js/src/vm/HelperThreads.h +++ b/js/src/vm/HelperThreads.h @@ -224,7 +224,7 @@ JS::OffThreadToken* StartOffThreadDecodeStencil( void* callbackData); JS::OffThreadToken* StartOffThreadDecodeMultiStencils( - JSContext* cx, const JS::ReadOnlyCompileOptions& options, + JSContext* cx, const JS::DecodeOptions& options, JS::TranscodeSources& sources, JS::OffThreadCompileCallback callback, void* callbackData); diff --git a/js/src/vm/JSScript.cpp b/js/src/vm/JSScript.cpp index 42fde94e16a0..7c79062ae0bc 100644 --- a/js/src/vm/JSScript.cpp +++ b/js/src/vm/JSScript.cpp @@ -419,7 +419,7 @@ void js::FillImmutableFlagsFromCompileOptionsForFunction( // FillImmutableFlagsFromCompileOptionsForTopLevel above. // // If isMultiDecode is true, this check minimal set of CompileOptions that is -// shared across multiple scripts in JS::DecodeMultiOffThreadStencils. +// shared across multiple scripts in JS::DecodeMultiStencilsOffThread. // Other options should be checked when getting the decoded script from the // cache. bool js::CheckCompileOptionsMatch(const ReadOnlyCompileOptions& options, diff --git a/js/src/vm/OffThreadScriptCompilation.cpp b/js/src/vm/OffThreadScriptCompilation.cpp index 1f1332b50831..b893c7486c29 100644 --- a/js/src/vm/OffThreadScriptCompilation.cpp +++ b/js/src/vm/OffThreadScriptCompilation.cpp @@ -168,22 +168,21 @@ JS_PUBLIC_API bool JS::CanDecodeOffThread(JSContext* cx, return CanDoOffThread(cx, options, length); } -JS_PUBLIC_API JS::OffThreadToken* JS::DecodeMultiOffThreadStencils( - JSContext* cx, const ReadOnlyCompileOptions& options, - TranscodeSources& sources, OffThreadCompileCallback callback, - void* callbackData) { +JS_PUBLIC_API JS::OffThreadToken* JS::DecodeMultiStencilsOffThread( + JSContext* cx, const DecodeOptions& options, TranscodeSources& sources, + OffThreadCompileCallback callback, void* callbackData) { #ifdef DEBUG size_t length = 0; for (auto& source : sources) { length += source.range.length(); } - MOZ_ASSERT(CanCompileOffThread(cx, options, length)); + MOZ_ASSERT(CanDecodeOffThread(cx, options, length)); #endif return StartOffThreadDecodeMultiStencils(cx, options, sources, callback, callbackData); } -JS_PUBLIC_API bool JS::FinishMultiOffThreadStencilDecoder( +JS_PUBLIC_API bool JS::FinishDecodeMultiStencilsOffThread( JSContext* cx, JS::OffThreadToken* token, mozilla::Vector>* stencils) { MOZ_ASSERT(cx); @@ -191,7 +190,7 @@ JS_PUBLIC_API bool JS::FinishMultiOffThreadStencilDecoder( return HelperThreadState().finishMultiStencilsDecodeTask(cx, token, stencils); } -JS_PUBLIC_API void JS::CancelMultiOffThreadScriptsDecoder( +JS_PUBLIC_API void JS::CancelDecodeMultiStencilsOffThread( JSContext* cx, JS::OffThreadToken* token) { MOZ_ASSERT(cx); MOZ_ASSERT(CurrentThreadCanAccessRuntime(cx->runtime())); diff --git a/js/xpconnect/loader/ScriptPreloader.cpp b/js/xpconnect/loader/ScriptPreloader.cpp index d04905611249..19bd283e6e92 100644 --- a/js/xpconnect/loader/ScriptPreloader.cpp +++ b/js/xpconnect/loader/ScriptPreloader.cpp @@ -1063,7 +1063,7 @@ void ScriptPreloader::FinishOffThreadDecode(JS::OffThreadToken* token) { // // The exception from the off-thread decode operation will be reported when // we pop the AutoJSAPI off the stack. - Unused << JS::FinishMultiOffThreadStencilDecoder(cx, token, &stencils); + Unused << JS::FinishDecodeMultiStencilsOffThread(cx, token, &stencils); unsigned i = 0; for (auto script : mParsingScripts) { @@ -1135,8 +1135,10 @@ void ScriptPreloader::DecodeNextBatch(size_t chunkSize, options.borrowBuffer = true; options.usePinnedBytecode = true; - if (!JS::CanCompileOffThread(cx, options, size) || - !JS::DecodeMultiOffThreadStencils(cx, options, mParsingSources, + JS::DecodeOptions decodeOptions(options); + + if (!JS::CanDecodeOffThread(cx, decodeOptions, size) || + !JS::DecodeMultiStencilsOffThread(cx, decodeOptions, mParsingSources, OffThreadDecodeCallback, static_cast(this))) { // If we fail here, we don't move on to process the next batch, so make