Commit badaf79f authored by mstarzinger's avatar mstarzinger Committed by Commit bot

[interpreter] Rename HandlerTable::depth field.

This makes the field in question more generic by renaming it from the
previous "depth" to "data". Pure refactoring, no function change.

R=rmcilroy@chromium.org,yangguo@chromium.org

Review URL: https://codereview.chromium.org/1670983003

Cr-Commit-Position: refs/heads/master@{#33779}
parent a0f6d5ed
......@@ -1677,9 +1677,7 @@ void BytecodeGraphBuilder::EnterAndExitExceptionHandlers(int current_offset) {
if (current_offset < next_start) break; // Not yet covered by range.
int next_end = table->GetRangeEnd(current_exception_handler_);
int next_handler = table->GetRangeHandler(current_exception_handler_);
// TODO(mstarzinger): We are hijacking the "depth" field in the exception
// handler table to hold the context register. We should rename the field.
int context_register = table->GetRangeDepth(current_exception_handler_);
int context_register = table->GetRangeData(current_exception_handler_);
exception_handlers_.push(
{next_start, next_end, next_handler, context_register});
current_exception_handler_++;
......
......@@ -822,8 +822,7 @@ void Debug::PrepareStepOnThrow() {
JavaScriptFrameIterator it(isolate_);
while (!it.done()) {
JavaScriptFrame* frame = it.frame();
int stack_slots = 0; // The computed stack slot count is not used.
if (frame->LookupExceptionHandlerInTable(&stack_slots, NULL) > 0) break;
if (frame->LookupExceptionHandlerInTable(nullptr, nullptr) > 0) break;
it.Advance();
}
......
......@@ -808,14 +808,13 @@ void JavaScriptFrame::Summarize(List<FrameSummary>* functions) {
functions->Add(summary);
}
int JavaScriptFrame::LookupExceptionHandlerInTable(
int* stack_slots, HandlerTable::CatchPrediction* prediction) {
int* stack_depth, HandlerTable::CatchPrediction* prediction) {
Code* code = LookupCode();
DCHECK(!code->is_optimized_code());
HandlerTable* table = HandlerTable::cast(code->handler_table());
int pc_offset = static_cast<int>(pc() - code->entry());
return table->LookupRange(pc_offset, stack_slots, prediction);
return table->LookupRange(pc_offset, stack_depth, prediction);
}
......@@ -1042,7 +1041,7 @@ int OptimizedFrame::LookupExceptionHandlerInTable(
DCHECK(code->is_optimized_code());
HandlerTable* table = HandlerTable::cast(code->handler_table());
int pc_offset = static_cast<int>(pc() - code->entry());
*stack_slots = code->stack_slots();
if (stack_slots) *stack_slots = code->stack_slots();
return table->LookupReturn(pc_offset, prediction);
}
......@@ -1135,13 +1134,12 @@ Object* OptimizedFrame::StackSlotAt(int index) const {
return Memory::Object_at(fp() + StackSlotOffsetRelativeToFp(index));
}
int InterpretedFrame::LookupExceptionHandlerInTable(
int* stack_slots, HandlerTable::CatchPrediction* prediction) {
int* context_register, HandlerTable::CatchPrediction* prediction) {
BytecodeArray* bytecode = function()->shared()->bytecode_array();
HandlerTable* table = HandlerTable::cast(bytecode->handler_table());
int pc_offset = GetBytecodeOffset() + 1; // Point after current bytecode.
return table->LookupRange(pc_offset, stack_slots, prediction);
return table->LookupRange(pc_offset, context_register, prediction);
}
......
......@@ -624,9 +624,12 @@ class JavaScriptFrame: public StandardFrame {
virtual void Summarize(List<FrameSummary>* frames);
// Lookup exception handler for current {pc}, returns -1 if none found. Also
// returns the expected number of stack slots at the handler site.
// returns data associated with the handler site specific to the frame type:
// - JavaScriptFrame : Data is the stack depth at entry of the try-block.
// - OptimizedFrame : Data is the stack slot count of the entire frame.
// - InterpretedFrame: Data is the register index holding the context.
virtual int LookupExceptionHandlerInTable(
int* stack_slots, HandlerTable::CatchPrediction* prediction);
int* data, HandlerTable::CatchPrediction* prediction);
// Architecture-specific register description.
static Register fp_register();
......@@ -698,10 +701,9 @@ class OptimizedFrame : public JavaScriptFrame {
void Summarize(List<FrameSummary>* frames) override;
// Lookup exception handler for current {pc}, returns -1 if none found. Also
// returns the expected number of stack slots at the handler site.
// Lookup exception handler for current {pc}, returns -1 if none found.
int LookupExceptionHandlerInTable(
int* stack_slots, HandlerTable::CatchPrediction* prediction) override;
int* data, HandlerTable::CatchPrediction* prediction) override;
DeoptimizationInputData* GetDeoptimizationData(int* deopt_index) const;
......@@ -721,10 +723,9 @@ class InterpretedFrame : public JavaScriptFrame {
public:
Type type() const override { return INTERPRETED; }
// Lookup exception handler for current {pc}, returns -1 if none found. Also
// returns the expected number of stack slots at the handler site.
// Lookup exception handler for current {pc}, returns -1 if none found.
int LookupExceptionHandlerInTable(
int* stack_slots, HandlerTable::CatchPrediction* prediction) override;
int* data, HandlerTable::CatchPrediction* prediction) override;
// Returns the current offset into the bytecode stream.
int GetBytecodeOffset() const;
......
......@@ -127,7 +127,7 @@ void FullCodeGenerator::PopulateHandlerTable(Handle<Code> code) {
table->SetRangeStart(i, handler_table_[i].range_start);
table->SetRangeEnd(i, handler_table_[i].range_end);
table->SetRangeHandler(i, handler_table_[i].handler_offset, prediction);
table->SetRangeDepth(i, handler_table_[i].stack_depth);
table->SetRangeData(i, handler_table_[i].stack_depth);
}
code->set_handler_table(*table);
}
......
......@@ -27,7 +27,7 @@ Handle<HandlerTable> HandlerTableBuilder::ToHandlerTable() {
table->SetRangeStart(i, static_cast<int>(entry.offset_start));
table->SetRangeEnd(i, static_cast<int>(entry.offset_end));
table->SetRangeHandler(i, static_cast<int>(entry.offset_target), pred);
table->SetRangeDepth(i, entry.context.index());
table->SetRangeData(i, entry.context.index());
}
return table;
}
......
......@@ -1199,10 +1199,8 @@ Isolate::CatchType Isolate::PredictExceptionCatcher() {
// For JavaScript frames we perform a lookup in the handler table.
if (frame->is_java_script()) {
JavaScriptFrame* js_frame = static_cast<JavaScriptFrame*>(frame);
int stack_slots = 0; // The computed stack slot count is not used.
HandlerTable::CatchPrediction prediction;
if (js_frame->LookupExceptionHandlerInTable(&stack_slots, &prediction) >
0) {
if (js_frame->LookupExceptionHandlerInTable(nullptr, &prediction) > 0) {
// We are conservative with our prediction: try-finally is considered
// to always rethrow, to meet the expectation of the debugger.
if (prediction == HandlerTable::CAUGHT) return CAUGHT_BY_JAVASCRIPT;
......@@ -1612,8 +1610,7 @@ Handle<Object> Isolate::GetPromiseOnStackOnThrow() {
if (PredictExceptionCatcher() != CAUGHT_BY_JAVASCRIPT) return undefined;
for (JavaScriptFrameIterator it(this); !it.done(); it.Advance()) {
JavaScriptFrame* frame = it.frame();
int stack_slots = 0; // The computed stack slot count is not used.
if (frame->LookupExceptionHandlerInTable(&stack_slots, NULL) > 0) {
if (frame->LookupExceptionHandlerInTable(nullptr, nullptr) > 0) {
// Throwing inside a Promise only leads to a reject if not caught by an
// inner try-catch or try-finally.
if (frame->function() == *promise_function) {
......
......@@ -3415,8 +3415,8 @@ int HandlerTable::GetRangeHandler(int index) const {
Smi::cast(get(index * kRangeEntrySize + kRangeHandlerIndex))->value());
}
int HandlerTable::GetRangeDepth(int index) const {
return Smi::cast(get(index * kRangeEntrySize + kRangeDepthIndex))->value();
int HandlerTable::GetRangeData(int index) const {
return Smi::cast(get(index * kRangeEntrySize + kRangeDataIndex))->value();
}
void HandlerTable::SetRangeStart(int index, int value) {
......@@ -3436,9 +3436,8 @@ void HandlerTable::SetRangeHandler(int index, int offset,
set(index * kRangeEntrySize + kRangeHandlerIndex, Smi::FromInt(value));
}
void HandlerTable::SetRangeDepth(int index, int value) {
set(index * kRangeEntrySize + kRangeDepthIndex, Smi::FromInt(value));
void HandlerTable::SetRangeData(int index, int value) {
set(index * kRangeEntrySize + kRangeDataIndex, Smi::FromInt(value));
}
......
......@@ -10977,8 +10977,7 @@ Handle<LiteralsArray> LiteralsArray::New(Isolate* isolate,
return casted_literals;
}
int HandlerTable::LookupRange(int pc_offset, int* stack_depth_out,
int HandlerTable::LookupRange(int pc_offset, int* data_out,
CatchPrediction* prediction_out) {
int innermost_handler = -1;
#ifdef DEBUG
......@@ -10993,7 +10992,7 @@ int HandlerTable::LookupRange(int pc_offset, int* stack_depth_out,
int handler_field = Smi::cast(get(i + kRangeHandlerIndex))->value();
int handler_offset = HandlerOffsetField::decode(handler_field);
CatchPrediction prediction = HandlerPredictionField::decode(handler_field);
int stack_depth = Smi::cast(get(i + kRangeDepthIndex))->value();
int handler_data = Smi::cast(get(i + kRangeDataIndex))->value();
if (pc_offset > start_offset && pc_offset <= end_offset) {
DCHECK_GE(start_offset, innermost_start);
DCHECK_LT(end_offset, innermost_end);
......@@ -11002,7 +11001,7 @@ int HandlerTable::LookupRange(int pc_offset, int* stack_depth_out,
innermost_start = start_offset;
innermost_end = end_offset;
#endif
*stack_depth_out = stack_depth;
if (data_out) *data_out = handler_data;
if (prediction_out) *prediction_out = prediction;
}
}
......@@ -14831,10 +14830,10 @@ void HandlerTable::HandlerTableRangePrint(std::ostream& os) {
int handler_field = Smi::cast(get(i + kRangeHandlerIndex))->value();
int handler_offset = HandlerOffsetField::decode(handler_field);
CatchPrediction prediction = HandlerPredictionField::decode(handler_field);
int depth = Smi::cast(get(i + kRangeDepthIndex))->value();
int data = Smi::cast(get(i + kRangeDataIndex))->value();
os << " (" << std::setw(4) << pc_start << "," << std::setw(4) << pc_end
<< ") -> " << std::setw(4) << handler_offset
<< " (prediction=" << prediction << ", depth=" << depth << ")\n";
<< " (prediction=" << prediction << ", data=" << data << ")\n";
}
}
......
......@@ -4746,7 +4746,7 @@ class LiteralsArray : public FixedArray {
// 1) Based on ranges: Used for unoptimized code. Contains one entry per
// exception handler and a range representing the try-block covered by that
// handler. Layout looks as follows:
// [ range-start , range-end , handler-offset , stack-depth ]
// [ range-start , range-end , handler-offset , handler-data ]
// 2) Based on return addresses: Used for turbofanned code. Contains one entry
// per call-site that could throw an exception. Layout looks as follows:
// [ return-address-offset , handler-offset ]
......@@ -4761,20 +4761,20 @@ class HandlerTable : public FixedArray {
inline int GetRangeStart(int index) const;
inline int GetRangeEnd(int index) const;
inline int GetRangeHandler(int index) const;
inline int GetRangeDepth(int index) const;
inline int GetRangeData(int index) const;
// Setters for handler table based on ranges.
inline void SetRangeStart(int index, int value);
inline void SetRangeEnd(int index, int value);
inline void SetRangeHandler(int index, int offset, CatchPrediction pred);
inline void SetRangeDepth(int index, int value);
inline void SetRangeData(int index, int value);
// Setters for handler table based on return addresses.
inline void SetReturnOffset(int index, int value);
inline void SetReturnHandler(int index, int offset, CatchPrediction pred);
// Lookup handler in a table based on ranges.
int LookupRange(int pc_offset, int* stack_depth, CatchPrediction* prediction);
int LookupRange(int pc_offset, int* data, CatchPrediction* prediction);
// Lookup handler in a table based on return addresses.
int LookupReturn(int pc_offset, CatchPrediction* prediction);
......@@ -4798,7 +4798,7 @@ class HandlerTable : public FixedArray {
static const int kRangeStartIndex = 0;
static const int kRangeEndIndex = 1;
static const int kRangeHandlerIndex = 2;
static const int kRangeDepthIndex = 3;
static const int kRangeDataIndex = 3;
static const int kRangeEntrySize = 4;
// Layout description for handler table based on return addresses.
......
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