Commit 6a852c41 authored by Jakob Gruber's avatar Jakob Gruber Committed by Commit Bot

Create a chokepoint for HandlerTable access on Code objects

Handler tables (and other inlined Code metadata) will have to move
outside the .text section. This CL creates Code::HandlerTableAddress()
as a single chokepoint for accessing the handler table of a Code
object.

Drive-by: Create a dedicated constructor for WasmCode handler tables.

Bug: v8:7777
Change-Id: I01c5157b732ba509b2c76f2744fde271c2ba1411
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2295605
Commit-Queue: Jakob Gruber <jgruber@chromium.org>
Commit-Queue: Clemens Backes <clemensb@chromium.org>
Auto-Submit: Jakob Gruber <jgruber@chromium.org>
Reviewed-by: 's avatarClemens Backes <clemensb@chromium.org>
Cr-Commit-Position: refs/heads/master@{#68835}
parent 0c8a5a86
......@@ -11,13 +11,18 @@
#include "src/codegen/assembler-inl.h"
#include "src/objects/code-inl.h"
#include "src/objects/objects-inl.h"
#include "src/wasm/wasm-code-manager.h"
namespace v8 {
namespace internal {
HandlerTable::HandlerTable(Code code)
: HandlerTable(code.InstructionStart() + code.handler_table_offset(),
code.handler_table_size(), kReturnAddressBasedEncoding) {}
: HandlerTable(code.HandlerTableAddress(), code.handler_table_size(),
kReturnAddressBasedEncoding) {}
HandlerTable::HandlerTable(const wasm::WasmCode* code)
: HandlerTable(code->handler_table(), code->handler_table_size(),
kReturnAddressBasedEncoding) {}
HandlerTable::HandlerTable(BytecodeArray bytecode_array)
: HandlerTable(bytecode_array.handler_table()) {}
......
......@@ -16,6 +16,10 @@ class Assembler;
class ByteArray;
class BytecodeArray;
namespace wasm {
class WasmCode;
}
// HandlerTable is a byte array containing entries for exception handlers in
// the code object it is associated with. The tables come in two flavors:
// 1) Based on ranges: Used for unoptimized code. Stored in a {ByteArray} that
......@@ -54,6 +58,7 @@ class V8_EXPORT_PRIVATE HandlerTable {
// Constructors for the various encodings.
explicit HandlerTable(Code code);
explicit HandlerTable(ByteArray byte_array);
explicit HandlerTable(const wasm::WasmCode* code);
explicit HandlerTable(BytecodeArray bytecode_array);
HandlerTable(Address handler_table, int handler_table_size,
EncodingMode encoding_mode);
......@@ -106,18 +111,18 @@ class V8_EXPORT_PRIVATE HandlerTable {
int GetReturnHandler(int index) const;
// Number of entries in the loaded handler table.
int number_of_entries_;
const int number_of_entries_;
#ifdef DEBUG
// The encoding mode of the table. Mostly useful for debugging to check that
// used accessors and constructors fit together.
EncodingMode mode_;
const EncodingMode mode_;
#endif
// 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_;
// Direct pointer into the encoded data. This pointer potentially points into
// objects on the GC heap (either {ByteArray} or {Code}) and could become
// stale during a collection. Hence we disallow any allocation.
const Address raw_encoded_data_;
DISALLOW_HEAP_ALLOCATION(no_gc_)
// Layout description for handler table based on ranges.
......
......@@ -1927,8 +1927,7 @@ int WasmFrame::LookupExceptionHandlerInTable() {
wasm::WasmCode* code =
isolate()->wasm_engine()->code_manager()->LookupCode(pc());
if (!code->IsAnonymous() && code->handler_table_size() > 0) {
HandlerTable table(code->handler_table(), code->handler_table_size(),
HandlerTable::kReturnAddressBasedEncoding);
HandlerTable table(code);
int pc_offset = static_cast<int>(pc() - code->instruction_start());
return table.LookupReturn(pc_offset);
}
......
......@@ -37,6 +37,10 @@ int Code::safepoint_table_size() const {
bool Code::has_safepoint_table() const { return safepoint_table_size() > 0; }
Address Code::HandlerTableAddress() const {
return InstructionStart() + handler_table_offset();
}
int Code::handler_table_size() const {
DCHECK_GE(constant_pool_offset() - handler_table_offset(), 0);
return constant_pool_offset() - handler_table_offset();
......
......@@ -157,6 +157,7 @@ class Code : public HeapObject {
// exception handler table starts.
inline int handler_table_offset() const;
inline void set_handler_table_offset(int offset);
Address HandlerTableAddress() const;
int handler_table_size() const;
bool has_handler_table() const;
......
......@@ -365,8 +365,7 @@ void WasmCode::Disassemble(const char* name, std::ostream& os,
os << "\n";
if (handler_table_size() > 0) {
HandlerTable table(handler_table(), handler_table_size(),
HandlerTable::kReturnAddressBasedEncoding);
HandlerTable table(this);
os << "Exception Handler Table (size = " << table.NumberOfReturnEntries()
<< "):\n";
table.HandlerTableReturnPrint(os);
......
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