Commit 01f824c1 authored by Clemens Hammacher's avatar Clemens Hammacher Committed by Commit Bot

[wasm] Merge foreground work after compilation

Instead of spawning several foreground tasks, execute the work in a
single chunk.
This will allow us in a follow-up step to remove the deferred handle
scope and pass the handles directly.

R=ahaas@chromium.org

Bug: v8:7921, v8:8423
Change-Id: I4dae6241e2a33e89e304a04cb67c2229c34f7b99
Reviewed-on: https://chromium-review.googlesource.com/c/1402545
Commit-Queue: Clemens Hammacher <clemensh@chromium.org>
Reviewed-by: 's avatarAndreas Haas <ahaas@chromium.org>
Cr-Commit-Position: refs/heads/master@{#58677}
parent 24a43b3c
......@@ -2549,12 +2549,11 @@ void AsyncCompileJob::FinishCompile() {
// TODO(bbudge) Allow deserialization without wrapper compilation, so we can
// just compile wrappers here.
if (is_after_deserialization) {
DoSync<AsyncCompileJob::FinishModule>();
} else {
// TODO(wasm): compiling wrappers should be made async as well.
DoSync<CompileWrappers>();
if (!is_after_deserialization) {
// TODO(wasm): compiling wrappers should be made async.
CompileWrappers();
}
FinishModule();
}
void AsyncCompileJob::AsyncCompileFailed(Handle<Object> error_reason) {
......@@ -2870,46 +2869,34 @@ class AsyncCompileJob::CompileFailed : public CompileStep {
Handle<Object> error_reason_;
};
//==========================================================================
// Step 5 (sync): Compile JS->wasm wrappers.
//==========================================================================
class AsyncCompileJob::CompileWrappers : public CompileStep {
void AsyncCompileJob::CompileWrappers() {
// TODO(wasm): Compile all wrappers here, including the start function wrapper
// and the wrappers for the function table elements.
void RunInForeground(AsyncCompileJob* job) override {
TRACE_COMPILE("(5) Compile wrappers...\n");
// Compile JS->wasm wrappers for exported functions.
CompileJsToWasmWrappers(
job->isolate_, job->module_object_->native_module()->module(),
handle(job->module_object_->export_wrappers(), job->isolate_));
job->DoSync<FinishModule>();
TRACE_COMPILE("(5) Compile wrappers...\n");
// Compile JS->wasm wrappers for exported functions.
CompileJsToWasmWrappers(isolate_, module_object_->native_module()->module(),
handle(module_object_->export_wrappers(), isolate_));
}
void AsyncCompileJob::FinishModule() {
TRACE_COMPILE("(6) Finish module...\n");
AsyncCompileSucceeded(module_object_);
size_t num_functions = native_module_->num_functions() -
native_module_->num_imported_functions();
auto* compilation_state = Impl(native_module_->compilation_state());
if (compilation_state->compile_mode() == CompileMode::kRegular ||
num_functions == 0) {
// If we do not tier up, the async compile job is done here and
// can be deleted.
isolate_->wasm_engine()->RemoveCompileJob(this);
return;
}
};
//==========================================================================
// Step 6 (sync): Finish the module and resolve the promise.
//==========================================================================
class AsyncCompileJob::FinishModule : public CompileStep {
void RunInForeground(AsyncCompileJob* job) override {
TRACE_COMPILE("(6) Finish module...\n");
job->AsyncCompileSucceeded(job->module_object_);
size_t num_functions = job->native_module_->num_functions() -
job->native_module_->num_imported_functions();
auto* compilation_state = Impl(job->native_module_->compilation_state());
if (compilation_state->compile_mode() == CompileMode::kRegular ||
num_functions == 0) {
// If we do not tier up, the async compile job is done here and
// can be deleted.
job->isolate_->wasm_engine()->RemoveCompileJob(job);
return;
}
DCHECK_EQ(CompileMode::kTiering, compilation_state->compile_mode());
if (compilation_state->baseline_compilation_finished()) {
job->isolate_->wasm_engine()->RemoveCompileJob(job);
}
DCHECK_EQ(CompileMode::kTiering, compilation_state->compile_mode());
if (compilation_state->baseline_compilation_finished()) {
isolate_->wasm_engine()->RemoveCompileJob(this);
}
};
}
AsyncStreamingProcessor::AsyncStreamingProcessor(AsyncCompileJob* job)
: decoder_(job->enabled_features_),
......
......@@ -93,8 +93,6 @@ class AsyncCompileJob {
class DecodeFail; // Step 1b (sync)
class PrepareAndStartCompile; // Step 2 (sync)
class CompileFailed; // Step 4b (sync)
class CompileWrappers; // Step 5 (sync)
class FinishModule; // Step 6 (sync)
friend class AsyncStreamingProcessor;
......@@ -114,6 +112,10 @@ class AsyncCompileJob {
void AsyncCompileSucceeded(Handle<WasmModuleObject> result);
void CompileWrappers();
void FinishModule();
void StartForegroundTask();
void ExecuteForegroundTaskImmediately();
......
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