[wasm] Fix --single-threaded for WebAssembly compilation
Due to the transition to the jobs API, WebAssembly compilation was using background threads, even when --single-threaded and therefore --wasm-num-compilation-tasks=0 was used. With this CL, the compilation job is started with a maximum concurrency of 0 when --wasm-num-compilation-tasks=0. To ensure compilation progress in asynchronous compilation, the main thread waits for baseline compilation to finish right after initializing all compilation units, and thereby participates in the compilation. R=clemensb@chromium.org Bug: v8:11279 Change-Id: I85f93f82c00cdbd6afd46110599089a052101a00 Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2599546 Reviewed-by: Clemens Backes <clemensb@chromium.org> Commit-Queue: Andreas Haas <ahaas@chromium.org> Cr-Commit-Position: refs/heads/master@{#71944}
This commit is contained in:
parent
b837e03389
commit
7fa695a2e4
@ -1611,10 +1611,8 @@ class BackgroundCompileJob final : public JobTask {
|
||||
if (compile_scope.cancelled()) return 0;
|
||||
// NumOutstandingCompilations() does not reflect the units that running
|
||||
// workers are processing, thus add the current worker count to that number.
|
||||
size_t flag_limit =
|
||||
static_cast<size_t>(std::max(1, FLAG_wasm_num_compilation_tasks));
|
||||
return std::min(
|
||||
flag_limit,
|
||||
static_cast<size_t>(FLAG_wasm_num_compilation_tasks),
|
||||
worker_count +
|
||||
compile_scope.compilation_state()->NumOutstandingCompilations());
|
||||
}
|
||||
@ -2319,6 +2317,13 @@ class AsyncCompileJob::PrepareAndStartCompile : public CompileStep {
|
||||
|
||||
// Add compilation units and kick off compilation.
|
||||
InitializeCompilationUnits(job->isolate(), job->native_module_.get());
|
||||
// We are in single-threaded mode, so there are no worker tasks that will
|
||||
// do the compilation. We call {WaitForCompilationEvent} here so that the
|
||||
// main thread paticipates and finishes the compilation.
|
||||
if (FLAG_wasm_num_compilation_tasks == 0) {
|
||||
compilation_state->WaitForCompilationEvent(
|
||||
CompilationEvent::kFinishedBaselineCompilation);
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
27
test/mjsunit/wasm/single-threaded-compilation.js
Normal file
27
test/mjsunit/wasm/single-threaded-compilation.js
Normal file
@ -0,0 +1,27 @@
|
||||
// Copyright 2020 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: --wasm-num-compilation-tasks=0
|
||||
|
||||
load('test/mjsunit/wasm/wasm-module-builder.js');
|
||||
|
||||
(function testSyncCompilation() {
|
||||
print(arguments.callee.name);
|
||||
const builder = new WasmModuleBuilder();
|
||||
builder.addFunction("main", kSig_d_d)
|
||||
.addBody([kExprLocalGet, 0])
|
||||
.exportFunc();
|
||||
|
||||
const instance = builder.instantiate();
|
||||
})();
|
||||
|
||||
(function testAsyncCompilation() {
|
||||
print(arguments.callee.name);
|
||||
const builder = new WasmModuleBuilder();
|
||||
builder.addFunction("main", kSig_i_i)
|
||||
.addBody([kExprLocalGet, 0])
|
||||
.exportFunc();
|
||||
|
||||
const instance = builder.asyncInstantiate();
|
||||
})();
|
Loading…
Reference in New Issue
Block a user