Bug 1788977 - Consolidate methods for finishing off-thread JS parse/decode. r=arai

Off-thread parse and decode all generate JS::Stencils so the various
specializations are not needed for methods that collect the results back to
main-thread.

Depends on D156335

Differential Revision: https://phabricator.services.mozilla.com/D156336
This commit is contained in:
Ted Campbell
2022-09-06 12:01:35 +00:00
parent db4c7cad42
commit d2f16d6095
13 changed files with 44 additions and 179 deletions

View File

@@ -97,7 +97,7 @@ nsresult JSExecutionContext::JoinCompile(JS::OffThreadToken** aOffThreadToken) {
JS::InstantiateOptions instantiateOptions(mCompileOptions); JS::InstantiateOptions instantiateOptions(mCompileOptions);
JS::Rooted<JS::InstantiationStorage> storage(mCx); JS::Rooted<JS::InstantiationStorage> storage(mCx);
RefPtr<JS::Stencil> stencil = JS::FinishCompileToStencilOffThread( RefPtr<JS::Stencil> stencil = JS::FinishOffThreadStencil(
mCx, *aOffThreadToken, storage.address()); mCx, *aOffThreadToken, storage.address());
*aOffThreadToken = nullptr; // Mark the token as having been finished. *aOffThreadToken = nullptr; // Mark the token as having been finished.
if (!stencil) { if (!stencil) {
@@ -249,7 +249,7 @@ nsresult JSExecutionContext::JoinDecode(JS::OffThreadToken** aOffThreadToken) {
MOZ_ASSERT(!mWantsReturnValue); MOZ_ASSERT(!mWantsReturnValue);
JS::Rooted<JS::InstantiationStorage> storage(mCx); JS::Rooted<JS::InstantiationStorage> storage(mCx);
RefPtr<JS::Stencil> stencil = JS::FinishDecodeStencilOffThread( RefPtr<JS::Stencil> stencil = JS::FinishOffThreadStencil(
mCx, *aOffThreadToken, storage.address()); mCx, *aOffThreadToken, storage.address());
*aOffThreadToken = nullptr; // Mark the token as having been finished. *aOffThreadToken = nullptr; // Mark the token as having been finished.
if (!stencil) { if (!stencil) {

View File

@@ -149,18 +149,9 @@ nsresult ModuleLoader::CompileFetchedModule(
ModuleLoadRequest* aRequest, JS::MutableHandle<JSObject*> aModuleOut) { ModuleLoadRequest* aRequest, JS::MutableHandle<JSObject*> aModuleOut) {
if (aRequest->GetScriptLoadContext()->mWasCompiledOMT) { if (aRequest->GetScriptLoadContext()->mWasCompiledOMT) {
JS::Rooted<JS::InstantiationStorage> storage(aCx); JS::Rooted<JS::InstantiationStorage> storage(aCx);
RefPtr<JS::Stencil> stencil = JS::FinishOffThreadStencil(
RefPtr<JS::Stencil> stencil; aCx, aRequest->GetScriptLoadContext()->mOffThreadToken,
if (aRequest->IsTextSource()) { storage.address());
stencil = JS::FinishCompileModuleToStencilOffThread(
aCx, aRequest->GetScriptLoadContext()->mOffThreadToken,
storage.address());
} else {
MOZ_ASSERT(aRequest->IsBytecode());
stencil = JS::FinishDecodeStencilOffThread(
aCx, aRequest->GetScriptLoadContext()->mOffThreadToken,
storage.address());
}
aRequest->GetScriptLoadContext()->mOffThreadToken = nullptr; aRequest->GetScriptLoadContext()->mOffThreadToken = nullptr;

View File

@@ -105,16 +105,7 @@ void ScriptLoadContext::MaybeCancelOffThreadScript() {
} }
JSContext* cx = danger::GetJSContext(); JSContext* cx = danger::GetJSContext();
// The conditions should match ScriptLoader::AttemptAsyncScriptCompile. JS::CancelOffThreadToken(cx, mOffThreadToken);
if (mRequest->IsBytecode()) {
JS::CancelDecodeStencilOffThread(cx, mOffThreadToken);
} else if (mRequest->IsModuleRequest()) {
MOZ_ASSERT(mRequest->IsTextSource());
JS::CancelCompileModuleToStencilOffThread(cx, mOffThreadToken);
} else {
MOZ_ASSERT(mRequest->IsTextSource());
JS::CancelCompileToStencilOffThread(cx, mOffThreadToken);
}
// Cancellation request above should guarantee removal of the parse task, so // Cancellation request above should guarantee removal of the parse task, so
// releasing the runnable should be safe to do here. // releasing the runnable should be safe to do here.

View File

@@ -1845,7 +1845,7 @@ NotifyOffThreadScriptCompletedRunnable::Run() {
return NS_ERROR_UNEXPECTED; return NS_ERROR_UNEXPECTED;
} }
JSContext* cx = jsapi.cx(); JSContext* cx = jsapi.cx();
stencil = JS::FinishCompileToStencilOffThread(cx, mToken); stencil = JS::FinishOffThreadStencil(cx, mToken);
} }
if (!sReceivers) { if (!sReceivers) {

View File

@@ -277,15 +277,7 @@ extern JS_PUBLIC_API OffThreadToken* DecodeMultiStencilsOffThread(
// If `options.allocateInstantiationStorage` was true in // If `options.allocateInstantiationStorage` was true in
// JS::CompileToStencilOffThread, pre-allocated JS::InstantiationStorage // JS::CompileToStencilOffThread, pre-allocated JS::InstantiationStorage
// is returned as `storage` out parameter. // is returned as `storage` out parameter.
extern JS_PUBLIC_API already_AddRefed<Stencil> FinishCompileToStencilOffThread( extern JS_PUBLIC_API already_AddRefed<Stencil> FinishOffThreadStencil(
JSContext* cx, OffThreadToken* token,
InstantiationStorage* storage = nullptr);
extern JS_PUBLIC_API already_AddRefed<Stencil>
FinishCompileModuleToStencilOffThread(JSContext* cx, OffThreadToken* token,
InstantiationStorage* storage = nullptr);
extern JS_PUBLIC_API already_AddRefed<Stencil> FinishDecodeStencilOffThread(
JSContext* cx, OffThreadToken* token, JSContext* cx, OffThreadToken* token,
InstantiationStorage* storage = nullptr); InstantiationStorage* storage = nullptr);
@@ -294,17 +286,8 @@ extern JS_PUBLIC_API bool FinishDecodeMultiStencilsOffThread(
mozilla::Vector<RefPtr<Stencil>>* stencils); mozilla::Vector<RefPtr<Stencil>>* stencils);
// Cancel the off-thread task to compile/decode. // Cancel the off-thread task to compile/decode.
extern JS_PUBLIC_API void CancelCompileToStencilOffThread( extern JS_PUBLIC_API void CancelOffThreadToken(JSContext* cx,
JSContext* cx, OffThreadToken* token); OffThreadToken* token);
extern JS_PUBLIC_API void CancelCompileModuleToStencilOffThread(
JSContext* cx, OffThreadToken* token);
extern JS_PUBLIC_API void CancelDecodeStencilOffThread(JSContext* cx,
OffThreadToken* token);
extern JS_PUBLIC_API void CancelDecodeMultiStencilsOffThread(
JSContext* cx, OffThreadToken* token);
} // namespace JS } // namespace JS

View File

@@ -104,7 +104,7 @@ bool testCompile(bool nonSyntactic) {
CHECK(CompileToStencilOffThread(cx, options, srcBuf, task.OffThreadCallback, CHECK(CompileToStencilOffThread(cx, options, srcBuf, task.OffThreadCallback,
&task)); &task));
CHECK(token = task.waitUntilDone(cx)); CHECK(token = task.waitUntilDone(cx));
CHECK(stencil = FinishCompileToStencilOffThread(cx, token)); CHECK(stencil = FinishOffThreadStencil(cx, token));
InstantiateOptions instantiateOptions(options); InstantiateOptions instantiateOptions(options);
CHECK(script = InstantiateGlobalStencil(cx, instantiateOptions, stencil)); CHECK(script = InstantiateGlobalStencil(cx, instantiateOptions, stencil));
CHECK_EQUAL(script->hasNonSyntacticScope(), nonSyntactic); CHECK_EQUAL(script->hasNonSyntacticScope(), nonSyntactic);

View File

@@ -524,7 +524,7 @@ BEGIN_TEST(testScriptSourceCompression_offThread) {
lock.wait(); lock.wait();
} }
RefPtr<JS::Stencil> stencil = JS::FinishCompileToStencilOffThread(cx, token); RefPtr<JS::Stencil> stencil = JS::FinishOffThreadStencil(cx, token);
CHECK(stencil); CHECK(stencil);
JS::InstantiateOptions instantiateOptions(options); JS::InstantiateOptions instantiateOptions(options);
JS::Rooted<JSScript*> script( JS::Rooted<JSScript*> script(

View File

@@ -351,7 +351,7 @@ BEGIN_TEST(testStencil_OffThread) {
lock.wait(); lock.wait();
} }
RefPtr<JS::Stencil> stencil = JS::FinishCompileToStencilOffThread(cx, token); RefPtr<JS::Stencil> stencil = JS::FinishOffThreadStencil(cx, token);
CHECK(stencil); CHECK(stencil);
JS::InstantiateOptions instantiateOptions(options); JS::InstantiateOptions instantiateOptions(options);
@@ -402,7 +402,7 @@ BEGIN_TEST(testStencil_OffThreadWithInstantiationStorage) {
JS::Rooted<JS::InstantiationStorage> storage(cx); JS::Rooted<JS::InstantiationStorage> storage(cx);
RefPtr<JS::Stencil> stencil = RefPtr<JS::Stencil> stencil =
JS::FinishCompileToStencilOffThread(cx, token, storage.address()); JS::FinishOffThreadStencil(cx, token, storage.address());
CHECK(stencil); CHECK(stencil);
JS::InstantiateOptions instantiateOptions(options); JS::InstantiateOptions instantiateOptions(options);
@@ -450,8 +450,7 @@ BEGIN_TEST(testStencil_OffThreadModule) {
lock.wait(); lock.wait();
} }
RefPtr<JS::Stencil> stencil = RefPtr<JS::Stencil> stencil = JS::FinishOffThreadStencil(cx, token);
JS::FinishCompileModuleToStencilOffThread(cx, token);
CHECK(stencil); CHECK(stencil);
JS::InstantiateOptions instantiateOptions(options); JS::InstantiateOptions instantiateOptions(options);
@@ -506,7 +505,7 @@ BEGIN_TEST(testStencil_OffThreadModuleWithInstantiationStorage) {
JS::Rooted<JS::InstantiationStorage> storage(cx); JS::Rooted<JS::InstantiationStorage> storage(cx);
RefPtr<JS::Stencil> stencil = RefPtr<JS::Stencil> stencil =
JS::FinishCompileModuleToStencilOffThread(cx, token, storage.address()); JS::FinishOffThreadStencil(cx, token, storage.address());
CHECK(stencil); CHECK(stencil);
JS::InstantiateOptions instantiateOptions(options); JS::InstantiateOptions instantiateOptions(options);
@@ -586,7 +585,7 @@ BEGIN_TEST(testStencil_OffThreadDecode) {
} }
} }
RefPtr<JS::Stencil> stencil = JS::FinishDecodeStencilOffThread(cx, token); RefPtr<JS::Stencil> stencil = JS::FinishOffThreadStencil(cx, token);
CHECK(stencil); CHECK(stencil);
CHECK(!JS::StencilIsBorrowed(stencil)); CHECK(!JS::StencilIsBorrowed(stencil));
@@ -669,7 +668,7 @@ BEGIN_TEST(testStencil_OffThreadDecodeWithInstantiationStorage) {
JS::Rooted<JS::InstantiationStorage> storage(cx); JS::Rooted<JS::InstantiationStorage> storage(cx);
RefPtr<JS::Stencil> stencil = RefPtr<JS::Stencil> stencil =
JS::FinishDecodeStencilOffThread(cx, token, storage.address()); JS::FinishOffThreadStencil(cx, token, storage.address());
CHECK(stencil); CHECK(stencil);
CHECK(!JS::StencilIsBorrowed(stencil)); CHECK(!JS::StencilIsBorrowed(stencil));
@@ -751,7 +750,7 @@ BEGIN_TEST(testStencil_OffThreadDecodeBorrow) {
} }
} }
RefPtr<JS::Stencil> stencil = JS::FinishDecodeStencilOffThread(cx, token); RefPtr<JS::Stencil> stencil = JS::FinishOffThreadStencil(cx, token);
CHECK(stencil); CHECK(stencil);
CHECK(JS::StencilIsBorrowed(stencil)); CHECK(JS::StencilIsBorrowed(stencil));
@@ -842,7 +841,7 @@ BEGIN_TEST(testStencil_OffThreadDecodePinned) {
} }
} }
RefPtr<JS::Stencil> stencil = JS::FinishDecodeStencilOffThread(cx, token); RefPtr<JS::Stencil> stencil = JS::FinishOffThreadStencil(cx, token);
CHECK(stencil); CHECK(stencil);
CHECK(JS::StencilIsBorrowed(stencil)); CHECK(JS::StencilIsBorrowed(stencil));

