Simplify encoding of handler table by removing size.
R=jgruber@chromium.org BUG=v8:8758 Change-Id: Iba62ca0f9010cd68b47966ad8d04c1a4149efe70 Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/1571415 Reviewed-by: Jakob Gruber <jgruber@chromium.org> Commit-Queue: Michael Starzinger <mstarzinger@chromium.org> Cr-Commit-Position: refs/heads/master@{#60918}
This commit is contained in:
parent
2c5f11fba2
commit
86f877de51
@ -110,9 +110,7 @@ Code BuildWithMacroAssembler(Isolate* isolate, int32_t builtin_index,
|
||||
DCHECK_EQ(Builtins::KindOf(Builtins::kJSConstructEntry), Builtins::ASM);
|
||||
DCHECK_EQ(Builtins::KindOf(Builtins::kJSRunMicrotasksEntry), Builtins::ASM);
|
||||
if (Builtins::IsJSEntryVariant(builtin_index)) {
|
||||
static constexpr int kJSEntryHandlerCount = 1;
|
||||
handler_table_offset =
|
||||
HandlerTable::EmitReturnTableStart(&masm, kJSEntryHandlerCount);
|
||||
handler_table_offset = HandlerTable::EmitReturnTableStart(&masm);
|
||||
HandlerTable::EmitReturnEntry(
|
||||
&masm, 0, isolate->builtins()->js_entry_handler_offset());
|
||||
}
|
||||
|
@ -305,8 +305,7 @@ void CodeGenerator::AssembleCode() {
|
||||
|
||||
// Emit the exception handler table.
|
||||
if (!handlers_.empty()) {
|
||||
handler_table_offset_ = HandlerTable::EmitReturnTableStart(
|
||||
tasm(), static_cast<int>(handlers_.size()));
|
||||
handler_table_offset_ = HandlerTable::EmitReturnTableStart(tasm());
|
||||
for (size_t i = 0; i < handlers_.size(); ++i) {
|
||||
HandlerTable::EmitReturnEntry(tasm(), handlers_[i].pc_offset,
|
||||
handlers_[i].handler->pos());
|
||||
|
@ -1892,8 +1892,8 @@ int WasmCompiledFrame::LookupExceptionHandlerInTable(int* stack_slots) {
|
||||
DCHECK_NOT_NULL(stack_slots);
|
||||
wasm::WasmCode* code =
|
||||
isolate()->wasm_engine()->code_manager()->LookupCode(pc());
|
||||
if (!code->IsAnonymous() && code->handler_table_offset() > 0) {
|
||||
HandlerTable table(code->instruction_start(), code->handler_table_offset());
|
||||
if (!code->IsAnonymous() && code->handler_table_size() > 0) {
|
||||
HandlerTable table(code->handler_table(), code->handler_table_size());
|
||||
int pc_offset = static_cast<int>(pc() - code->instruction_start());
|
||||
*stack_slots = static_cast<int>(code->stack_slots());
|
||||
return table.LookupReturn(pc_offset);
|
||||
|
@ -14,9 +14,8 @@ namespace v8 {
|
||||
namespace internal {
|
||||
|
||||
HandlerTable::HandlerTable(Code code)
|
||||
: HandlerTable(code->InstructionStart(), code->has_handler_table()
|
||||
? code->handler_table_offset()
|
||||
: 0) {}
|
||||
: HandlerTable(code->InstructionStart() + code->handler_table_offset(),
|
||||
code->handler_table_size()) {}
|
||||
|
||||
HandlerTable::HandlerTable(BytecodeArray bytecode_array)
|
||||
: HandlerTable(bytecode_array->handler_table()) {}
|
||||
@ -29,24 +28,17 @@ HandlerTable::HandlerTable(ByteArray byte_array)
|
||||
#endif
|
||||
raw_encoded_data_(
|
||||
reinterpret_cast<Address>(byte_array->GetDataStartAddress())) {
|
||||
DCHECK_EQ(0, byte_array->length() % (kRangeEntrySize * sizeof(int32_t)));
|
||||
}
|
||||
|
||||
// TODO(jgruber,v8:8758): This constructor should eventually take the handler
|
||||
// table size in addition to the offset. That way the {HandlerTable} class
|
||||
// remains independent of how the offset/size is encoded in the various code
|
||||
// objects. This could even allow us to change the encoding to no longer expect
|
||||
// the "number of entries" in the beginning.
|
||||
HandlerTable::HandlerTable(Address instruction_start,
|
||||
size_t handler_table_offset)
|
||||
: number_of_entries_(0),
|
||||
HandlerTable::HandlerTable(Address handler_table, int handler_table_size)
|
||||
: number_of_entries_(handler_table_size / kReturnEntrySize /
|
||||
sizeof(int32_t)),
|
||||
#ifdef DEBUG
|
||||
mode_(kReturnAddressBasedEncoding),
|
||||
#endif
|
||||
raw_encoded_data_(instruction_start + handler_table_offset) {
|
||||
if (handler_table_offset > 0) {
|
||||
number_of_entries_ = Memory<int32_t>(raw_encoded_data_);
|
||||
raw_encoded_data_ += sizeof(int32_t);
|
||||
}
|
||||
raw_encoded_data_(handler_table) {
|
||||
DCHECK_EQ(0, handler_table_size % (kReturnEntrySize * sizeof(int32_t)));
|
||||
}
|
||||
|
||||
int HandlerTable::GetRangeStart(int index) const {
|
||||
@ -131,11 +123,10 @@ int HandlerTable::LengthForRange(int entries) {
|
||||
}
|
||||
|
||||
// static
|
||||
int HandlerTable::EmitReturnTableStart(Assembler* masm, int entries) {
|
||||
int HandlerTable::EmitReturnTableStart(Assembler* masm) {
|
||||
masm->DataAlign(sizeof(int32_t)); // Make sure entries are aligned.
|
||||
masm->RecordComment(";;; Exception handler table.");
|
||||
int table_start = masm->pc_offset();
|
||||
masm->dd(entries);
|
||||
return table_start;
|
||||
}
|
||||
|
||||
|
@ -49,7 +49,7 @@ class V8_EXPORT_PRIVATE HandlerTable {
|
||||
explicit HandlerTable(Code code);
|
||||
explicit HandlerTable(ByteArray byte_array);
|
||||
explicit HandlerTable(BytecodeArray bytecode_array);
|
||||
explicit HandlerTable(Address instruction_start, size_t handler_table_offset);
|
||||
explicit HandlerTable(Address handler_table, int handler_table_size);
|
||||
|
||||
// Getters for handler table based on ranges.
|
||||
int GetRangeStart(int index) const;
|
||||
@ -67,7 +67,7 @@ class V8_EXPORT_PRIVATE HandlerTable {
|
||||
static int LengthForRange(int entries);
|
||||
|
||||
// Emitters for handler table based on return addresses.
|
||||
static int EmitReturnTableStart(Assembler* masm, int entries);
|
||||
static int EmitReturnTableStart(Assembler* masm);
|
||||
static void EmitReturnEntry(Assembler* masm, int offset, int handler);
|
||||
|
||||
// Lookup handler in a table based on ranges. The {pc_offset} is an offset to
|
||||
@ -106,7 +106,7 @@ class V8_EXPORT_PRIVATE HandlerTable {
|
||||
EncodingMode mode_;
|
||||
#endif
|
||||
|
||||
// Direct pointer into the encoded data. This pointer points into object on
|
||||
// Direct pointer into the encoded data. This pointer points into objects on
|
||||
// the GC heap (either {ByteArray} or {Code}) and hence would become stale
|
||||
// during a collection. Hence we disallow any allocation.
|
||||
Address raw_encoded_data_;
|
||||
|
@ -1741,7 +1741,7 @@ Object Isolate::UnwindAndFindHandler() {
|
||||
// It is safe to skip Wasm runtime stubs as none of them contain local
|
||||
// exception handlers.
|
||||
CHECK_EQ(wasm::WasmCode::kRuntimeStub, wasm_code->kind());
|
||||
CHECK_EQ(0, wasm_code->handler_table_offset());
|
||||
CHECK_EQ(0, wasm_code->handler_table_size());
|
||||
break;
|
||||
}
|
||||
Code code = stub_frame->LookupCode();
|
||||
|
@ -108,6 +108,15 @@ Address WasmCode::constant_pool() const {
|
||||
return kNullAddress;
|
||||
}
|
||||
|
||||
Address WasmCode::handler_table() const {
|
||||
return instruction_start() + handler_table_offset_;
|
||||
}
|
||||
|
||||
uint32_t WasmCode::handler_table_size() const {
|
||||
DCHECK_GE(constant_pool_offset_, handler_table_offset_);
|
||||
return static_cast<uint32_t>(constant_pool_offset_ - handler_table_offset_);
|
||||
}
|
||||
|
||||
Address WasmCode::code_comments() const {
|
||||
return instruction_start() + code_comments_offset_;
|
||||
}
|
||||
@ -274,7 +283,7 @@ void WasmCode::Disassemble(const char* name, std::ostream& os,
|
||||
if (safepoint_table_offset_ && safepoint_table_offset_ < instruction_size) {
|
||||
instruction_size = safepoint_table_offset_;
|
||||
}
|
||||
if (handler_table_offset_ && handler_table_offset_ < instruction_size) {
|
||||
if (handler_table_offset_ < instruction_size) {
|
||||
instruction_size = handler_table_offset_;
|
||||
}
|
||||
DCHECK_LT(0, instruction_size);
|
||||
@ -284,8 +293,8 @@ void WasmCode::Disassemble(const char* name, std::ostream& os,
|
||||
CodeReference(this), current_pc);
|
||||
os << "\n";
|
||||
|
||||
if (handler_table_offset_ > 0) {
|
||||
HandlerTable table(instruction_start(), handler_table_offset_);
|
||||
if (handler_table_size() > 0) {
|
||||
HandlerTable table(handler_table(), handler_table_size());
|
||||
os << "Exception Handler Table (size = " << table.NumberOfReturnEntries()
|
||||
<< "):\n";
|
||||
table.HandlerTableReturnPrint(os);
|
||||
@ -592,8 +601,8 @@ WasmCode* NativeModule::AddAndPublishAnonymousCode(Handle<Code> code,
|
||||
// mean 'empty'.
|
||||
const size_t safepoint_table_offset = static_cast<size_t>(
|
||||
code->has_safepoint_table() ? code->safepoint_table_offset() : 0);
|
||||
const size_t handler_table_offset = static_cast<size_t>(
|
||||
code->has_handler_table() ? code->handler_table_offset() : 0);
|
||||
const size_t handler_table_offset =
|
||||
static_cast<size_t>(code->handler_table_offset());
|
||||
const size_t constant_pool_offset =
|
||||
static_cast<size_t>(code->constant_pool_offset());
|
||||
const size_t code_comments_offset =
|
||||
@ -681,8 +690,8 @@ std::unique_ptr<WasmCode> NativeModule::AddCodeWithCodeSpace(
|
||||
// 'empty'.
|
||||
const size_t safepoint_table_offset = static_cast<size_t>(
|
||||
desc.safepoint_table_size == 0 ? 0 : desc.safepoint_table_offset);
|
||||
const size_t handler_table_offset = static_cast<size_t>(
|
||||
desc.handler_table_size == 0 ? 0 : desc.handler_table_offset);
|
||||
const size_t handler_table_offset =
|
||||
static_cast<size_t>(desc.handler_table_offset);
|
||||
const size_t constant_pool_offset =
|
||||
static_cast<size_t>(desc.constant_pool_offset);
|
||||
const size_t code_comments_offset =
|
||||
@ -868,7 +877,7 @@ WasmCode* NativeModule::CreateEmptyJumpTable(uint32_t jump_table_size) {
|
||||
0, // stack_slots
|
||||
0, // tagged_parameter_slots
|
||||
0, // safepoint_table_offset
|
||||
0, // handler_table_offset
|
||||
jump_table_size, // handler_table_offset
|
||||
jump_table_size, // constant_pool_offset
|
||||
jump_table_size, // code_comments_offset
|
||||
jump_table_size, // unpadded_binary_size
|
||||
|
@ -114,6 +114,8 @@ class V8_EXPORT_PRIVATE WasmCode final {
|
||||
NativeModule* native_module() const { return native_module_; }
|
||||
ExecutionTier tier() const { return tier_; }
|
||||
Address constant_pool() const;
|
||||
Address handler_table() const;
|
||||
uint32_t handler_table_size() const;
|
||||
Address code_comments() const;
|
||||
uint32_t code_comments_size() const;
|
||||
size_t constant_pool_offset() const { return constant_pool_offset_; }
|
||||
|
Loading…
Reference in New Issue
Block a user