Commit e9036451 authored by Z Nguyen-Huu's avatar Z Nguyen-Huu Committed by Commit Bot

[wasm] Keep new module in tiered down upon "debugger.enable"

Store a flag per isolate whether new modules should be kept in
tiered-down state from the beginning. Adjust initial compilation if flag
is set.

Bug: v8:9654
Change-Id: I5aae435fb807f3eaa7efafe9af60451ad3c7e14d
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2028452
Commit-Queue: Z Nguyen-Huu <duongn@microsoft.com>
Reviewed-by: 's avatarClemens Backes <clemensb@chromium.org>
Cr-Commit-Position: refs/heads/master@{#66321}
parent 215f22dc
...@@ -1202,10 +1202,15 @@ void InitializeCompilationUnits(Isolate* isolate, NativeModule* native_module) { ...@@ -1202,10 +1202,15 @@ void InitializeCompilationUnits(Isolate* isolate, NativeModule* native_module) {
ModuleWireBytes wire_bytes(native_module->wire_bytes()); ModuleWireBytes wire_bytes(native_module->wire_bytes());
CompilationUnitBuilder builder(native_module); CompilationUnitBuilder builder(native_module);
auto* module = native_module->module(); auto* module = native_module->module();
const bool prefer_liftoff = native_module->IsTieredDown();
uint32_t start = module->num_imported_functions; uint32_t start = module->num_imported_functions;
uint32_t end = start + module->num_declared_functions; uint32_t end = start + module->num_declared_functions;
for (uint32_t func_index = start; func_index < end; func_index++) { for (uint32_t func_index = start; func_index < end; func_index++) {
if (prefer_liftoff) {
builder.AddBaselineUnit(func_index);
continue;
}
CompileStrategy strategy = GetCompileStrategy( CompileStrategy strategy = GetCompileStrategy(
module, native_module->enabled_features(), func_index, lazy_module); module, native_module->enabled_features(), func_index, lazy_module);
if (strategy == CompileStrategy::kLazy) { if (strategy == CompileStrategy::kLazy) {
...@@ -2472,7 +2477,21 @@ void CompilationStateImpl::InitializeCompilationProgress(bool lazy_module, ...@@ -2472,7 +2477,21 @@ void CompilationStateImpl::InitializeCompilationProgress(bool lazy_module,
compilation_progress_.reserve(module->num_declared_functions); compilation_progress_.reserve(module->num_declared_functions);
int start = module->num_imported_functions; int start = module->num_imported_functions;
int end = start + module->num_declared_functions; int end = start + module->num_declared_functions;
const bool prefer_liftoff = native_module_->IsTieredDown();
for (int func_index = start; func_index < end; func_index++) { for (int func_index = start; func_index < end; func_index++) {
if (prefer_liftoff) {
constexpr uint8_t kLiftoffOnlyFunctionProgress =
RequiredTopTierField::update(
RequiredBaselineTierField::update(
ReachedTierField::encode(ExecutionTier::kNone),
ExecutionTier::kLiftoff),
ExecutionTier::kLiftoff);
compilation_progress_.push_back(kLiftoffOnlyFunctionProgress);
outstanding_baseline_units_++;
outstanding_top_tier_functions_++;
continue;
}
ExecutionTierPair requested_tiers = GetRequestedExecutionTiers( ExecutionTierPair requested_tiers = GetRequestedExecutionTiers(
module, compile_mode(), enabled_features, func_index); module, compile_mode(), enabled_features, func_index);
CompileStrategy strategy = CompileStrategy strategy =
......
...@@ -1043,7 +1043,7 @@ WasmCode* NativeModule::PublishCodeLocked(std::unique_ptr<WasmCode> code) { ...@@ -1043,7 +1043,7 @@ WasmCode* NativeModule::PublishCodeLocked(std::unique_ptr<WasmCode> code) {
// TODO(clemensb): Revisit this logic once tier down is fully working. // TODO(clemensb): Revisit this logic once tier down is fully working.
const bool prefer_liftoff = tier_down_ || debug_info_; const bool prefer_liftoff = tier_down_ || debug_info_;
const bool update_code_table = const bool update_code_table =
prefer_liftoff ? code->tier() == ExecutionTier::kLiftoff prefer_liftoff ? !prior_code || code->tier() == ExecutionTier::kLiftoff
: !prior_code || prior_code->tier() < code->tier(); : !prior_code || prior_code->tier() < code->tier();
if (update_code_table) { if (update_code_table) {
code_table_[slot_idx] = code.get(); code_table_[slot_idx] = code.get();
...@@ -1799,15 +1799,28 @@ bool NativeModule::IsRedirectedToInterpreter(uint32_t func_index) { ...@@ -1799,15 +1799,28 @@ bool NativeModule::IsRedirectedToInterpreter(uint32_t func_index) {
return has_interpreter_redirection(func_index); return has_interpreter_redirection(func_index);
} }
bool NativeModule::SetTieredDown() {
// Do not tier down asm.js.
if (module()->origin != kWasmOrigin) return false;
base::MutexGuard lock(&allocation_mutex_);
if (tier_down_) return true;
tier_down_ = true;
return false;
}
bool NativeModule::IsTieredDown() {
base::MutexGuard lock(&allocation_mutex_);
return tier_down_;
}
void NativeModule::TierDown(Isolate* isolate) { void NativeModule::TierDown(Isolate* isolate) {
// Do not tier down asm.js. // Do not tier down asm.js.
if (module()->origin != kWasmOrigin) return; if (module()->origin != kWasmOrigin) return;
// Set the flag.
{ // Set the flag. Return if it is already set.
base::MutexGuard lock(&allocation_mutex_); if (SetTieredDown()) return;
if (tier_down_) return;
tier_down_ = true;
}
// Tier down all functions. // Tier down all functions.
isolate->wasm_engine()->RecompileAllFunctions(isolate, this, isolate->wasm_engine()->RecompileAllFunctions(isolate, this,
ExecutionTier::kLiftoff); ExecutionTier::kLiftoff);
......
...@@ -549,6 +549,10 @@ class V8_EXPORT_PRIVATE NativeModule final { ...@@ -549,6 +549,10 @@ class V8_EXPORT_PRIVATE NativeModule final {
// by publishing an entry stub with the {Kind::kInterpreterEntry} code kind. // by publishing an entry stub with the {Kind::kInterpreterEntry} code kind.
bool IsRedirectedToInterpreter(uint32_t func_index); bool IsRedirectedToInterpreter(uint32_t func_index);
// Set {tier_down_} flag. Return previous state.
bool SetTieredDown();
bool IsTieredDown();
// Sets the flag, triggers recompilation of all methods to tier down or up, // Sets the flag, triggers recompilation of all methods to tier down or up,
// waits for that to complete. // waits for that to complete.
void TierDown(Isolate* isolate); void TierDown(Isolate* isolate);
......
...@@ -331,6 +331,9 @@ struct WasmEngine::IsolateInfo { ...@@ -331,6 +331,9 @@ struct WasmEngine::IsolateInfo {
std::shared_ptr<v8::TaskRunner> foreground_task_runner; std::shared_ptr<v8::TaskRunner> foreground_task_runner;
const std::shared_ptr<Counters> async_counters; const std::shared_ptr<Counters> async_counters;
// Keep new modules in tiered down state.
bool keep_tiered_down = false;
}; };
struct WasmEngine::NativeModuleInfo { struct WasmEngine::NativeModuleInfo {
...@@ -577,6 +580,8 @@ void WasmEngine::TierDownAllModulesPerIsolate(Isolate* isolate) { ...@@ -577,6 +580,8 @@ void WasmEngine::TierDownAllModulesPerIsolate(Isolate* isolate) {
std::vector<NativeModule*> native_modules; std::vector<NativeModule*> native_modules;
{ {
base::MutexGuard lock(&mutex_); base::MutexGuard lock(&mutex_);
if (isolates_[isolate]->keep_tiered_down) return;
isolates_[isolate]->keep_tiered_down = true;
for (auto* native_module : isolates_[isolate]->native_modules) { for (auto* native_module : isolates_[isolate]->native_modules) {
native_modules.push_back(native_module); native_modules.push_back(native_module);
} }
...@@ -841,6 +846,9 @@ std::shared_ptr<NativeModule> WasmEngine::NewNativeModule( ...@@ -841,6 +846,9 @@ std::shared_ptr<NativeModule> WasmEngine::NewNativeModule(
DCHECK(pair.second); // inserted new entry. DCHECK(pair.second); // inserted new entry.
pair.first->second.get()->isolates.insert(isolate); pair.first->second.get()->isolates.insert(isolate);
isolates_[isolate]->native_modules.insert(native_module.get()); isolates_[isolate]->native_modules.insert(native_module.get());
if (isolates_[isolate]->keep_tiered_down) {
native_module->SetTieredDown();
}
return native_module; return native_module;
} }
......
...@@ -7,33 +7,36 @@ ...@@ -7,33 +7,36 @@
load("test/mjsunit/wasm/wasm-module-builder.js"); load("test/mjsunit/wasm/wasm-module-builder.js");
// Create a simple Wasm module. // Create a simple Wasm module.
function create_builder() { function create_builder(i) {
const builder = new WasmModuleBuilder(); const builder = new WasmModuleBuilder();
builder.addFunction('main', kSig_r_v) builder.addFunction('main', kSig_i_r)
.addBody([kExprRefNull]) .addBody([
.exportFunc(); kExprLocalGet, 0, kExprRefIsNull,
...wasmI32Const(i),
kExprI32Add])
.exportFunc();
return builder; return builder;
} }
const instance = create_builder().instantiate(); const instance = create_builder(0).instantiate();
// Test recompilation. // Test recompilation.
const Debug = new DebugWrapper(); const Debug = new DebugWrapper();
Debug.enable(); Debug.enable();
assertFalse(%IsLiftoffFunction(instance.exports.main)); assertFalse(%IsLiftoffFunction(instance.exports.main));
const newInstance = create_builder(1).instantiate();
assertFalse(%IsLiftoffFunction(newInstance.exports.main));
// Async. // Async.
async function testTierDownToLiftoffAsync() { async function testTierDownToLiftoffAsync() {
Debug.disable(); Debug.disable();
const builder = new WasmModuleBuilder(); const asyncInstance = await create_builder(2).asyncInstantiate();
builder.addFunction('main', kSig_i_r)
.addBody([kExprLocalGet, 0, kExprRefIsNull])
.exportFunc();
const asyncInstance = await builder.asyncInstantiate();
// Test recompilation. // Test recompilation.
Debug.enable(); Debug.enable();
assertFalse(%IsLiftoffFunction(instance.exports.main)); assertFalse(%IsLiftoffFunction(asyncInstance.exports.main));
const newAsyncInstance = await create_builder(3).asyncInstantiate();
assertFalse(%IsLiftoffFunction(newAsyncInstance.exports.main));
} }
assertPromiseResult(testTierDownToLiftoffAsync()); assertPromiseResult(testTierDownToLiftoffAsync());
...@@ -27,6 +27,8 @@ const instance = create_builder().instantiate(); ...@@ -27,6 +27,8 @@ const instance = create_builder().instantiate();
const Debug = new DebugWrapper(); const Debug = new DebugWrapper();
Debug.enable(); Debug.enable();
check(instance); check(instance);
const newInstance = create_builder(num_functions*2).instantiate();
check(newInstance);
// Async. // Async.
async function testTierDownToLiftoffAsync() { async function testTierDownToLiftoffAsync() {
...@@ -34,6 +36,8 @@ async function testTierDownToLiftoffAsync() { ...@@ -34,6 +36,8 @@ async function testTierDownToLiftoffAsync() {
const asyncInstance = await create_builder(num_functions).asyncInstantiate(); const asyncInstance = await create_builder(num_functions).asyncInstantiate();
Debug.enable(); Debug.enable();
check(asyncInstance); check(asyncInstance);
const newAsyncInstance = await create_builder(num_functions*3).asyncInstantiate();
check(newAsyncInstance);
} }
assertPromiseResult(testTierDownToLiftoffAsync()); assertPromiseResult(testTierDownToLiftoffAsync());
...@@ -21,6 +21,8 @@ at call_func (0:58): ...@@ -21,6 +21,8 @@ at call_func (0:58):
- scope (global): - scope (global):
globals: "global#0": 0 (number) globals: "global#0": 0 (number)
- scope (local): - scope (local):
locals: "arg#0": 4 (number), "local#1": 7.199999809265137 (number)
stack:
at (anonymous) (0:17): at (anonymous) (0:17):
- scope (global): - scope (global):
-- skipped globals -- skipped globals
...@@ -38,6 +40,8 @@ at call_func (0:58): ...@@ -38,6 +40,8 @@ at call_func (0:58):
- scope (global): - scope (global):
globals: "global#0": 0 (number) globals: "global#0": 0 (number)
- scope (local): - scope (local):
locals: "arg#0": 4 (number), "local#1": 7.199999809265137 (number)
stack:
at (anonymous) (0:17): at (anonymous) (0:17):
- scope (global): - scope (global):
-- skipped globals -- skipped globals
...@@ -55,6 +59,8 @@ at call_func (0:58): ...@@ -55,6 +59,8 @@ at call_func (0:58):
- scope (global): - scope (global):
globals: "global#0": 0 (number) globals: "global#0": 0 (number)
- scope (local): - scope (local):
locals: "arg#0": 4 (number), "local#1": 7.199999809265137 (number)
stack:
at (anonymous) (0:17): at (anonymous) (0:17):
- scope (global): - scope (global):
-- skipped globals -- skipped globals
...@@ -72,6 +78,8 @@ at call_func (0:58): ...@@ -72,6 +78,8 @@ at call_func (0:58):
- scope (global): - scope (global):
globals: "global#0": 0 (number) globals: "global#0": 0 (number)
- scope (local): - scope (local):
locals: "arg#0": 4 (number), "local#1": 7.199999809265137 (number)
stack:
at (anonymous) (0:17): at (anonymous) (0:17):
- scope (global): - scope (global):
-- skipped globals -- skipped globals
...@@ -89,6 +97,8 @@ at call_func (0:58): ...@@ -89,6 +97,8 @@ at call_func (0:58):
- scope (global): - scope (global):
globals: "global#0": 0 (number) globals: "global#0": 0 (number)
- scope (local): - scope (local):
locals: "arg#0": 4 (number), "local#1": 7.199999809265137 (number)
stack:
at (anonymous) (0:17): at (anonymous) (0:17):
- scope (global): - scope (global):
-- skipped globals -- skipped globals
...@@ -106,6 +116,8 @@ at call_func (0:58): ...@@ -106,6 +116,8 @@ at call_func (0:58):
- scope (global): - scope (global):
globals: "global#0": 0 (number) globals: "global#0": 0 (number)
- scope (local): - scope (local):
locals: "arg#0": 4 (number), "local#1": 7.199999809265137 (number)
stack:
at (anonymous) (0:17): at (anonymous) (0:17):
- scope (global): - scope (global):
-- skipped globals -- skipped globals
...@@ -123,6 +135,8 @@ at call_func (0:58): ...@@ -123,6 +135,8 @@ at call_func (0:58):
- scope (global): - scope (global):
globals: "global#0": 0 (number) globals: "global#0": 0 (number)
- scope (local): - scope (local):
locals: "arg#0": 4 (number), "local#1": 7.199999809265137 (number)
stack:
at (anonymous) (0:17): at (anonymous) (0:17):
- scope (global): - scope (global):
-- skipped globals -- skipped globals
...@@ -140,6 +154,8 @@ at call_func (0:58): ...@@ -140,6 +154,8 @@ at call_func (0:58):
- scope (global): - scope (global):
globals: "global#0": 0 (number) globals: "global#0": 0 (number)
- scope (local): - scope (local):
locals: "arg#0": 4 (number), "local#1": 7.199999809265137 (number)
stack:
at (anonymous) (0:17): at (anonymous) (0:17):
- scope (global): - scope (global):
-- skipped globals -- skipped globals
...@@ -157,6 +173,8 @@ at call_func (0:58): ...@@ -157,6 +173,8 @@ at call_func (0:58):
- scope (global): - scope (global):
globals: "global#0": 0 (number) globals: "global#0": 0 (number)
- scope (local): - scope (local):
locals: "arg#0": 4 (number), "local#1": 7.199999809265137 (number)
stack:
at (anonymous) (0:17): at (anonymous) (0:17):
- scope (global): - scope (global):
-- skipped globals -- skipped globals
...@@ -174,6 +192,8 @@ at call_func (0:58): ...@@ -174,6 +192,8 @@ at call_func (0:58):
- scope (global): - scope (global):
globals: "global#0": 0 (number) globals: "global#0": 0 (number)
- scope (local): - scope (local):
locals: "arg#0": 4 (number), "local#1": 7.199999809265137 (number)
stack:
at (anonymous) (0:17): at (anonymous) (0:17):
- scope (global): - scope (global):
-- skipped globals -- skipped globals
...@@ -191,6 +211,8 @@ at call_func (0:58): ...@@ -191,6 +211,8 @@ at call_func (0:58):
- scope (global): - scope (global):
globals: "global#0": 0 (number) globals: "global#0": 0 (number)
- scope (local): - scope (local):
locals: "arg#0": 4 (number), "local#1": 7.199999809265137 (number)
stack:
at (anonymous) (0:17): at (anonymous) (0:17):
- scope (global): - scope (global):
-- skipped globals -- skipped globals
...@@ -208,6 +230,8 @@ at call_func (0:58): ...@@ -208,6 +230,8 @@ at call_func (0:58):
- scope (global): - scope (global):
globals: "global#0": 0 (number) globals: "global#0": 0 (number)
- scope (local): - scope (local):
locals: "arg#0": 4 (number), "local#1": 7.199999809265137 (number)
stack:
at (anonymous) (0:17): at (anonymous) (0:17):
- scope (global): - scope (global):
-- skipped globals -- skipped globals
...@@ -225,6 +249,8 @@ at call_func (0:58): ...@@ -225,6 +249,8 @@ at call_func (0:58):
- scope (global): - scope (global):
globals: "global#0": 0 (number) globals: "global#0": 0 (number)
- scope (local): - scope (local):
locals: "arg#0": 4 (number), "local#1": 7.199999809265137 (number)
stack:
at (anonymous) (0:17): at (anonymous) (0:17):
- scope (global): - scope (global):
-- skipped globals -- skipped globals
...@@ -242,6 +268,8 @@ at call_func (0:58): ...@@ -242,6 +268,8 @@ at call_func (0:58):
- scope (global): - scope (global):
globals: "global#0": 0 (number) globals: "global#0": 0 (number)
- scope (local): - scope (local):
locals: "arg#0": 4 (number), "local#1": 7.199999809265137 (number)
stack:
at (anonymous) (0:17): at (anonymous) (0:17):
- scope (global): - scope (global):
-- skipped globals -- skipped globals
...@@ -259,6 +287,8 @@ at call_func (0:58): ...@@ -259,6 +287,8 @@ at call_func (0:58):
- scope (global): - scope (global):
globals: "global#0": 0 (number) globals: "global#0": 0 (number)
- scope (local): - scope (local):
locals: "arg#0": 4 (number), "local#1": 7.199999809265137 (number)
stack:
at (anonymous) (0:17): at (anonymous) (0:17):
- scope (global): - scope (global):
-- skipped globals -- skipped globals
...@@ -276,6 +306,8 @@ at call_func (0:58): ...@@ -276,6 +306,8 @@ at call_func (0:58):
- scope (global): - scope (global):
globals: "global#0": 0 (number) globals: "global#0": 0 (number)
- scope (local): - scope (local):
locals: "arg#0": 4 (number), "local#1": 7.199999809265137 (number)
stack:
at (anonymous) (0:17): at (anonymous) (0:17):
- scope (global): - scope (global):
-- skipped globals -- skipped globals
...@@ -293,6 +325,8 @@ at call_func (0:58): ...@@ -293,6 +325,8 @@ at call_func (0:58):
- scope (global): - scope (global):
globals: "global#0": 15 (number) globals: "global#0": 15 (number)
- scope (local): - scope (local):
locals: "arg#0": 4 (number), "local#1": 7.199999809265137 (number)
stack:
at (anonymous) (0:17): at (anonymous) (0:17):
- scope (global): - scope (global):
-- skipped globals -- skipped globals
......
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