[wasm] Refactor GetNextUncompiledFunctionId and CompileAndSchedule
The only difference between GetNextUncompiledFunctionId + CompileAndSchedule and FetchAndExecuteCompilationUnit is that FetchAndExecuteCompilationUnit potentially calls a callback if it detects that no finishing task is executing. With this CL I replace the two functions again with FetchAndExecuteCompilationUnit. I add a flag so that no callback is called when the flag is not set. If no callback is called, FetchAndExecuteCompilationUnit behaves exactly the same as the other two functions together. R=clemensh@chromium.org Change-Id: I17318381eec2d17b13d0902984f2620b909c7ea0 Reviewed-on: https://chromium-review.googlesource.com/544954 Reviewed-by: Clemens Hammacher <clemensh@chromium.org> Commit-Queue: Andreas Haas <ahaas@chromium.org> Cr-Commit-Position: refs/heads/master@{#46210}
This commit is contained in:
parent
c950963be3
commit
cd2dda8d50
@ -100,24 +100,16 @@ ModuleCompiler::ModuleCompiler(Isolate* isolate,
|
||||
counters_ = counters_shared_.get();
|
||||
}
|
||||
|
||||
bool ModuleCompiler::GetNextUncompiledFunctionId(size_t* index) {
|
||||
DCHECK_NOT_NULL(index);
|
||||
// - 1 because AtomicIncrement returns the value after the atomic increment.
|
||||
*index = next_unit_.Increment(1) - 1;
|
||||
return *index < compilation_units_.size();
|
||||
}
|
||||
|
||||
// The actual runnable task that performs compilations in the background.
|
||||
ModuleCompiler::CompilationTask::CompilationTask(ModuleCompiler* compiler)
|
||||
: CancelableTask(&compiler->background_task_manager_),
|
||||
compiler_(compiler) {}
|
||||
|
||||
void ModuleCompiler::CompilationTask::RunInternal() {
|
||||
size_t index = 0;
|
||||
while (compiler_->executed_units_.CanAcceptWork() &&
|
||||
compiler_->GetNextUncompiledFunctionId(&index)) {
|
||||
compiler_->CompileAndSchedule(index);
|
||||
compiler_->FetchAndExecuteCompilationUnit()) {
|
||||
}
|
||||
|
||||
compiler_->OnBackgroundTaskStopped();
|
||||
}
|
||||
|
||||
@ -127,22 +119,6 @@ void ModuleCompiler::OnBackgroundTaskStopped() {
|
||||
DCHECK_LE(stopped_compilation_tasks_, num_background_tasks_);
|
||||
}
|
||||
|
||||
void ModuleCompiler::CompileAndSchedule(size_t index) {
|
||||
DisallowHeapAllocation no_allocation;
|
||||
DisallowHandleAllocation no_handles;
|
||||
DisallowHandleDereference no_deref;
|
||||
DisallowCodeDependencyChange no_dependency_change;
|
||||
DCHECK_LT(index, compilation_units_.size());
|
||||
|
||||
std::unique_ptr<compiler::WasmCompilationUnit> unit =
|
||||
std::move(compilation_units_.at(index));
|
||||
unit->ExecuteCompilation();
|
||||
{
|
||||
base::LockGuard<base::Mutex> guard(&result_mutex_);
|
||||
executed_units_.Schedule(std::move(unit));
|
||||
}
|
||||
}
|
||||
|
||||
// Run by each compilation task The no_finisher_callback is called
|
||||
// within the result_mutex_ lock when no finishing task is running,
|
||||
// i.e. when the finisher_is_running_ flag is not set.
|
||||
@ -166,7 +142,7 @@ bool ModuleCompiler::FetchAndExecuteCompilationUnit(
|
||||
{
|
||||
base::LockGuard<base::Mutex> guard(&result_mutex_);
|
||||
executed_units_.Schedule(std::move(unit));
|
||||
if (!finisher_is_running_) {
|
||||
if (no_finisher_callback != nullptr && !finisher_is_running_) {
|
||||
no_finisher_callback();
|
||||
// We set the flag here so that not more than one finisher is started.
|
||||
finisher_is_running_ = true;
|
||||
@ -277,10 +253,7 @@ void ModuleCompiler::CompileInParallel(ModuleBytesEnv* module_env,
|
||||
// result is enqueued in {executed_units}.
|
||||
// The foreground task bypasses waiting on memory threshold, because
|
||||
// its results will immediately be converted to code (below).
|
||||
size_t index = 0;
|
||||
if (GetNextUncompiledFunctionId(&index)) {
|
||||
CompileAndSchedule(index);
|
||||
}
|
||||
FetchAndExecuteCompilationUnit();
|
||||
|
||||
// 3.b) If {executed_units} contains a compilation unit, the main thread
|
||||
// dequeues it and finishes the compilation unit. Compilation units
|
||||
|
@ -87,10 +87,8 @@ class ModuleCompiler {
|
||||
// finishing task is running, i.e. when the finisher_is_running_ flag is not
|
||||
// set.
|
||||
bool FetchAndExecuteCompilationUnit(
|
||||
std::function<void()> no_finisher_callback = [] {});
|
||||
std::function<void()> no_finisher_callback = nullptr);
|
||||
|
||||
void CompileAndSchedule(size_t index);
|
||||
bool GetNextUncompiledFunctionId(size_t* index);
|
||||
void OnBackgroundTaskStopped();
|
||||
|
||||
void EnableThrottling() { executed_units_.EnableThrottling(); }
|
||||
|
Loading…
Reference in New Issue
Block a user