Skip to content

Commit

Permalink
8318609: Upcall stubs should be smaller
Browse files Browse the repository at this point in the history
Co-authored-by: Jorn Vernee <jvernee@openjdk.org>
Reviewed-by: rrich, jvernee
  • Loading branch information
TheRealMDoerr and JornVernee committed Oct 24, 2023
1 parent e6f23a9 commit a644670
Show file tree
Hide file tree
Showing 18 changed files with 129 additions and 112 deletions.
18 changes: 18 additions & 0 deletions src/hotspot/cpu/aarch64/stubGenerator_aarch64.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
#include "oops/objArrayKlass.hpp"
#include "oops/oop.inline.hpp"
#include "prims/methodHandles.hpp"
#include "prims/upcallLinker.hpp"
#include "runtime/atomic.hpp"
#include "runtime/continuation.hpp"
#include "runtime/continuationEntry.inline.hpp"
Expand Down Expand Up @@ -7326,6 +7327,21 @@ class StubGenerator: public StubCodeGenerator {

#endif // INCLUDE_JFR

// exception handler for upcall stubs
address generate_upcall_stub_exception_handler() {
StubCodeMark mark(this, "StubRoutines", "upcall stub exception handler");
address start = __ pc();

// Native caller has no idea how to handle exceptions,
// so we just crash here. Up to callee to catch exceptions.
__ verify_oop(r0);
__ movptr(rscratch1, CAST_FROM_FN_PTR(uint64_t, UpcallLinker::handle_uncaught_exception));
__ blr(rscratch1);
__ should_not_reach_here();

return start;
}

// Continuation point for throwing of implicit exceptions that are
// not handled in the current activation. Fabricates an exception
// oop and initiates normal exception dispatching in this
Expand Down Expand Up @@ -8377,6 +8393,8 @@ class StubGenerator: public StubCodeGenerator {

#endif // LINUX

StubRoutines::_upcall_stub_exception_handler = generate_upcall_stub_exception_handler();

StubRoutines::aarch64::set_completed(); // Inidicate that arraycopy and zero_blocks stubs are generated
}

Expand Down
19 changes: 2 additions & 17 deletions src/hotspot/cpu/aarch64/upcallLinker_aarch64.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,7 @@ address UpcallLinker::make_upcall_stub(jobject receiver, Method* entry,

__ block_comment("{ on_entry");
__ lea(c_rarg0, Address(sp, frame_data_offset));
__ movptr(c_rarg1, (intptr_t)receiver);
__ movptr(rscratch1, CAST_FROM_FN_PTR(uint64_t, UpcallLinker::on_entry));
__ blr(rscratch1);
__ mov(rthread, r0);
Expand All @@ -233,9 +234,7 @@ address UpcallLinker::make_upcall_stub(jobject receiver, Method* entry,
__ block_comment("} argument shuffle");

__ block_comment("{ receiver ");
__ movptr(shuffle_reg, (intptr_t)receiver);
__ resolve_jobject(shuffle_reg, rscratch1, rscratch2);
__ mov(j_rarg0, shuffle_reg);
__ get_vm_result(j_rarg0, rthread);
__ block_comment("} receiver ");

__ mov_metadata(rmethod, entry);
Expand Down Expand Up @@ -306,19 +305,6 @@ address UpcallLinker::make_upcall_stub(jobject receiver, Method* entry,

//////////////////////////////////////////////////////////////////////////////

__ block_comment("{ exception handler");

intptr_t exception_handler_offset = __ pc() - start;

// Native caller has no idea how to handle exceptions,
// so we just crash here. Up to callee to catch exceptions.
__ verify_oop(r0);
__ movptr(rscratch1, CAST_FROM_FN_PTR(uint64_t, UpcallLinker::handle_uncaught_exception));
__ blr(rscratch1);
__ should_not_reach_here();

__ block_comment("} exception handler");

_masm->flush();

#ifndef PRODUCT
Expand All @@ -334,7 +320,6 @@ address UpcallLinker::make_upcall_stub(jobject receiver, Method* entry,
UpcallStub* blob
= UpcallStub::create(name,
&buffer,
exception_handler_offset,
receiver,
in_ByteSize(frame_data_offset));

Expand Down
17 changes: 17 additions & 0 deletions src/hotspot/cpu/ppc/stubGenerator_ppc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
#include "oops/objArrayKlass.hpp"
#include "oops/oop.inline.hpp"
#include "prims/methodHandles.hpp"
#include "prims/upcallLinker.hpp"
#include "runtime/continuation.hpp"
#include "runtime/continuationEntry.inline.hpp"
#include "runtime/frame.inline.hpp"
Expand Down Expand Up @@ -4717,6 +4718,20 @@ class StubGenerator: public StubCodeGenerator {

#endif // INCLUDE_JFR

// exception handler for upcall stubs
address generate_upcall_stub_exception_handler() {
StubCodeMark mark(this, "StubRoutines", "upcall stub exception handler");
address start = __ pc();

// Native caller has no idea how to handle exceptions,
// so we just crash here. Up to callee to catch exceptions.
__ verify_oop(R3_ARG1);
__ load_const_optimized(R12_scratch2, CAST_FROM_FN_PTR(uint64_t, UpcallLinker::handle_uncaught_exception), R0);
__ call_c(R12_scratch2);
__ should_not_reach_here();

return start;
}

// Initialization
void generate_initial_stubs() {
Expand Down Expand Up @@ -4796,6 +4811,8 @@ class StubGenerator: public StubCodeGenerator {

// arraycopy stubs used by compilers
generate_arraycopy_stubs();

StubRoutines::_upcall_stub_exception_handler = generate_upcall_stub_exception_handler();
}

void generate_compiler_stubs() {
Expand Down
20 changes: 3 additions & 17 deletions src/hotspot/cpu/ppc/upcallLinker_ppc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ static void restore_callee_saved_registers(MacroAssembler* _masm, const ABIDescr
__ block_comment("} restore_callee_saved_regs ");
}

static const int upcall_stub_code_base_size = 1536; // depends on GC (resolve_jobject)
static const int upcall_stub_code_base_size = 1024;
static const int upcall_stub_size_per_arg = 16; // arg save & restore + move

address UpcallLinker::make_upcall_stub(jobject receiver, Method* entry,
Expand Down Expand Up @@ -217,6 +217,7 @@ address UpcallLinker::make_upcall_stub(jobject receiver, Method* entry,
__ block_comment("{ on_entry");
__ load_const_optimized(call_target_address, CAST_FROM_FN_PTR(uint64_t, UpcallLinker::on_entry), R0);
__ addi(R3_ARG1, R1_SP, frame_data_offset);
__ load_const_optimized(R4_ARG2, (intptr_t)receiver, R0);
__ call_c(call_target_address);
__ mr(R16_thread, R3_RET);
__ block_comment("} on_entry");
Expand All @@ -232,8 +233,7 @@ address UpcallLinker::make_upcall_stub(jobject receiver, Method* entry,
__ block_comment("} argument shuffle");

__ block_comment("{ receiver ");
__ load_const_optimized(R3_ARG1, (intptr_t)receiver, R0);
__ resolve_jobject(R3_ARG1, tmp, R31, MacroAssembler::PRESERVATION_FRAME_LR_GP_FP_REGS); // kills R31
__ get_vm_result(R3_ARG1);
__ block_comment("} receiver ");

__ load_const_optimized(R19_method, (intptr_t)entry);
Expand Down Expand Up @@ -314,19 +314,6 @@ address UpcallLinker::make_upcall_stub(jobject receiver, Method* entry,

//////////////////////////////////////////////////////////////////////////////

__ block_comment("{ exception handler");

intptr_t exception_handler_offset = __ pc() - start;

// Native caller has no idea how to handle exceptions,
// so we just crash here. Up to callee to catch exceptions.
__ verify_oop(R3_ARG1);
__ load_const_optimized(call_target_address, CAST_FROM_FN_PTR(uint64_t, UpcallLinker::handle_uncaught_exception), R0);
__ call_c(call_target_address);
__ should_not_reach_here();

__ block_comment("} exception handler");

_masm->flush();

#ifndef PRODUCT
Expand All @@ -342,7 +329,6 @@ address UpcallLinker::make_upcall_stub(jobject receiver, Method* entry,
UpcallStub* blob
= UpcallStub::create(name,
&buffer,
exception_handler_offset,
receiver,
in_ByteSize(frame_data_offset));
#ifndef ABI_ELFv2
Expand Down
17 changes: 17 additions & 0 deletions src/hotspot/cpu/riscv/stubGenerator_riscv.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
#include "oops/objArrayKlass.hpp"
#include "oops/oop.inline.hpp"
#include "prims/methodHandles.hpp"
#include "prims/upcallLinker.hpp"
#include "runtime/continuation.hpp"
#include "runtime/continuationEntry.inline.hpp"
#include "runtime/frame.inline.hpp"
Expand Down Expand Up @@ -4504,6 +4505,20 @@ class StubGenerator: public StubCodeGenerator {

#endif // INCLUDE_JFR

// exception handler for upcall stubs
address generate_upcall_stub_exception_handler() {
StubCodeMark mark(this, "StubRoutines", "upcall stub exception handler");
address start = __ pc();

// Native caller has no idea how to handle exceptions,
// so we just crash here. Up to callee to catch exceptions.
__ verify_oop(x10); // return a exception oop in a0
__ rt_call(CAST_FROM_FN_PTR(address, UpcallLinker::handle_uncaught_exception));
__ should_not_reach_here();

return start;
}

#undef __

// Initialization
Expand Down Expand Up @@ -4588,6 +4603,8 @@ class StubGenerator: public StubCodeGenerator {
StubRoutines::riscv::_method_entry_barrier = generate_method_entry_barrier();
}

StubRoutines::_upcall_stub_exception_handler = generate_upcall_stub_exception_handler();

StubRoutines::riscv::set_completed();
}

Expand Down
19 changes: 3 additions & 16 deletions src/hotspot/cpu/riscv/upcallLinker_riscv.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ static void restore_callee_saved_registers(MacroAssembler* _masm, const ABIDescr
__ block_comment("} restore_callee_saved_regs ");
}

static const int upcall_stub_code_base_size = 2048;
static const int upcall_stub_code_base_size = 1024;
static const int upcall_stub_size_per_arg = 16;

address UpcallLinker::make_upcall_stub(jobject receiver, Method* entry,
Expand Down Expand Up @@ -218,6 +218,7 @@ address UpcallLinker::make_upcall_stub(jobject receiver, Method* entry,

__ block_comment("{ on_entry");
__ la(c_rarg0, Address(sp, frame_data_offset));
__ movptr(c_rarg1, (intptr_t) receiver);
__ rt_call(CAST_FROM_FN_PTR(address, UpcallLinker::on_entry));
__ mv(xthread, x10);
__ reinit_heapbase();
Expand Down Expand Up @@ -255,9 +256,7 @@ address UpcallLinker::make_upcall_stub(jobject receiver, Method* entry,
__ block_comment("} argument shuffle");

__ block_comment("{ receiver ");
__ movptr(shuffle_reg, (intptr_t) receiver);
__ resolve_jobject(shuffle_reg, t0, t1);
__ mv(j_rarg0, shuffle_reg);
__ get_vm_result(j_rarg0, xthread);
__ block_comment("} receiver ");

__ mov_metadata(xmethod, entry);
Expand Down Expand Up @@ -326,17 +325,6 @@ address UpcallLinker::make_upcall_stub(jobject receiver, Method* entry,

//////////////////////////////////////////////////////////////////////////////

__ block_comment("{ exception handler");

intptr_t exception_handler_offset = __ pc() - start;

// Native caller has no idea how to handle exceptions,
// so we just crash here. Up to callee to catch exceptions.
__ verify_oop(x10); // return a exception oop in a0
__ rt_call(CAST_FROM_FN_PTR(address, UpcallLinker::handle_uncaught_exception));
__ should_not_reach_here();

__ block_comment("} exception handler");
__ flush();

#ifndef PRODUCT
Expand All @@ -352,7 +340,6 @@ address UpcallLinker::make_upcall_stub(jobject receiver, Method* entry,
UpcallStub* blob
= UpcallStub::create(name,
&buffer,
exception_handler_offset,
receiver,
in_ByteSize(frame_data_offset));
#ifndef PRODUCT
Expand Down
17 changes: 17 additions & 0 deletions src/hotspot/cpu/s390/stubGenerator_s390.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
#include "oops/objArrayKlass.hpp"
#include "oops/oop.inline.hpp"
#include "prims/methodHandles.hpp"
#include "prims/upcallLinker.hpp"
#include "runtime/frame.inline.hpp"
#include "runtime/handles.inline.hpp"
#include "runtime/javaThread.hpp"
Expand Down Expand Up @@ -3094,6 +3095,21 @@ class StubGenerator: public StubCodeGenerator {

#endif // INCLUDE_JFR

// exception handler for upcall stubs
address generate_upcall_stub_exception_handler() {
StubCodeMark mark(this, "StubRoutines", "upcall stub exception handler");
address start = __ pc();

// Native caller has no idea how to handle exceptions,
// so we just crash here. Up to callee to catch exceptions.
__ verify_oop(Z_ARG1);
__ load_const_optimized(Z_R1_scratch, CAST_FROM_FN_PTR(uint64_t, UpcallLinker::handle_uncaught_exception));
__ call_c(Z_R1_scratch);
__ should_not_reach_here();

return start;
}

void generate_initial_stubs() {
// Generates all stubs and initializes the entry points.

Expand Down Expand Up @@ -3174,6 +3190,7 @@ class StubGenerator: public StubCodeGenerator {
StubRoutines::zarch::_nmethod_entry_barrier = generate_nmethod_entry_barrier();
}

StubRoutines::_upcall_stub_exception_handler = generate_upcall_stub_exception_handler();
}

void generate_compiler_stubs() {
Expand Down
20 changes: 3 additions & 17 deletions src/hotspot/cpu/s390/upcallLinker_s390.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ static void restore_callee_saved_registers(MacroAssembler* _masm, const ABIDescr
__ block_comment("} restore_callee_saved_regs ");
}

static const int upcall_stub_code_base_size = 1024; // depends on GC (resolve_jobject)
static const int upcall_stub_code_base_size = 1024;
static const int upcall_stub_size_per_arg = 16; // arg save & restore + move
address UpcallLinker::make_upcall_stub(jobject receiver, Method* entry,
BasicType* in_sig_bt, int total_in_args,
Expand Down Expand Up @@ -202,6 +202,7 @@ address UpcallLinker::make_upcall_stub(jobject receiver, Method* entry,
__ block_comment("{ on_entry");
__ load_const_optimized(call_target_address, CAST_FROM_FN_PTR(uint64_t, UpcallLinker::on_entry));
__ z_aghik(Z_ARG1, Z_SP, frame_data_offset);
__ load_const_optimized(Z_ARG2, (intptr_t)receiver);
__ call(call_target_address);
__ z_lgr(Z_thread, Z_RET);
__ block_comment("} on_entry");
Expand All @@ -212,8 +213,7 @@ address UpcallLinker::make_upcall_stub(jobject receiver, Method* entry,
__ block_comment("} argument shuffle");

__ block_comment("{ receiver ");
__ load_const_optimized(Z_ARG1, (intptr_t)receiver);
__ resolve_jobject(Z_ARG1, Z_tmp_1, Z_tmp_2);
__ get_vm_result(Z_ARG1);
__ block_comment("} receiver ");

__ load_const_optimized(Z_method, (intptr_t)entry);
Expand Down Expand Up @@ -266,19 +266,6 @@ address UpcallLinker::make_upcall_stub(jobject receiver, Method* entry,

//////////////////////////////////////////////////////////////////////////////

__ block_comment("{ exception handler");

intptr_t exception_handler_offset = __ pc() - start;

// Native caller has no idea how to handle exceptions,
// so we just crash here. Up to callee to catch exceptions.
__ verify_oop(Z_ARG1);
__ load_const_optimized(call_target_address, CAST_FROM_FN_PTR(uint64_t, UpcallLinker::handle_uncaught_exception));
__ call_c(call_target_address);
__ should_not_reach_here();

__ block_comment("} exception handler");

_masm->flush();

#ifndef PRODUCT
Expand All @@ -293,7 +280,6 @@ address UpcallLinker::make_upcall_stub(jobject receiver, Method* entry,
UpcallStub* blob
= UpcallStub::create(name,
&buffer,
exception_handler_offset,
receiver,
in_ByteSize(frame_data_offset));
#ifndef PRODUCT
Expand Down

1 comment on commit a644670

@openjdk-notifier
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.