Skip to content

Commit 6600161

Browse files
committed
8338379: Accesses to class init state should be properly synchronized
Reviewed-by: mdoerr, dholmes, coleenp, fyang, amitkumar
1 parent 20f36c6 commit 6600161

17 files changed

+32
-17
lines changed

src/hotspot/cpu/aarch64/c1_LIRAssembler_aarch64.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1168,8 +1168,8 @@ void LIR_Assembler::emit_opConvert(LIR_OpConvert* op) {
11681168

11691169
void LIR_Assembler::emit_alloc_obj(LIR_OpAllocObj* op) {
11701170
if (op->init_check()) {
1171-
__ ldrb(rscratch1, Address(op->klass()->as_register(),
1172-
InstanceKlass::init_state_offset()));
1171+
__ lea(rscratch1, Address(op->klass()->as_register(), InstanceKlass::init_state_offset()));
1172+
__ ldarb(rscratch1, rscratch1);
11731173
__ cmpw(rscratch1, InstanceKlass::fully_initialized);
11741174
add_debug_info_for_null_check_here(op->stub()->info());
11751175
__ br(Assembler::NE, *op->stub()->entry());

src/hotspot/cpu/aarch64/macroAssembler_aarch64.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1838,7 +1838,8 @@ void MacroAssembler::clinit_barrier(Register klass, Register scratch, Label* L_f
18381838
L_slow_path = &L_fallthrough;
18391839
}
18401840
// Fast path check: class is fully initialized
1841-
ldrb(scratch, Address(klass, InstanceKlass::init_state_offset()));
1841+
lea(scratch, Address(klass, InstanceKlass::init_state_offset()));
1842+
ldarb(scratch, scratch);
18421843
subs(zr, scratch, InstanceKlass::fully_initialized);
18431844
br(Assembler::EQ, *L_fast_path);
18441845

src/hotspot/cpu/arm/c1_LIRAssembler_arm.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -948,6 +948,7 @@ void LIR_Assembler::emit_alloc_obj(LIR_OpAllocObj* op) {
948948
if (op->init_check()) {
949949
Register tmp = op->tmp1()->as_register();
950950
__ ldrb(tmp, Address(op->klass()->as_register(), InstanceKlass::init_state_offset()));
951+
__ membar(MacroAssembler::Membar_mask_bits(MacroAssembler::LoadLoad | MacroAssembler::LoadStore), Rtemp);
951952
add_debug_info_for_null_check_here(op->stub()->info());
952953
__ cmp(tmp, InstanceKlass::fully_initialized);
953954
__ b(*op->stub()->entry(), ne);

src/hotspot/cpu/arm/templateTable_arm.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3974,6 +3974,7 @@ void TemplateTable::_new() {
39743974
// make sure klass is initialized
39753975
// make sure klass is fully initialized
39763976
__ ldrb(Rtemp, Address(Rklass, InstanceKlass::init_state_offset()));
3977+
__ membar(MacroAssembler::Membar_mask_bits(MacroAssembler::LoadLoad | MacroAssembler::LoadStore), Rtemp);
39773978
__ cmp(Rtemp, InstanceKlass::fully_initialized);
39783979
__ b(slow_case, ne);
39793980

src/hotspot/cpu/ppc/c1_LIRAssembler_ppc.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2274,6 +2274,7 @@ void LIR_Assembler::emit_alloc_obj(LIR_OpAllocObj* op) {
22742274
}
22752275
__ lbz(op->tmp1()->as_register(),
22762276
in_bytes(InstanceKlass::init_state_offset()), op->klass()->as_register());
2277+
// acquire barrier included in membar_storestore() which follows the allocation immediately.
22772278
__ cmpwi(CCR0, op->tmp1()->as_register(), InstanceKlass::fully_initialized);
22782279
__ bc_far_optimized(Assembler::bcondCRbiIs0, __ bi0(CCR0, Assembler::equal), *op->stub()->entry());
22792280
}

src/hotspot/cpu/ppc/macroAssembler_ppc.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2410,7 +2410,7 @@ void MacroAssembler::verify_secondary_supers_table(Register r_sub_klass,
24102410
void MacroAssembler::clinit_barrier(Register klass, Register thread, Label* L_fast_path, Label* L_slow_path) {
24112411
assert(L_fast_path != nullptr || L_slow_path != nullptr, "at least one is required");
24122412

2413-
Label L_fallthrough;
2413+
Label L_check_thread, L_fallthrough;
24142414
if (L_fast_path == nullptr) {
24152415
L_fast_path = &L_fallthrough;
24162416
} else if (L_slow_path == nullptr) {
@@ -2419,10 +2419,14 @@ void MacroAssembler::clinit_barrier(Register klass, Register thread, Label* L_fa
24192419

24202420
// Fast path check: class is fully initialized
24212421
lbz(R0, in_bytes(InstanceKlass::init_state_offset()), klass);
2422+
// acquire by cmp-branch-isync if fully_initialized
24222423
cmpwi(CCR0, R0, InstanceKlass::fully_initialized);
2423-
beq(CCR0, *L_fast_path);
2424+
bne(CCR0, L_check_thread);
2425+
isync();
2426+
b(*L_fast_path);
24242427

24252428
// Fast path check: current thread is initializer thread
2429+
bind(L_check_thread);
24262430
ld(R0, in_bytes(InstanceKlass::init_thread_offset()), klass);
24272431
cmpd(CCR0, thread, R0);
24282432
if (L_slow_path == &L_fallthrough) {

src/hotspot/cpu/riscv/c1_LIRAssembler_riscv.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -980,6 +980,7 @@ void LIR_Assembler::emit_alloc_obj(LIR_OpAllocObj* op) {
980980
if (op->init_check()) {
981981
__ lbu(t0, Address(op->klass()->as_register(),
982982
InstanceKlass::init_state_offset()));
983+
__ membar(MacroAssembler::LoadLoad | MacroAssembler::LoadStore);
983984
__ mv(t1, (u1)InstanceKlass::fully_initialized);
984985
add_debug_info_for_null_check_here(op->stub()->info());
985986
__ bne(t0, t1, *op->stub()->entry(), /* is_far */ true);

src/hotspot/cpu/riscv/macroAssembler_riscv.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -493,6 +493,7 @@ void MacroAssembler::clinit_barrier(Register klass, Register tmp, Label* L_fast_
493493

494494
// Fast path check: class is fully initialized
495495
lbu(tmp, Address(klass, InstanceKlass::init_state_offset()));
496+
membar(MacroAssembler::LoadLoad | MacroAssembler::LoadStore);
496497
sub(tmp, tmp, InstanceKlass::fully_initialized);
497498
beqz(tmp, *L_fast_path);
498499

src/hotspot/cpu/s390/c1_LIRAssembler_s390.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2350,6 +2350,7 @@ void LIR_Assembler::shift_op(LIR_Code code, LIR_Opr left, jint count, LIR_Opr de
23502350
void LIR_Assembler::emit_alloc_obj(LIR_OpAllocObj* op) {
23512351
if (op->init_check()) {
23522352
// Make sure klass is initialized & doesn't have finalizer.
2353+
// init_state needs acquire, but S390 is TSO, and so we are already good.
23532354
const int state_offset = in_bytes(InstanceKlass::init_state_offset());
23542355
Register iklass = op->klass()->as_register();
23552356
add_debug_info_for_null_check_here(op->stub()->info());

src/hotspot/cpu/s390/macroAssembler_s390.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3459,7 +3459,8 @@ void MacroAssembler::clinit_barrier(Register klass, Register thread, Label* L_fa
34593459
L_slow_path = &L_fallthrough;
34603460
}
34613461

3462-
// Fast path check: class is fully initialized
3462+
// Fast path check: class is fully initialized.
3463+
// init_state needs acquire, but S390 is TSO, and so we are already good.
34633464
z_cli(Address(klass, InstanceKlass::init_state_offset()), InstanceKlass::fully_initialized);
34643465
z_bre(*L_fast_path);
34653466

0 commit comments

Comments
 (0)