Commit e4f595c2 authored by Clemens Hammacher's avatar Clemens Hammacher Committed by Commit Bot

[wasm] Remove redundant cancelling of compile tasks

All compile tasks are already canceled when the {CompilationState}
dies. This happens when the {NativeModule} dies, and all
{NativeModule}s die before the {WasmEngine} dies. Thus, the WasmEngine
does not need to cancel any compile jobs, because there are none anyway.

R=mstarzinger@chromium.org

Bug: chromium:869420
Change-Id: I7e006392a1f9126333733c81c4c19985f626a470
Reviewed-on: https://chromium-review.googlesource.com/1158411Reviewed-by: 's avatarMichael Starzinger <mstarzinger@chromium.org>
Commit-Queue: Clemens Hammacher <clemensh@chromium.org>
Cr-Commit-Position: refs/heads/master@{#54840}
parent 91ab657e
......@@ -2734,16 +2734,11 @@ CompilationState::CompilationState(internal::Isolate* isolate,
v8::Isolate* v8_isolate = reinterpret_cast<v8::Isolate*>(isolate_);
v8::Platform* platform = V8::GetCurrentPlatform();
foreground_task_runner_ = platform->GetForegroundTaskRunner(v8_isolate);
// Register task manager for clean shutdown in case of an engine shutdown.
wasm_engine_->Register(&background_task_manager_);
wasm_engine_->Register(&foreground_task_manager_);
}
CompilationState::~CompilationState() {
CancelAndWait();
foreground_task_manager_.CancelAndWait();
wasm_engine_->Unregister(&foreground_task_manager_);
NotifyOnEvent(CompilationEvent::kDestroyed, nullptr);
}
......@@ -2877,7 +2872,6 @@ void CompilationState::ScheduleUnitForFinishing(
void CompilationState::CancelAndWait() {
background_task_manager_.CancelAndWait();
wasm_engine_->Unregister(&background_task_manager_);
}
void CompilationState::OnBackgroundTaskStopped() {
......
......@@ -20,7 +20,10 @@ namespace wasm {
WasmEngine::WasmEngine(std::unique_ptr<WasmCodeManager> code_manager)
: code_manager_(std::move(code_manager)) {}
WasmEngine::~WasmEngine() { TearDown(); }
WasmEngine::~WasmEngine() {
// All AsyncCompileJobs have been canceled.
DCHECK(jobs_.empty());
}
bool WasmEngine::SyncValidate(Isolate* isolate, const ModuleWireBytes& bytes) {
// TODO(titzer): remove dependency on the isolate.
......@@ -205,16 +208,6 @@ CodeTracer* WasmEngine::GetCodeTracer() {
return code_tracer_.get();
}
void WasmEngine::Register(CancelableTaskManager* task_manager) {
base::LockGuard<base::Mutex> guard(&mutex_);
task_managers_.emplace_back(task_manager);
}
void WasmEngine::Unregister(CancelableTaskManager* task_manager) {
base::LockGuard<base::Mutex> guard(&mutex_);
task_managers_.remove(task_manager);
}
AsyncCompileJob* WasmEngine::CreateAsyncCompileJob(
Isolate* isolate, std::unique_ptr<byte[]> bytes_copy, size_t length,
Handle<Context> context,
......@@ -263,17 +256,6 @@ void WasmEngine::DeleteCompileJobsOnIsolate(Isolate* isolate) {
}
}
void WasmEngine::TearDown() {
// Cancel all registered task managers. Locking not required since no more
// Isolates that could register or unregister task managers exist.
for (auto task_manager : task_managers_) {
task_manager->CancelAndWait();
}
// All AsyncCompileJobs have been canceled.
DCHECK(jobs_.empty());
}
namespace {
WasmEngine* AllocateNewWasmEngine() {
......
......@@ -113,11 +113,6 @@ class V8_EXPORT_PRIVATE WasmEngine {
// Used to redirect tracing output from {stdout} to a file.
CodeTracer* GetCodeTracer();
// We register and unregister CancelableTaskManagers that run engine-dependent
// tasks. These tasks need to be shutdown if the engine is shut down.
void Register(CancelableTaskManager* task_manager);
void Unregister(CancelableTaskManager* task_manager);
// Remove {job} from the list of active compile jobs.
std::unique_ptr<AsyncCompileJob> RemoveCompileJob(AsyncCompileJob* job);
......@@ -148,8 +143,6 @@ class V8_EXPORT_PRIVATE WasmEngine {
Handle<Context> context,
std::shared_ptr<CompilationResultResolver> resolver);
void TearDown();
std::unique_ptr<WasmCodeManager> code_manager_;
WasmMemoryTracker memory_tracker_;
AccountingAllocator allocator_;
......@@ -165,10 +158,6 @@ class V8_EXPORT_PRIVATE WasmEngine {
// job from the map when it is finished.
std::unordered_map<AsyncCompileJob*, std::unique_ptr<AsyncCompileJob>> jobs_;
// Contains all CancelableTaskManagers that run tasks that are dependent
// on the engine. Will be canceled on engine tear down.
std::list<CancelableTaskManager*> task_managers_;
std::unique_ptr<CompilationStatistics> compilation_stats_;
std::unique_ptr<CodeTracer> code_tracer_;
......
// Copyright 2018 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// Flags: --no-wait-for-wasm --wasm-tier-up
load("test/mjsunit/wasm/wasm-constants.js");
load("test/mjsunit/wasm/wasm-module-builder.js");
(function ShutdownDuringTierUp() {
// Create a big module.
var builder = new WasmModuleBuilder();
builder.addMemory(1, 1, true);
for (i = 0; i < 100; i++) {
builder.addFunction("sub" + i, kSig_i_i)
.addBody([ // --
kExprGetLocal, 0, // --
kExprI32Const, i % 61, // --
kExprI32Sub]) // --
.exportFunc()
}
var buffer = builder.toBuffer();
// Wait for compilation to finish, but then shutdown while tier-up is still
// running.
assertPromiseResult(WebAssembly.compile(buffer));
})();
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