Skip to content

Commit 5df7089

Browse files
committed
8350398: [s390x] Relativize initial_sp/monitors in interpreter frames
Reviewed-by: lucy, aph
1 parent 2c1eb33 commit 5df7089

File tree

5 files changed

+43
-16
lines changed

5 files changed

+43
-16
lines changed

src/hotspot/cpu/s390/frame_s390.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -498,8 +498,6 @@
498498

499499
inline z_ijava_state* ijava_state() const;
500500

501-
// Where z_ijava_state.monitors is saved.
502-
inline BasicObjectLock** interpreter_frame_monitors_addr() const;
503501
// Where z_ijava_state.esp is saved.
504502
inline intptr_t** interpreter_frame_esp_addr() const;
505503

@@ -517,6 +515,8 @@
517515
// Next two functions read and write z_ijava_state.monitors.
518516
private:
519517
inline BasicObjectLock* interpreter_frame_monitors() const;
518+
519+
// Where z_ijava_state.monitors is saved.
520520
inline void interpreter_frame_set_monitors(BasicObjectLock* monitors);
521521

522522
public:

src/hotspot/cpu/s390/frame_s390.inline.hpp

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -109,16 +109,19 @@ inline frame::z_ijava_state* frame::ijava_state() const {
109109
return state;
110110
}
111111

112-
inline BasicObjectLock** frame::interpreter_frame_monitors_addr() const {
113-
return (BasicObjectLock**) &(ijava_state()->monitors);
114-
}
115-
116112
// The next two functions read and write z_ijava_state.monitors.
117113
inline BasicObjectLock* frame::interpreter_frame_monitors() const {
118-
return *interpreter_frame_monitors_addr();
114+
BasicObjectLock* result = (BasicObjectLock*) at_relative(_z_ijava_idx(monitors));
115+
// make sure the pointer points inside the frame
116+
assert(sp() <= (intptr_t*) result, "monitor end should be above the stack pointer");
117+
assert((intptr_t*) result < fp(), "monitor end should be strictly below the frame pointer: result: " INTPTR_FORMAT " fp: " INTPTR_FORMAT, p2i(result), p2i(fp()));
118+
return result;
119119
}
120+
120121
inline void frame::interpreter_frame_set_monitors(BasicObjectLock* monitors) {
121-
*interpreter_frame_monitors_addr() = monitors;
122+
assert(is_interpreted_frame(), "interpreted frame expected");
123+
// set relativized monitors
124+
ijava_state()->monitors = (intptr_t) ((intptr_t*)monitors - fp());
122125
}
123126

124127
// Accessors

