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,16 +1132,22 @@ WasmCode::Kind GetCodeKind(const WasmCompilationResult& result) { ...@@ -1132,16 +1132,22 @@ 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. // The caller must hold the {allocation_mutex_}, thus we fail to lock it here.
DCHECK(!allocation_mutex_.TryLock()); 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 // Add the code to the surrounding code ref scope, so the returned pointer is
// guaranteed to be valid. // guaranteed to be valid.
WasmCodeRefScope::AddRef(code.get()); WasmCodeRefScope::AddRef(code);
if (code->IsAnonymous() || code->index() < module_->num_imported_functions) {
return code;
}
if (!code->IsAnonymous() &&
code->index() >= module_->num_imported_functions) {
DCHECK_LT(code->index(), num_functions()); DCHECK_LT(code->index(), num_functions());
code->RegisterTrapHandlerData(); code->RegisterTrapHandlerData();
...@@ -1171,7 +1177,7 @@ WasmCode* NativeModule::PublishCodeLocked(std::unique_ptr<WasmCode> code) { ...@@ -1171,7 +1177,7 @@ WasmCode* NativeModule::PublishCodeLocked(std::unique_ptr<WasmCode> code) {
// Tiered up: Install if the tier is higher than before. // Tiered up: Install if the tier is higher than before.
: prior_code->tier() < code->tier())); : prior_code->tier() < code->tier()));
if (update_code_table) { if (update_code_table) {
code_table_[slot_idx] = code.get(); code_table_[slot_idx] = code;
if (prior_code) { if (prior_code) {
WasmCodeRefScope::AddRef(prior_code); WasmCodeRefScope::AddRef(prior_code);
// The code is added to the current {WasmCodeRefScope}, hence the ref // The code is added to the current {WasmCodeRefScope}, hence the ref
...@@ -1190,10 +1196,8 @@ WasmCode* NativeModule::PublishCodeLocked(std::unique_ptr<WasmCode> code) { ...@@ -1190,10 +1196,8 @@ WasmCode* NativeModule::PublishCodeLocked(std::unique_ptr<WasmCode> code) {
code->tier() == ExecutionTier::kTurbofan) { code->tier() == ExecutionTier::kTurbofan) {
liftoff_bailout_count_.fetch_add(1); liftoff_bailout_count_.fetch_add(1);
} }
}
WasmCode* result = code.get(); return code;
new_owned_code_.emplace_back(std::move(code));
return result;
} }
void NativeModule::ReinstallDebugCode(WasmCode* 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