Commit 21a0a5f1 authored by Clemens Backes's avatar Clemens Backes Committed by Commit Bot

[wasm][serialization] Look up jump tables only once

... per code space. This avoids redudant work, including potentially
locking the NativeModule.

R=thibaudm@chromium.org

Bug: v8:11164
Change-Id: I34d5aa9aaff5a487042889613676d2a8d96497e2
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2644948
Commit-Queue: Clemens Backes <clemensb@chromium.org>
Reviewed-by: 's avatarThibaud Michaud <thibaudm@chromium.org>
Cr-Commit-Position: refs/heads/master@{#72353}
parent e75d8dbc
...@@ -541,8 +541,8 @@ class V8_EXPORT_PRIVATE NativeModule final { ...@@ -541,8 +541,8 @@ class V8_EXPORT_PRIVATE NativeModule final {
Address GetCallTargetForFunction(uint32_t func_index) const; Address GetCallTargetForFunction(uint32_t func_index) const;
struct JumpTablesRef { struct JumpTablesRef {
const Address jump_table_start = kNullAddress; Address jump_table_start = kNullAddress;
const Address far_jump_table_start = kNullAddress; Address far_jump_table_start = kNullAddress;
bool is_valid() const { return far_jump_table_start != kNullAddress; } bool is_valid() const { return far_jump_table_start != kNullAddress; }
}; };
......
...@@ -482,6 +482,7 @@ bool WasmSerializer::SerializeNativeModule(Vector<byte> buffer) const { ...@@ -482,6 +482,7 @@ bool WasmSerializer::SerializeNativeModule(Vector<byte> buffer) const {
struct DeserializationUnit { struct DeserializationUnit {
Vector<const byte> src_code_buffer; Vector<const byte> src_code_buffer;
std::unique_ptr<WasmCode> code; std::unique_ptr<WasmCode> code;
NativeModule::JumpTablesRef jump_tables;
}; };
class DeserializationQueue { class DeserializationQueue {
...@@ -548,6 +549,7 @@ class V8_EXPORT_PRIVATE NativeModuleDeserializer { ...@@ -548,6 +549,7 @@ class V8_EXPORT_PRIVATE NativeModuleDeserializer {
// Updated in {ReadCode}. // Updated in {ReadCode}.
size_t remaining_code_size_ = 0; size_t remaining_code_size_ = 0;
Vector<byte> current_code_space_; Vector<byte> current_code_space_;
NativeModule::JumpTablesRef current_jump_tables_;
}; };
class CopyAndRelocTask : public JobTask { class CopyAndRelocTask : public JobTask {
...@@ -687,7 +689,7 @@ DeserializationUnit NativeModuleDeserializer::ReadCode(int fn_index, ...@@ -687,7 +689,7 @@ DeserializationUnit NativeModuleDeserializer::ReadCode(int fn_index,
DCHECK(FLAG_wasm_lazy_compilation || DCHECK(FLAG_wasm_lazy_compilation ||
native_module_->enabled_features().has_compilation_hints()); native_module_->enabled_features().has_compilation_hints());
native_module_->UseLazyStub(fn_index); native_module_->UseLazyStub(fn_index);
return {{}, nullptr}; return {};
} }
int constant_pool_offset = reader->Read<int>(); int constant_pool_offset = reader->Read<int>();
int safepoint_table_offset = reader->Read<int>(); int safepoint_table_offset = reader->Read<int>();
...@@ -714,6 +716,9 @@ DeserializationUnit NativeModuleDeserializer::ReadCode(int fn_index, ...@@ -714,6 +716,9 @@ DeserializationUnit NativeModuleDeserializer::ReadCode(int fn_index,
current_code_space_ = current_code_space_ =
native_module_->AllocateForDeserializedCode(code_space_size); native_module_->AllocateForDeserializedCode(code_space_size);
DCHECK_EQ(current_code_space_.size(), code_space_size); DCHECK_EQ(current_code_space_.size(), code_space_size);
current_jump_tables_ = native_module_->FindJumpTablesForRegion(
base::AddressRegionOf(current_code_space_));
DCHECK(current_jump_tables_.is_valid());
} }
DeserializationUnit unit; DeserializationUnit unit;
...@@ -732,6 +737,7 @@ DeserializationUnit NativeModuleDeserializer::ReadCode(int fn_index, ...@@ -732,6 +737,7 @@ DeserializationUnit NativeModuleDeserializer::ReadCode(int fn_index,
safepoint_table_offset, handler_table_offset, constant_pool_offset, safepoint_table_offset, handler_table_offset, constant_pool_offset,
code_comment_offset, unpadded_binary_size, protected_instructions, code_comment_offset, unpadded_binary_size, protected_instructions,
reloc_info, source_pos, kind, tier); reloc_info, source_pos, kind, tier);
unit.jump_tables = current_jump_tables_;
return unit; return unit;
} }
...@@ -746,8 +752,6 @@ void NativeModuleDeserializer::CopyAndRelocate( ...@@ -746,8 +752,6 @@ void NativeModuleDeserializer::CopyAndRelocate(
RelocInfo::ModeMask(RelocInfo::EXTERNAL_REFERENCE) | RelocInfo::ModeMask(RelocInfo::EXTERNAL_REFERENCE) |
RelocInfo::ModeMask(RelocInfo::INTERNAL_REFERENCE) | RelocInfo::ModeMask(RelocInfo::INTERNAL_REFERENCE) |
RelocInfo::ModeMask(RelocInfo::INTERNAL_REFERENCE_ENCODED); RelocInfo::ModeMask(RelocInfo::INTERNAL_REFERENCE_ENCODED);
auto jump_tables_ref = native_module_->FindJumpTablesForRegion(
base::AddressRegionOf(unit.code->instructions()));
for (RelocIterator iter(unit.code->instructions(), unit.code->reloc_info(), for (RelocIterator iter(unit.code->instructions(), unit.code->reloc_info(),
unit.code->constant_pool(), mask); unit.code->constant_pool(), mask);
!iter.done(); iter.next()) { !iter.done(); iter.next()) {
...@@ -756,7 +760,7 @@ void NativeModuleDeserializer::CopyAndRelocate( ...@@ -756,7 +760,7 @@ void NativeModuleDeserializer::CopyAndRelocate(
case RelocInfo::WASM_CALL: { case RelocInfo::WASM_CALL: {
uint32_t tag = GetWasmCalleeTag(iter.rinfo()); uint32_t tag = GetWasmCalleeTag(iter.rinfo());
Address target = Address target =
native_module_->GetNearCallTargetForFunction(tag, jump_tables_ref); native_module_->GetNearCallTargetForFunction(tag, unit.jump_tables);
iter.rinfo()->set_wasm_call_address(target, SKIP_ICACHE_FLUSH); iter.rinfo()->set_wasm_call_address(target, SKIP_ICACHE_FLUSH);
break; break;
} }
...@@ -764,7 +768,7 @@ void NativeModuleDeserializer::CopyAndRelocate( ...@@ -764,7 +768,7 @@ void NativeModuleDeserializer::CopyAndRelocate(
uint32_t tag = GetWasmCalleeTag(iter.rinfo()); uint32_t tag = GetWasmCalleeTag(iter.rinfo());
DCHECK_LT(tag, WasmCode::kRuntimeStubCount); DCHECK_LT(tag, WasmCode::kRuntimeStubCount);
Address target = native_module_->GetNearRuntimeStubEntry( Address target = native_module_->GetNearRuntimeStubEntry(
static_cast<WasmCode::RuntimeStubId>(tag), jump_tables_ref); static_cast<WasmCode::RuntimeStubId>(tag), unit.jump_tables);
iter.rinfo()->set_wasm_stub_call_address(target, SKIP_ICACHE_FLUSH); iter.rinfo()->set_wasm_stub_call_address(target, SKIP_ICACHE_FLUSH);
break; break;
} }
......
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