Commit 4a5167ef authored by Clemens Backes's avatar Clemens Backes Committed by Commit Bot

[wasm] Syntactially refactor {PublishCodeLocked}

This is just adding an early exit, to avoid a big if-block spanning the
whole method.
Instead of doing this in the follow-up CL, which adds even more code to
that block, I pulled it out for easier review.

R=thibaudm@chromium.org

Bug: v8:11556
Change-Id: Ie4f2e0635fe9875c90d32be8224f1b0709c82e00
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2757687Reviewed-by: 's avatarThibaud Michaud <thibaudm@chromium.org>
Commit-Queue: Clemens Backes <clemensb@chromium.org>
Cr-Commit-Position: refs/heads/master@{#73405}
parent a536a77f
......@@ -1132,68 +1132,72 @@ WasmCode::Kind GetCodeKind(const WasmCompilationResult& result) {
}
}
WasmCode* NativeModule::PublishCodeLocked(std::unique_ptr<WasmCode> code) {
WasmCode* NativeModule::PublishCodeLocked(
std::unique_ptr<WasmCode> owned_code) {
// The caller must hold the {allocation_mutex_}, thus we fail to lock it here.
DCHECK(!allocation_mutex_.TryLock());
WasmCode* code = owned_code.get();
new_owned_code_.emplace_back(std::move(owned_code));
// Add the code to the surrounding code ref scope, so the returned pointer is
// guaranteed to be valid.
WasmCodeRefScope::AddRef(code.get());
if (!code->IsAnonymous() &&
code->index() >= module_->num_imported_functions) {
DCHECK_LT(code->index(), num_functions());
code->RegisterTrapHandlerData();
// Assume an order of execution tiers that represents the quality of their
// generated code.
static_assert(ExecutionTier::kNone < ExecutionTier::kLiftoff &&
ExecutionTier::kLiftoff < ExecutionTier::kTurbofan,
"Assume an order on execution tiers");
uint32_t slot_idx = declared_function_index(module(), code->index());
WasmCode* prior_code = code_table_[slot_idx];
// If we are tiered down, install all debugging code (except for stepping
// code, which is only used for a single frame and never installed in the
// code table of jump table). Otherwise, install code if it was compiled
// with a higher tier.
static_assert(
kForDebugging > kNoDebugging && kWithBreakpoints > kForDebugging,
"for_debugging is ordered");
const bool update_code_table =
// Never install stepping code.
code->for_debugging() != kForStepping &&
(!prior_code ||
(tiering_state_ == kTieredDown
// Tiered down: Install breakpoints over normal debug code.
? prior_code->for_debugging() <= code->for_debugging()
// Tiered up: Install if the tier is higher than before.
: prior_code->tier() < code->tier()));
if (update_code_table) {
code_table_[slot_idx] = code.get();
if (prior_code) {
WasmCodeRefScope::AddRef(prior_code);
// The code is added to the current {WasmCodeRefScope}, hence the ref
// count cannot drop to zero here.
prior_code->DecRefOnLiveCode();
}
WasmCodeRefScope::AddRef(code);
PatchJumpTablesLocked(slot_idx, code->instruction_start());
} else {
// The code tables does not hold a reference to the code, hence decrement
// the initial ref count of 1. The code was added to the
// {WasmCodeRefScope} though, so it cannot die here.
code->DecRefOnLiveCode();
}
if (!code->for_debugging() && tiering_state_ == kTieredDown &&
code->tier() == ExecutionTier::kTurbofan) {
liftoff_bailout_count_.fetch_add(1);
if (code->IsAnonymous() || code->index() < module_->num_imported_functions) {
return code;
}
DCHECK_LT(code->index(), num_functions());
code->RegisterTrapHandlerData();
// Assume an order of execution tiers that represents the quality of their
// generated code.
static_assert(ExecutionTier::kNone < ExecutionTier::kLiftoff &&
ExecutionTier::kLiftoff < ExecutionTier::kTurbofan,
"Assume an order on execution tiers");
uint32_t slot_idx = declared_function_index(module(), code->index());
WasmCode* prior_code = code_table_[slot_idx];
// If we are tiered down, install all debugging code (except for stepping
// code, which is only used for a single frame and never installed in the
// code table of jump table). Otherwise, install code if it was compiled
// with a higher tier.
static_assert(
kForDebugging > kNoDebugging && kWithBreakpoints > kForDebugging,
"for_debugging is ordered");
const bool update_code_table =
// Never install stepping code.
code->for_debugging() != kForStepping &&
(!prior_code ||
(tiering_state_ == kTieredDown
// Tiered down: Install breakpoints over normal debug code.
? prior_code->for_debugging() <= code->for_debugging()
// Tiered up: Install if the tier is higher than before.
: prior_code->tier() < code->tier()));
if (update_code_table) {
code_table_[slot_idx] = code;
if (prior_code) {
WasmCodeRefScope::AddRef(prior_code);
// The code is added to the current {WasmCodeRefScope}, hence the ref
// count cannot drop to zero here.
prior_code->DecRefOnLiveCode();
}
PatchJumpTablesLocked(slot_idx, code->instruction_start());
} else {
// The code tables does not hold a reference to the code, hence decrement
// the initial ref count of 1. The code was added to the
// {WasmCodeRefScope} though, so it cannot die here.
code->DecRefOnLiveCode();
}
WasmCode* result = code.get();
new_owned_code_.emplace_back(std::move(code));
return result;
if (!code->for_debugging() && tiering_state_ == kTieredDown &&
code->tier() == ExecutionTier::kTurbofan) {
liftoff_bailout_count_.fetch_add(1);
}
return code;
}
void NativeModule::ReinstallDebugCode(WasmCode* code) {
......
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