Commit 71845472 authored by Frederik Gossen's avatar Frederik Gossen Committed by Commit Bot

[wasm-hints] Verify Baseline/Top Tier Finished

Verify that baseline and top tier compilation are finished when
expected. Test cases will use the newly exposed functions
{baseline_compilation_finished} and {top_tier_compilation_finished} for
this.

Bug: v8:9003
Change-Id: I023af3390ed5e087a3b40efe7c340d7e93071a51
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/1581941Reviewed-by: 's avatarClemens Hammacher <clemensh@chromium.org>
Reviewed-by: 's avatarMichael Starzinger <mstarzinger@chromium.org>
Commit-Queue: Frederik Gossen <frgossen@google.com>
Cr-Commit-Position: refs/heads/master@{#61010}
parent 475741d5
......@@ -119,6 +119,8 @@ class CompilationState {
void AddCallback(callback_t);
bool failed() const;
V8_EXPORT_PRIVATE bool baseline_compilation_finished() const;
V8_EXPORT_PRIVATE bool top_tier_compilation_finished() const;
void OnFinishedUnit(WasmCode*);
void OnFinishedUnits(Vector<WasmCode*>);
......
......@@ -338,6 +338,12 @@ class CompilationStateImpl {
return outstanding_baseline_functions_ == 0;
}
bool top_tier_compilation_finished() const {
base::MutexGuard guard(&callbacks_mutex_);
DCHECK_LE(outstanding_baseline_functions_, outstanding_top_tier_functions_);
return outstanding_top_tier_functions_ == 0;
}
CompileMode compile_mode() const { return compile_mode_; }
Counters* counters() const { return async_counters_.get(); }
WasmFeatures* detected_features() { return &detected_features_; }
......@@ -458,6 +464,14 @@ void CompilationState::AddCallback(CompilationState::callback_t callback) {
bool CompilationState::failed() const { return Impl(this)->failed(); }
bool CompilationState::baseline_compilation_finished() const {
return Impl(this)->baseline_compilation_finished();
}
bool CompilationState::top_tier_compilation_finished() const {
return Impl(this)->top_tier_compilation_finished();
}
void CompilationState::OnFinishedUnit(WasmCode* code) {
Impl(this)->OnFinishedUnit(code);
}
......
......@@ -125,9 +125,11 @@ TEST(Run_WasmModule_CompilationHintsLazy) {
CHECK(!module.is_null());
// Lazy function was not invoked and therefore not compiled yet.
int func_index = 0;
static const int kFuncIndex = 0;
NativeModule* native_module = module.ToHandleChecked()->native_module();
CHECK(!native_module->HasCode(func_index));
CHECK(!native_module->HasCode(kFuncIndex));
auto* compilation_state = native_module->compilation_state();
CHECK(compilation_state->baseline_compilation_finished());
// Instantiate and invoke function.
MaybeHandle<WasmInstanceObject> instance =
......@@ -139,14 +141,15 @@ TEST(Run_WasmModule_CompilationHintsLazy) {
CHECK_EQ(kReturnValue, result);
// Lazy function was invoked and therefore compiled.
CHECK(native_module->HasCode(func_index));
CHECK(native_module->HasCode(kFuncIndex));
WasmCodeRefScope code_ref_scope;
ExecutionTier actual_tier = native_module->GetCode(func_index)->tier();
ExecutionTier actual_tier = native_module->GetCode(kFuncIndex)->tier();
static_assert(ExecutionTier::kInterpreter < ExecutionTier::kLiftoff &&
ExecutionTier::kLiftoff < ExecutionTier::kTurbofan,
"Assume an order on execution tiers");
ExecutionTier baseline_tier = ExecutionTier::kLiftoff;
CHECK_LE(baseline_tier, actual_tier);
CHECK(compilation_state->baseline_compilation_finished());
}
Cleanup();
}
......@@ -183,13 +186,16 @@ TEST(Run_WasmModule_CompilationHintsNoTiering) {
CHECK(!module.is_null());
// Synchronous compilation finished and no tiering units were initialized.
int func_index = 0;
static const int kFuncIndex = 0;
NativeModule* native_module = module.ToHandleChecked()->native_module();
CHECK(native_module->HasCode(func_index));
WasmCodeRefScope code_ref_scope;
CHECK(native_module->HasCode(kFuncIndex));
ExecutionTier expected_tier = ExecutionTier::kLiftoff;
ExecutionTier actual_tier = native_module->GetCode(func_index)->tier();
WasmCodeRefScope code_ref_scope;
ExecutionTier actual_tier = native_module->GetCode(kFuncIndex)->tier();
CHECK_EQ(expected_tier, actual_tier);
auto* compilation_state = native_module->compilation_state();
CHECK(compilation_state->baseline_compilation_finished());
CHECK(compilation_state->top_tier_compilation_finished());
}
Cleanup();
}
......@@ -225,19 +231,36 @@ TEST(Run_WasmModule_CompilationHintsTierUp) {
isolate, &thrower, ModuleWireBytes(buffer.begin(), buffer.end()));
CHECK(!module.is_null());
// Expect code baseline code or top tier code.
int func_index = 0;
// Expect baseline or top tier code.
static const int kFuncIndex = 0;
NativeModule* native_module = module.ToHandleChecked()->native_module();
CHECK(native_module->HasCode(func_index));
WasmCodeRefScope code_ref_scope;
ExecutionTier actual_tier = native_module->GetCode(func_index)->tier();
auto* compilation_state = native_module->compilation_state();
static_assert(ExecutionTier::kInterpreter < ExecutionTier::kLiftoff &&
ExecutionTier::kLiftoff < ExecutionTier::kTurbofan,
"Assume an order on execution tiers");
ExecutionTier baseline_tier = ExecutionTier::kLiftoff;
CHECK_LE(baseline_tier, actual_tier);
{
CHECK(native_module->HasCode(kFuncIndex));
WasmCodeRefScope code_ref_scope;
ExecutionTier actual_tier = native_module->GetCode(kFuncIndex)->tier();
CHECK_LE(baseline_tier, actual_tier);
CHECK(compilation_state->baseline_compilation_finished());
}
// Busy wait for top tier compilation to finish.
while (!compilation_state->top_tier_compilation_finished()) {
}
// Expect top tier code.
ExecutionTier top_tier = ExecutionTier::kTurbofan;
CHECK_LE(actual_tier, top_tier);
{
CHECK(native_module->HasCode(kFuncIndex));
WasmCodeRefScope code_ref_scope;
ExecutionTier actual_tier = native_module->GetCode(kFuncIndex)->tier();
CHECK_EQ(top_tier, actual_tier);
CHECK(compilation_state->baseline_compilation_finished());
CHECK(compilation_state->top_tier_compilation_finished());
}
}
Cleanup();
}
......
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