Skip to content

Commit

Permalink
More fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
TobiHartmann committed Nov 7, 2024
1 parent 88c9466 commit bb3b87f
Show file tree
Hide file tree
Showing 10 changed files with 24 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,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
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 @@ -103,7 +103,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 @@ -102,7 +102,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 @@ -112,7 +112,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 @@ -103,7 +103,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
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 @@ -112,9 +112,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
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 @@ -101,7 +101,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
27 changes: 6 additions & 21 deletions src/hotspot/share/runtime/continuationFreezeThaw.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1042,15 +1042,7 @@ void FreezeBase::patch(const frame& f, frame& hf, const frame& caller, bool is_b
// caller's pc.
address last_pc = caller.pc();
assert((last_pc == nullptr) == _cont.tail()->is_empty(), "");
ContinuationHelper::Frame::patch_pc(caller, last_pc);
// TODO new needed? Add assert
if (false && f.needs_stack_repair()) {
// We also need to patch the return address copy which is at the expected location just below the unextended caller sp
// All other code in this method patches based on the caller sp which we already updated such that the (real) frame pointer is just below
address* pc_addr = &(((address*) caller.unextended_sp())[-1]);
*pc_addr = last_pc;
tty->print_cr("FREEZE PATCHING BOTTOM " PTR_FORMAT, p2i(pc_addr));
}
ContinuationHelper::Frame::patch_pc(caller, last_pc, f.needs_stack_repair());
} else {
assert(!caller.is_empty(), "");
}
Expand Down Expand Up @@ -2203,19 +2195,12 @@ inline void ThawBase::patch(frame& f, const frame& caller, bool bottom) {
assert(!bottom || caller.fp() == _cont.entryFP(), "");
if (bottom) {
ContinuationHelper::Frame::patch_pc(caller, _cont.is_empty() ? caller.pc()
: StubRoutines::cont_returnBarrier());
if (f.needs_stack_repair()) {
// We also need to patch the return address copy which is at the expected location just below the unextended caller sp
// All other code in this method patches based on the caller sp which we already updated such that the (real) frame pointer is just below
address* pc_addr = &(((address*) caller.unextended_sp())[-1]);
*pc_addr = StubRoutines::cont_returnBarrier();
}
: StubRoutines::cont_returnBarrier(),
f.needs_stack_repair());
} else {
// caller might have been deoptimized during thaw but we've overwritten the return address when copying f from the heap.
// If the caller is not deoptimized, pc is unchanged.
// TODO we need a test for this
assert(!f.needs_stack_repair(), "f needs repair, we need to patch the return address copy as well");
ContinuationHelper::Frame::patch_pc(caller, caller.raw_pc());
ContinuationHelper::Frame::patch_pc(caller, caller.raw_pc(), f.needs_stack_repair());
}

patch_pd(f, caller);
Expand Down Expand Up @@ -2391,7 +2376,7 @@ void ThawBase::recurse_thaw_compiled_frame(const frame& hf, frame& caller, int n
assert(_thread->is_interp_only_mode() || stub_caller, "expected a stub-caller");

log_develop_trace(continuations)("Deoptimizing thawed frame");
DEBUG_ONLY(ContinuationHelper::Frame::patch_pc(f, nullptr));
DEBUG_ONLY(ContinuationHelper::Frame::patch_pc(f, nullptr, false));

f.deoptimize(nullptr); // the null thread simply avoids the assertion in deoptimize which we're not set up for
assert(f.is_deoptimized_frame(), "");
Expand Down Expand Up @@ -2512,7 +2497,7 @@ void ThawBase::push_return_frame(frame& f) { // see generate_cont_thaw

assert(f.sp() - frame::metadata_words_at_bottom >= _top_stack_address, "overwrote past thawing space"
" to: " INTPTR_FORMAT " top_address: " INTPTR_FORMAT, p2i(f.sp() - frame::metadata_words), p2i(_top_stack_address));
ContinuationHelper::Frame::patch_pc(f, f.raw_pc()); // in case we want to deopt the frame in a full transition, this is checked.
ContinuationHelper::Frame::patch_pc(f, f.raw_pc(), false); // in case we want to deopt the frame in a full transition, this is checked.
ContinuationHelper::push_pd(f);

assert(ContinuationHelper::Frame::assert_frame_laid_out(f), "");
Expand Down
2 changes: 1 addition & 1 deletion src/hotspot/share/runtime/continuationHelper.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ class ContinuationHelper::Frame : public AllStatic {
static inline intptr_t** callee_link_address(const frame& f);
static Method* frame_method(const frame& f);
static inline address real_pc(const frame& f);
static inline void patch_pc(const frame& f, address pc);
static inline void patch_pc(const frame& f, address pc, bool needs_stack_repair);
static address* return_pc_address(const frame& f);
static address return_pc(const frame& f);
static bool is_stub(CodeBlob* cb);
Expand Down
3 changes: 3 additions & 0 deletions src/hotspot/share/runtime/frame.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -423,6 +423,9 @@ frame frame::real_sender(RegisterMap* map) const {
}

bool frame::needs_stack_repair() const {
if (!is_compiled_frame()) {
return false;
}
assert(is_empty() || cb() == get_cb(), "sanity");
nmethod* nm = cb()->as_nmethod_or_null();
return nm != nullptr && nm->needs_stack_repair();
Expand Down

0 comments on commit bb3b87f

Please sign in to comment.