Commit 2547e1ce authored by Clemens Backes's avatar Clemens Backes Committed by Commit Bot

[wasm] Fix tier down after deserialization

Since the compilation progress was never initialized on deserialization,
tier down was always skipped on such modules.
By initializing to the expected state after deserialization (i.e. all
code as TurboFan code), we make sure that later recompilation works as
expected.

Drive-by: Fix an unnecessary copy of a {shared_ptr} in deserialization.

R=thibaudm@chromium.org

Bug: chromium:1110258
Change-Id: Ia12af888e4b11aabfb8cd4e1201e9fa3cd2ceb47
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2323355
Commit-Queue: Clemens Backes <clemensb@chromium.org>
Reviewed-by: 's avatarThibaud Michaud <thibaudm@chromium.org>
Cr-Commit-Position: refs/heads/master@{#69458}
parent 0f4b9cef
......@@ -117,6 +117,8 @@ class V8_EXPORT_PRIVATE CompilationState {
void AddCallback(callback_t);
void InitializeAfterDeserialization();
// Wait until baseline compilation finished, or compilation failed.
void WaitForBaselineFinished();
......
......@@ -458,6 +458,10 @@ class CompilationStateImpl {
// is invoked which triggers background compilation.
void InitializeCompilationProgress(bool lazy_module, int num_wrappers);
// Initialize the compilation progress after deserialization. This is needed
// for recompilation (e.g. for tier down) to work later.
void InitializeCompilationProgressAfterDeserialization();
// Initialize recompilation of the whole module: Setup compilation progress
// for recompilation and add the respective compilation units. The callback is
// called immediately if no recompilation is needed, or called later
......@@ -701,6 +705,10 @@ void CompilationState::WaitForTopTierFinished() {
top_tier_finished_semaphore->Wait();
}
void CompilationState::InitializeAfterDeserialization() {
Impl(this)->InitializeCompilationProgressAfterDeserialization();
}
bool CompilationState::failed() const { return Impl(this)->failed(); }
bool CompilationState::baseline_compilation_finished() const {
......@@ -2603,6 +2611,18 @@ void CompilationStateImpl::InitializeCompilationProgress(bool lazy_module,
TriggerCallbacks();
}
void CompilationStateImpl::InitializeCompilationProgressAfterDeserialization() {
auto* module = native_module_->module();
base::MutexGuard guard(&callbacks_mutex_);
DCHECK(compilation_progress_.empty());
constexpr uint8_t kProgressAfterDeserialization =
RequiredBaselineTierField::encode(ExecutionTier::kTurbofan) |
RequiredTopTierField::encode(ExecutionTier::kTurbofan) |
ReachedTierField::encode(ExecutionTier::kTurbofan);
compilation_progress_.assign(module->num_declared_functions,
kProgressAfterDeserialization);
}
void CompilationStateImpl::InitializeRecompilation(
TieringState new_tiering_state,
CompilationState::callback_t recompilation_finished_callback) {
......
......@@ -620,7 +620,7 @@ MaybeHandle<WasmModuleObject> DeserializeNativeModule(
isolate->GetOrRegisterRecorderContextId(isolate->native_context()),
DecodingMethod::kDeserialize, wasm_engine->allocator());
if (decode_result.failed()) return {};
std::shared_ptr<WasmModule> module = std::move(decode_result.value());
std::shared_ptr<WasmModule> module = std::move(decode_result).value();
CHECK_NOT_NULL(module);
auto shared_native_module = wasm_engine->MaybeGetNativeModule(
......@@ -638,6 +638,7 @@ MaybeHandle<WasmModuleObject> DeserializeNativeModule(
NativeModuleDeserializer deserializer(shared_native_module.get());
Reader reader(data + WasmSerializer::kHeaderSize);
bool error = !deserializer.Read(&reader);
shared_native_module->compilation_state()->InitializeAfterDeserialization();
wasm_engine->UpdateNativeModuleCache(error, &shared_native_module, isolate);
if (error) return {};
}
......
......@@ -329,6 +329,26 @@ UNINITIALIZED_TEST(CompiledWasmModulesTransfer) {
from_isolate->Dispose();
}
TEST(TierDownAfterDeserialization) {
WasmSerializationTest test;
Isolate* isolate = CcTest::i_isolate();
HandleScope scope(isolate);
Handle<WasmModuleObject> module_object;
CHECK(test.Deserialize().ToHandle(&module_object));
auto* native_module = module_object->native_module();
CHECK_EQ(1, native_module->module()->functions.size());
WasmCodeRefScope code_ref_scope;
auto* turbofan_code = native_module->GetCode(0);
CHECK_EQ(ExecutionTier::kTurbofan, turbofan_code->tier());
isolate->wasm_engine()->TierDownAllModulesPerIsolate(isolate);
auto* liftoff_code = native_module->GetCode(0);
CHECK_EQ(ExecutionTier::kLiftoff, liftoff_code->tier());
}
} // namespace test_wasm_serialization
} // namespace wasm
} // namespace internal
......
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