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) {
WasmCode::kFlushICache);
}
}
WasmCodeRefScope::AddRef(code.get());
update.code = code.get();
owned_code_.emplace_back(std::move(code));
return update;
......@@ -1003,7 +1004,10 @@ WasmCode* NativeModule::Lookup(Address pc) const {
--iter;
WasmCode* candidate = iter->get();
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;
std::sort(owned_code_.begin(), owned_code_.end(),
......@@ -1350,7 +1354,8 @@ std::vector<WasmCodeUpdate> NativeModule::AddCompiledCode(
}
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;
code_updates.reserve(results.size());
{
......@@ -1460,9 +1465,7 @@ WasmCodeRefScope::~WasmCodeRefScope() {
// static
void WasmCodeRefScope::AddRef(WasmCode* code) {
WasmCodeRefScope* current_scope = current_code_refs_scope;
// TODO(clemensh): Remove early return, activate DCHECK instead.
// DCHECK_NOT_NULL(current_scope);
if (!current_scope) return;
DCHECK_NOT_NULL(current_scope);
auto entry = current_scope->code_ptrs_.insert(code);
// If we added a new entry, increment the ref counter.
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