View File

@@ -5827,7 +5827,7 @@ static bool FinishOffThreadCompileToStencil(JSContext* cx, unsigned argc,
JS::OffThreadToken* token = job->waitUntilDone(cx); JS::OffThreadToken* token = job->waitUntilDone(cx);
MOZ_ASSERT(token); MOZ_ASSERT(token);
RefPtr<JS::Stencil> stencil = JS::FinishCompileToStencilOffThread(cx, token); RefPtr<JS::Stencil> stencil = JS::FinishOffThreadStencil(cx, token);
DeleteOffThreadJob(cx, job); DeleteOffThreadJob(cx, job);
if (!stencil) { if (!stencil) {
return false; return false;
@@ -5923,7 +5923,7 @@ static bool FinishOffThreadCompileModuleToStencil(JSContext* cx, unsigned argc,
MOZ_ASSERT(token); MOZ_ASSERT(token);
RefPtr<JS::Stencil> stencil = RefPtr<JS::Stencil> stencil =
JS::FinishCompileModuleToStencilOffThread(cx, token); JS::FinishOffThreadStencil(cx, token);
DeleteOffThreadJob(cx, job); DeleteOffThreadJob(cx, job);
if (!stencil) { if (!stencil) {
return false; return false;
@@ -6033,7 +6033,7 @@ static bool FinishOffThreadDecodeStencil(JSContext* cx, unsigned argc,
JS::OffThreadToken* token = job->waitUntilDone(cx); JS::OffThreadToken* token = job->waitUntilDone(cx);
MOZ_ASSERT(token); MOZ_ASSERT(token);
RefPtr<JS::Stencil> stencil = JS::FinishDecodeStencilOffThread(cx, token); RefPtr<JS::Stencil> stencil = JS::FinishOffThreadStencil(cx, token);
DeleteOffThreadJob(cx, job); DeleteOffThreadJob(cx, job);
if (!stencil) { if (!stencil) {
return false; return false;

View File

@@ -193,8 +193,7 @@ class GlobalHelperThreadState {
bool useInternalThreadPool_ = true; bool useInternalThreadPool_ = true;
ParseTask* removeFinishedParseTask(JSContext* cx, ParseTaskKind kind, ParseTask* removeFinishedParseTask(JSContext* cx, JS::OffThreadToken* token);
JS::OffThreadToken* token);
public: public:
void addSizeOfIncludingThis(JS::GlobalStats* stats, void addSizeOfIncludingThis(JS::GlobalStats* stats,
@@ -399,30 +398,20 @@ class GlobalHelperThreadState {
const AutoLockHelperThreadState& lock, bool checkExecutionStatus); const AutoLockHelperThreadState& lock, bool checkExecutionStatus);
private: private:
UniquePtr<ParseTask> finishParseTaskCommon(JSContext* cx, ParseTaskKind kind, UniquePtr<ParseTask> finishParseTaskCommon(JSContext* cx,
JS::OffThreadToken* token); JS::OffThreadToken* token);
already_AddRefed<frontend::CompilationStencil> finishCompileToStencilTask(
JSContext* cx, ParseTaskKind kind, JS::OffThreadToken* token,
JS::InstantiationStorage* storage);
bool finishMultiParseTask(JSContext* cx, ParseTaskKind kind, bool finishMultiParseTask(JSContext* cx, ParseTaskKind kind,
JS::OffThreadToken* token, JS::OffThreadToken* token,
mozilla::Vector<RefPtr<JS::Stencil>>* stencils); mozilla::Vector<RefPtr<JS::Stencil>>* stencils);
public: public:
void cancelParseTask(JSRuntime* rt, ParseTaskKind kind, void cancelParseTask(JSRuntime* rt, JS::OffThreadToken* token);
JS::OffThreadToken* token);
void destroyParseTask(JSRuntime* rt, ParseTask* parseTask); void destroyParseTask(JSRuntime* rt, ParseTask* parseTask);
void trace(JSTracer* trc); void trace(JSTracer* trc);
already_AddRefed<frontend::CompilationStencil> finishCompileToStencilTask( already_AddRefed<frontend::CompilationStencil> finishStencilTask(
JSContext* cx, JS::OffThreadToken* token,
JS::InstantiationStorage* storage);
already_AddRefed<frontend::CompilationStencil>
finishCompileModuleToStencilTask(JSContext* cx, JS::OffThreadToken* token,
JS::InstantiationStorage* storage);
already_AddRefed<frontend::CompilationStencil> finishDecodeStencilTask(
JSContext* cx, JS::OffThreadToken* token, JSContext* cx, JS::OffThreadToken* token,
JS::InstantiationStorage* storage); JS::InstantiationStorage* storage);
bool finishMultiStencilsDecodeTask( bool finishMultiStencilsDecodeTask(

View File

@@ -2309,14 +2309,13 @@ bool GlobalHelperThreadState::canStartGCParallelTask(
} }
ParseTask* GlobalHelperThreadState::removeFinishedParseTask( ParseTask* GlobalHelperThreadState::removeFinishedParseTask(
JSContext* cx, ParseTaskKind kind, JS::OffThreadToken* token) { JSContext* cx, JS::OffThreadToken* token) {
// The token is really a ParseTask* which should be in the finished list. // The token is really a ParseTask* which should be in the finished list.
auto task = static_cast<ParseTask*>(token); auto task = static_cast<ParseTask*>(token);
// The token was passed in from the browser. Check that the pointer is likely // The token was passed in from the browser. Check that the pointer is likely
// a valid parse task of the expected kind. // a valid parse task of the expected kind.
MOZ_RELEASE_ASSERT(task->runtime == cx->runtime()); MOZ_RELEASE_ASSERT(task->runtime == cx->runtime());
MOZ_RELEASE_ASSERT(task->kind == kind);
// Remove the task from the finished list. // Remove the task from the finished list.
AutoLockHelperThreadState lock; AutoLockHelperThreadState lock;
@@ -2326,12 +2325,12 @@ ParseTask* GlobalHelperThreadState::removeFinishedParseTask(
} }
UniquePtr<ParseTask> GlobalHelperThreadState::finishParseTaskCommon( UniquePtr<ParseTask> GlobalHelperThreadState::finishParseTaskCommon(
JSContext* cx, ParseTaskKind kind, JS::OffThreadToken* token) { JSContext* cx, JS::OffThreadToken* token) {
MOZ_ASSERT(!cx->isHelperThreadContext()); MOZ_ASSERT(!cx->isHelperThreadContext());
MOZ_ASSERT(cx->realm()); MOZ_ASSERT(cx->realm());
Rooted<UniquePtr<ParseTask>> parseTask( Rooted<UniquePtr<ParseTask>> parseTask(cx,
cx, removeFinishedParseTask(cx, kind, token)); removeFinishedParseTask(cx, token));
// Report out of memory errors eagerly, or errors could be malformed. // Report out of memory errors eagerly, or errors could be malformed.
if (parseTask->ec_.hadOutOfMemory()) { if (parseTask->ec_.hadOutOfMemory()) {
@@ -2354,11 +2353,10 @@ UniquePtr<ParseTask> GlobalHelperThreadState::finishParseTaskCommon(
} }
already_AddRefed<frontend::CompilationStencil> already_AddRefed<frontend::CompilationStencil>
GlobalHelperThreadState::finishCompileToStencilTask( GlobalHelperThreadState::finishStencilTask(JSContext* cx,
JSContext* cx, ParseTaskKind kind, JS::OffThreadToken* token, JS::OffThreadToken* token,
JS::InstantiationStorage* storage) { JS::InstantiationStorage* storage) {
Rooted<UniquePtr<ParseTask>> parseTask( Rooted<UniquePtr<ParseTask>> parseTask(cx, finishParseTaskCommon(cx, token));
cx, finishParseTaskCommon(cx, kind, token));
if (!parseTask) { if (!parseTask) {
return nullptr; return nullptr;
} }
@@ -2378,8 +2376,7 @@ bool GlobalHelperThreadState::finishMultiParseTask(
JSContext* cx, ParseTaskKind kind, JS::OffThreadToken* token, JSContext* cx, ParseTaskKind kind, JS::OffThreadToken* token,
mozilla::Vector<RefPtr<JS::Stencil>>* stencils) { mozilla::Vector<RefPtr<JS::Stencil>>* stencils) {
MOZ_ASSERT(stencils); MOZ_ASSERT(stencils);
Rooted<UniquePtr<ParseTask>> parseTask( Rooted<UniquePtr<ParseTask>> parseTask(cx, finishParseTaskCommon(cx, token));
cx, finishParseTaskCommon(cx, kind, token));
if (!parseTask) { if (!parseTask) {
return false; return false;
} }
@@ -2408,42 +2405,6 @@ bool GlobalHelperThreadState::finishMultiParseTask(
return true; return true;
} }
already_AddRefed<frontend::CompilationStencil>
GlobalHelperThreadState::finishCompileToStencilTask(
JSContext* cx, JS::OffThreadToken* token,
JS::InstantiationStorage* storage) {
return finishCompileToStencilTask(cx, ParseTaskKind::ScriptStencil, token,
storage);
}
already_AddRefed<frontend::CompilationStencil>
GlobalHelperThreadState::finishCompileModuleToStencilTask(
JSContext* cx, JS::OffThreadToken* token,
JS::InstantiationStorage* storage) {
return finishCompileToStencilTask(cx, ParseTaskKind::ModuleStencil, token,
storage);
}
already_AddRefed<frontend::CompilationStencil>
GlobalHelperThreadState::finishDecodeStencilTask(
JSContext* cx, JS::OffThreadToken* token,
JS::InstantiationStorage* storage) {
Rooted<UniquePtr<ParseTask>> parseTask(
cx, finishParseTaskCommon(cx, ParseTaskKind::StencilDecode, token));
if (!parseTask) {
return nullptr;
}
MOZ_ASSERT(parseTask->stencil_.get());
if (storage) {
MOZ_ASSERT(parseTask->options.allocateInstantiationStorage);
parseTask->moveGCOutputInto(*storage);
}
return parseTask->stencil_.forget();
}
bool GlobalHelperThreadState::finishMultiStencilsDecodeTask( bool GlobalHelperThreadState::finishMultiStencilsDecodeTask(
JSContext* cx, JS::OffThreadToken* token, JSContext* cx, JS::OffThreadToken* token,
mozilla::Vector<RefPtr<JS::Stencil>>* stencils) { mozilla::Vector<RefPtr<JS::Stencil>>* stencils) {
@@ -2451,7 +2412,7 @@ bool GlobalHelperThreadState::finishMultiStencilsDecodeTask(
stencils); stencils);
} }
void GlobalHelperThreadState::cancelParseTask(JSRuntime* rt, ParseTaskKind kind, void GlobalHelperThreadState::cancelParseTask(JSRuntime* rt,
JS::OffThreadToken* token) { JS::OffThreadToken* token) {
AutoLockHelperThreadState lock; AutoLockHelperThreadState lock;
MOZ_ASSERT(token); MOZ_ASSERT(token);
@@ -2462,7 +2423,6 @@ void GlobalHelperThreadState::cancelParseTask(JSRuntime* rt, ParseTaskKind kind,
HelperThreadState().parseWorklist(lock); HelperThreadState().parseWorklist(lock);
for (size_t i = 0; i < worklist.length(); i++) { for (size_t i = 0; i < worklist.length(); i++) {
if (task == worklist[i]) { if (task == worklist[i]) {
MOZ_ASSERT(task->kind == kind);
MOZ_ASSERT(task->runtimeMatches(rt)); MOZ_ASSERT(task->runtimeMatches(rt));
task->deactivate(rt); task->deactivate(rt);
HelperThreadState().remove(worklist, &i); HelperThreadState().remove(worklist, &i);
@@ -2475,7 +2435,6 @@ void GlobalHelperThreadState::cancelParseTask(JSRuntime* rt, ParseTaskKind kind,
bool foundTask = false; bool foundTask = false;
for (auto* helper : HelperThreadState().helperTasks(lock)) { for (auto* helper : HelperThreadState().helperTasks(lock)) {
if (helper->is<ParseTask>() && helper->as<ParseTask>() == task) { if (helper->is<ParseTask>() && helper->as<ParseTask>() == task) {
MOZ_ASSERT(helper->as<ParseTask>()->kind == kind);
MOZ_ASSERT(helper->as<ParseTask>()->runtimeMatches(rt)); MOZ_ASSERT(helper->as<ParseTask>()->runtimeMatches(rt));
foundTask = true; foundTask = true;
break; break;
@@ -2492,7 +2451,6 @@ void GlobalHelperThreadState::cancelParseTask(JSRuntime* rt, ParseTaskKind kind,
auto& finished = HelperThreadState().parseFinishedList(lock); auto& finished = HelperThreadState().parseFinishedList(lock);
for (auto* t : finished) { for (auto* t : finished) {
if (task == t) { if (task == t) {
MOZ_ASSERT(task->kind == kind);
MOZ_ASSERT(task->runtimeMatches(rt)); MOZ_ASSERT(task->runtimeMatches(rt));
task->remove(); task->remove();
HelperThreadState().destroyParseTask(rt, task); HelperThreadState().destroyParseTask(rt, task);

View File

@@ -107,59 +107,21 @@ JS_PUBLIC_API JS::OffThreadToken* JS::DecodeStencilOffThread(
callbackData); callbackData);
} }
JS_PUBLIC_API already_AddRefed<JS::Stencil> JS::FinishCompileToStencilOffThread( JS_PUBLIC_API already_AddRefed<JS::Stencil> JS::FinishOffThreadStencil(
JSContext* cx, JS::OffThreadToken* token, JSContext* cx, JS::OffThreadToken* token,
JS::InstantiationStorage* storage /* = nullptr */) { JS::InstantiationStorage* storage /* = nullptr */) {
MOZ_ASSERT(cx); MOZ_ASSERT(cx);
MOZ_ASSERT(CurrentThreadCanAccessRuntime(cx->runtime())); MOZ_ASSERT(CurrentThreadCanAccessRuntime(cx->runtime()));
RefPtr<JS::Stencil> stencil = RefPtr<JS::Stencil> stencil =
HelperThreadState().finishCompileToStencilTask(cx, token, storage); HelperThreadState().finishStencilTask(cx, token, storage);
return stencil.forget(); return stencil.forget();
} }
JS_PUBLIC_API already_AddRefed<JS::Stencil> JS_PUBLIC_API void JS::CancelOffThreadToken(JSContext* cx,
JS::FinishCompileModuleToStencilOffThread( JS::OffThreadToken* token) {
JSContext* cx, JS::OffThreadToken* token,
JS::InstantiationStorage* storage /* = nullptr */) {
MOZ_ASSERT(cx); MOZ_ASSERT(cx);
MOZ_ASSERT(CurrentThreadCanAccessRuntime(cx->runtime())); MOZ_ASSERT(CurrentThreadCanAccessRuntime(cx->runtime()));
RefPtr<JS::Stencil> stencil = HelperThreadState().cancelParseTask(cx->runtime(), token);
HelperThreadState().finishCompileModuleToStencilTask(cx, token, storage);
return stencil.forget();
}
JS_PUBLIC_API already_AddRefed<JS::Stencil> JS::FinishDecodeStencilOffThread(
JSContext* cx, JS::OffThreadToken* token,
JS::InstantiationStorage* storage /* = nullptr */) {
MOZ_ASSERT(cx);
MOZ_ASSERT(CurrentThreadCanAccessRuntime(cx->runtime()));
RefPtr<JS::Stencil> stencil =
HelperThreadState().finishDecodeStencilTask(cx, token, storage);
return stencil.forget();
}
JS_PUBLIC_API void JS::CancelCompileToStencilOffThread(
JSContext* cx, JS::OffThreadToken* token) {
MOZ_ASSERT(cx);
MOZ_ASSERT(CurrentThreadCanAccessRuntime(cx->runtime()));
HelperThreadState().cancelParseTask(cx->runtime(),
ParseTaskKind::ScriptStencil, token);
}
JS_PUBLIC_API void JS::CancelCompileModuleToStencilOffThread(
JSContext* cx, JS::OffThreadToken* token) {
MOZ_ASSERT(cx);
MOZ_ASSERT(CurrentThreadCanAccessRuntime(cx->runtime()));
HelperThreadState().cancelParseTask(cx->runtime(),
ParseTaskKind::ModuleStencil, token);
}
JS_PUBLIC_API void JS::CancelDecodeStencilOffThread(JSContext* cx,
JS::OffThreadToken* token) {
MOZ_ASSERT(cx);
MOZ_ASSERT(CurrentThreadCanAccessRuntime(cx->runtime()));
HelperThreadState().cancelParseTask(cx->runtime(),
ParseTaskKind::StencilDecode, token);
} }
JS_PUBLIC_API bool JS::CanDecodeOffThread(JSContext* cx, JS_PUBLIC_API bool JS::CanDecodeOffThread(JSContext* cx,
@@ -189,11 +151,3 @@ JS_PUBLIC_API bool JS::FinishDecodeMultiStencilsOffThread(
MOZ_ASSERT(CurrentThreadCanAccessRuntime(cx->runtime())); MOZ_ASSERT(CurrentThreadCanAccessRuntime(cx->runtime()));
return HelperThreadState().finishMultiStencilsDecodeTask(cx, token, stencils); return HelperThreadState().finishMultiStencilsDecodeTask(cx, token, stencils);
} }
JS_PUBLIC_API void JS::CancelDecodeMultiStencilsOffThread(
JSContext* cx, JS::OffThreadToken* token) {
MOZ_ASSERT(cx);
MOZ_ASSERT(CurrentThreadCanAccessRuntime(cx->runtime()));
HelperThreadState().cancelParseTask(
cx->runtime(), ParseTaskKind::MultiStencilsDecode, token);
}

View File

@@ -169,7 +169,7 @@ AsyncScriptCompiler::Run() {
FinishCompile(jsapi.cx()); FinishCompile(jsapi.cx());
} else { } else {
jsapi.Init(); jsapi.Init();
JS::CancelCompileToStencilOffThread(jsapi.cx(), mToken); JS::CancelOffThreadToken(jsapi.cx(), mToken);
mPromise->MaybeReject(NS_ERROR_FAILURE); mPromise->MaybeReject(NS_ERROR_FAILURE);
} }
@@ -179,7 +179,7 @@ AsyncScriptCompiler::Run() {
void AsyncScriptCompiler::FinishCompile(JSContext* aCx) { void AsyncScriptCompiler::FinishCompile(JSContext* aCx) {
RefPtr<JS::Stencil> stencil = RefPtr<JS::Stencil> stencil =
JS::FinishCompileToStencilOffThread(aCx, mToken); JS::FinishOffThreadStencil(aCx, mToken);
if (stencil) { if (stencil) {
Finish(aCx, stencil); Finish(aCx, stencil);
} else { } else {