Commit 7637ed59 authored by Clemens Backes's avatar Clemens Backes Committed by Commit Bot

[wasm][debug] Fully tier up on Debugger.disable

When the last debugger is disabled, we tier up the module to TurboFan.
Doing this in the background creates problems with profiling, where the
debugger is disabled before starting to profile, in order to guarantee
profiling of top-tier code.

Hence this CL changes the logic such that we only return from the
{TierUpAllModulesPerIsolate} methods once tier up is complete. Since
the DevTools frontend disables all debuggers before starting a profile,
this will ensure that all new calls execute TurboFan code.
Because of this change, the {TriggerRecompilation} method is renamed to
{RecompileForTiering}.

The test cases stay unchanged (do a busy wait until tier up is done),
because in the multi-isolates tests it is not guaranteed that tier up is
complete after disabling a single debugger.

R=thibaudm@chromium.org

Bug: v8:10580
Change-Id: I75c4b97825f856f562cfa656c11293d3b964898b
Cq-Include-Trybots: luci.v8.try:v8_linux64_tsan_rel
Cq-Include-Trybots: luci.v8.try:v8_linux64_tsan_isolates_rel_ng
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2232539
Commit-Queue: Clemens Backes <clemensb@chromium.org>
Reviewed-by: 's avatarThibaud Michaud <thibaudm@chromium.org>
Cr-Commit-Position: refs/heads/master@{#68212}
parent f78d69fa
......@@ -1469,7 +1469,7 @@ RUNTIME_FUNCTION(Runtime_WasmTierDownModule) {
CONVERT_ARG_HANDLE_CHECKED(WasmInstanceObject, instance, 0);
auto* native_module = instance->module_object().native_module();
native_module->SetTieringState(wasm::kTieredDown);
native_module->TriggerRecompilation();
native_module->RecompileForTiering();
CHECK(!native_module->compilation_state()->failed());
return ReadOnlyRoots(isolate).undefined_value();
}
......@@ -1480,7 +1480,7 @@ RUNTIME_FUNCTION(Runtime_WasmTierUpModule) {
CONVERT_ARG_HANDLE_CHECKED(WasmInstanceObject, instance, 0);
auto* native_module = instance->module_object().native_module();
native_module->SetTieringState(wasm::kTieredUp);
native_module->TriggerRecompilation();
native_module->RecompileForTiering();
CHECK(!native_module->compilation_state()->failed());
return ReadOnlyRoots(isolate).undefined_value();
}
......
......@@ -1483,21 +1483,17 @@ void RecompileNativeModule(NativeModule* native_module,
}
});
// Always wait for tier down. Tier up usually happens in the background,
// except in single-threaded mode.
if (tiering_state == kTieredDown || FLAG_single_threaded) {
// The main thread contributes to the compilation.
constexpr Counters* kNoCounters = nullptr;
while (ExecuteCompilationUnits(
compilation_state->background_compile_token(), kNoCounters,
kMainThreadTaskId, kBaselineOnly)) {
while (ExecuteCompilationUnits(compilation_state->background_compile_token(),
kNoCounters, kMainThreadTaskId,
kBaselineOnly)) {
// Continue executing compilation units.
}
// Now wait until baseline recompilation finished.
// Now wait until all compilation units finished.
recompilation_finished_semaphore->Wait();
DCHECK(!compilation_state->failed());
}
}
AsyncCompileJob::AsyncCompileJob(
......@@ -2420,7 +2416,7 @@ void AsyncStreamingProcessor::OnFinishedStream(OwnedVector<uint8_t> bytes) {
// compiling via streaming is tricky, we just tier down now, before publishing
// the module.
if (job_->native_module_->IsTieredDown()) {
job_->native_module_->TriggerRecompilation();
job_->native_module_->RecompileForTiering();
}
if (needs_finish) {
const bool failed = job_->native_module_->compilation_state()->failed();
......
......@@ -1857,7 +1857,7 @@ bool NativeModule::IsTieredDown() {
return tiering_state_ == kTieredDown;
}
void NativeModule::TriggerRecompilation() {
void NativeModule::RecompileForTiering() {
// Read the tiering state under the lock, then trigger recompilation after
// releasing the lock. If the tiering state was changed when the triggered
// compilation units finish, code installation will handle that correctly.
......
......@@ -601,18 +601,17 @@ class V8_EXPORT_PRIVATE NativeModule final {
Vector<WasmCompilationResult>);
// Set a new tiering state, but don't trigger any recompilation yet; use
// {TriggerRecompilation} for that. The two steps are split because In some
// {RecompileForTiering} for that. The two steps are split because In some
// scenarios we need to drop locks before triggering recompilation.
void SetTieringState(TieringState);
// Check whether this modules is tiered down for debugging.
bool IsTieredDown();
// Trigger a full recompilation of this module, in the tier set previously via
// {SetTieringState}. When tiering down, the calling thread contributes to
// compilation and only returns once recompilation is done. Tiering up happens
// concurrently, so this method might return before it is complete.
void TriggerRecompilation();
// Fully recompile this module in the tier set previously via
// {SetTieringState}. The calling thread contributes to compilation and only
// returns once recompilation is done.
void RecompileForTiering();
// Find all functions that need to be recompiled for a new tier. Note that
// compilation jobs might run concurrently, so this method only considers the
......
......@@ -640,7 +640,7 @@ void WasmEngine::TierDownAllModulesPerIsolate(Isolate* isolate) {
}
}
for (auto& native_module : native_modules) {
native_module->TriggerRecompilation();
native_module->RecompileForTiering();
}
}
......@@ -672,7 +672,7 @@ void WasmEngine::TierUpAllModulesPerIsolate(Isolate* isolate) {
}
}
for (auto& native_module : native_modules_to_recompile) {
native_module->TriggerRecompilation();
native_module->RecompileForTiering();
}
}
......@@ -1054,7 +1054,7 @@ std::shared_ptr<NativeModule> WasmEngine::MaybeGetNativeModule(
}
}
// Potentially recompile the module for tier down, after releasing the mutex.
if (recompile_module) native_module->TriggerRecompilation();
if (recompile_module) native_module->RecompileForTiering();
return native_module;
}
......@@ -1084,7 +1084,7 @@ bool WasmEngine::UpdateNativeModuleCache(
}
}
// Potentially recompile the module for tier down, after releasing the mutex.
if (recompile_module) native_module->get()->TriggerRecompilation();
if (recompile_module) native_module->get()->RecompileForTiering();
return false;
}
......
......@@ -222,7 +222,7 @@ class TestingModuleBuilder {
void TierDown() {
native_module_->SetTieringState(kTieredDown);
native_module_->TriggerRecompilation();
native_module_->RecompileForTiering();
execution_tier_ = ExecutionTier::kLiftoff;
}
......
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