Commit 714b528a authored by Kim-Anh Tran's avatar Kim-Anh Tran Committed by Commit Bot

[wasm] Stop compilation when error was thrown in CompileInParallel()

Synchronous compilation currently continues creating new tasks even
though compilation has already failed. This stops the creation of
new background tasks and makes sure that the background task manager
in the CompilationState is not canceled twice.

Change-Id: Ic4c55275ff70e7eca901ad357253f81aa8e2e8e1
Reviewed-on: https://chromium-review.googlesource.com/968781
Commit-Queue: Kim-Anh Tran <kimanh@google.com>
Reviewed-by: 's avatarClemens Hammacher <clemensh@chromium.org>
Cr-Commit-Position: refs/heads/master@{#52044}
parent 60efd46f
......@@ -1171,6 +1171,7 @@ wasm::WasmCode* FinishCompilationUnit(CompilationState* compilation_state,
void FinishCompilationUnits(CompilationState* compilation_state,
ErrorThrower* thrower) {
while (true) {
if (compilation_state->failed()) break;
int func_index = -1;
wasm::WasmCode* result =
FinishCompilationUnit(compilation_state, thrower, &func_index);
......@@ -1183,8 +1184,10 @@ void FinishCompilationUnits(CompilationState* compilation_state,
DCHECK_IMPLIES(result == nullptr, thrower->error());
if (result == nullptr) break;
}
if (compilation_state->ShouldIncreaseWorkload())
if (compilation_state->ShouldIncreaseWorkload() &&
!compilation_state->failed()) {
compilation_state->RestartBackgroundTasks();
}
}
void CompileInParallel(Isolate* isolate, NativeModule* native_module,
......@@ -1245,16 +1248,22 @@ void CompileInParallel(Isolate* isolate, NativeModule* native_module,
// are finished concurrently to the background threads to save
// memory.
FinishCompilationUnits(compilation_state, thrower);
if (compilation_state->failed()) break;
}
// 3) After the parallel phase of all compilation units has started, the
// main thread waits for all {BackgroundCompileTasks} instances to finish -
// which happens once they all realize there's no next work item to
// process.
compilation_state->CancelAndWait();
// process. If compilation already failed, all background tasks have
// already been canceled in {FinishCompilationUnits}, and there are
// no units to finish.
if (!compilation_state->failed()) {
compilation_state->CancelAndWait();
// 4) Finish all compilation units which have been executed while we waited.
FinishCompilationUnits(compilation_state, thrower);
// 4) Finish all compilation units which have been executed while we waited.
FinishCompilationUnits(compilation_state, thrower);
}
}
void CompileSequentially(Isolate* isolate, NativeModule* native_module,
......
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