Commit 9f7fb728 authored by Andreas Haas's avatar Andreas Haas Committed by Commit Bot

[wasm] Abort AsyncCompileJobs when a Chrome tab refreshes

When a tab in Chrome gets refreshed, the refreshed page reuses the
isolate of the original page. This means that at the moment,
AsyncCompileJobs which were stared on the original page do not get
aborted and will therefore eventually finish and resolve their promise.
With this CL I abort all running AsyncCompileJobs when V8 gets the tab
refresh signal, i.e. Isolate::ContextDisposedNotification. Note that I
cannot just call CompilationManager::TearDown because it assumes that
there are no pending tasks anymore.

R=clemensh@chromium.org, hpayer@chromium.org

Bug: chromium:803476
Cq-Include-Trybots: master.tryserver.chromium.linux:linux_chromium_rel_ng
Change-Id: I88d28fdaba6f55b7aa7379c4b5338ae62134fc8a
Reviewed-on: https://chromium-review.googlesource.com/875923
Commit-Queue: Andreas Haas <ahaas@chromium.org>
Reviewed-by: 's avatarClemens Hammacher <clemensh@chromium.org>
Reviewed-by: 's avatarHannes Payer <hpayer@chromium.org>
Cr-Commit-Position: refs/heads/master@{#50765}
parent 174485e9
......@@ -8818,6 +8818,12 @@ void Isolate::LowMemoryNotification() {
int Isolate::ContextDisposedNotification(bool dependant_context) {
i::Isolate* isolate = reinterpret_cast<i::Isolate*>(this);
if (!dependant_context) {
// We left the current context, we can abort all running WebAssembly
// compilations.
isolate->wasm_engine()->compilation_manager()->AbortAllJobs();
}
// TODO(ahaas): move other non-heap activity out of the heap call.
return isolate->heap()->NotifyContextDisposed(dependant_context);
}
......
......@@ -47,6 +47,15 @@ std::shared_ptr<AsyncCompileJob> CompilationManager::RemoveJob(
void CompilationManager::TearDown() { jobs_.clear(); }
void CompilationManager::AbortAllJobs() {
// Iterate over a copy of {jobs_}, because {job->Abort} modifies {jobs_}.
std::vector<AsyncCompileJob*> copy;
for (auto entry : jobs_) copy.push_back(entry.first);
for (auto job : copy) job->Abort();
}
} // namespace wasm
} // namespace internal
} // namespace v8
......@@ -30,11 +30,17 @@ class CompilationManager {
std::shared_ptr<StreamingDecoder> StartStreamingCompilation(
Isolate* isolate, Handle<Context> context, Handle<JSPromise> promise);
// Removes {job} from the list of active compile jobs.
// Remove {job} from the list of active compile jobs.
std::shared_ptr<AsyncCompileJob> RemoveJob(AsyncCompileJob* job);
// Cancel all AsyncCompileJobs and delete their state immediately.
void TearDown();
// Cancel all AsyncCompileJobs so that they are not processed any further,
// but delay the deletion of their state until all tasks accessing the
// AsyncCompileJob finish their execution.
void AbortAllJobs();
private:
AsyncCompileJob* CreateAsyncCompileJob(Isolate* isolate,
std::unique_ptr<byte[]> bytes_copy,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment