diff --git a/src/hotspot/cpu/aarch64/continuationFreezeThaw_aarch64.inline.hpp b/src/hotspot/cpu/aarch64/continuationFreezeThaw_aarch64.inline.hpp index 23a5ad71025..eca3cc33bfe 100644 --- a/src/hotspot/cpu/aarch64/continuationFreezeThaw_aarch64.inline.hpp +++ b/src/hotspot/cpu/aarch64/continuationFreezeThaw_aarch64.inline.hpp @@ -153,11 +153,14 @@ inline void FreezeBase::relativize_interpreted_frame_metadata(const frame& f, co assert((intptr_t*)hf.at_relative(frame::interpreter_frame_last_sp_offset) == hf.unextended_sp(), ""); relativize_one(vfp, hfp, frame::interpreter_frame_initial_sp_offset); // == block_top == block_bottom - relativize_one(vfp, hfp, frame::interpreter_frame_extended_sp_offset); + + // extended_sp is already relativized by TemplateInterpreterGenerator::generate_normal_entry or + // AbstractInterpreter::layout_activation assert((hf.fp() - hf.unextended_sp()) == (f.fp() - f.unextended_sp()), ""); assert(hf.unextended_sp() == (intptr_t*)hf.at(frame::interpreter_frame_last_sp_offset), ""); assert(hf.unextended_sp() <= (intptr_t*)hf.at(frame::interpreter_frame_initial_sp_offset), ""); + assert(hf.unextended_sp() > (intptr_t*)hf.at(frame::interpreter_frame_extended_sp_offset), ""); assert(hf.fp() > (intptr_t*)hf.at(frame::interpreter_frame_initial_sp_offset), ""); assert(hf.fp() <= (intptr_t*)hf.at(frame::interpreter_frame_locals_offset), ""); } @@ -294,7 +297,9 @@ inline void ThawBase::derelativize_interpreted_frame_metadata(const frame& hf, c assert((intptr_t*)f.at_relative(frame::interpreter_frame_last_sp_offset) == f.unextended_sp(), ""); derelativize_one(vfp, frame::interpreter_frame_initial_sp_offset); - derelativize_one(vfp, frame::interpreter_frame_extended_sp_offset); + + // Make sure that extended_sp is kept relativized. + assert((intptr_t*)f.at_relative(frame::interpreter_frame_extended_sp_offset) < f.unextended_sp(), ""); } #endif // CPU_AARCH64_CONTINUATIONFREEZETHAW_AARCH64_INLINE_HPP diff --git a/src/hotspot/cpu/aarch64/frame_aarch64.cpp b/src/hotspot/cpu/aarch64/frame_aarch64.cpp index 4ceae831e66..24a710de21f 100644 --- a/src/hotspot/cpu/aarch64/frame_aarch64.cpp +++ b/src/hotspot/cpu/aarch64/frame_aarch64.cpp @@ -362,7 +362,9 @@ void frame::interpreter_frame_set_last_sp(intptr_t* sp) { // Used by template based interpreter deoptimization void frame::interpreter_frame_set_extended_sp(intptr_t* sp) { - *((intptr_t**)addr_at(interpreter_frame_extended_sp_offset)) = sp; + assert(is_interpreted_frame(), "interpreted frame expected"); + // set relativized extended_sp + ptr_at_put(interpreter_frame_extended_sp_offset, (sp - fp())); } frame frame::sender_for_entry_frame(RegisterMap* map) const { diff --git a/src/hotspot/cpu/aarch64/interp_masm_aarch64.hpp b/src/hotspot/cpu/aarch64/interp_masm_aarch64.hpp index 70822b6c424..5eb917f41a7 100644 --- a/src/hotspot/cpu/aarch64/interp_masm_aarch64.hpp +++ b/src/hotspot/cpu/aarch64/interp_masm_aarch64.hpp @@ -86,6 +86,7 @@ class InterpreterMacroAssembler: public MacroAssembler { void restore_sp_after_call() { Label L; ldr(rscratch1, Address(rfp, frame::interpreter_frame_extended_sp_offset * wordSize)); + lea(rscratch1, Address(rfp, rscratch1, Address::lsl(LogBytesPerWord))); #ifdef ASSERT cbnz(rscratch1, L); stop("SP is null"); @@ -98,6 +99,7 @@ class InterpreterMacroAssembler: public MacroAssembler { #ifdef ASSERT Label L; ldr(rscratch1, Address(rfp, frame::interpreter_frame_extended_sp_offset * wordSize)); + lea(rscratch1, Address(rfp, rscratch1, Address::lsl(LogBytesPerWord))); cmp(sp, rscratch1); br(EQ, L); stop(msg); diff --git a/src/hotspot/cpu/aarch64/templateInterpreterGenerator_aarch64.cpp b/src/hotspot/cpu/aarch64/templateInterpreterGenerator_aarch64.cpp index cafd61cff40..4f6e5a01b62 100644 --- a/src/hotspot/cpu/aarch64/templateInterpreterGenerator_aarch64.cpp +++ b/src/hotspot/cpu/aarch64/templateInterpreterGenerator_aarch64.cpp @@ -812,7 +812,8 @@ void TemplateInterpreterGenerator::lock_method() { __ check_extended_sp(); __ sub(sp, sp, entry_size); // add space for a monitor entry __ sub(esp, esp, entry_size); - __ mov(rscratch1, sp); + __ sub(rscratch1, sp, rfp); + __ asr(rscratch1, rscratch1, Interpreter::logStackElementSize); __ str(rscratch1, Address(rfp, frame::interpreter_frame_extended_sp_offset * wordSize)); __ str(esp, monitor_block_top); // set new monitor block top // store object @@ -880,15 +881,19 @@ void TemplateInterpreterGenerator::generate_fixed_frame(bool native_call) { __ add(rscratch1, rscratch1, MAX2(3, Method::extra_stack_entries())); __ sub(rscratch1, sp, rscratch1, ext::uxtw, 3); __ andr(rscratch1, rscratch1, -16); + __ sub(rscratch2, rscratch1, rfp); + __ asr(rscratch2, rscratch2, Interpreter::logStackElementSize); // Store extended SP and mirror - __ stp(r10, rscratch1, Address(sp, 4 * wordSize)); + __ stp(r10, rscratch2, Address(sp, 4 * wordSize)); // Move SP out of the way __ mov(sp, rscratch1); } else { // Make sure there is room for the exception oop pushed in case method throws // an exception (see TemplateInterpreterGenerator::generate_throw_exception()) __ sub(rscratch1, sp, 2 * wordSize); - __ stp(r10, rscratch1, Address(sp, 4 * wordSize)); + __ sub(rscratch2, rscratch1, rfp); + __ asr(rscratch2, rscratch2, Interpreter::logStackElementSize); + __ stp(r10, rscratch2, Address(sp, 4 * wordSize)); __ mov(sp, rscratch1); } } diff --git a/src/hotspot/cpu/aarch64/templateTable_aarch64.cpp b/src/hotspot/cpu/aarch64/templateTable_aarch64.cpp index 3fed9c33033..d1cdbe4fd43 100644 --- a/src/hotspot/cpu/aarch64/templateTable_aarch64.cpp +++ b/src/hotspot/cpu/aarch64/templateTable_aarch64.cpp @@ -3910,7 +3910,8 @@ void TemplateTable::monitorenter() __ check_extended_sp(); __ sub(sp, sp, entry_size); // make room for the monitor - __ mov(rscratch1, sp); + __ sub(rscratch1, sp, rfp); + __ asr(rscratch1, rscratch1, Interpreter::logStackElementSize); __ str(rscratch1, Address(rfp, frame::interpreter_frame_extended_sp_offset * wordSize)); __ ldr(c_rarg1, monitor_block_bot); // c_rarg1: old expression stack bottom diff --git a/src/hotspot/cpu/riscv/continuationFreezeThaw_riscv.inline.hpp b/src/hotspot/cpu/riscv/continuationFreezeThaw_riscv.inline.hpp index c581871fd8e..042b43bca7d 100644 --- a/src/hotspot/cpu/riscv/continuationFreezeThaw_riscv.inline.hpp +++ b/src/hotspot/cpu/riscv/continuationFreezeThaw_riscv.inline.hpp @@ -151,11 +151,14 @@ inline void FreezeBase::relativize_interpreted_frame_metadata(const frame& f, co assert((intptr_t*)hf.at_relative(frame::interpreter_frame_last_sp_offset) == hf.unextended_sp(), ""); relativize_one(vfp, hfp, frame::interpreter_frame_initial_sp_offset); // == block_top == block_bottom - relativize_one(vfp, hfp, frame::interpreter_frame_extended_sp_offset); + + // extended_sp is already relativized by TemplateInterpreterGenerator::generate_normal_entry or + // AbstractInterpreter::layout_activation assert((hf.fp() - hf.unextended_sp()) == (f.fp() - f.unextended_sp()), ""); assert(hf.unextended_sp() == (intptr_t*)hf.at(frame::interpreter_frame_last_sp_offset), ""); assert(hf.unextended_sp() <= (intptr_t*)hf.at(frame::interpreter_frame_initial_sp_offset), ""); + assert(hf.unextended_sp() > (intptr_t*)hf.at(frame::interpreter_frame_extended_sp_offset), ""); assert(hf.fp() > (intptr_t*)hf.at(frame::interpreter_frame_initial_sp_offset), ""); #ifdef ASSERT if (f.interpreter_frame_method()->max_locals() > 0) { @@ -296,7 +299,9 @@ inline void ThawBase::derelativize_interpreted_frame_metadata(const frame& hf, c assert((intptr_t*)f.at_relative(frame::interpreter_frame_last_sp_offset) == f.unextended_sp(), ""); derelativize_one(vfp, frame::interpreter_frame_initial_sp_offset); - derelativize_one(vfp, frame::interpreter_frame_extended_sp_offset); + + // Make sure that extended_sp is kept relativized. + assert((intptr_t*)f.at_relative(frame::interpreter_frame_extended_sp_offset) < f.unextended_sp(), ""); } #endif // CPU_RISCV_CONTINUATIONFREEZETHAW_RISCV_INLINE_HPP diff --git a/src/hotspot/cpu/riscv/frame_riscv.cpp b/src/hotspot/cpu/riscv/frame_riscv.cpp index e91b722bd02..a1738eb4517 100644 --- a/src/hotspot/cpu/riscv/frame_riscv.cpp +++ b/src/hotspot/cpu/riscv/frame_riscv.cpp @@ -337,7 +337,9 @@ void frame::interpreter_frame_set_last_sp(intptr_t* last_sp) { } void frame::interpreter_frame_set_extended_sp(intptr_t* sp) { - *((intptr_t**)addr_at(interpreter_frame_extended_sp_offset)) = sp; + assert(is_interpreted_frame(), "interpreted frame expected"); + // set relativized extended_sp + ptr_at_put(interpreter_frame_extended_sp_offset, (sp - fp())); } frame frame::sender_for_entry_frame(RegisterMap* map) const { diff --git a/src/hotspot/cpu/riscv/interp_masm_riscv.hpp b/src/hotspot/cpu/riscv/interp_masm_riscv.hpp index 9b004cb081b..8926d608bfb 100644 --- a/src/hotspot/cpu/riscv/interp_masm_riscv.hpp +++ b/src/hotspot/cpu/riscv/interp_masm_riscv.hpp @@ -85,6 +85,7 @@ class InterpreterMacroAssembler: public MacroAssembler { void restore_sp_after_call() { Label L; ld(t0, Address(fp, frame::interpreter_frame_extended_sp_offset * wordSize)); + shadd(t0, t0, fp, t0, LogBytesPerWord); #ifdef ASSERT bnez(t0, L); stop("SP is null"); @@ -97,6 +98,7 @@ class InterpreterMacroAssembler: public MacroAssembler { #ifdef ASSERT Label L; ld(t0, Address(fp, frame::interpreter_frame_extended_sp_offset * wordSize)); + shadd(t0, t0, fp, t0, LogBytesPerWord); beq(sp, t0, L); stop(msg); bind(L); diff --git a/src/hotspot/cpu/riscv/templateInterpreterGenerator_riscv.cpp b/src/hotspot/cpu/riscv/templateInterpreterGenerator_riscv.cpp index 1e4730e4275..f7c7fbfb07b 100644 --- a/src/hotspot/cpu/riscv/templateInterpreterGenerator_riscv.cpp +++ b/src/hotspot/cpu/riscv/templateInterpreterGenerator_riscv.cpp @@ -710,7 +710,9 @@ void TemplateInterpreterGenerator::lock_method() { __ check_extended_sp(); __ add(sp, sp, - entry_size); // add space for a monitor entry __ add(esp, esp, - entry_size); - __ sd(sp, Address(fp, frame::interpreter_frame_extended_sp_offset * wordSize)); + __ sub(t0, sp, fp); + __ srai(t0, t0, Interpreter::logStackElementSize); + __ sd(t0, Address(fp, frame::interpreter_frame_extended_sp_offset * wordSize)); __ sd(esp, monitor_block_top); // set new monitor block top // store object __ sd(x10, Address(esp, BasicObjectLock::obj_offset())); @@ -785,15 +787,19 @@ void TemplateInterpreterGenerator::generate_fixed_frame(bool native_call) { __ slli(t0, t0, 3); __ sub(t0, sp, t0); __ andi(t0, t0, -16); + __ sub(t1, t0, fp); + __ srai(t1, t1, Interpreter::logStackElementSize); // Store extended SP - __ sd(t0, Address(sp, 5 * wordSize)); + __ sd(t1, Address(sp, 5 * wordSize)); // Move SP out of the way __ mv(sp, t0); } else { // Make sure there is room for the exception oop pushed in case method throws // an exception (see TemplateInterpreterGenerator::generate_throw_exception()) __ sub(t0, sp, 2 * wordSize); - __ sd(t0, Address(sp, 5 * wordSize)); + __ sub(t1, t0, fp); + __ srai(t1, t1, Interpreter::logStackElementSize); + __ sd(t1, Address(sp, 5 * wordSize)); __ mv(sp, t0); } } diff --git a/src/hotspot/cpu/riscv/templateTable_riscv.cpp b/src/hotspot/cpu/riscv/templateTable_riscv.cpp index c2ab9cc1d6d..c2c826b6c32 100644 --- a/src/hotspot/cpu/riscv/templateTable_riscv.cpp +++ b/src/hotspot/cpu/riscv/templateTable_riscv.cpp @@ -3844,7 +3844,9 @@ void TemplateTable::monitorenter() { __ check_extended_sp(); __ sub(sp, sp, entry_size); // make room for the monitor - __ sd(sp, Address(fp, frame::interpreter_frame_extended_sp_offset * wordSize)); + __ sub(t0, sp, fp); + __ srai(t0, t0, Interpreter::logStackElementSize); + __ sd(t0, Address(fp, frame::interpreter_frame_extended_sp_offset * wordSize)); __ ld(c_rarg1, monitor_block_bot); // c_rarg1: old expression stack bottom __ sub(esp, esp, entry_size); // move expression stack top