Commit d38ea7d9 authored by Clemens Backes's avatar Clemens Backes Committed by V8 LUCI CQ

[wasm] Avoid code modifications during code freeing

Code freeing can happen at any point in time where a GC might be
triggered. Hence it's difficult to ensure that no other
{CodeSpaceWriteScope} is already open at that point. The way these scope
objects are implemented forbids multiple scopes for different modules
though.
To solve this, this CL just avoids the code zapping in
{WasmCodeAllocator::FreeCode}, which is the only place that actually
writes to the code space. Without this, we do not need the
{CodeSpaceWriteScope} in {NativeModule::FreeCode} any more.

R=jkummerow@chromium.org

Bug: v8:11974
Change-Id: I1f01979e1eaea6c311c9ad568d605aabeef3bfc4
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/3081522
Commit-Queue: Clemens Backes <clemensb@chromium.org>
Reviewed-by: 's avatarJakob Kummerow <jkummerow@chromium.org>
Cr-Commit-Position: refs/heads/master@{#76174}
parent e82a3b1e
...@@ -822,13 +822,6 @@ void WasmCodeAllocator::FreeCode(base::Vector<WasmCode* const> codes) { ...@@ -822,13 +822,6 @@ void WasmCodeAllocator::FreeCode(base::Vector<WasmCode* const> codes) {
DisjointAllocationPool freed_regions; DisjointAllocationPool freed_regions;
size_t code_size = 0; size_t code_size = 0;
for (WasmCode* code : codes) { for (WasmCode* code : codes) {
// TODO(clemensb): If zapping is worth it, we need to unprotect the code
// memory first.
if (!protect_code_memory_) {
ZapCode(code->instruction_start(), code->instructions().size());
FlushInstructionCache(code->instruction_start(),
code->instructions().size());
}
code_size += code->instructions().size(); code_size += code->instructions().size();
freed_regions.Merge(base::AddressRegion{code->instruction_start(), freed_regions.Merge(base::AddressRegion{code->instruction_start(),
code->instructions().size()}); code->instructions().size()});
...@@ -2356,10 +2349,6 @@ std::vector<int> NativeModule::FindFunctionsToRecompile( ...@@ -2356,10 +2349,6 @@ std::vector<int> NativeModule::FindFunctionsToRecompile(
void NativeModule::FreeCode(base::Vector<WasmCode* const> codes) { void NativeModule::FreeCode(base::Vector<WasmCode* const> codes) {
base::RecursiveMutexGuard guard(&allocation_mutex_); base::RecursiveMutexGuard guard(&allocation_mutex_);
// Get writable permission already here (and not inside the loop in
// {WasmCodeAllocator::FreeCode}), to avoid switching for each {code}
// individually.
CodeSpaceWriteScope code_space_write_scope(this);
// Free the code space. // Free the code space.
code_allocator_.FreeCode(codes); code_allocator_.FreeCode(codes);
......
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