Commit a39e7973 authored by Junliang Yan's avatar Junliang Yan Committed by Commit Bot

PPC/s390: Precalculate the exception handler address.

Port c1925690

Original Commit Message:

    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.

R=mtrofin@chromium.org, mstarzinger@chromium.org, bradnelson@chromium.org, titzer@chromium.org, joransiu@ca.ibm.com, bjaideep@ca.ibm.com, michael_dawson@ca.ibm.com

Change-Id: I139fddabef9f601b46dac9011db3ab8e01e3346d
Reviewed-on: https://chromium-review.googlesource.com/752483Reviewed-by: 's avatarMichael Starzinger <mstarzinger@chromium.org>
Reviewed-by: 's avatarMircea Trofin <mtrofin@chromium.org>
Commit-Queue: Junliang Yan <jyan@ca.ibm.com>
Cr-Commit-Position: refs/heads/master@{#49107}
parent 7d231e57
......@@ -1447,17 +1447,18 @@ 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(PendingHandlerEntrypoint, pending_handler_entrypoint) \
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(PendingHandlerConstantPool, pending_handler_constant_pool) \
C(PendingHandlerFP, pending_handler_fp) \
C(PendingHandlerSP, pending_handler_sp) \
C(ExternalCaughtException, external_caught_exception) \
C(JSEntrySP, js_entry_sp)
enum IsolateAddressId {
......
......@@ -1222,12 +1222,14 @@ Object* Isolate::UnwindAndFindHandler() {
Object* exception = pending_exception();
auto FoundHandler = [&](Context* context, Address instruction_start,
intptr_t handler_offset, Address handler_sp,
intptr_t handler_offset,
Address constant_pool_address, 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_entrypoint_ =
instruction_start + handler_offset;
thread_local_top()->pending_handler_constant_pool_ = constant_pool_address;
thread_local_top()->pending_handler_fp_ = handler_fp;
thread_local_top()->pending_handler_sp_ = handler_sp;
......@@ -1259,10 +1261,10 @@ Object* Isolate::UnwindAndFindHandler() {
// Gather information from the handler.
Code* code = frame->LookupCode();
return FoundHandler(nullptr, code->instruction_start(),
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)), code->constant_pool(),
handler->address() + StackHandlerConstants::kSize, 0);
}
case StackFrame::WASM_COMPILED: {
......@@ -1288,8 +1290,9 @@ Object* Isolate::UnwindAndFindHandler() {
trap_handler::SetThreadInWasm();
set_wasm_caught_exception(exception);
return FoundHandler(nullptr, frame->LookupCode()->instruction_start(),
offset, return_sp, frame->fp());
Code* code = frame->LookupCode();
return FoundHandler(nullptr, code->instruction_start(), offset,
code->constant_pool(), return_sp, frame->fp());
}
case StackFrame::OPTIMIZED: {
......@@ -1321,7 +1324,7 @@ Object* Isolate::UnwindAndFindHandler() {
}
return FoundHandler(nullptr, code->instruction_start(), offset,
return_sp, frame->fp());
code->constant_pool(), return_sp, frame->fp());
}
case StackFrame::STUB: {
......@@ -1345,7 +1348,7 @@ Object* Isolate::UnwindAndFindHandler() {
stack_slots * kPointerSize;
return FoundHandler(nullptr, code->instruction_start(), offset,
return_sp, frame->fp());
code->constant_pool(), return_sp, frame->fp());
}
case StackFrame::INTERPRETED: {
......@@ -1377,8 +1380,8 @@ Object* Isolate::UnwindAndFindHandler() {
Code* code =
builtins()->builtin(Builtins::kInterpreterEnterBytecodeDispatch);
return FoundHandler(context, code->instruction_start(), 0, return_sp,
frame->fp());
return FoundHandler(context, code->instruction_start(), 0,
code->constant_pool(), return_sp, frame->fp());
}
case StackFrame::BUILTIN:
......
......@@ -335,6 +335,7 @@ class ThreadLocalTop BASE_EMBEDDED {
// Communication channel between Isolate::FindHandler and the CEntryStub.
Context* pending_handler_context_;
Address pending_handler_entrypoint_;
Address pending_handler_constant_pool_;
Address pending_handler_fp_;
Address pending_handler_sp_;
......@@ -619,6 +620,7 @@ class Isolate {
THREAD_LOCAL_TOP_ADDRESS(Context*, pending_handler_context)
THREAD_LOCAL_TOP_ADDRESS(Address, pending_handler_entrypoint)
THREAD_LOCAL_TOP_ADDRESS(Address, pending_handler_constant_pool)
THREAD_LOCAL_TOP_ADDRESS(Address, pending_handler_fp)
THREAD_LOCAL_TOP_ADDRESS(Address, pending_handler_sp)
......
......@@ -470,10 +470,10 @@ 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_constant_pool_address(
IsolateAddressId::kPendingHandlerConstantPoolAddress, isolate());
ExternalReference pending_handler_fp_address(
IsolateAddressId::kPendingHandlerFPAddress, isolate());
ExternalReference pending_handler_sp_address(
......@@ -510,15 +510,13 @@ void CEntryStub::Generate(MacroAssembler* masm) {
// Compute the handler entry address and jump to it.
ConstantPoolUnavailableScope constant_pool_unavailable(masm);
__ mov(r4, Operand(pending_handler_code_address));
__ LoadP(r4, MemOperand(r4));
__ mov(r5, Operand(pending_handler_offset_address));
__ LoadP(r5, MemOperand(r5));
__ addi(r4, r4, Operand(Code::kHeaderSize - kHeapObjectTag)); // Code start
__ mov(ip, Operand(pending_handler_entrypoint_address));
__ LoadP(ip, MemOperand(ip));
if (FLAG_enable_embedded_constant_pool) {
__ LoadConstantPoolPointerRegisterFromCodeTargetAddress(r4);
__ mov(kConstantPoolRegister,
Operand(pending_handler_constant_pool_address));
__ LoadP(kConstantPoolRegister, MemOperand(kConstantPoolRegister));
}
__ add(ip, r4, r5);
__ Jump(ip);
}
......
......@@ -448,10 +448,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(
......@@ -487,13 +485,9 @@ void CEntryStub::Generate(MacroAssembler* masm) {
__ bind(&skip);
// Compute the handler entry address and jump to it.
__ mov(r3, Operand(pending_handler_code_address));
__ mov(r3, Operand(pending_handler_entrypoint_address));
__ LoadP(r3, MemOperand(r3));
__ mov(r4, Operand(pending_handler_offset_address));
__ LoadP(r4, MemOperand(r4));
__ AddP(r3, r3, Operand(Code::kHeaderSize - kHeapObjectTag)); // Code start
__ AddP(ip, r3, r4);
__ Jump(ip);
__ Jump(r3);
}
void JSEntryStub::Generate(MacroAssembler* masm) {
......
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