From 84179d10cc02ee73590b47fd193c3221320d70cc Mon Sep 17 00:00:00 2001 From: Clemens Backes Date: Wed, 27 Jul 2022 18:08:24 +0200 Subject: [PATCH] [wasm] Use CreateJob instead of PostJob We sometimes create jobs that initially hold no work. In those cases, use CreateJob instead of PostJob. New background threads will later be spawned when NotifyConcurrencyIncrease is called. R=etiennep@chromium.org Bug: v8:13096 Change-Id: Ieb9f9e03d01af6a72fe5785be72c523a553d0f1d Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/3762578 Reviewed-by: Thibaud Michaud Commit-Queue: Clemens Backes Cr-Commit-Position: refs/heads/main@{#82060} --- src/wasm/module-compiler.cc | 6 ++++-- src/wasm/module-instantiate.cc | 2 +- src/wasm/wasm-serialization.cc | 4 +++- 3 files changed, 8 insertions(+), 4 deletions(-) diff --git a/src/wasm/module-compiler.cc b/src/wasm/module-compiler.cc index 200b1779b0..7b3e511b51 100644 --- a/src/wasm/module-compiler.cc +++ b/src/wasm/module-compiler.cc @@ -3035,7 +3035,9 @@ CompilationStateImpl::CompilationStateImpl( void CompilationStateImpl::InitCompileJob() { DCHECK_NULL(compile_job_); - compile_job_ = V8::GetCurrentPlatform()->PostJob( + // Create the job, but don't spawn workers yet. This will happen on + // {NotifyConcurrencyIncrease}. + compile_job_ = V8::GetCurrentPlatform()->CreateJob( TaskPriority::kUserVisible, std::make_unique( native_module_weak_, async_counters_)); } @@ -3863,7 +3865,7 @@ void CompileJsToWasmWrappers(Isolate* isolate, const WasmModule* module, auto job = std::make_unique(&queue, &compilation_units); if (FLAG_wasm_num_compilation_tasks > 0) { - auto job_handle = V8::GetCurrentPlatform()->PostJob( + auto job_handle = V8::GetCurrentPlatform()->CreateJob( TaskPriority::kUserVisible, std::move(job)); // Wait for completion, while contributing to the work. diff --git a/src/wasm/module-instantiate.cc b/src/wasm/module-instantiate.cc index b115542469..4fff32be4b 100644 --- a/src/wasm/module-instantiate.cc +++ b/src/wasm/module-instantiate.cc @@ -1566,7 +1566,7 @@ void InstanceBuilder::CompileImportWrappers( auto compile_job_task = std::make_unique( isolate_->counters(), native_module, &import_wrapper_queue, &cache_scope); - auto compile_job = V8::GetCurrentPlatform()->PostJob( + auto compile_job = V8::GetCurrentPlatform()->CreateJob( TaskPriority::kUserVisible, std::move(compile_job_task)); // Wait for the job to finish, while contributing in this thread. diff --git a/src/wasm/wasm-serialization.cc b/src/wasm/wasm-serialization.cc index 807171d388..f959cebb4d 100644 --- a/src/wasm/wasm-serialization.cc +++ b/src/wasm/wasm-serialization.cc @@ -657,7 +657,9 @@ bool NativeModuleDeserializer::Read(Reader* reader) { DeserializationQueue reloc_queue; - std::unique_ptr job_handle = V8::GetCurrentPlatform()->PostJob( + // Create a new job without any workers; those are spawned on + // {NotifyConcurrencyIncrease}. + std::unique_ptr job_handle = V8::GetCurrentPlatform()->CreateJob( TaskPriority::kUserVisible, std::make_unique(this, &reloc_queue));