Skip to content

Commit e56002c

Browse files
committedAug 21, 2020
8242263: Diagnose synchronization on primitive wrappers
Added diagnostic flag DiagnoseSyncOnPrimitiveWrappers Reviewed-by: dholmes, mdoerr, dcubed, coleenp, egahlin, mgronlun
1 parent fac22ce commit e56002c

36 files changed

+528
-88
lines changed
 

‎src/hotspot/cpu/aarch64/aarch64.ad

+7
Original file line numberDiff line numberDiff line change
@@ -3511,6 +3511,13 @@ encode %{
35113511
// Load markWord from object into displaced_header.
35123512
__ ldr(disp_hdr, Address(oop, oopDesc::mark_offset_in_bytes()));
35133513

3514+
if (DiagnoseSyncOnPrimitiveWrappers != 0) {
3515+
__ load_klass(tmp, oop);
3516+
__ ldrw(tmp, Address(tmp, Klass::access_flags_offset()));
3517+
__ tstw(tmp, JVM_ACC_IS_BOX_CLASS);
3518+
__ br(Assembler::NE, cont);
3519+
}
3520+
35143521
if (UseBiasedLocking && !UseOptoBiasInlining) {
35153522
__ biased_locking_enter(box, oop, disp_hdr, tmp, true, cont);
35163523
}

‎src/hotspot/cpu/aarch64/c1_MacroAssembler_aarch64.cpp

+11-4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 1999, 2018, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 1999, 2020, Oracle and/or its affiliates. All rights reserved.
33
* Copyright (c) 2014, Red Hat Inc. All rights reserved.
44
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
55
*
@@ -73,11 +73,18 @@ int C1_MacroAssembler::lock_object(Register hdr, Register obj, Register disp_hdr
7373
// save object being locked into the BasicObjectLock
7474
str(obj, Address(disp_hdr, BasicObjectLock::obj_offset_in_bytes()));
7575

76+
null_check_offset = offset();
77+
78+
if (DiagnoseSyncOnPrimitiveWrappers != 0) {
79+
load_klass(hdr, obj);
80+
ldrw(hdr, Address(hdr, Klass::access_flags_offset()));
81+
tstw(hdr, JVM_ACC_IS_BOX_CLASS);
82+
br(Assembler::NE, slow_case);
83+
}
84+
7685
if (UseBiasedLocking) {
7786
assert(scratch != noreg, "should have scratch register at this point");
78-
null_check_offset = biased_locking_enter(disp_hdr, obj, hdr, scratch, false, done, &slow_case);
79-
} else {
80-
null_check_offset = offset();
87+
biased_locking_enter(disp_hdr, obj, hdr, scratch, false, done, &slow_case);
8188
}
8289

8390
// Load object header

‎src/hotspot/cpu/aarch64/interp_masm_aarch64.cpp

+7
Original file line numberDiff line numberDiff line change
@@ -725,6 +725,13 @@ void InterpreterMacroAssembler::lock_object(Register lock_reg)
725725
// Load object pointer into obj_reg %c_rarg3
726726
ldr(obj_reg, Address(lock_reg, obj_offset));
727727

728+
if (DiagnoseSyncOnPrimitiveWrappers != 0) {
729+
load_klass(tmp, obj_reg);
730+
ldrw(tmp, Address(tmp, Klass::access_flags_offset()));
731+
tstw(tmp, JVM_ACC_IS_BOX_CLASS);
732+
br(Assembler::NE, slow_case);
733+
}
734+
728735
if (UseBiasedLocking) {
729736
biased_locking_enter(lock_reg, obj_reg, swap_reg, tmp, false, done, &slow_case);
730737
}

‎src/hotspot/cpu/aarch64/macroAssembler_aarch64.cpp

+8-12
Original file line numberDiff line numberDiff line change
@@ -444,14 +444,14 @@ void MacroAssembler::reserved_stack_check() {
444444
bind(no_reserved_zone_enabling);
445445
}
446446

447-
int MacroAssembler::biased_locking_enter(Register lock_reg,
448-
Register obj_reg,
449-
Register swap_reg,
450-
Register tmp_reg,
451-
bool swap_reg_contains_mark,
452-
Label& done,
453-
Label* slow_case,
454-
BiasedLockingCounters* counters) {
447+
void MacroAssembler::biased_locking_enter(Register lock_reg,
448+
Register obj_reg,
449+
Register swap_reg,
450+
Register tmp_reg,
451+
bool swap_reg_contains_mark,
452+
Label& done,
453+
Label* slow_case,
454+
BiasedLockingCounters* counters) {
455455
assert(UseBiasedLocking, "why call this otherwise?");
456456
assert_different_registers(lock_reg, obj_reg, swap_reg);
457457

@@ -471,9 +471,7 @@ int MacroAssembler::biased_locking_enter(Register lock_reg,
471471
// pointers to allow age to be placed into low bits
472472
// First check to see whether biasing is even enabled for this object
473473
Label cas_label;
474-
int null_check_offset = -1;
475474
if (!swap_reg_contains_mark) {
476-
null_check_offset = offset();
477475
ldr(swap_reg, mark_addr);
478476
}
479477
andr(tmp_reg, swap_reg, markWord::biased_lock_mask_in_place);
@@ -601,8 +599,6 @@ int MacroAssembler::biased_locking_enter(Register lock_reg,
601599
}
602600

603601
bind(cas_label);
604-
605-
return null_check_offset;
606602
}
607603

608604
void MacroAssembler::biased_locking_exit(Register obj_reg, Register temp_reg, Label& done) {

‎src/hotspot/cpu/aarch64/macroAssembler_aarch64.hpp

+5-9
Original file line numberDiff line numberDiff line change
@@ -111,15 +111,11 @@ class MacroAssembler: public Assembler {
111111
// tmp_reg must be supplied and must not be rscratch1 or rscratch2
112112
// Optional slow case is for implementations (interpreter and C1) which branch to
113113
// slow case directly. Leaves condition codes set for C2's Fast_Lock node.
114-
// Returns offset of first potentially-faulting instruction for null
115-
// check info (currently consumed only by C1). If
116-
// swap_reg_contains_mark is true then returns -1 as it is assumed
117-
// the calling code has already passed any potential faults.
118-
int biased_locking_enter(Register lock_reg, Register obj_reg,
119-
Register swap_reg, Register tmp_reg,
120-
bool swap_reg_contains_mark,
121-
Label& done, Label* slow_case = NULL,
122-
BiasedLockingCounters* counters = NULL);
114+
void biased_locking_enter(Register lock_reg, Register obj_reg,
115+
Register swap_reg, Register tmp_reg,
116+
bool swap_reg_contains_mark,
117+
Label& done, Label* slow_case = NULL,
118+
BiasedLockingCounters* counters = NULL);
123119
void biased_locking_exit (Register obj_reg, Register temp_reg, Label& done);
124120

125121

‎src/hotspot/cpu/arm/c1_MacroAssembler_arm.cpp

+13-10
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2008, 2018, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2008, 2020, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -200,26 +200,29 @@ int C1_MacroAssembler::lock_object(Register hdr, Register obj,
200200
const int obj_offset = BasicObjectLock::obj_offset_in_bytes();
201201
const int mark_offset = BasicLock::displaced_header_offset_in_bytes();
202202

203-
if (UseBiasedLocking) {
204-
// load object
205-
str(obj, Address(disp_hdr, obj_offset));
206-
null_check_offset = biased_locking_enter(obj, hdr/*scratched*/, tmp1, false, tmp2, done, slow_case);
207-
}
203+
str(obj, Address(disp_hdr, obj_offset));
208204

209-
assert(oopDesc::mark_offset_in_bytes() == 0, "Required by atomic instructions");
205+
null_check_offset = offset();
210206

207+
if (DiagnoseSyncOnPrimitiveWrappers != 0) {
208+
load_klass(tmp1, obj);
209+
ldr_u32(tmp1, Address(tmp1, Klass::access_flags_offset()));
210+
tst(tmp1, JVM_ACC_IS_BOX_CLASS);
211+
b(slow_case, ne);
212+
}
211213

212-
if (!UseBiasedLocking) {
213-
null_check_offset = offset();
214+
if (UseBiasedLocking) {
215+
biased_locking_enter(obj, hdr/*scratched*/, tmp1, false, tmp2, done, slow_case);
214216
}
215217

218+
assert(oopDesc::mark_offset_in_bytes() == 0, "Required by atomic instructions");
219+
216220
// On MP platforms the next load could return a 'stale' value if the memory location has been modified by another thread.
217221
// That would be acceptable as ether CAS or slow case path is taken in that case.
218222

219223
// Must be the first instruction here, because implicit null check relies on it
220224
ldr(hdr, Address(obj, oopDesc::mark_offset_in_bytes()));
221225

222-
str(obj, Address(disp_hdr, obj_offset));
223226
tst(hdr, markWord::unlocked_value);
224227
b(fast_lock, ne);
225228

‎src/hotspot/cpu/arm/c2_MacroAssembler_arm.cpp

+7
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,13 @@ void C2_MacroAssembler::fast_lock(Register Roop, Register Rbox, Register Rscratc
9090

9191
Label fast_lock, done;
9292

93+
if (DiagnoseSyncOnPrimitiveWrappers != 0) {
94+
load_klass(Rscratch, Roop);
95+
ldr_u32(Rscratch, Address(Rscratch, Klass::access_flags_offset()));
96+
tst(Rscratch, JVM_ACC_IS_BOX_CLASS);
97+
b(done, ne);
98+
}
99+
93100
if (UseBiasedLocking && !UseOptoBiasInlining) {
94101
assert(scratch3 != noreg, "need extra temporary for -XX:-UseOptoBiasInlining");
95102
biased_locking_enter(Roop, Rmark, Rscratch, false, scratch3, done, done);

‎src/hotspot/cpu/arm/interp_masm_arm.cpp

+7
Original file line numberDiff line numberDiff line change
@@ -883,6 +883,13 @@ void InterpreterMacroAssembler::lock_object(Register Rlock) {
883883
// Load object pointer
884884
ldr(Robj, Address(Rlock, obj_offset));
885885

886+
if (DiagnoseSyncOnPrimitiveWrappers != 0) {
887+
load_klass(R0, Robj);
888+
ldr_u32(R0, Address(R0, Klass::access_flags_offset()));
889+
tst(R0, JVM_ACC_IS_BOX_CLASS);
890+
b(slow_case, ne);
891+
}
892+
886893
if (UseBiasedLocking) {
887894
biased_locking_enter(Robj, Rmark/*scratched*/, R0, false, Rtemp, done, slow_case);
888895
}

‎src/hotspot/cpu/arm/macroAssembler_arm.cpp

+5-11
Original file line numberDiff line numberDiff line change
@@ -1322,11 +1322,11 @@ void MacroAssembler::biased_locking_enter_with_cas(Register obj_reg, Register ol
13221322
#endif // !PRODUCT
13231323
}
13241324

1325-
int MacroAssembler::biased_locking_enter(Register obj_reg, Register swap_reg, Register tmp_reg,
1326-
bool swap_reg_contains_mark,
1327-
Register tmp2,
1328-
Label& done, Label& slow_case,
1329-
BiasedLockingCounters* counters) {
1325+
void MacroAssembler::biased_locking_enter(Register obj_reg, Register swap_reg, Register tmp_reg,
1326+
bool swap_reg_contains_mark,
1327+
Register tmp2,
1328+
Label& done, Label& slow_case,
1329+
BiasedLockingCounters* counters) {
13301330
// obj_reg must be preserved (at least) if the bias locking fails
13311331
// tmp_reg is a temporary register
13321332
// swap_reg was used as a temporary but contained a value
@@ -1357,10 +1357,6 @@ int MacroAssembler::biased_locking_enter(Register obj_reg, Register swap_reg, Re
13571357
// First check to see whether biasing is even enabled for this object
13581358
Label cas_label;
13591359

1360-
// The null check applies to the mark loading, if we need to load it.
1361-
// If the mark has already been loaded in swap_reg then it has already
1362-
// been performed and the offset is irrelevant.
1363-
int null_check_offset = offset();
13641360
if (!swap_reg_contains_mark) {
13651361
ldr(swap_reg, mark_addr);
13661362
}
@@ -1504,8 +1500,6 @@ int MacroAssembler::biased_locking_enter(Register obj_reg, Register swap_reg, Re
15041500
// removing the bias bit from the object's header.
15051501

15061502
bind(cas_label);
1507-
1508-
return null_check_offset;
15091503
}
15101504

15111505

‎src/hotspot/cpu/arm/macroAssembler_arm.hpp

+5-9
Original file line numberDiff line numberDiff line change
@@ -375,18 +375,14 @@ class MacroAssembler: public Assembler {
375375
// biased and we acquired it. Slow case label is branched to with
376376
// condition code NE set if the lock is biased but we failed to acquire
377377
// it. Otherwise fall through.
378-
// Returns offset of first potentially-faulting instruction for null
379-
// check info (currently consumed only by C1). If
380-
// swap_reg_contains_mark is true then returns -1 as it is assumed
381-
// the calling code has already passed any potential faults.
382378
// Notes:
383379
// - swap_reg and tmp_reg are scratched
384380
// - Rtemp was (implicitly) scratched and can now be specified as the tmp2
385-
int biased_locking_enter(Register obj_reg, Register swap_reg, Register tmp_reg,
386-
bool swap_reg_contains_mark,
387-
Register tmp2,
388-
Label& done, Label& slow_case,
389-
BiasedLockingCounters* counters = NULL);
381+
void biased_locking_enter(Register obj_reg, Register swap_reg, Register tmp_reg,
382+
bool swap_reg_contains_mark,
383+
Register tmp2,
384+
Label& done, Label& slow_case,
385+
BiasedLockingCounters* counters = NULL);
390386
void biased_locking_exit(Register obj_reg, Register temp_reg, Label& done);
391387

392388
// Building block for CAS cases of biased locking: makes CAS and records statistics.

‎src/hotspot/cpu/ppc/c1_MacroAssembler_ppc.cpp

+7
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,13 @@ void C1_MacroAssembler::lock_object(Register Rmark, Register Roop, Register Rbox
105105
// Save object being locked into the BasicObjectLock...
106106
std(Roop, BasicObjectLock::obj_offset_in_bytes(), Rbox);
107107

108+
if (DiagnoseSyncOnPrimitiveWrappers != 0) {
109+
load_klass(Rscratch, Roop);
110+
lwz(Rscratch, in_bytes(Klass::access_flags_offset()), Rscratch);
111+
testbitdi(CCR0, R0, Rscratch, exact_log2(JVM_ACC_IS_BOX_CLASS));
112+
bne(CCR0, slow_int);
113+
}
114+
108115
if (UseBiasedLocking) {
109116
biased_locking_enter(CCR0, Roop, Rmark, Rscratch, R0, done, &slow_int);
110117
}

‎src/hotspot/cpu/ppc/interp_masm_ppc_64.cpp

+7
Original file line numberDiff line numberDiff line change
@@ -910,6 +910,13 @@ void InterpreterMacroAssembler::lock_object(Register monitor, Register object) {
910910
// Load markWord from object into displaced_header.
911911
ld(displaced_header, oopDesc::mark_offset_in_bytes(), object);
912912

913+
if (DiagnoseSyncOnPrimitiveWrappers != 0) {
914+
load_klass(tmp, object);
915+
lwz(tmp, in_bytes(Klass::access_flags_offset()), tmp);
916+
testbitdi(CCR0, R0, tmp, exact_log2(JVM_ACC_IS_BOX_CLASS));
917+
bne(CCR0, slow_case);
918+
}
919+
913920
if (UseBiasedLocking) {
914921
biased_locking_enter(CCR0, object, displaced_header, tmp, current_header, done, &slow_case);
915922
}

‎src/hotspot/cpu/ppc/macroAssembler_ppc.cpp

+6
Original file line numberDiff line numberDiff line change
@@ -2836,6 +2836,12 @@ void MacroAssembler::compiler_fast_lock_object(ConditionRegister flag, Register
28362836
// Load markWord from object into displaced_header.
28372837
ld(displaced_header, oopDesc::mark_offset_in_bytes(), oop);
28382838

2839+
if (DiagnoseSyncOnPrimitiveWrappers != 0) {
2840+
load_klass(temp, oop);
2841+
lwz(temp, in_bytes(Klass::access_flags_offset()), temp);
2842+
testbitdi(flag, R0, temp, exact_log2(JVM_ACC_IS_BOX_CLASS));
2843+
bne(flag, cont);
2844+
}
28392845

28402846
if (try_bias) {
28412847
biased_locking_enter(flag, oop, displaced_header, temp, current_header, cont);

‎src/hotspot/cpu/s390/c1_MacroAssembler_s390.cpp

+6
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,12 @@ void C1_MacroAssembler::lock_object(Register hdr, Register obj, Register disp_hd
9191
// Save object being locked into the BasicObjectLock...
9292
z_stg(obj, Address(disp_hdr, BasicObjectLock::obj_offset_in_bytes()));
9393

94+
if (DiagnoseSyncOnPrimitiveWrappers != 0) {
95+
load_klass(Z_R1_scratch, obj);
96+
testbit(Address(Z_R1_scratch, Klass::access_flags_offset()), exact_log2(JVM_ACC_IS_BOX_CLASS));
97+
z_btrue(slow_case);
98+
}
99+
94100
if (UseBiasedLocking) {
95101
biased_locking_enter(obj, hdr, Z_R1_scratch, Z_R0_scratch, done, &slow_case);
96102
}

‎src/hotspot/cpu/s390/interp_masm_s390.cpp

+6
Original file line numberDiff line numberDiff line change
@@ -1000,6 +1000,12 @@ void InterpreterMacroAssembler::lock_object(Register monitor, Register object) {
10001000
// Load markWord from object into displaced_header.
10011001
z_lg(displaced_header, oopDesc::mark_offset_in_bytes(), object);
10021002

1003+
if (DiagnoseSyncOnPrimitiveWrappers != 0) {
1004+
load_klass(Z_R1_scratch, object);
1005+
testbit(Address(Z_R1_scratch, Klass::access_flags_offset()), exact_log2(JVM_ACC_IS_BOX_CLASS));
1006+
z_btrue(slow_case);
1007+
}
1008+
10031009
if (UseBiasedLocking) {
10041010
biased_locking_enter(object, displaced_header, Z_R1, Z_R0, done, &slow_case);
10051011
}

‎src/hotspot/cpu/s390/macroAssembler_s390.cpp

+8
Original file line numberDiff line numberDiff line change
@@ -3358,6 +3358,14 @@ void MacroAssembler::compiler_fast_lock_object(Register oop, Register box, Regis
33583358
// Load markWord from oop into mark.
33593359
z_lg(displacedHeader, 0, oop);
33603360

3361+
if (DiagnoseSyncOnPrimitiveWrappers != 0) {
3362+
load_klass(Z_R1_scratch, oop);
3363+
z_l(Z_R1_scratch, Address(Z_R1_scratch, Klass::access_flags_offset()));
3364+
assert((JVM_ACC_IS_BOX_CLASS & 0xFFFF) == 0, "or change following instruction");
3365+
z_nilh(Z_R1_scratch, JVM_ACC_IS_BOX_CLASS >> 16);
3366+
z_brne(done);
3367+
}
3368+
33613369
if (try_bias) {
33623370
biased_locking_enter(oop, displacedHeader, temp, Z_R0, done);
33633371
}

‎src/hotspot/cpu/x86/c1_MacroAssembler_x86.cpp

+12-5
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 1999, 2018, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 1999, 2020, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -39,6 +39,7 @@
3939
#include "runtime/stubRoutines.hpp"
4040

4141
int C1_MacroAssembler::lock_object(Register hdr, Register obj, Register disp_hdr, Register scratch, Label& slow_case) {
42+
const Register rklass_decode_tmp = LP64_ONLY(rscratch1) NOT_LP64(noreg);
4243
const int aligned_mask = BytesPerWord -1;
4344
const int hdr_offset = oopDesc::mark_offset_in_bytes();
4445
assert(hdr == rax, "hdr must be rax, for the cmpxchg instruction");
@@ -51,12 +52,18 @@ int C1_MacroAssembler::lock_object(Register hdr, Register obj, Register disp_hdr
5152
// save object being locked into the BasicObjectLock
5253
movptr(Address(disp_hdr, BasicObjectLock::obj_offset_in_bytes()), obj);
5354

55+
null_check_offset = offset();
56+
57+
if (DiagnoseSyncOnPrimitiveWrappers != 0) {
58+
load_klass(hdr, obj, rklass_decode_tmp);
59+
movl(hdr, Address(hdr, Klass::access_flags_offset()));
60+
testl(hdr, JVM_ACC_IS_BOX_CLASS);
61+
jcc(Assembler::notZero, slow_case);
62+
}
63+
5464
if (UseBiasedLocking) {
5565
assert(scratch != noreg, "should have scratch register at this point");
56-
Register rklass_decode_tmp = LP64_ONLY(rscratch1) NOT_LP64(noreg);
57-
null_check_offset = biased_locking_enter(disp_hdr, obj, hdr, scratch, rklass_decode_tmp, false, done, &slow_case);
58-
} else {
59-
null_check_offset = offset();
66+
biased_locking_enter(disp_hdr, obj, hdr, scratch, rklass_decode_tmp, false, done, &slow_case);
6067
}
6168

6269
// Load object header

‎src/hotspot/cpu/x86/c2_MacroAssembler_x86.cpp

+7
Original file line numberDiff line numberDiff line change
@@ -470,6 +470,13 @@ void C2_MacroAssembler::fast_lock(Register objReg, Register boxReg, Register tmp
470470

471471
Label IsInflated, DONE_LABEL;
472472

473+
if (DiagnoseSyncOnPrimitiveWrappers != 0) {
474+
load_klass(tmpReg, objReg, cx1Reg);
475+
movl(tmpReg, Address(tmpReg, Klass::access_flags_offset()));
476+
testl(tmpReg, JVM_ACC_IS_BOX_CLASS);
477+
jcc(Assembler::notZero, DONE_LABEL);
478+
}
479+
473480
// it's stack-locked, biased or neutral
474481
// TODO: optimize away redundant LDs of obj->mark and improve the markword triage
475482
// order to reduce the number of conditional branches in the most common cases.

0 commit comments

Comments
 (0)
Please sign in to comment.