Skip to content

Commit 5b3ae92

Browse files
committed
8350182: [s390x] Relativize locals in interpreter frames
Reviewed-by: lucy, rrich
1 parent 03f0ec4 commit 5b3ae92

File tree

5 files changed

+27
-7
lines changed

5 files changed

+27
-7
lines changed

src/hotspot/cpu/s390/frame_s390.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,8 @@ bool frame::is_interpreted_frame() const {
185185

186186
void frame::interpreter_frame_set_locals(intptr_t* locs) {
187187
assert(is_interpreted_frame(), "interpreted frame expected");
188-
ijava_state_unchecked()->locals = (uint64_t)locs;
188+
// set relativized locals
189+
*addr_at(_z_ijava_idx(locals)) = (intptr_t) (locs - fp());
189190
}
190191

191192
// sender_sp
@@ -340,7 +341,7 @@ bool frame::is_interpreted_frame_valid(JavaThread* thread) const {
340341
if (MetaspaceObj::is_valid(cp) == false) return false;
341342

342343
// validate locals
343-
address locals = (address)(ijava_state_unchecked()->locals);
344+
address locals = (address)interpreter_frame_locals();
344345
return thread->is_in_stack_range_incl(locals, (address)fp());
345346
}
346347

src/hotspot/cpu/s390/frame_s390.hpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2016, 2024, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2016, 2025, Oracle and/or its affiliates. All rights reserved.
33
* Copyright (c) 2016, 2024 SAP SE. All rights reserved.
44
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
55
*
@@ -330,6 +330,10 @@
330330
#define _z_ijava_state_neg(_component) \
331331
(int) (-frame::z_ijava_state_size + offset_of(frame::z_ijava_state, _component))
332332

333+
// Frame slot index relative to fp
334+
#define _z_ijava_idx(_component) \
335+
(_z_ijava_state_neg(_component) >> LogBytesPerWord)
336+
333337
// ENTRY_FRAME
334338

335339
struct z_entry_frame_locals {

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2016, 2024, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2016, 2025, Oracle and/or its affiliates. All rights reserved.
33
* Copyright (c) 2016, 2024 SAP SE. All rights reserved.
44
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
55
*
@@ -180,7 +180,8 @@ inline intptr_t* frame::link_or_null() const {
180180
}
181181

182182
inline intptr_t* frame::interpreter_frame_locals() const {
183-
return (intptr_t*) (ijava_state()->locals);
183+
intptr_t n = *addr_at(_z_ijava_idx(locals));
184+
return &fp()[n]; // return relativized locals
184185
}
185186

186187
inline intptr_t* frame::interpreter_frame_bcp_addr() const {

src/hotspot/cpu/s390/interp_masm_s390.cpp

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,15 @@ void InterpreterMacroAssembler::dispatch_base(TosState state, address* table, bo
104104
}
105105
{ Label OK;
106106
// check if the locals pointer in Z_locals is correct
107-
z_cg(Z_locals, _z_ijava_state_neg(locals), Z_fp);
107+
108+
// _z_ijava_state_neg(locals)) is fp relativized, so we need to
109+
// extract the pointer.
110+
111+
z_lg(Z_R1_scratch, Address(Z_fp, _z_ijava_state_neg(locals)));
112+
z_sllg(Z_R1_scratch, Z_R1_scratch, Interpreter::logStackElementSize);
113+
z_agr(Z_R1_scratch, Z_fp);
114+
115+
z_cgr(Z_locals, Z_R1_scratch);
108116
z_bre(OK);
109117
reentry = stop_chain_static(reentry, "invalid locals pointer Z_locals: " FILE_AND_LINE);
110118
bind(OK);
@@ -684,6 +692,8 @@ void InterpreterMacroAssembler::save_mdp(Register mdp) {
684692
void InterpreterMacroAssembler::restore_locals() {
685693
asm_assert_ijava_state_magic(Z_locals);
686694
z_lg(Z_locals, Address(Z_fp, _z_ijava_state_neg(locals)));
695+
z_sllg(Z_locals, Z_locals, Interpreter::logStackElementSize);
696+
z_agr(Z_locals, Z_fp);
687697
}
688698

689699
void InterpreterMacroAssembler::get_method(Register reg) {

src/hotspot/cpu/s390/templateInterpreterGenerator_s390.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1134,7 +1134,11 @@ void TemplateInterpreterGenerator::generate_fixed_frame(bool native_call) {
11341134
__ z_agr(Z_locals, Z_esp);
11351135
// z_ijava_state->locals - i*BytesPerWord points to i-th Java local (i starts at 0)
11361136
// z_ijava_state->locals = Z_esp + parameter_count bytes
1137-
__ z_stg(Z_locals, _z_ijava_state_neg(locals), fp);
1137+
1138+
__ z_sgrk(Z_R0, Z_locals, fp); // Z_R0 = Z_locals - fp();
1139+
__ z_srlg(Z_R0, Z_R0, Interpreter::logStackElementSize);
1140+
// Store relativized Z_locals, see frame::interpreter_frame_locals().
1141+
__ z_stg(Z_R0, _z_ijava_state_neg(locals), fp);
11381142

11391143
// z_ijava_state->oop_temp = nullptr;
11401144
__ store_const(Address(fp, oop_tmp_offset), 0);

0 commit comments

Comments
 (0)