Skip to content

Commit

Permalink
Merge branch 'upstream-master'
Browse files Browse the repository at this point in the history
  • Loading branch information
Datadog Syncup Service committed Oct 24, 2023
2 parents a45208b + e67550c commit 8292c8b
Show file tree
Hide file tree
Showing 101 changed files with 2,801 additions and 1,426 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
29 changes: 25 additions & 4 deletions src/hotspot/cpu/riscv/macroAssembler_riscv.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4404,8 +4404,8 @@ void MacroAssembler::sign_extend(Register dst, Register src, int bits) {
}
}

void MacroAssembler::cmp_l2i(Register dst, Register src1, Register src2, Register tmp)
{
void MacroAssembler::cmp_x2i(Register dst, Register src1, Register src2,
Register tmp, bool is_signed) {
if (src1 == src2) {
mv(dst, zr);
return;
Expand All @@ -4424,14 +4424,35 @@ void MacroAssembler::cmp_l2i(Register dst, Register src1, Register src2, Registe
}

// installs 1 if gt else 0
slt(dst, right, left);
if (is_signed) {
slt(dst, right, left);
} else {
sltu(dst, right, left);
}
bnez(dst, done);
slt(dst, left, right);
if (is_signed) {
slt(dst, left, right);
} else {
sltu(dst, left, right);
}
// dst = -1 if lt; else if eq , dst = 0
neg(dst, dst);
bind(done);
}

void MacroAssembler::cmp_l2i(Register dst, Register src1, Register src2, Register tmp)
{
cmp_x2i(dst, src1, src2, tmp);
}

void MacroAssembler::cmp_ul2i(Register dst, Register src1, Register src2, Register tmp) {
cmp_x2i(dst, src1, src2, tmp, false);
}

void MacroAssembler::cmp_uw2i(Register dst, Register src1, Register src2, Register tmp) {
cmp_x2i(dst, src1, src2, tmp, false);
}

// The java_calling_convention describes stack locations as ideal slots on
// a frame with no abi restrictions. Since we must observe abi restrictions
// (like the placement of the register window) the slots must be biased by
Expand Down
6 changes: 6 additions & 0 deletions src/hotspot/cpu/riscv/macroAssembler_riscv.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -1394,11 +1394,17 @@ class MacroAssembler: public Assembler {
void zero_extend(Register dst, Register src, int bits);
void sign_extend(Register dst, Register src, int bits);

private:
void cmp_x2i(Register dst, Register src1, Register src2, Register tmp, bool is_signed = true);

public:
// compare src1 and src2 and get -1/0/1 in dst.
// if [src1 > src2], dst = 1;
// if [src1 == src2], dst = 0;
// if [src1 < src2], dst = -1;
void cmp_l2i(Register dst, Register src1, Register src2, Register tmp = t0);
void cmp_ul2i(Register dst, Register src1, Register src2, Register tmp = t0);
void cmp_uw2i(Register dst, Register src1, Register src2, Register tmp = t0);

// support for argument shuffling
void move32_64(VMRegPair src, VMRegPair dst, Register tmp = t0);
Expand Down
36 changes: 36 additions & 0 deletions src/hotspot/cpu/riscv/riscv.ad
Original file line number Diff line number Diff line change
Expand Up @@ -8641,6 +8641,42 @@ instruct cmpL3_reg_reg(iRegINoSp dst, iRegL op1, iRegL op2)
ins_pipe(pipe_class_default);
%}

instruct cmpUL3_reg_reg(iRegINoSp dst, iRegL op1, iRegL op2)
%{
match(Set dst (CmpUL3 op1 op2));

ins_cost(ALU_COST * 3 + BRANCH_COST);
format %{ "sltu $dst, $op2, $op1\t#@cmpUL3_reg_reg\n\t"
"bnez $dst, done\n\t"
"sltu $dst, $op1, $op2\n\t"
"neg $dst, $dst\t#@cmpUL3_reg_reg"
%}
ins_encode %{
__ cmp_ul2i(t0, as_Register($op1$$reg), as_Register($op2$$reg));
__ mv(as_Register($dst$$reg), t0);
%}

ins_pipe(pipe_class_default);
%}

instruct cmpU3_reg_reg(iRegINoSp dst, iRegI op1, iRegI op2)
%{
match(Set dst (CmpU3 op1 op2));

ins_cost(ALU_COST * 3 + BRANCH_COST);
format %{ "sltu $dst, $op2, $op1\t#@cmpU3_reg_reg\n\t"
"bnez $dst, done\n\t"
"sltu $dst, $op1, $op2\n\t"
"neg $dst, $dst\t#@cmpU3_reg_reg"
%}
ins_encode %{
__ cmp_uw2i(t0, as_Register($op1$$reg), as_Register($op2$$reg));
__ mv(as_Register($dst$$reg), t0);
%}

ins_pipe(pipe_class_default);
%}

instruct cmpLTMask_reg_reg(iRegINoSp dst, iRegI p, iRegI q)
%{
match(Set dst (CmpLTMask p q));
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
Loading

0 comments on commit 8292c8b

Please sign in to comment.