Commit c1925690 authored by Mircea Trofin's avatar Mircea Trofin Committed by Commit Bot

Precalculate the exception handler address.

We expect no GC between the call to UnwindAndFindHandler and
the call to that handler. We can precalculate the handler entrypoint
and then let the CEntryStub just load and call that address.

The main motivation for this change is the wasm on the native heap
work, and making the CEntryStub able to work with non- Code* values.

Bug: v8:6876
Change-Id: I660f29619edc315afbb537ef3df018865fab7ba4
Reviewed-on: https://chromium-review.googlesource.com/744723
Commit-Queue: Mircea Trofin <mtrofin@chromium.org>
Reviewed-by: 's avatarBrad Nelson <bradnelson@chromium.org>
Reviewed-by: 's avatarMichael Starzinger <mstarzinger@chromium.org>
Cr-Commit-Position: refs/heads/master@{#49084}
parent 49c62872
......@@ -384,10 +384,8 @@ void CEntryStub::Generate(MacroAssembler* masm) {
ExternalReference pending_handler_context_address(
IsolateAddressId::kPendingHandlerContextAddress, isolate());
ExternalReference pending_handler_code_address(
IsolateAddressId::kPendingHandlerCodeAddress, isolate());
ExternalReference pending_handler_offset_address(
IsolateAddressId::kPendingHandlerOffsetAddress, isolate());
ExternalReference pending_handler_entrypoint_address(
IsolateAddressId::kPendingHandlerEntrypointAddress, isolate());
ExternalReference pending_handler_fp_address(
IsolateAddressId::kPendingHandlerFPAddress, isolate());
ExternalReference pending_handler_sp_address(
......@@ -421,12 +419,9 @@ void CEntryStub::Generate(MacroAssembler* masm) {
// Compute the handler entry address and jump to it.
ConstantPoolUnavailableScope constant_pool_unavailable(masm);
__ mov(r1, Operand(pending_handler_code_address));
__ mov(r1, Operand(pending_handler_entrypoint_address));
__ ldr(r1, MemOperand(r1));
__ mov(r2, Operand(pending_handler_offset_address));
__ ldr(r2, MemOperand(r2));
__ add(r1, r1, Operand(Code::kHeaderSize - kHeapObjectTag)); // Code start
__ add(pc, r1, r2);
__ Jump(r1);
}
......
......@@ -479,10 +479,8 @@ void CEntryStub::Generate(MacroAssembler* masm) {
ExternalReference pending_handler_context_address(
IsolateAddressId::kPendingHandlerContextAddress, isolate());
ExternalReference pending_handler_code_address(
IsolateAddressId::kPendingHandlerCodeAddress, isolate());
ExternalReference pending_handler_offset_address(
IsolateAddressId::kPendingHandlerOffsetAddress, isolate());
ExternalReference pending_handler_entrypoint_address(
IsolateAddressId::kPendingHandlerEntrypointAddress, isolate());
ExternalReference pending_handler_fp_address(
IsolateAddressId::kPendingHandlerFPAddress, isolate());
ExternalReference pending_handler_sp_address(
......@@ -524,12 +522,8 @@ void CEntryStub::Generate(MacroAssembler* masm) {
__ Bind(&not_js_frame);
// Compute the handler entry address and jump to it.
__ Mov(x10, Operand(pending_handler_code_address));
__ Mov(x10, Operand(pending_handler_entrypoint_address));
__ Ldr(x10, MemOperand(x10));
__ Mov(x11, Operand(pending_handler_offset_address));
__ Ldr(x11, MemOperand(x11));
__ Add(x10, x10, Code::kHeaderSize - kHeapObjectTag);
__ Add(x10, x10, x11);
__ Br(x10);
}
......
......@@ -1447,18 +1447,17 @@ inline std::ostream& operator<<(std::ostream& os,
enum class ConcurrencyMode { kNotConcurrent, kConcurrent };
#define FOR_EACH_ISOLATE_ADDRESS_NAME(C) \
C(Handler, handler) \
C(CEntryFP, c_entry_fp) \
C(CFunction, c_function) \
C(Context, context) \
C(PendingException, pending_exception) \
C(PendingHandlerContext, pending_handler_context) \
C(PendingHandlerCode, pending_handler_code) \
C(PendingHandlerOffset, pending_handler_offset) \
C(PendingHandlerFP, pending_handler_fp) \
C(PendingHandlerSP, pending_handler_sp) \
C(ExternalCaughtException, external_caught_exception) \
#define FOR_EACH_ISOLATE_ADDRESS_NAME(C) \
C(Handler, handler) \
C(CEntryFP, c_entry_fp) \
C(CFunction, c_function) \
C(Context, context) \
C(PendingException, pending_exception) \
C(PendingHandlerContext, pending_handler_context) \
C(PendingHandlerEntrypoint, pending_handler_entrypoint) \
C(PendingHandlerFP, pending_handler_fp) \
C(PendingHandlerSP, pending_handler_sp) \
C(ExternalCaughtException, external_caught_exception) \
C(JSEntrySP, js_entry_sp)
enum IsolateAddressId {
......
......@@ -431,10 +431,8 @@ void CEntryStub::Generate(MacroAssembler* masm) {
ExternalReference pending_handler_context_address(
IsolateAddressId::kPendingHandlerContextAddress, isolate());
ExternalReference pending_handler_code_address(
IsolateAddressId::kPendingHandlerCodeAddress, isolate());
ExternalReference pending_handler_offset_address(
IsolateAddressId::kPendingHandlerOffsetAddress, isolate());
ExternalReference pending_handler_entrypoint_address(
IsolateAddressId::kPendingHandlerEntrypointAddress, isolate());
ExternalReference pending_handler_fp_address(
IsolateAddressId::kPendingHandlerFPAddress, isolate());
ExternalReference pending_handler_sp_address(
......@@ -468,9 +466,7 @@ void CEntryStub::Generate(MacroAssembler* masm) {
__ bind(&skip);
// Compute the handler entry address and jump to it.
__ mov(edi, Operand::StaticVariable(pending_handler_code_address));
__ mov(edx, Operand::StaticVariable(pending_handler_offset_address));
__ lea(edi, FieldOperand(edi, edx, times_1, Code::kHeaderSize));
__ mov(edi, Operand::StaticVariable(pending_handler_entrypoint_address));
__ jmp(edi);
}
......
......@@ -1221,12 +1221,13 @@ Object* Isolate::ReThrow(Object* exception) {
Object* Isolate::UnwindAndFindHandler() {
Object* exception = pending_exception();
auto FoundHandler = [&](Context* context, Code* code, intptr_t offset,
Address handler_sp, Address handler_fp) {
auto FoundHandler = [&](Context* context, Address instruction_start,
intptr_t handler_offset, Address handler_sp,
Address handler_fp) {
// Store information to be consumed by the CEntryStub.
thread_local_top()->pending_handler_context_ = context;
thread_local_top()->pending_handler_code_ = code;
thread_local_top()->pending_handler_offset_ = offset;
thread_local_top()->pending_handler_entrypoint_ =
instruction_start + handler_offset;
thread_local_top()->pending_handler_fp_ = handler_fp;
thread_local_top()->pending_handler_sp_ = handler_sp;
......@@ -1258,9 +1259,10 @@ Object* Isolate::UnwindAndFindHandler() {
// Gather information from the handler.
Code* code = frame->LookupCode();
return FoundHandler(
nullptr, code, Smi::ToInt(code->handler_table()->get(0)),
handler->address() + StackHandlerConstants::kSize, 0);
return FoundHandler(nullptr, code->instruction_start(),
Smi::ToInt(code->handler_table()->get(0)),
handler->address() + StackHandlerConstants::kSize,
0);
}
case StackFrame::WASM_COMPILED: {
......@@ -1286,8 +1288,8 @@ Object* Isolate::UnwindAndFindHandler() {
trap_handler::SetThreadInWasm();
set_wasm_caught_exception(exception);
return FoundHandler(nullptr, frame->LookupCode(), offset, return_sp,
frame->fp());
return FoundHandler(nullptr, frame->LookupCode()->instruction_start(),
offset, return_sp, frame->fp());
}
case StackFrame::OPTIMIZED: {
......@@ -1318,7 +1320,8 @@ Object* Isolate::UnwindAndFindHandler() {
set_deoptimizer_lazy_throw(true);
}
return FoundHandler(nullptr, code, offset, return_sp, frame->fp());
return FoundHandler(nullptr, code->instruction_start(), offset,
return_sp, frame->fp());
}
case StackFrame::STUB: {
......@@ -1341,7 +1344,8 @@ Object* Isolate::UnwindAndFindHandler() {
StandardFrameConstants::kFixedFrameSizeAboveFp -
stack_slots * kPointerSize;
return FoundHandler(nullptr, code, offset, return_sp, frame->fp());
return FoundHandler(nullptr, code->instruction_start(), offset,
return_sp, frame->fp());
}
case StackFrame::INTERPRETED: {
......@@ -1373,7 +1377,8 @@ Object* Isolate::UnwindAndFindHandler() {
Code* code =
builtins()->builtin(Builtins::kInterpreterEnterBytecodeDispatch);
return FoundHandler(context, code, 0, return_sp, frame->fp());
return FoundHandler(context, code->instruction_start(), 0, return_sp,
frame->fp());
}
case StackFrame::BUILTIN:
......
......@@ -334,8 +334,7 @@ class ThreadLocalTop BASE_EMBEDDED {
// Communication channel between Isolate::FindHandler and the CEntryStub.
Context* pending_handler_context_;
Code* pending_handler_code_;
intptr_t pending_handler_offset_;
Address pending_handler_entrypoint_;
Address pending_handler_fp_;
Address pending_handler_sp_;
......@@ -619,8 +618,7 @@ class Isolate {
inline bool has_pending_exception();
THREAD_LOCAL_TOP_ADDRESS(Context*, pending_handler_context)
THREAD_LOCAL_TOP_ADDRESS(Code*, pending_handler_code)
THREAD_LOCAL_TOP_ADDRESS(intptr_t, pending_handler_offset)
THREAD_LOCAL_TOP_ADDRESS(Address, pending_handler_entrypoint)
THREAD_LOCAL_TOP_ADDRESS(Address, pending_handler_fp)
THREAD_LOCAL_TOP_ADDRESS(Address, pending_handler_sp)
......
......@@ -493,10 +493,8 @@ void CEntryStub::Generate(MacroAssembler* masm) {
ExternalReference pending_handler_context_address(
IsolateAddressId::kPendingHandlerContextAddress, isolate());
ExternalReference pending_handler_code_address(
IsolateAddressId::kPendingHandlerCodeAddress, isolate());
ExternalReference pending_handler_offset_address(
IsolateAddressId::kPendingHandlerOffsetAddress, isolate());
ExternalReference pending_handler_entrypoint_address(
IsolateAddressId::kPendingHandlerEntrypointAddress, isolate());
ExternalReference pending_handler_fp_address(
IsolateAddressId::kPendingHandlerFPAddress, isolate());
ExternalReference pending_handler_sp_address(
......@@ -531,12 +529,9 @@ void CEntryStub::Generate(MacroAssembler* masm) {
__ bind(&zero);
// Compute the handler entry address and jump to it.
__ li(a1, Operand(pending_handler_code_address));
__ lw(a1, MemOperand(a1));
__ li(a2, Operand(pending_handler_offset_address));
__ lw(a2, MemOperand(a2));
__ Addu(t9, a1, a2);
__ Jump(t9, Code::kHeaderSize - kHeapObjectTag);
__ li(t9, Operand(pending_handler_entrypoint_address));
__ lw(t9, MemOperand(t9));
__ Jump(t9);
}
......
......@@ -492,10 +492,8 @@ void CEntryStub::Generate(MacroAssembler* masm) {
ExternalReference pending_handler_context_address(
IsolateAddressId::kPendingHandlerContextAddress, isolate());
ExternalReference pending_handler_code_address(
IsolateAddressId::kPendingHandlerCodeAddress, isolate());
ExternalReference pending_handler_offset_address(
IsolateAddressId::kPendingHandlerOffsetAddress, isolate());
ExternalReference pending_handler_entrypoint_address(
IsolateAddressId::kPendingHandlerEntrypointAddress, isolate());
ExternalReference pending_handler_fp_address(
IsolateAddressId::kPendingHandlerFPAddress, isolate());
ExternalReference pending_handler_sp_address(
......@@ -530,12 +528,8 @@ void CEntryStub::Generate(MacroAssembler* masm) {
__ bind(&zero);
// Compute the handler entry address and jump to it.
__ li(a1, Operand(pending_handler_code_address));
__ Ld(a1, MemOperand(a1));
__ li(a2, Operand(pending_handler_offset_address));
__ Ld(a2, MemOperand(a2));
__ Daddu(a1, a1, Operand(Code::kHeaderSize - kHeapObjectTag));
__ Daddu(t9, a1, a2);
__ li(t9, Operand(pending_handler_entrypoint_address));
__ Ld(t9, MemOperand(t9));
__ Jump(t9);
}
......
......@@ -417,10 +417,8 @@ void CEntryStub::Generate(MacroAssembler* masm) {
ExternalReference pending_handler_context_address(
IsolateAddressId::kPendingHandlerContextAddress, isolate());
ExternalReference pending_handler_code_address(
IsolateAddressId::kPendingHandlerCodeAddress, isolate());
ExternalReference pending_handler_offset_address(
IsolateAddressId::kPendingHandlerOffsetAddress, isolate());
ExternalReference pending_handler_entrypoint_address(
IsolateAddressId::kPendingHandlerEntrypointAddress, isolate());
ExternalReference pending_handler_fp_address(
IsolateAddressId::kPendingHandlerFPAddress, isolate());
ExternalReference pending_handler_sp_address(
......@@ -438,7 +436,6 @@ void CEntryStub::Generate(MacroAssembler* masm) {
__ PrepareCallCFunction(3);
__ CallCFunction(find_handler, 3);
}
// Retrieve the handler context, SP and FP.
__ movp(rsi, masm->ExternalOperand(pending_handler_context_address));
__ movp(rsp, masm->ExternalOperand(pending_handler_sp_address));
......@@ -453,9 +450,7 @@ void CEntryStub::Generate(MacroAssembler* masm) {
__ bind(&skip);
// Compute the handler entry address and jump to it.
__ movp(rdi, masm->ExternalOperand(pending_handler_code_address));
__ movp(rdx, masm->ExternalOperand(pending_handler_offset_address));
__ leap(rdi, FieldOperand(rdi, rdx, times_1, Code::kHeaderSize));
__ movp(rdi, masm->ExternalOperand(pending_handler_entrypoint_address));
__ jmp(rdi);
}
......
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