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