8167659: Access of mark word should use oopDesc::mark_offset_in_bytes() instead of '0'
Summary: Use oopDesc::mark_offset_in_bytes() when addressing mark word, instead of '0'.
Reviewed-by: dholmes, coleenp
--- a/hotspot/src/cpu/aarch64/vm/interp_masm_aarch64.cpp Tue May 09 13:50:06 2017 -0400
+++ b/hotspot/src/cpu/aarch64/vm/interp_masm_aarch64.cpp Thu Oct 13 11:27:20 2016 +0200
@@ -692,7 +692,7 @@
}
// Load (object->mark() | 1) into swap_reg
- ldr(rscratch1, Address(obj_reg, 0));
+ ldr(rscratch1, Address(obj_reg, oopDesc::mark_offset_in_bytes()));
orr(swap_reg, rscratch1, 1);
// Save (object->mark() | 1) into BasicLock's displaced header
@@ -704,14 +704,14 @@
Label fail;
if (PrintBiasedLockingStatistics) {
Label fast;
- cmpxchgptr(swap_reg, lock_reg, obj_reg, rscratch1, fast, &fail);
+ cmpxchg_obj_header(swap_reg, lock_reg, obj_reg, rscratch1, fast, &fail);
bind(fast);
atomic_incw(Address((address)BiasedLocking::fast_path_entry_count_addr()),
rscratch2, rscratch1, tmp);
b(done);
bind(fail);
} else {
- cmpxchgptr(swap_reg, lock_reg, obj_reg, rscratch1, done, /*fallthrough*/NULL);
+ cmpxchg_obj_header(swap_reg, lock_reg, obj_reg, rscratch1, done, /*fallthrough*/NULL);
}
// Test if the oopMark is an obvious stack pointer, i.e.,
@@ -801,7 +801,7 @@
cbz(header_reg, done);
// Atomic swap back the old header
- cmpxchgptr(swap_reg, header_reg, obj_reg, rscratch1, done, /*fallthrough*/NULL);
+ cmpxchg_obj_header(swap_reg, header_reg, obj_reg, rscratch1, done, /*fallthrough*/NULL);
// Call the runtime routine for slow case.
str(obj_reg, Address(lock_reg, BasicObjectLock::obj_offset_in_bytes())); // restore obj
--- a/hotspot/src/cpu/aarch64/vm/macroAssembler_aarch64.cpp Tue May 09 13:50:06 2017 -0400
+++ b/hotspot/src/cpu/aarch64/vm/macroAssembler_aarch64.cpp Thu Oct 13 11:27:20 2016 +0200
@@ -515,7 +515,7 @@
mov(rscratch1, markOopDesc::biased_lock_mask_in_place | markOopDesc::age_mask_in_place | markOopDesc::epoch_mask_in_place);
andr(swap_reg, swap_reg, rscratch1);
orr(tmp_reg, swap_reg, rthread);
- cmpxchgptr(swap_reg, tmp_reg, obj_reg, rscratch1, here, slow_case);
+ cmpxchg_obj_header(swap_reg, tmp_reg, obj_reg, rscratch1, here, slow_case);
// If the biasing toward our thread failed, this means that
// another thread succeeded in biasing it toward itself and we
// need to revoke that bias. The revocation will occur in the
@@ -542,7 +542,7 @@
Label here;
load_prototype_header(tmp_reg, obj_reg);
orr(tmp_reg, rthread, tmp_reg);
- cmpxchgptr(swap_reg, tmp_reg, obj_reg, rscratch1, here, slow_case);
+ cmpxchg_obj_header(swap_reg, tmp_reg, obj_reg, rscratch1, here, slow_case);
// If the biasing toward our thread failed, then another thread
// succeeded in biasing it toward itself and we need to revoke that
// bias. The revocation will occur in the runtime in the slow case.
@@ -569,7 +569,7 @@
{
Label here, nope;
load_prototype_header(tmp_reg, obj_reg);
- cmpxchgptr(swap_reg, tmp_reg, obj_reg, rscratch1, here, &nope);
+ cmpxchg_obj_header(swap_reg, tmp_reg, obj_reg, rscratch1, here, &nope);
bind(here);
// Fall through to the normal CAS-based lock, because no matter what
@@ -2140,6 +2140,12 @@
b(*fail);
}
+void MacroAssembler::cmpxchg_obj_header(Register oldv, Register newv, Register obj, Register tmp,
+ Label &succeed, Label *fail) {
+ assert(oopDesc::mark_offset_in_bytes() == 0, "assumption");
+ cmpxchgptr(oldv, newv, obj, tmp, succeed, fail);
+}
+
void MacroAssembler::cmpxchgw(Register oldv, Register newv, Register addr, Register tmp,
Label &succeed, Label *fail) {
// oldv holds comparison value
--- a/hotspot/src/cpu/aarch64/vm/macroAssembler_aarch64.hpp Tue May 09 13:50:06 2017 -0400
+++ b/hotspot/src/cpu/aarch64/vm/macroAssembler_aarch64.hpp Thu Oct 13 11:27:20 2016 +0200
@@ -974,6 +974,8 @@
// Various forms of CAS
+ void cmpxchg_obj_header(Register oldv, Register newv, Register obj, Register tmp,
+ Label &suceed, Label *fail);
void cmpxchgptr(Register oldv, Register newv, Register addr, Register tmp,
Label &suceed, Label *fail);
--- a/hotspot/src/cpu/aarch64/vm/sharedRuntime_aarch64.cpp Tue May 09 13:50:06 2017 -0400
+++ b/hotspot/src/cpu/aarch64/vm/sharedRuntime_aarch64.cpp Thu Oct 13 11:27:20 2016 +0200
@@ -1842,7 +1842,7 @@
}
// Load (object->mark() | 1) into swap_reg %r0
- __ ldr(rscratch1, Address(obj_reg, 0));
+ __ ldr(rscratch1, Address(obj_reg, oopDesc::mark_offset_in_bytes()));
__ orr(swap_reg, rscratch1, 1);
// Save (object->mark() | 1) into BasicLock's displaced header
@@ -1850,7 +1850,7 @@
// src -> dest iff dest == r0 else r0 <- dest
{ Label here;
- __ cmpxchgptr(r0, lock_reg, obj_reg, rscratch1, lock_done, /*fallthrough*/NULL);
+ __ cmpxchg_obj_header(r0, lock_reg, obj_reg, rscratch1, lock_done, /*fallthrough*/NULL);
}
// Hmm should this move to the slow path code area???
@@ -2029,7 +2029,7 @@
// Atomic swap old header if oop still contains the stack lock
Label succeed;
- __ cmpxchgptr(r0, old_hdr, obj_reg, rscratch1, succeed, &slow_path_unlock);
+ __ cmpxchg_obj_header(r0, old_hdr, obj_reg, rscratch1, succeed, &slow_path_unlock);
__ bind(succeed);
// slow path re-enters here
--- a/hotspot/src/cpu/x86/vm/interp_masm_x86.cpp Tue May 09 13:50:06 2017 -0400
+++ b/hotspot/src/cpu/x86/vm/interp_masm_x86.cpp Thu Oct 13 11:27:20 2016 +0200
@@ -1157,7 +1157,7 @@
movl(swap_reg, (int32_t)1);
// Load (object->mark() | 1) into swap_reg %rax
- orptr(swap_reg, Address(obj_reg, 0));
+ orptr(swap_reg, Address(obj_reg, oopDesc::mark_offset_in_bytes()));
// Save (object->mark() | 1) into BasicLock's displaced header
movptr(Address(lock_reg, mark_offset), swap_reg);
@@ -1166,7 +1166,7 @@
"displaced header must be first word in BasicObjectLock");
if (os::is_MP()) lock();
- cmpxchgptr(lock_reg, Address(obj_reg, 0));
+ cmpxchgptr(lock_reg, Address(obj_reg, oopDesc::mark_offset_in_bytes()));
if (PrintBiasedLockingStatistics) {
cond_inc32(Assembler::zero,
ExternalAddress((address) BiasedLocking::fast_path_entry_count_addr()));
@@ -1263,7 +1263,7 @@
// Atomic swap back the old header
if (os::is_MP()) lock();
- cmpxchgptr(header_reg, Address(obj_reg, 0));
+ cmpxchgptr(header_reg, Address(obj_reg, oopDesc::mark_offset_in_bytes()));
// zero for simple unlock of a stack-lock case
jcc(Assembler::zero, done);
--- a/hotspot/src/cpu/x86/vm/macroAssembler_x86.cpp Tue May 09 13:50:06 2017 -0400
+++ b/hotspot/src/cpu/x86/vm/macroAssembler_x86.cpp Thu Oct 13 11:27:20 2016 +0200
@@ -1484,7 +1484,7 @@
movl(retry_on_abort_count_Reg, RTMRetryCount); // Retry on abort
bind(L_rtm_retry);
}
- movptr(tmpReg, Address(objReg, 0));
+ movptr(tmpReg, Address(objReg, oopDesc::mark_offset_in_bytes()));
testptr(tmpReg, markOopDesc::monitor_value); // inflated vs stack-locked|neutral|biased
jcc(Assembler::notZero, IsInflated);
@@ -1499,7 +1499,7 @@
bind(L_noincrement);
}
xbegin(L_on_abort);
- movptr(tmpReg, Address(objReg, 0)); // fetch markword
+ movptr(tmpReg, Address(objReg, oopDesc::mark_offset_in_bytes())); // fetch markword
andptr(tmpReg, markOopDesc::biased_lock_mask_in_place); // look at 3 lock bits
cmpptr(tmpReg, markOopDesc::unlocked_value); // bits = 001 unlocked
jcc(Assembler::equal, DONE_LABEL); // all done if unlocked
@@ -1560,7 +1560,7 @@
bind(L_noincrement);
}
xbegin(L_on_abort);
- movptr(tmpReg, Address(objReg, 0));
+ movptr(tmpReg, Address(objReg, oopDesc::mark_offset_in_bytes()));
movptr(tmpReg, Address(tmpReg, owner_offset));
testptr(tmpReg, tmpReg);
jcc(Assembler::zero, DONE_LABEL);
@@ -1753,7 +1753,7 @@
}
#endif // INCLUDE_RTM_OPT
- movptr(tmpReg, Address(objReg, 0)); // [FETCH]
+ movptr(tmpReg, Address(objReg, oopDesc::mark_offset_in_bytes())); // [FETCH]
testptr(tmpReg, markOopDesc::monitor_value); // inflated vs stack-locked|neutral|biased
jccb(Assembler::notZero, IsInflated);
@@ -1763,7 +1763,7 @@
if (os::is_MP()) {
lock();
}
- cmpxchgptr(boxReg, Address(objReg, 0)); // Updates tmpReg
+ cmpxchgptr(boxReg, Address(objReg, oopDesc::mark_offset_in_bytes())); // Updates tmpReg
if (counters != NULL) {
cond_inc32(Assembler::equal,
ExternalAddress((address)counters->fast_path_entry_count_addr()));
@@ -1984,7 +1984,7 @@
if (UseRTMForStackLocks && use_rtm) {
assert(!UseBiasedLocking, "Biased locking is not supported with RTM locking");
Label L_regular_unlock;
- movptr(tmpReg, Address(objReg, 0)); // fetch markword
+ movptr(tmpReg, Address(objReg, oopDesc::mark_offset_in_bytes())); // fetch markword
andptr(tmpReg, markOopDesc::biased_lock_mask_in_place); // look at 3 lock bits
cmpptr(tmpReg, markOopDesc::unlocked_value); // bits = 001 unlocked
jccb(Assembler::notEqual, L_regular_unlock); // if !HLE RegularLock
@@ -1996,7 +1996,7 @@
cmpptr(Address(boxReg, 0), (int32_t)NULL_WORD); // Examine the displaced header
jcc (Assembler::zero, DONE_LABEL); // 0 indicates recursive stack-lock
- movptr(tmpReg, Address(objReg, 0)); // Examine the object's markword
+ movptr(tmpReg, Address(objReg, oopDesc::mark_offset_in_bytes())); // Examine the object's markword
testptr(tmpReg, markOopDesc::monitor_value); // Inflated?
jccb (Assembler::zero, Stacked);
@@ -2150,7 +2150,7 @@
if (os::is_MP()) {
lock();
}
- cmpxchgptr(tmpReg, Address(objReg, 0)); // Uses RAX which is box
+ cmpxchgptr(tmpReg, Address(objReg, oopDesc::mark_offset_in_bytes())); // Uses RAX which is box
// Intention fall-thru into DONE_LABEL
// DONE_LABEL is a hot target - we'd really like to place it at the
@@ -2247,7 +2247,7 @@
bind (Stacked);
movptr(tmpReg, Address (boxReg, 0)); // re-fetch
if (os::is_MP()) { lock(); }
- cmpxchgptr(tmpReg, Address(objReg, 0)); // Uses RAX which is box
+ cmpxchgptr(tmpReg, Address(objReg, oopDesc::mark_offset_in_bytes())); // Uses RAX which is box
if (EmitSync & 65536) {
bind (CheckSucc);
--- a/hotspot/src/cpu/x86/vm/sharedRuntime_x86_32.cpp Tue May 09 13:50:06 2017 -0400
+++ b/hotspot/src/cpu/x86/vm/sharedRuntime_x86_32.cpp Thu Oct 13 11:27:20 2016 +0200
@@ -1998,7 +1998,7 @@
__ movptr(swap_reg, 1);
// Load (object->mark() | 1) into swap_reg %rax,
- __ orptr(swap_reg, Address(obj_reg, 0));
+ __ orptr(swap_reg, Address(obj_reg, oopDesc::mark_offset_in_bytes()));
// Save (object->mark() | 1) into BasicLock's displaced header
__ movptr(Address(lock_reg, mark_word_offset), swap_reg);
@@ -2009,7 +2009,7 @@
// src -> dest iff dest == rax, else rax, <- dest
// *obj_reg = lock_reg iff *obj_reg == rax, else rax, = *(obj_reg)
- __ cmpxchgptr(lock_reg, Address(obj_reg, 0));
+ __ cmpxchgptr(lock_reg, Address(obj_reg, oopDesc::mark_offset_in_bytes()));
__ jcc(Assembler::equal, lock_done);
// Test if the oopMark is an obvious stack pointer, i.e.,
@@ -2204,7 +2204,7 @@
// src -> dest iff dest == rax, else rax, <- dest
// *obj_reg = rbx, iff *obj_reg == rax, else rax, = *(obj_reg)
- __ cmpxchgptr(rbx, Address(obj_reg, 0));
+ __ cmpxchgptr(rbx, Address(obj_reg, oopDesc::mark_offset_in_bytes()));
__ jcc(Assembler::notEqual, slow_path_unlock);
// slow path re-enters here
--- a/hotspot/src/cpu/x86/vm/sharedRuntime_x86_64.cpp Tue May 09 13:50:06 2017 -0400
+++ b/hotspot/src/cpu/x86/vm/sharedRuntime_x86_64.cpp Thu Oct 13 11:27:20 2016 +0200
@@ -2372,7 +2372,7 @@
__ movl(swap_reg, 1);
// Load (object->mark() | 1) into swap_reg %rax
- __ orptr(swap_reg, Address(obj_reg, 0));
+ __ orptr(swap_reg, Address(obj_reg, oopDesc::mark_offset_in_bytes()));
// Save (object->mark() | 1) into BasicLock's displaced header
__ movptr(Address(lock_reg, mark_word_offset), swap_reg);
@@ -2382,7 +2382,7 @@
}
// src -> dest iff dest == rax else rax <- dest
- __ cmpxchgptr(lock_reg, Address(obj_reg, 0));
+ __ cmpxchgptr(lock_reg, Address(obj_reg, oopDesc::mark_offset_in_bytes()));
__ jcc(Assembler::equal, lock_done);
// Hmm should this move to the slow path code area???
@@ -2560,7 +2560,7 @@
if (os::is_MP()) {
__ lock();
}
- __ cmpxchgptr(old_hdr, Address(obj_reg, 0));
+ __ cmpxchgptr(old_hdr, Address(obj_reg, oopDesc::mark_offset_in_bytes()));
__ jcc(Assembler::notEqual, slow_path_unlock);
// slow path re-enters here