[runtime] Simplify handler table lookup semantics.
The range-based exception handler table is by now only used for bytecode arrays. The semantics of the interpreter are that bytecode offsets point to the beginning of the currently executing bytecode instruction. Uses hence need to compensate for lookups based on a "retrun address". This change removes the need for such off-by-one compensations by changing lookup semantics to be based on "current instruction" offsets. R=jarin@chromium.org Review-Url: https://codereview.chromium.org/2534893002 Cr-Commit-Position: refs/heads/master@{#41339}
This commit is contained in:
parent
4e7571a5a9
commit
7a82d8e9e4
@ -642,8 +642,8 @@ int LookupCatchHandler(TranslatedFrame* translated_frame, int* data_out) {
|
||||
JSFunction* function =
|
||||
JSFunction::cast(translated_frame->begin()->GetRawValue());
|
||||
BytecodeArray* bytecode = function->shared()->bytecode_array();
|
||||
return bytecode->LookupRangeInHandlerTable(bytecode_offset, data_out,
|
||||
nullptr);
|
||||
HandlerTable* table = HandlerTable::cast(bytecode->handler_table());
|
||||
return table->LookupRange(bytecode_offset, data_out, nullptr);
|
||||
}
|
||||
default:
|
||||
break;
|
||||
|
@ -1357,8 +1357,8 @@ int InterpretedFrame::position() const {
|
||||
int InterpretedFrame::LookupExceptionHandlerInTable(
|
||||
int* context_register, HandlerTable::CatchPrediction* prediction) {
|
||||
BytecodeArray* bytecode = function()->shared()->bytecode_array();
|
||||
return bytecode->LookupRangeInHandlerTable(GetBytecodeOffset(),
|
||||
context_register, prediction);
|
||||
HandlerTable* table = HandlerTable::cast(bytecode->handler_table());
|
||||
return table->LookupRange(GetBytecodeOffset(), context_register, prediction);
|
||||
}
|
||||
|
||||
int InterpretedFrame::GetBytecodeOffset() const {
|
||||
|
@ -1344,8 +1344,9 @@ HandlerTable::CatchPrediction PredictException(JavaScriptFrame* frame) {
|
||||
// Must have been constructed from a bytecode array.
|
||||
CHECK_EQ(AbstractCode::INTERPRETED_FUNCTION, code->kind());
|
||||
int code_offset = summary.code_offset();
|
||||
int index = code->GetBytecodeArray()->LookupRangeInHandlerTable(
|
||||
code_offset, nullptr, &prediction);
|
||||
BytecodeArray* bytecode = code->GetBytecodeArray();
|
||||
HandlerTable* table = HandlerTable::cast(bytecode->handler_table());
|
||||
int index = table->LookupRange(code_offset, nullptr, &prediction);
|
||||
if (index <= 0) continue;
|
||||
if (prediction == HandlerTable::UNCAUGHT) continue;
|
||||
return prediction;
|
||||
|
@ -10657,7 +10657,7 @@ int HandlerTable::LookupRange(int pc_offset, int* data_out,
|
||||
int handler_offset = HandlerOffsetField::decode(handler_field);
|
||||
CatchPrediction prediction = HandlerPredictionField::decode(handler_field);
|
||||
int handler_data = Smi::cast(get(i + kRangeDataIndex))->value();
|
||||
if (pc_offset > start_offset && pc_offset <= end_offset) {
|
||||
if (pc_offset >= start_offset && pc_offset < end_offset) {
|
||||
DCHECK_GE(start_offset, innermost_start);
|
||||
DCHECK_LT(end_offset, innermost_end);
|
||||
innermost_handler = handler_offset;
|
||||
@ -15177,13 +15177,6 @@ void BytecodeArray::CopyBytecodesTo(BytecodeArray* to) {
|
||||
from->length());
|
||||
}
|
||||
|
||||
int BytecodeArray::LookupRangeInHandlerTable(
|
||||
int code_offset, int* data, HandlerTable::CatchPrediction* prediction) {
|
||||
HandlerTable* table = HandlerTable::cast(handler_table());
|
||||
code_offset++; // Point after current bytecode.
|
||||
return table->LookupRange(code_offset, data, prediction);
|
||||
}
|
||||
|
||||
// static
|
||||
void JSArray::Initialize(Handle<JSArray> array, int capacity, int length) {
|
||||
DCHECK(capacity >= 0);
|
||||
|
@ -4817,7 +4817,9 @@ class HandlerTable : public FixedArray {
|
||||
inline void SetReturnOffset(int index, int value);
|
||||
inline void SetReturnHandler(int index, int offset);
|
||||
|
||||
// Lookup handler in a table based on ranges.
|
||||
// Lookup handler in a table based on ranges. The {pc_offset} is an offset to
|
||||
// the start of the potentially throwing instruction (using return addresses
|
||||
// for this value would be invalid).
|
||||
int LookupRange(int pc_offset, int* data, CatchPrediction* prediction);
|
||||
|
||||
// Lookup handler in a table based on return addresses.
|
||||
@ -5002,9 +5004,6 @@ class BytecodeArray : public FixedArrayBase {
|
||||
|
||||
void CopyBytecodesTo(BytecodeArray* to);
|
||||
|
||||
int LookupRangeInHandlerTable(int code_offset, int* data,
|
||||
HandlerTable::CatchPrediction* prediction);
|
||||
|
||||
// Layout description.
|
||||
static const int kConstantPoolOffset = FixedArrayBase::kHeaderSize;
|
||||
static const int kHandlerTableOffset = kConstantPoolOffset + kPointerSize;
|
||||
|
Loading…
Reference in New Issue
Block a user