Skip to content

8336845: [lworld] Virtual threads don't support the value class calling convention #1399

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 24 commits into
base: lworld
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,8 @@ inline address ContinuationHelper::Frame::real_pc(const frame& f) {
return pauth_strip_pointer(*pc_addr);
}

inline void ContinuationHelper::Frame::patch_pc(const frame& f, address pc) {
inline void ContinuationHelper::Frame::patch_pc(const frame& f, address pc, bool needs_stack_repair) {
// TODO Fix, see x86 version
address* pc_addr = &(((address*) f.sp())[-1]);
*pc_addr = pauth_sign_return_address(pc);
}
Expand Down
4 changes: 4 additions & 0 deletions src/hotspot/cpu/aarch64/stubGenerator_aarch64.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8603,6 +8603,7 @@ class StubGenerator: public StubCodeGenerator {
assert_asm(_masm, (__ ldr(rscratch1, Address(rthread, JavaThread::cont_entry_offset())), __ cmp(sp, rscratch1)), Assembler::EQ, "incorrect sp");

if (return_barrier) {
// TODO fix for InlineTypeReturnedAsFields, see x86 version
// preserve possible return value from a method returning to the return barrier
__ fmovd(rscratch1, v0);
__ stp(rscratch1, r0, Address(__ pre(sp, -2 * wordSize)));
Expand All @@ -8613,6 +8614,7 @@ class StubGenerator: public StubCodeGenerator {
__ mov(rscratch2, r0); // r0 contains the size of the frames to thaw, 0 if overflow or no more frames

if (return_barrier) {
// TODO fix for InlineTypeReturnedAsFields, see x86 version
// restore return value (no safepoint in the call to thaw, so even an oop return value should be OK)
__ ldp(rscratch1, r0, Address(__ post(sp, 2 * wordSize)));
__ fmovd(v0, rscratch1);
Expand All @@ -8633,6 +8635,7 @@ class StubGenerator: public StubCodeGenerator {
__ mov(sp, rscratch1);

if (return_barrier) {
// TODO fix for InlineTypeReturnedAsFields, see x86 version
// save original return value -- again
__ fmovd(rscratch1, v0);
__ stp(rscratch1, r0, Address(__ pre(sp, -2 * wordSize)));
Expand All @@ -8645,6 +8648,7 @@ class StubGenerator: public StubCodeGenerator {
__ mov(rscratch2, r0); // r0 is the sp of the yielding frame

if (return_barrier) {
// TODO fix for InlineTypeReturnedAsFields, see x86 version
// restore return value (no safepoint in the call to thaw, so even an oop return value should be OK)
__ ldp(rscratch1, r0, Address(__ post(sp, 2 * wordSize)));
__ fmovd(v0, rscratch1);
Expand Down
2 changes: 1 addition & 1 deletion src/hotspot/cpu/arm/continuationHelper_arm.inline.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ inline address ContinuationHelper::Frame::real_pc(const frame& f) {
return nullptr;
}

inline void ContinuationHelper::Frame::patch_pc(const frame& f, address pc) {
inline void ContinuationHelper::Frame::patch_pc(const frame& f, address pc, bool needs_stack_repair) {
Unimplemented();
}

Expand Down
2 changes: 1 addition & 1 deletion src/hotspot/cpu/ppc/continuationHelper_ppc.inline.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ inline address ContinuationHelper::Frame::real_pc(const frame& f) {
return (address)f.own_abi()->lr;
}

inline void ContinuationHelper::Frame::patch_pc(const frame& f, address pc) {
inline void ContinuationHelper::Frame::patch_pc(const frame& f, address pc, bool needs_stack_repair) {
f.own_abi()->lr = (uint64_t)pc;
}

Expand Down
2 changes: 1 addition & 1 deletion src/hotspot/cpu/riscv/continuationHelper_riscv.inline.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ inline address ContinuationHelper::Frame::real_pc(const frame& f) {
return *pc_addr;
}

inline void ContinuationHelper::Frame::patch_pc(const frame& f, address pc) {
inline void ContinuationHelper::Frame::patch_pc(const frame& f, address pc, bool needs_stack_repair) {
address* pc_addr = &(((address*) f.sp())[-1]);
*pc_addr = pc;
}
Expand Down
2 changes: 1 addition & 1 deletion src/hotspot/cpu/s390/continuationHelper_s390.inline.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ inline address ContinuationHelper::Frame::real_pc(const frame& f) {
return nullptr;
}

inline void ContinuationHelper::Frame::patch_pc(const frame& f, address pc) {
inline void ContinuationHelper::Frame::patch_pc(const frame& f, address pc, bool needs_stack_repair) {
Unimplemented();
}

Expand Down
7 changes: 6 additions & 1 deletion src/hotspot/cpu/x86/continuationFreezeThaw_x86.inline.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ inline frame FreezeBase::sender(const frame& f) {
intptr_t** link_addr = link_address<FKind>(f);

intptr_t* sender_sp = (intptr_t*)(link_addr + frame::sender_sp_offset); // f.unextended_sp() + (fsize/wordSize); //
sender_sp = f.repair_sender_sp(sender_sp, link_addr);
address sender_pc = (address) *(sender_sp-1);
assert(sender_sp != f.sp(), "must have changed");

Expand Down Expand Up @@ -114,6 +115,10 @@ frame FreezeBase::new_heap_frame(frame& f, frame& caller) {

assert(_cont.tail()->is_in_chunk(sp), "");

if (f.cb()->as_nmethod()->is_compiled_by_c2() && f.cb()->as_nmethod()->needs_stack_repair() && caller.is_compiled_frame() && caller.cb()->as_nmethod()->is_compiled_by_c1()) {
sp -= FKind::stack_argsize(f);
}

return frame(sp, sp, fp, f.pc(), nullptr, nullptr, true /* on_heap */);
}
}
Expand Down Expand Up @@ -238,7 +243,7 @@ template<typename FKind> frame ThawBase::new_stack_frame(const frame& hf, frame&
int argsize = FKind::stack_argsize(hf);

fsize += argsize;
frame_sp -= argsize;
frame_sp -= argsize;
caller.set_sp(caller.sp() - argsize);
assert(caller.sp() == frame_sp + (fsize-argsize), "");

Expand Down
8 changes: 7 additions & 1 deletion src/hotspot/cpu/x86/continuationHelper_x86.inline.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -126,9 +126,15 @@ inline address ContinuationHelper::Frame::real_pc(const frame& f) {
return *pc_addr;
}

inline void ContinuationHelper::Frame::patch_pc(const frame& f, address pc) {
inline void ContinuationHelper::Frame::patch_pc(const frame& f, address pc, bool needs_stack_repair) {
address* pc_addr = &(((address*) f.sp())[-1]);
*pc_addr = pc;

if (needs_stack_repair) {
// The callee extended the stack. Patch the return address copy which resides below the unextended sp.
pc_addr = &(((address*) f.unextended_sp())[-1]);
*pc_addr = pc;
}
}

inline intptr_t* ContinuationHelper::InterpretedFrame::frame_top(const frame& f, InterpreterOopMap* mask) { // inclusive; this will be copied with the frame
Expand Down
4 changes: 4 additions & 0 deletions src/hotspot/cpu/x86/frame_x86.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -676,6 +676,10 @@ void frame::describe_pd(FrameValues& values, int frame_no) {
} else {
ret_pc_loc = real_fp() - return_addr_offset;
fp_loc = real_fp() - sender_sp_offset;
nmethod* nm = cb()->as_nmethod_or_null();
if (nm != nullptr && nm->needs_stack_repair()) {
values.describe(-1, fp_loc - 1, "real frame size");
}
}
address ret_pc = *(address*)ret_pc_loc;
values.describe(frame_no, ret_pc_loc,
Expand Down
5 changes: 3 additions & 2 deletions src/hotspot/cpu/x86/frame_x86.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -144,8 +144,6 @@
return (intptr_t*) addr_at(offset);
}

// Support for scalarized inline type calling convention
intptr_t* repair_sender_sp(intptr_t* sender_sp, intptr_t** saved_fp_addr) const;

#ifdef ASSERT
// Used in frame::sender_for_{interpreter,compiled}_frame
Expand All @@ -155,6 +153,9 @@
public:
// Constructors

// Support for scalarized inline type calling convention
intptr_t* repair_sender_sp(intptr_t* sender_sp, intptr_t** saved_fp_addr) const;

frame(intptr_t* sp, intptr_t* fp, address pc);

frame(intptr_t* sp, intptr_t* unextended_sp, intptr_t* fp, address pc);
Expand Down
24 changes: 23 additions & 1 deletion src/hotspot/cpu/x86/frame_x86.inline.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -228,8 +228,30 @@ inline int frame::frame_size() const {
: cb()->frame_size();
}

inline int frame::compiled_frame_stack_argsize() const {
inline int frame::compiled_frame_stack_argsize(bool scalarized) const {
assert(cb()->is_nmethod(), "");

if (cb()->as_nmethod()->is_compiled_by_c2() && needs_stack_repair() && scalarized) {
// TODO this computation should be cached
ResourceMark rm;
CompiledEntrySignature ces(cb()->as_nmethod()->method());
ces.compute_calling_conventions(false);

const GrowableArray<SigEntry>* sig_cc = ces.sig_cc();
const VMRegPair* regs = ces.regs_cc();
int sig_index = 0;
int cnt = 1; // Account for the return address copy
for (ExtendedSignature sig = ExtendedSignature(sig_cc, SigEntryFilter()); !sig.at_end(); ++sig) {
BasicType t = (*sig)._bt;
VMReg fst = regs[sig_index].first();
if (fst->is_stack()) {
cnt++;
}
sig_index += type2size[t];
}
// TODO use StackAlignmentInBytes for alignment here
return align_up(cnt, 2);
}
return (cb()->as_nmethod()->num_stack_arg_slots() * VMRegImpl::stack_slot_size) >> LogBytesPerWord;
}

Expand Down
34 changes: 32 additions & 2 deletions src/hotspot/cpu/x86/stubGenerator_x86_64.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3804,8 +3804,6 @@ address StubGenerator::generate_cont_thaw(StubGenStubId stub_id) {
StubCodeMark mark(this, stub_id);
address start = __ pc();

// TODO: Handle Valhalla return types. May require generating different return barriers.

if (!return_barrier) {
// Pop return address. If we don't do this, we get a drift,
// where the bottom-most frozen frame continuously grows.
Expand All @@ -3827,6 +3825,14 @@ address StubGenerator::generate_cont_thaw(StubGenStubId stub_id) {
if (return_barrier) {
// Preserve possible return value from a method returning to the return barrier.
__ push(rax);
if (InlineTypeReturnedAsFields) {
__ push(rdi);
__ push(rsi);
__ push(rdx);
__ push(rcx);
__ push(r8);
__ push(r9);
}
__ push_d(xmm0);
}

Expand All @@ -3839,6 +3845,14 @@ address StubGenerator::generate_cont_thaw(StubGenStubId stub_id) {
// Restore return value from a method returning to the return barrier.
// No safepoint in the call to thaw, so even an oop return value should be OK.
__ pop_d(xmm0);
if (InlineTypeReturnedAsFields) {
__ pop(r9);
__ pop(r8);
__ pop(rcx);
__ pop(rdx);
__ pop(rsi);
__ pop(rdi);
}
__ pop(rax);
}

Expand Down Expand Up @@ -3866,6 +3880,14 @@ address StubGenerator::generate_cont_thaw(StubGenStubId stub_id) {
if (return_barrier) {
// Preserve possible return value from a method returning to the return barrier. (Again.)
__ push(rax);
if (InlineTypeReturnedAsFields) {
__ push(rdi);
__ push(rsi);
__ push(rdx);
__ push(rcx);
__ push(r8);
__ push(r9);
}
__ push_d(xmm0);
}

Expand All @@ -3879,6 +3901,14 @@ address StubGenerator::generate_cont_thaw(StubGenStubId stub_id) {
// Restore return value from a method returning to the return barrier. (Again.)
// No safepoint in the call to thaw, so even an oop return value should be OK.
__ pop_d(xmm0);
if (InlineTypeReturnedAsFields) {
__ pop(r9);
__ pop(r8);
__ pop(rcx);
__ pop(rdx);
__ pop(rsi);
__ pop(rdi);
}
__ pop(rax);
} else {
// Return 0 (success) from doYield.
Expand Down
2 changes: 1 addition & 1 deletion src/hotspot/cpu/zero/continuationHelper_zero.inline.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ inline address ContinuationHelper::Frame::real_pc(const frame& f) {
return nullptr;
}

inline void ContinuationHelper::Frame::patch_pc(const frame& f, address pc) {
inline void ContinuationHelper::Frame::patch_pc(const frame& f, address pc, bool needs_stack_repair) {
Unimplemented();
}

Expand Down
Loading