Commit aff3fe30 authored by Clemens Hammacher's avatar Clemens Hammacher Committed by Commit Bot

[wasm][gc] Activate code ref scopes

This CL enables adding code to the top-most {WasmCodeRefScope} when
either adding code to the {NativeModule} (we have a nice choke point
for that in {PublishCodeLocked}), or when looking up existing code from
a {NativeModule}.
It also enables the DCHECK that for each such operation, there must be
an enclosing {WasmCodeRefScope}.

R=titzer@chromium.org

Bug: v8:8217
Change-Id: Ie93ca0b31b1577bef074923b3d228a9f214a909c
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/1533861
Commit-Queue: Clemens Hammacher <clemensh@chromium.org>
Reviewed-by: 's avatarBen Titzer <titzer@chromium.org>
Cr-Commit-Position: refs/heads/master@{#60608}
parent acdeb64c
...@@ -800,6 +800,7 @@ WasmCodeUpdate NativeModule::PublishCodeLocked(std::unique_ptr<WasmCode> code) { ...@@ -800,6 +800,7 @@ WasmCodeUpdate NativeModule::PublishCodeLocked(std::unique_ptr<WasmCode> code) {
WasmCode::kFlushICache); WasmCode::kFlushICache);
} }
} }
WasmCodeRefScope::AddRef(code.get());
update.code = code.get(); update.code = code.get();
owned_code_.emplace_back(std::move(code)); owned_code_.emplace_back(std::move(code));
return update; return update;
...@@ -1003,7 +1004,10 @@ WasmCode* NativeModule::Lookup(Address pc) const { ...@@ -1003,7 +1004,10 @@ WasmCode* NativeModule::Lookup(Address pc) const {
--iter; --iter;
WasmCode* candidate = iter->get(); WasmCode* candidate = iter->get();
DCHECK_NOT_NULL(candidate); DCHECK_NOT_NULL(candidate);
if (candidate->contains(pc)) return candidate; if (candidate->contains(pc)) {
WasmCodeRefScope::AddRef(candidate);
return candidate;
}
} }
if (owned_code_sorted_portion_ == owned_code_.size()) return nullptr; if (owned_code_sorted_portion_ == owned_code_.size()) return nullptr;
std::sort(owned_code_.begin(), owned_code_.end(), std::sort(owned_code_.begin(), owned_code_.end(),
...@@ -1350,7 +1354,8 @@ std::vector<WasmCodeUpdate> NativeModule::AddCompiledCode( ...@@ -1350,7 +1354,8 @@ std::vector<WasmCodeUpdate> NativeModule::AddCompiledCode(
} }
DCHECK_EQ(0, code_space.size()); DCHECK_EQ(0, code_space.size());
// Under the {allocation_mutex_}, publish the code. // Under the {allocation_mutex_}, publish the code. The published code is put
// into the top-most surrounding {WasmCodeRefScope} by {PublishCodeLocked}.
std::vector<WasmCodeUpdate> code_updates; std::vector<WasmCodeUpdate> code_updates;
code_updates.reserve(results.size()); code_updates.reserve(results.size());
{ {
...@@ -1460,9 +1465,7 @@ WasmCodeRefScope::~WasmCodeRefScope() { ...@@ -1460,9 +1465,7 @@ WasmCodeRefScope::~WasmCodeRefScope() {
// static // static
void WasmCodeRefScope::AddRef(WasmCode* code) { void WasmCodeRefScope::AddRef(WasmCode* code) {
WasmCodeRefScope* current_scope = current_code_refs_scope; WasmCodeRefScope* current_scope = current_code_refs_scope;
// TODO(clemensh): Remove early return, activate DCHECK instead. DCHECK_NOT_NULL(current_scope);
// DCHECK_NOT_NULL(current_scope);
if (!current_scope) return;
auto entry = current_scope->code_ptrs_.insert(code); auto entry = current_scope->code_ptrs_.insert(code);
// If we added a new entry, increment the ref counter. // If we added a new entry, increment the ref counter.
if (entry.second) code->IncRef(); if (entry.second) code->IncRef();
......
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