Skip to content

Commit 064cc92

Browse files
committed
8384223: RISC-V: entry_barrier_offset should consider UseZtso
Backport-of: 776bb72
1 parent 19f1136 commit 064cc92

2 files changed

Lines changed: 22 additions & 20 deletions

File tree

src/hotspot/cpu/riscv/gc/shared/barrierSetAssembler_riscv.cpp

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,7 @@ void BarrierSetAssembler::nmethod_entry_barrier(MacroAssembler* masm, Label* slo
228228
BarrierSetNMethod* bs_nm = BarrierSet::barrier_set()->barrier_set_nmethod();
229229
Assembler::IncompressibleScope scope(masm); // Fixed length: see entry_barrier_offset()
230230

231-
Label local_guard;
231+
Label local_guard, skip_barrier;
232232
NMethodPatchingType patching_type = nmethod_patching_type();
233233

234234
if (slow_path == nullptr) {
@@ -290,24 +290,26 @@ void BarrierSetAssembler::nmethod_entry_barrier(MacroAssembler* masm, Label* slo
290290
ShouldNotReachHere();
291291
}
292292

293+
Label& barrier_target = slow_path == nullptr ? skip_barrier : *slow_path;
293294
if (slow_path == nullptr) {
294-
Label skip_barrier;
295-
__ beq(t0, t1, skip_barrier);
295+
__ beq(t0, t1, barrier_target, true /* is_far */);
296+
} else {
297+
__ bne(t0, t1, barrier_target, true /* is_far */);
298+
}
296299

300+
if (slow_path == nullptr) {
297301
__ rt_call(StubRoutines::method_entry_barrier());
298-
299302
__ j(skip_barrier);
300303

301304
__ bind(local_guard);
302305

303306
MacroAssembler::assert_alignment(__ pc());
304307
__ emit_int32(0); // nmethod guard value. Skipped over in common case.
305-
__ bind(skip_barrier);
306308
} else {
307-
__ beq(t0, t1, *continuation);
308-
__ j(*slow_path);
309309
__ bind(*continuation);
310310
}
311+
312+
__ bind(skip_barrier);
311313
}
312314

313315
void BarrierSetAssembler::c2i_entry_barrier(MacroAssembler* masm) {

src/hotspot/cpu/riscv/gc/shared/barrierSetNMethod_riscv.cpp

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2018, 2025, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2018, 2026, Oracle and/or its affiliates. All rights reserved.
33
* Copyright (c) 2020, 2022, Huawei Technologies Co., Ltd. All rights reserved.
44
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
55
*
@@ -41,17 +41,16 @@
4141

4242
static int slow_path_size(nmethod* nm) {
4343
// The slow path code is out of line with C2.
44-
// Leave a jal to the stub in the fast path.
45-
return nm->is_compiled_by_c2() ? 1 : 8;
44+
return nm->is_compiled_by_c2() ? 0 : 4;
4645
}
4746

4847
static int entry_barrier_offset(nmethod* nm) {
4948
BarrierSetAssembler* bs_asm = BarrierSet::barrier_set()->barrier_set_assembler();
5049
switch (bs_asm->nmethod_patching_type()) {
5150
case NMethodPatchingType::stw_instruction_and_data_patch:
52-
return -4 * (4 + slow_path_size(nm));
51+
return -4 * (5 + slow_path_size(nm));
5352
case NMethodPatchingType::conc_instruction_and_data_patch:
54-
return -4 * (15 + slow_path_size(nm));
53+
return -4 * ((UseZtso ? 14 : 16) + slow_path_size(nm));
5554
}
5655
ShouldNotReachHere();
5756
return 0;
@@ -103,6 +102,10 @@ class NativeNMethodBarrier {
103102
}
104103
_guard_addr = reinterpret_cast<int*>(instruction_address() + local_guard_offset(nm));
105104
}
105+
106+
// Perform the checking as verification.
107+
err_msg msg("%s", "");
108+
assert(check_barrier(msg), "%s", msg.buffer());
106109
}
107110

108111
int get_value() {
@@ -114,10 +117,6 @@ class NativeNMethodBarrier {
114117
}
115118

116119
bool check_barrier(err_msg& msg) const;
117-
void verify() const {
118-
err_msg msg("%s", "");
119-
assert(check_barrier(msg), "%s", msg.buffer());
120-
}
121120
};
122121

123122
// Store the instruction bitmask, bits and name for checking the barrier.
@@ -128,8 +127,8 @@ struct CheckInsn {
128127
};
129128

130129
static const struct CheckInsn barrierInsn[] = {
131-
{ 0x00000fff, 0x00000297, "auipc t0, 0 "},
132-
{ 0x000fffff, 0x0002e283, "lwu t0, guard_offset(t0) "},
130+
{ 0x00000fff, 0x00000297, "auipc t0, 0 " },
131+
{ 0x000fffff, 0x0002e283, "lwu t0, guard_offset(t0)" },
133132
/* ...... */
134133
/* ...... */
135134
/* guard: */
@@ -141,10 +140,11 @@ static const struct CheckInsn barrierInsn[] = {
141140
// register numbers and immediate values in the encoding.
142141
bool NativeNMethodBarrier::check_barrier(err_msg& msg) const {
143142
address addr = instruction_address();
144-
for(unsigned int i = 0; i < sizeof(barrierInsn)/sizeof(struct CheckInsn); i++ ) {
143+
for (unsigned int i = 0; i < sizeof(barrierInsn) / sizeof(struct CheckInsn); i++) {
145144
uint32_t inst = Assembler::ld_instr(addr);
146145
if ((inst & barrierInsn[i].mask) != barrierInsn[i].bits) {
147-
msg.print("Addr: " INTPTR_FORMAT " Code: 0x%x not an %s instruction", p2i(addr), inst, barrierInsn[i].name);
146+
msg.print("Nmethod entry barrier did not start with auipc & lwu as expected. "
147+
"Addr: " INTPTR_FORMAT " Code: 0x%x not an %s instruction.", p2i(addr), inst, barrierInsn[i].name);
148148
return false;
149149
}
150150
addr += 4;

0 commit comments

Comments
 (0)