зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1734098 - Part 15: Use consistent name for decode multi stencils API. r=tcampbell
* DecodeMultiOffThreadStencils => DecodeMultiStencilsOffThread * FinishMultiOffThreadStencilDecoder => FinishDecodeMultiStencilsOffThread * CancelMultiOffThreadScriptsDecoder => CancelDecodeMultiStencilsOffThread Also make JS::DecodeMultiStencilsOffThread to receive JS::DecodeOptions, and make ScriptPreloader to call JS::CanDecodeOffThread. Differential Revision: https://phabricator.services.mozilla.com/D133056
This commit is contained in:
Родитель
149129c9ce
Коммит
57a8e099d3
|
@ -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 */
|
||||
|
|
|
@ -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.
|
||||
|
|
|
@ -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<Stencil> FinishDecodeStencilOffThread(
|
|||
JSContext* cx, OffThreadToken* token,
|
||||
InstantiationStorage* storage = nullptr);
|
||||
|
||||
extern JS_PUBLIC_API bool FinishDecodeMultiStencilsOffThread(
|
||||
JSContext* cx, OffThreadToken* token,
|
||||
mozilla::Vector<RefPtr<Stencil>>* 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>&& stencil);
|
||||
|
||||
extern JS_PUBLIC_API OffThreadToken* DecodeMultiOffThreadStencils(
|
||||
JSContext* cx, const ReadOnlyCompileOptions& options,
|
||||
mozilla::Vector<TranscodeSource>& sources,
|
||||
OffThreadCompileCallback callback, void* callbackData);
|
||||
|
||||
extern JS_PUBLIC_API bool FinishMultiOffThreadStencilDecoder(
|
||||
JSContext* cx, OffThreadToken* token,
|
||||
mozilla::Vector<RefPtr<Stencil>>* stencils);
|
||||
|
||||
} // namespace JS
|
||||
|
||||
namespace mozilla {
|
||||
|
|
|
@ -546,15 +546,6 @@ struct ParseTask : public mozilla::LinkedListElement<ParseTask>,
|
|||
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.
|
||||
|
|
|
@ -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 <typename Unit>
|
||||
CompileToStencilTask<Unit>::CompileToStencilTask(
|
||||
JSContext* cx, JS::SourceText<Unit>& 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<MultiStencilsDecodeTask>(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
|
||||
|
|
|
@ -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);
|
||||
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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<RefPtr<JS::Stencil>>* 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()));
|
||||
|
|
|
@ -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<void*>(this))) {
|
||||
// If we fail here, we don't move on to process the next batch, so make
|
||||
|
|
Загрузка…
Ссылка в новой задаче