Commit d13a1e66 authored by Clemens Backes's avatar Clemens Backes Committed by Commit Bot

[wasm][debug] Re-install cached code

If we use code from the cache, we have to re-install it in the
NativeModule. Otherwise it won't be hit on calls.

R=thibaudm@chromium.org

Bug: v8:11516
Change-Id: Ie5f035e490d6525147a05b1fda1038b030e25d18
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2739644Reviewed-by: 's avatarThibaud Michaud <thibaudm@chromium.org>
Commit-Queue: Clemens Backes <clemensb@chromium.org>
Cr-Commit-Position: refs/heads/master@{#73228}
parent eb24cf54
......@@ -1191,6 +1191,29 @@ WasmCode* NativeModule::PublishCodeLocked(std::unique_ptr<WasmCode> code) {
return result;
}
void NativeModule::ReinstallDebugCode(WasmCode* code) {
base::MutexGuard lock(&allocation_mutex_);
DCHECK_EQ(this, code->native_module());
DCHECK_EQ(kWithBreakpoints, code->for_debugging());
DCHECK(!code->IsAnonymous());
DCHECK_LE(module_->num_imported_functions, code->index());
DCHECK_LT(code->index(), num_functions());
DCHECK_EQ(kTieredDown, tiering_state_);
uint32_t slot_idx = declared_function_index(module(), code->index());
if (WasmCode* prior_code = code_table_[slot_idx]) {
WasmCodeRefScope::AddRef(prior_code);
// The code is added to the current {WasmCodeRefScope}, hence the ref
// count cannot drop to zero here.
prior_code->DecRefOnLiveCode();
}
code_table_[slot_idx] = code;
code->IncRef();
PatchJumpTablesLocked(slot_idx, code->instruction_start());
}
Vector<uint8_t> NativeModule::AllocateForDeserializedCode(
size_t total_code_size) {
return code_allocator_.AllocateForCode(this, total_code_size);
......
......@@ -511,6 +511,13 @@ class V8_EXPORT_PRIVATE NativeModule final {
WasmCode* PublishCode(std::unique_ptr<WasmCode>);
std::vector<WasmCode*> PublishCode(Vector<std::unique_ptr<WasmCode>>);
// ReinstallDebugCode does a subset of PublishCode: It installs the code in
// the code table and patches the jump table. The given code must be debug
// code (with breakpoints) and must be owned by this {NativeModule} already.
// This method is used to re-instantiate code that was removed from the code
// table and jump table via another {PublishCode}.
void ReinstallDebugCode(WasmCode*);
Vector<uint8_t> AllocateForDeserializedCode(size_t total_code_size);
std::unique_ptr<WasmCode> AddDeserializedCode(
......
......@@ -238,6 +238,10 @@ class DebugInfoImpl {
int dead_breakpoint) {
DCHECK(!mutex_.TryLock()); // Mutex is held externally.
ForDebugging for_debugging = offsets.size() == 1 && offsets[0] == 0
? kForStepping
: kWithBreakpoints;
// Check the cache first.
for (auto begin = cached_debugging_code_.begin(), it = begin,
end = cached_debugging_code_.end();
......@@ -247,6 +251,10 @@ class DebugInfoImpl {
it->dead_breakpoint == dead_breakpoint) {
// Rotate the cache entry to the front (for LRU).
for (; it != begin; --it) std::iter_swap(it, it - 1);
if (for_debugging == kWithBreakpoints) {
// Re-install the code, in case it was replaced in the meantime.
native_module_->ReinstallDebugCode(it->code);
}
return it->code;
}
}
......@@ -261,9 +269,6 @@ class DebugInfoImpl {
wire_bytes.begin() + function->code.end_offset()};
std::unique_ptr<DebugSideTable> debug_sidetable;
ForDebugging for_debugging = offsets.size() == 1 && offsets[0] == 0
? kForStepping
: kWithBreakpoints;
// Debug side tables for stepping are generated lazily.
bool generate_debug_sidetable = for_debugging == kWithBreakpoints;
Counters* counters = nullptr;
......
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