src/hotspot/cpu/s390/interp_masm_s390.cpp

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -627,7 +627,7 @@ void InterpreterMacroAssembler::verify_esp(Register Resp, Register Rtemp) {
627627
// i.e. IJAVA_STATE.monitors > Resp.
628628
NearLabel OK;
629629
Register Rmonitors = Rtemp;
630-
z_lg(Rmonitors, _z_ijava_state_neg(monitors), Z_fp);
630+
get_monitors(Rmonitors);
631631
compareU64_and_branch(Rmonitors, Resp, bcondHigh, OK);
632632
reentry = stop_chain_static(reentry, "too many pops: Z_esp points into monitor area");
633633
bind(OK);
@@ -676,10 +676,28 @@ void InterpreterMacroAssembler::restore_esp() {
676676

677677
void InterpreterMacroAssembler::get_monitors(Register reg) {
678678
asm_assert_ijava_state_magic(reg);
679+
#ifdef ASSERT
680+
NearLabel ok;
681+
z_cg(Z_fp, 0, Z_SP);
682+
z_bre(ok);
683+
stop("Z_fp is corrupted");
684+
bind(ok);
685+
#endif // ASSERT
679686
mem2reg_opt(reg, Address(Z_fp, _z_ijava_state_neg(monitors)));
687+
z_slag(reg, reg, Interpreter::logStackElementSize);
688+
z_agr(reg, Z_fp);
680689
}
681690

682691
void InterpreterMacroAssembler::save_monitors(Register reg) {
692+
#ifdef ASSERT
693+
NearLabel ok;
694+
z_cg(Z_fp, 0, Z_SP);
695+
z_bre(ok);
696+
stop("Z_fp is corrupted");
697+
bind(ok);
698+
#endif // ASSERT
699+
z_sgr(reg, Z_fp);
700+
z_srag(reg, reg, Interpreter::logStackElementSize);
683701
reg2mem_opt(reg, Address(Z_fp, _z_ijava_state_neg(monitors)));
684702
}
685703

@@ -840,12 +858,11 @@ void InterpreterMacroAssembler::unlock_if_synchronized_method(TosState state,
840858
// register for unlock_object to pass to VM directly.
841859
Register R_current_monitor = Z_ARG2;
842860
Register R_monitor_block_bot = Z_ARG1;
843-
const Address monitor_block_top(Z_fp, _z_ijava_state_neg(monitors));
844861
const Address monitor_block_bot(Z_fp, -frame::z_ijava_state_size);
845862

846863
bind(restart);
847864
// Starting with top-most entry.
848-
z_lg(R_current_monitor, monitor_block_top);
865+
get_monitors(R_current_monitor);
849866
// Points to word before bottom of monitor block.
850867
load_address(R_monitor_block_bot, monitor_block_bot);
851868
z_bru(entry);

src/hotspot/cpu/s390/templateInterpreterGenerator_s390.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1174,7 +1174,11 @@ void TemplateInterpreterGenerator::generate_fixed_frame(bool native_call) {
11741174
// z_ijava_state->monitors = fp - frame::z_ijava_state_size - Interpreter::stackElementSize;
11751175
// z_ijava_state->esp = Z_esp = z_ijava_state->monitors;
11761176
__ add2reg(Z_esp, -frame::z_ijava_state_size, fp);
1177-
__ z_stg(Z_esp, _z_ijava_state_neg(monitors), fp);
1177+
1178+
__ z_sgrk(Z_R0, Z_esp, fp);
1179+
__ z_srag(Z_R0, Z_R0, Interpreter::logStackElementSize);
1180+
__ z_stg(Z_R0, _z_ijava_state_neg(monitors), fp);
1181+
11781182
__ add2reg(Z_esp, -Interpreter::stackElementSize);
11791183
__ z_stg(Z_esp, _z_ijava_state_neg(esp), fp);
11801184

@@ -1633,7 +1637,7 @@ address TemplateInterpreterGenerator::generate_native_entry(bool synchronized) {
16331637
__ add2reg(Rfirst_monitor, -(frame::z_ijava_state_size + (int)sizeof(BasicObjectLock)), Z_fp);
16341638
#ifdef ASSERT
16351639
NearLabel ok;
1636-
__ z_lg(Z_R1, _z_ijava_state_neg(monitors), Z_fp);
1640+
__ get_monitors(Z_R1);
16371641
__ compareU64_and_branch(Rfirst_monitor, Z_R1, Assembler::bcondEqual, ok);
16381642
reentry = __ stop_chain_static(reentry, "native_entry:unlock: inconsistent z_ijava_state.monitors");
16391643
__ bind(ok);

src/hotspot/cpu/s390/templateTable_s390.cpp

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,8 @@
6565
// The actual size of each block heavily depends on the CPU capabilities and,
6666
// of course, on the logic implemented in each block.
6767
#ifdef ASSERT
68-
#define BTB_MINSIZE 256
68+
// With introduced assert in get_monitor() & set_monitor(), required block size is now 322.
69+
#define BTB_MINSIZE 512
6970
#else
7071
#define BTB_MINSIZE 64
7172
#endif
@@ -91,7 +92,8 @@
9192
if (len > alignment) { \
9293
tty->print_cr("%4d of %4d @ " INTPTR_FORMAT ": Block len for %s", \
9394
len, alignment, e_addr-len, name); \
94-
guarantee(len <= alignment, "block too large"); \
95+
guarantee(len <= alignment, "block too large, len = %d, alignment = %d", \
96+
len, alignment); \
9597
} \
9698
guarantee(len == e_addr-b_addr, "block len mismatch"); \
9799
}
@@ -112,7 +114,8 @@
112114
if (len > alignment) { \
113115
tty->print_cr("%4d of %4d @ " INTPTR_FORMAT ": Block len for %s", \
114116
len, alignment, e_addr-len, name); \
115-
guarantee(len <= alignment, "block too large"); \
117+
guarantee(len <= alignment, "block too large, len = %d, alignment = %d", \
118+
len, alignment); \
116119
} \
117120
guarantee(len == e_addr-b_addr, "block len mismatch"); \
118121
}

0 commit comments

Comments
 (0)