Commit ce3f0187 authored by Michael Starzinger's avatar Michael Starzinger Committed by Commit Bot

[execution] Simplify handler table lookup interface.

This removes the output parameter returning the number of stack slot for
the frame from {LookupExceptionHandlerInTable}. This is a remnant from
when V8 had dynamically sized frames (aka. full-codegen), which is no
longer the case. The frame size can easily be computed independent of
the exception handler found during the lookup.

R=jkummerow@chromium.org
BUG=v8:9810

Change-Id: I0c7e04c75d7e24f2731e22370833005c17d0297a
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/1847155Reviewed-by: 's avatarJakob Kummerow <jkummerow@chromium.org>
Commit-Queue: Michael Starzinger <mstarzinger@chromium.org>
Cr-Commit-Position: refs/heads/master@{#64159}
parent 90d161ff
...@@ -1071,13 +1071,12 @@ Address StubFrame::GetCallerStackPointer() const { ...@@ -1071,13 +1071,12 @@ Address StubFrame::GetCallerStackPointer() const {
return fp() + ExitFrameConstants::kCallerSPOffset; return fp() + ExitFrameConstants::kCallerSPOffset;
} }
int StubFrame::LookupExceptionHandlerInTable(int* stack_slots) { int StubFrame::LookupExceptionHandlerInTable() {
Code code = LookupCode(); Code code = LookupCode();
DCHECK(code.is_turbofanned()); DCHECK(code.is_turbofanned());
DCHECK_EQ(code.kind(), Code::BUILTIN); DCHECK_EQ(code.kind(), Code::BUILTIN);
HandlerTable table(code); HandlerTable table(code);
int pc_offset = static_cast<int>(pc() - code.InstructionStart()); int pc_offset = static_cast<int>(pc() - code.InstructionStart());
*stack_slots = code.stack_slots();
return table.LookupReturn(pc_offset); return table.LookupReturn(pc_offset);
} }
...@@ -1620,7 +1619,7 @@ void OptimizedFrame::Summarize(std::vector<FrameSummary>* frames) const { ...@@ -1620,7 +1619,7 @@ void OptimizedFrame::Summarize(std::vector<FrameSummary>* frames) const {
} }
int OptimizedFrame::LookupExceptionHandlerInTable( int OptimizedFrame::LookupExceptionHandlerInTable(
int* stack_slots, HandlerTable::CatchPrediction* prediction) { int* data, HandlerTable::CatchPrediction* prediction) {
// We cannot perform exception prediction on optimized code. Instead, we need // We cannot perform exception prediction on optimized code. Instead, we need
// to use FrameSummary to find the corresponding code offset in unoptimized // to use FrameSummary to find the corresponding code offset in unoptimized
// code to perform prediction there. // code to perform prediction there.
...@@ -1628,7 +1627,7 @@ int OptimizedFrame::LookupExceptionHandlerInTable( ...@@ -1628,7 +1627,7 @@ int OptimizedFrame::LookupExceptionHandlerInTable(
Code code = LookupCode(); Code code = LookupCode();
HandlerTable table(code); HandlerTable table(code);
int pc_offset = static_cast<int>(pc() - code.InstructionStart()); int pc_offset = static_cast<int>(pc() - code.InstructionStart());
if (stack_slots) *stack_slots = code.stack_slots(); DCHECK_NULL(data); // Data is not used and will not return a value.
// When the return pc has been replaced by a trampoline there won't be // When the return pc has been replaced by a trampoline there won't be
// a handler for this trampoline. Thus we need to use the return pc that // a handler for this trampoline. Thus we need to use the return pc that
...@@ -1943,15 +1942,13 @@ bool WasmCompiledFrame::at_to_number_conversion() const { ...@@ -1943,15 +1942,13 @@ bool WasmCompiledFrame::at_to_number_conversion() const {
return !!pos; return !!pos;
} }
int WasmCompiledFrame::LookupExceptionHandlerInTable(int* stack_slots) { int WasmCompiledFrame::LookupExceptionHandlerInTable() {
DCHECK_NOT_NULL(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); 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());
return table.LookupReturn(pc_offset); return table.LookupReturn(pc_offset);
} }
return -1; return -1;
......
...@@ -738,7 +738,7 @@ class JavaScriptFrame : public StandardFrame { ...@@ -738,7 +738,7 @@ class JavaScriptFrame : public StandardFrame {
// Lookup exception handler for current {pc}, returns -1 if none found. Also // Lookup exception handler for current {pc}, returns -1 if none found. Also
// returns data associated with the handler site specific to the frame type: // returns data associated with the handler site specific to the frame type:
// - OptimizedFrame : Data is the stack slot count of the entire frame. // - OptimizedFrame : Data is not used and will not return a value.
// - InterpretedFrame: Data is the register index holding the context. // - InterpretedFrame: Data is the register index holding the context.
virtual int LookupExceptionHandlerInTable( virtual int LookupExceptionHandlerInTable(
int* data, HandlerTable::CatchPrediction* prediction); int* data, HandlerTable::CatchPrediction* prediction);
...@@ -788,10 +788,8 @@ class StubFrame : public StandardFrame { ...@@ -788,10 +788,8 @@ class StubFrame : public StandardFrame {
Code unchecked_code() const override; Code unchecked_code() const override;
// Lookup exception handler for current {pc}, returns -1 if none found. Only // Lookup exception handler for current {pc}, returns -1 if none found. Only
// TurboFan stub frames are supported. Also returns data associated with the // TurboFan stub frames are supported.
// handler site: int LookupExceptionHandlerInTable();
// - TurboFan stub: Data is the stack slot count of the entire frame.
int LookupExceptionHandlerInTable(int* data);
protected: protected:
inline explicit StubFrame(StackFrameIteratorBase* iterator); inline explicit StubFrame(StackFrameIteratorBase* iterator);
...@@ -943,9 +941,8 @@ class WasmCompiledFrame : public StandardFrame { ...@@ -943,9 +941,8 @@ class WasmCompiledFrame : public StandardFrame {
void Print(StringStream* accumulator, PrintMode mode, void Print(StringStream* accumulator, PrintMode mode,
int index) const override; int index) const override;
// Lookup exception handler for current {pc}, returns -1 if none found. Also // Lookup exception handler for current {pc}, returns -1 if none found.
// returns the stack slot count of the entire frame. int LookupExceptionHandlerInTable();
int LookupExceptionHandlerInTable(int* data);
// Determine the code for the frame. // Determine the code for the frame.
Code unchecked_code() const override; Code unchecked_code() const override;
......
...@@ -1699,22 +1699,20 @@ Object Isolate::UnwindAndFindHandler() { ...@@ -1699,22 +1699,20 @@ Object Isolate::UnwindAndFindHandler() {
// currently being executed. // currently being executed.
wasm::WasmCodeRefScope code_ref_scope; wasm::WasmCodeRefScope code_ref_scope;
WasmCompiledFrame* wasm_frame = static_cast<WasmCompiledFrame*>(frame); WasmCompiledFrame* wasm_frame = static_cast<WasmCompiledFrame*>(frame);
int stack_slots = 0; // Will contain stack slot count of frame. wasm::WasmCode* wasm_code =
int offset = wasm_frame->LookupExceptionHandlerInTable(&stack_slots); wasm_engine()->code_manager()->LookupCode(frame->pc());
int offset = wasm_frame->LookupExceptionHandlerInTable();
if (offset < 0) break; if (offset < 0) break;
// Compute the stack pointer from the frame pointer. This ensures that // Compute the stack pointer from the frame pointer. This ensures that
// argument slots on the stack are dropped as returning would. // argument slots on the stack are dropped as returning would.
Address return_sp = frame->fp() + Address return_sp = frame->fp() +
StandardFrameConstants::kFixedFrameSizeAboveFp - StandardFrameConstants::kFixedFrameSizeAboveFp -
stack_slots * kSystemPointerSize; wasm_code->stack_slots() * kSystemPointerSize;
// This is going to be handled by Wasm, so we need to set the TLS flag // This is going to be handled by Wasm, so we need to set the TLS flag
// again. It was cleared above assuming the frame would be unwound. // again. It was cleared above assuming the frame would be unwound.
trap_handler::SetThreadInWasm(); trap_handler::SetThreadInWasm();
// Gather information from the frame.
wasm::WasmCode* wasm_code =
wasm_engine()->code_manager()->LookupCode(frame->pc());
return FoundHandler(Context(), wasm_code->instruction_start(), offset, return FoundHandler(Context(), wasm_code->instruction_start(), offset,
wasm_code->constant_pool(), return_sp, frame->fp()); wasm_code->constant_pool(), return_sp, frame->fp());
} }
...@@ -1733,18 +1731,14 @@ Object Isolate::UnwindAndFindHandler() { ...@@ -1733,18 +1731,14 @@ Object Isolate::UnwindAndFindHandler() {
// For optimized frames we perform a lookup in the handler table. // For optimized frames we perform a lookup in the handler table.
if (!catchable_by_js) break; if (!catchable_by_js) break;
OptimizedFrame* js_frame = static_cast<OptimizedFrame*>(frame); OptimizedFrame* js_frame = static_cast<OptimizedFrame*>(frame);
int stack_slots = 0; // Will contain stack slot count of frame. Code code = frame->LookupCode();
int offset = int offset = js_frame->LookupExceptionHandlerInTable(nullptr, nullptr);
js_frame->LookupExceptionHandlerInTable(&stack_slots, nullptr);
if (offset < 0) break; if (offset < 0) break;
// Compute the stack pointer from the frame pointer. This ensures // Compute the stack pointer from the frame pointer. This ensures
// that argument slots on the stack are dropped as returning would. // that argument slots on the stack are dropped as returning would.
Address return_sp = frame->fp() + Address return_sp = frame->fp() +
StandardFrameConstants::kFixedFrameSizeAboveFp - StandardFrameConstants::kFixedFrameSizeAboveFp -
stack_slots * kSystemPointerSize; code.stack_slots() * kSystemPointerSize;
// Gather information from the frame.
Code code = frame->LookupCode();
// TODO(bmeurer): Turbofanned BUILTIN frames appear as OPTIMIZED, // TODO(bmeurer): Turbofanned BUILTIN frames appear as OPTIMIZED,
// but do not have a code kind of OPTIMIZED_FUNCTION. // but do not have a code kind of OPTIMIZED_FUNCTION.
...@@ -1775,15 +1769,14 @@ Object Isolate::UnwindAndFindHandler() { ...@@ -1775,15 +1769,14 @@ Object Isolate::UnwindAndFindHandler() {
break; break;
} }
int stack_slots = 0; // Will contain stack slot count of frame. int offset = stub_frame->LookupExceptionHandlerInTable();
int offset = stub_frame->LookupExceptionHandlerInTable(&stack_slots);
if (offset < 0) break; if (offset < 0) break;
// Compute the stack pointer from the frame pointer. This ensures // Compute the stack pointer from the frame pointer. This ensures
// that argument slots on the stack are dropped as returning would. // that argument slots on the stack are dropped as returning would.
Address return_sp = frame->fp() + Address return_sp = frame->fp() +
StandardFrameConstants::kFixedFrameSizeAboveFp - StandardFrameConstants::kFixedFrameSizeAboveFp -
stack_slots * kSystemPointerSize; code.stack_slots() * kSystemPointerSize;
return FoundHandler(Context(), code.InstructionStart(), offset, return FoundHandler(Context(), code.InstructionStart(), offset,
code.constant_pool(), return_sp, frame->fp()); code.constant_pool(), return_sp, frame->fp());
......
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