Commit 8ee003e1 authored by Clemens Hammacher's avatar Clemens Hammacher Committed by Commit Bot

[wasm] Refactor generation of stub table

Instantiating a JumpTableAssembler has some overhead (at least one heap
allocation), so use a single JumpTableAssembler to generate the whole
table, just as the lazy compile table.

R=mstarzinger@chromium.org

Bug: v8:9477
Change-Id: I66622909ac06e6bda9fca3e71c83d4c9d1ded500
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/1706054Reviewed-by: 's avatarMichael Starzinger <mstarzinger@chromium.org>
Commit-Queue: Clemens Hammacher <clemensh@chromium.org>
Cr-Commit-Position: refs/heads/master@{#62762}
parent 10f8ecb4
......@@ -100,16 +100,20 @@ class V8_EXPORT_PRIVATE JumpTableAssembler : public MacroAssembler {
FlushInstructionCache(base, lazy_compile_table_size);
}
static void EmitRuntimeStubSlot(Address base, uint32_t slot_index,
Address builtin_target,
WasmCode::FlushICache flush_i_cache) {
Address slot = base + StubSlotIndexToOffset(slot_index);
JumpTableAssembler jtasm(slot);
jtasm.EmitRuntimeStubSlot(builtin_target);
jtasm.NopBytes(kJumpTableStubSlotSize - jtasm.pc_offset());
if (flush_i_cache) {
FlushInstructionCache(slot, kJumpTableStubSlotSize);
static void GenerateRuntimeStubTable(Address base, Address* targets,
int num_stubs) {
uint32_t table_size = num_stubs * kJumpTableStubSlotSize;
// Assume enough space, so the Assembler does not try to grow the buffer.
JumpTableAssembler jtasm(base, table_size + 256);
int offset = 0;
for (int index = 0; index < num_stubs; ++index) {
DCHECK_EQ(offset, StubSlotIndexToOffset(index));
DCHECK_EQ(offset, jtasm.pc_offset());
jtasm.EmitRuntimeStubSlot(targets[index]);
offset += kJumpTableStubSlotSize;
jtasm.NopBytes(offset - jtasm.pc_offset());
}
FlushInstructionCache(base, table_size);
}
static void PatchJumpTableSlot(Address base, uint32_t slot_index,
......
......@@ -729,23 +729,22 @@ void NativeModule::SetRuntimeStubs(Isolate* isolate) {
WasmCode::kRuntimeStubCount));
Address base = jump_table->instruction_start();
EmbeddedData embedded_data = EmbeddedData::FromBlob();
#define RUNTIME_STUB(Name) {Builtins::k##Name, WasmCode::k##Name},
#define RUNTIME_STUB(Name) Builtins::k##Name,
#define RUNTIME_STUB_TRAP(Name) RUNTIME_STUB(ThrowWasm##Name)
std::pair<Builtins::Name, WasmCode::RuntimeStubId> wasm_runtime_stubs[] = {
Builtins::Name wasm_runtime_stubs[WasmCode::kRuntimeStubCount] = {
WASM_RUNTIME_STUB_LIST(RUNTIME_STUB, RUNTIME_STUB_TRAP)};
#undef RUNTIME_STUB
#undef RUNTIME_STUB_TRAP
for (auto pair : wasm_runtime_stubs) {
CHECK(embedded_data.ContainsBuiltin(pair.first));
Address builtin = embedded_data.InstructionStartOfBuiltin(pair.first);
JumpTableAssembler::EmitRuntimeStubSlot(base, pair.second, builtin,
WasmCode::kNoFlushICache);
uint32_t slot_offset =
JumpTableAssembler::StubSlotIndexToOffset(pair.second);
runtime_stub_entries_[pair.second] = base + slot_offset;
Address builtin_address[WasmCode::kRuntimeStubCount];
for (int i = 0; i < WasmCode::kRuntimeStubCount; ++i) {
Builtins::Name builtin = wasm_runtime_stubs[i];
CHECK(embedded_data.ContainsBuiltin(builtin));
builtin_address[i] = embedded_data.InstructionStartOfBuiltin(builtin);
runtime_stub_entries_[i] =
base + JumpTableAssembler::StubSlotIndexToOffset(i);
}
FlushInstructionCache(jump_table->instructions().begin(),
jump_table->instructions().size());
JumpTableAssembler::GenerateRuntimeStubTable(base, builtin_address,
WasmCode::kRuntimeStubCount);
DCHECK_NULL(runtime_stub_table_);
runtime_stub_table_ = jump_table;
#else // V8_EMBEDDED_BUILTINS
......
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