Commit b1f408fb authored by Mike Stanton's avatar Mike Stanton Committed by Commit Bot

[turbofan] Serialize exception handler table

... for building the TurboFan graph from bytecode concurrently.

Bug: v8:7790
Change-Id: Iceb838990355ee76e2dabb8a00ed5464d41764c2
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/1681120
Commit-Queue: Michael Stanton <mvstanton@chromium.org>
Reviewed-by: 's avatarMichael Starzinger <mstarzinger@chromium.org>
Reviewed-by: 's avatarMaya Lekova <mslekova@chromium.org>
Reviewed-by: 's avatarGeorg Neis <neis@chromium.org>
Cr-Commit-Position: refs/heads/master@{#62615}
parent 897b6ba0
...@@ -15,31 +15,41 @@ namespace internal { ...@@ -15,31 +15,41 @@ namespace internal {
HandlerTable::HandlerTable(Code code) HandlerTable::HandlerTable(Code code)
: HandlerTable(code.InstructionStart() + code.handler_table_offset(), : HandlerTable(code.InstructionStart() + code.handler_table_offset(),
code.handler_table_size()) {} code.handler_table_size(), kReturnAddressBasedEncoding) {}
HandlerTable::HandlerTable(BytecodeArray bytecode_array) HandlerTable::HandlerTable(BytecodeArray bytecode_array)
: HandlerTable(bytecode_array.handler_table()) {} : HandlerTable(bytecode_array.handler_table()) {}
HandlerTable::HandlerTable(ByteArray byte_array) HandlerTable::HandlerTable(ByteArray byte_array)
: number_of_entries_(byte_array.length() / kRangeEntrySize / : HandlerTable(reinterpret_cast<Address>(byte_array.GetDataStartAddress()),
sizeof(int32_t)), byte_array.length(), kRangeBasedEncoding) {}
#ifdef DEBUG
mode_(kRangeBasedEncoding),
#endif
raw_encoded_data_(
reinterpret_cast<Address>(byte_array.GetDataStartAddress())) {
DCHECK_EQ(0, byte_array.length() % (kRangeEntrySize * sizeof(int32_t)));
}
HandlerTable::HandlerTable(Address handler_table, int handler_table_size) HandlerTable::HandlerTable(Address handler_table, int handler_table_size,
: number_of_entries_(handler_table_size / kReturnEntrySize / EncodingMode encoding_mode)
: number_of_entries_(handler_table_size / EntrySizeFromMode(encoding_mode) /
sizeof(int32_t)), sizeof(int32_t)),
#ifdef DEBUG #ifdef DEBUG
mode_(kReturnAddressBasedEncoding), mode_(encoding_mode),
#endif #endif
raw_encoded_data_(handler_table) { raw_encoded_data_(handler_table) {
// Check padding.
static_assert(4 < kReturnEntrySize * sizeof(int32_t), "allowed padding"); static_assert(4 < kReturnEntrySize * sizeof(int32_t), "allowed padding");
DCHECK_GE(4, handler_table_size % (kReturnEntrySize * sizeof(int32_t))); // For return address encoding, maximum padding is 4; otherwise, there should
// be no padding.
DCHECK_GE(kReturnAddressBasedEncoding == encoding_mode ? 4 : 0,
handler_table_size %
(EntrySizeFromMode(encoding_mode) * sizeof(int32_t)));
}
// static
int HandlerTable::EntrySizeFromMode(EncodingMode mode) {
switch (mode) {
case kReturnAddressBasedEncoding:
return kReturnEntrySize;
case kRangeBasedEncoding:
return kRangeEntrySize;
}
UNREACHABLE();
} }
int HandlerTable::GetRangeStart(int index) const { int HandlerTable::GetRangeStart(int index) const {
......
...@@ -45,11 +45,14 @@ class V8_EXPORT_PRIVATE HandlerTable { ...@@ -45,11 +45,14 @@ class V8_EXPORT_PRIVATE HandlerTable {
// async/await handling in the debugger can take place. // async/await handling in the debugger can take place.
}; };
enum EncodingMode { kRangeBasedEncoding, kReturnAddressBasedEncoding };
// Constructors for the various encodings. // Constructors for the various encodings.
explicit HandlerTable(Code code); explicit HandlerTable(Code code);
explicit HandlerTable(ByteArray byte_array); explicit HandlerTable(ByteArray byte_array);
explicit HandlerTable(BytecodeArray bytecode_array); explicit HandlerTable(BytecodeArray bytecode_array);
explicit HandlerTable(Address handler_table, int handler_table_size); HandlerTable(Address handler_table, int handler_table_size,
EncodingMode encoding_mode);
// Getters for handler table based on ranges. // Getters for handler table based on ranges.
int GetRangeStart(int index) const; int GetRangeStart(int index) const;
...@@ -88,11 +91,12 @@ class V8_EXPORT_PRIVATE HandlerTable { ...@@ -88,11 +91,12 @@ class V8_EXPORT_PRIVATE HandlerTable {
#endif #endif
private: private:
enum EncodingMode { kRangeBasedEncoding, kReturnAddressBasedEncoding };
// Getters for handler table based on ranges. // Getters for handler table based on ranges.
CatchPrediction GetRangePrediction(int index) const; CatchPrediction GetRangePrediction(int index) const;
// Gets entry size based on mode.
static int EntrySizeFromMode(EncodingMode mode);
// Getters for handler table based on return addresses. // Getters for handler table based on return addresses.
int GetReturnOffset(int index) const; int GetReturnOffset(int index) const;
int GetReturnHandler(int index) const; int GetReturnHandler(int index) const;
......
...@@ -3833,7 +3833,10 @@ Node** BytecodeGraphBuilder::EnsureInputBufferSize(int size) { ...@@ -3833,7 +3833,10 @@ Node** BytecodeGraphBuilder::EnsureInputBufferSize(int size) {
} }
void BytecodeGraphBuilder::ExitThenEnterExceptionHandlers(int current_offset) { void BytecodeGraphBuilder::ExitThenEnterExceptionHandlers(int current_offset) {
HandlerTable table(*(bytecode_array().object())); DisallowHeapAllocation no_allocation;
HandlerTable table(bytecode_array().handler_table_address(),
bytecode_array().handler_table_size(),
HandlerTable::kRangeBasedEncoding);
// Potentially exit exception handlers. // Potentially exit exception handlers.
while (!exception_handlers_.empty()) { while (!exception_handlers_.empty()) {
......
...@@ -621,6 +621,10 @@ class BytecodeArrayRef : public FixedArrayBaseRef { ...@@ -621,6 +621,10 @@ class BytecodeArrayRef : public FixedArrayBaseRef {
bool IsConstantAtIndexSmi(int index) const; bool IsConstantAtIndexSmi(int index) const;
Smi GetConstantAtIndexAsSmi(int index) const; Smi GetConstantAtIndexAsSmi(int index) const;
// Exception handler table.
Address handler_table_address() const;
int handler_table_size() const;
bool IsSerializedForCompilation() const; bool IsSerializedForCompilation() const;
void SerializeForCompilation(); void SerializeForCompilation();
}; };
......
...@@ -1366,6 +1366,13 @@ class BytecodeArrayData : public FixedArrayBaseData { ...@@ -1366,6 +1366,13 @@ class BytecodeArrayData : public FixedArrayBaseData {
source_positions_.push_back(source_position_table->get(i)); source_positions_.push_back(source_position_table->get(i));
} }
Handle<ByteArray> handlers(bytecode_array->handler_table(),
broker->isolate());
handler_table_.reserve(handlers->length());
for (int i = 0; i < handlers->length(); i++) {
handler_table_.push_back(handlers->get(i));
}
is_serialized_for_compilation_ = true; is_serialized_for_compilation_ = true;
} }
...@@ -1375,6 +1382,16 @@ class BytecodeArrayData : public FixedArrayBaseData { ...@@ -1375,6 +1382,16 @@ class BytecodeArrayData : public FixedArrayBaseData {
size_t source_positions_size() const { return source_positions_.size(); } size_t source_positions_size() const { return source_positions_.size(); }
Address handler_table_address() const {
CHECK(is_serialized_for_compilation_);
return reinterpret_cast<Address>(handler_table_.data());
}
int handler_table_size() const {
CHECK(is_serialized_for_compilation_);
return static_cast<int>(handler_table_.size());
}
BytecodeArrayData(JSHeapBroker* broker, ObjectData** storage, BytecodeArrayData(JSHeapBroker* broker, ObjectData** storage,
Handle<BytecodeArray> object) Handle<BytecodeArray> object)
: FixedArrayBaseData(broker, storage, object), : FixedArrayBaseData(broker, storage, object),
...@@ -1384,6 +1401,7 @@ class BytecodeArrayData : public FixedArrayBaseData { ...@@ -1384,6 +1401,7 @@ class BytecodeArrayData : public FixedArrayBaseData {
object->incoming_new_target_or_generator_register()), object->incoming_new_target_or_generator_register()),
bytecodes_(broker->zone()), bytecodes_(broker->zone()),
source_positions_(broker->zone()), source_positions_(broker->zone()),
handler_table_(broker->zone()),
constant_pool_(broker->zone()) {} constant_pool_(broker->zone()) {}
private: private:
...@@ -1394,6 +1412,7 @@ class BytecodeArrayData : public FixedArrayBaseData { ...@@ -1394,6 +1412,7 @@ class BytecodeArrayData : public FixedArrayBaseData {
bool is_serialized_for_compilation_ = false; bool is_serialized_for_compilation_ = false;
ZoneVector<uint8_t> bytecodes_; ZoneVector<uint8_t> bytecodes_;
ZoneVector<uint8_t> source_positions_; ZoneVector<uint8_t> source_positions_;
ZoneVector<uint8_t> handler_table_;
ZoneVector<ObjectData*> constant_pool_; ZoneVector<ObjectData*> constant_pool_;
}; };
...@@ -2786,6 +2805,23 @@ int BytecodeArrayRef::source_positions_size() const { ...@@ -2786,6 +2805,23 @@ int BytecodeArrayRef::source_positions_size() const {
return static_cast<int>(data()->AsBytecodeArray()->source_positions_size()); return static_cast<int>(data()->AsBytecodeArray()->source_positions_size());
} }
Address BytecodeArrayRef::handler_table_address() const {
if (broker()->mode() == JSHeapBroker::kDisabled) {
AllowHandleDereference allow_handle_dereference;
return reinterpret_cast<Address>(
object()->handler_table().GetDataStartAddress());
}
return data()->AsBytecodeArray()->handler_table_address();
}
int BytecodeArrayRef::handler_table_size() const {
if (broker()->mode() == JSHeapBroker::kDisabled) {
AllowHandleDereference allow_handle_dereference;
return object()->handler_table().length();
}
return data()->AsBytecodeArray()->handler_table_size();
}
#define IF_BROKER_DISABLED_ACCESS_HANDLE_C(holder, name) \ #define IF_BROKER_DISABLED_ACCESS_HANDLE_C(holder, name) \
if (broker()->mode() == JSHeapBroker::kDisabled) { \ if (broker()->mode() == JSHeapBroker::kDisabled) { \
AllowHandleAllocation handle_allocation; \ AllowHandleAllocation handle_allocation; \
......
...@@ -1938,7 +1938,8 @@ int WasmCompiledFrame::LookupExceptionHandlerInTable(int* stack_slots) { ...@@ -1938,7 +1938,8 @@ int WasmCompiledFrame::LookupExceptionHandlerInTable(int* stack_slots) {
wasm::WasmCode* code = wasm::WasmCode* code =
isolate()->wasm_engine()->code_manager()->LookupCode(pc()); isolate()->wasm_engine()->code_manager()->LookupCode(pc());
if (!code->IsAnonymous() && code->handler_table_size() > 0) { if (!code->IsAnonymous() && code->handler_table_size() > 0) {
HandlerTable table(code->handler_table(), code->handler_table_size()); HandlerTable table(code->handler_table(), code->handler_table_size(),
HandlerTable::kReturnAddressBasedEncoding);
int pc_offset = static_cast<int>(pc() - code->instruction_start()); int pc_offset = static_cast<int>(pc() - code->instruction_start());
*stack_slots = static_cast<int>(code->stack_slots()); *stack_slots = static_cast<int>(code->stack_slots());
return table.LookupReturn(pc_offset); return table.LookupReturn(pc_offset);
......
...@@ -286,7 +286,8 @@ void WasmCode::Disassemble(const char* name, std::ostream& os, ...@@ -286,7 +286,8 @@ void WasmCode::Disassemble(const char* name, std::ostream& os,
os << "\n"; os << "\n";
if (handler_table_size() > 0) { if (handler_table_size() > 0) {
HandlerTable table(handler_table(), handler_table_size()); HandlerTable table(handler_table(), handler_table_size(),
HandlerTable::kReturnAddressBasedEncoding);
os << "Exception Handler Table (size = " << table.NumberOfReturnEntries() os << "Exception Handler Table (size = " << table.NumberOfReturnEntries()
<< "):\n"; << "):\n";
table.HandlerTableReturnPrint(os); 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