Skip to content

Commit

Permalink
Pass may_be_unordered information to lightweight_unlock.
Browse files Browse the repository at this point in the history
  • Loading branch information
TheRealMDoerr committed Sep 28, 2023
1 parent 28176e0 commit 2ad3283
Show file tree
Hide file tree
Showing 8 changed files with 29 additions and 21 deletions.
4 changes: 2 additions & 2 deletions src/hotspot/cpu/ppc/c1_LIRAssembler_ppc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ int LIR_Assembler::emit_unwind_handler() {
if (method()->is_synchronized()) {
monitor_address(0, FrameMap::R4_opr);
stub = new MonitorExitStub(FrameMap::R4_opr, true, 0);
__ unlock_object(R5, R6, R4, *stub->entry());
__ unlock_object(R5, R6, R4, *stub->entry(), compilation()->is_osr_compile());
__ bind(*stub->continuation());
}

Expand Down Expand Up @@ -2679,7 +2679,7 @@ void LIR_Assembler::emit_lock(LIR_OpLock* op) {
assert (op->code() == lir_unlock, "Invalid code, expected lir_unlock");
if (LockingMode != LM_MONITOR) {
assert(BasicLock::displaced_header_offset_in_bytes() == 0, "lock_reg must point to the displaced header");
__ unlock_object(hdr, obj, lock, *op->stub()->entry());
__ unlock_object(hdr, obj, lock, *op->stub()->entry(), compilation()->is_osr_compile());
} else {
// always do slow unlocking
// note: The slow unlocking code could be inlined here, however if we use
Expand Down
4 changes: 2 additions & 2 deletions src/hotspot/cpu/ppc/c1_MacroAssembler_ppc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ void C1_MacroAssembler::lock_object(Register Rmark, Register Roop, Register Rbox
}


void C1_MacroAssembler::unlock_object(Register Rmark, Register Roop, Register Rbox, Label& slow_case) {
void C1_MacroAssembler::unlock_object(Register Rmark, Register Roop, Register Rbox, Label& slow_case, bool may_be_unordered) {
assert_different_registers(Rmark, Roop, Rbox);

Label slow_int, done;
Expand All @@ -181,7 +181,7 @@ void C1_MacroAssembler::unlock_object(Register Rmark, Register Roop, Register Rb
ld(Rmark, oopDesc::mark_offset_in_bytes(), Roop);
andi_(R0, Rmark, markWord::monitor_value);
bne(CCR0, slow_int);
lightweight_unlock(Roop, Rmark, noreg, slow_int);
lightweight_unlock(Roop, Rmark, noreg, slow_int, may_be_unordered);
} else if (LockingMode == LM_LEGACY) {
// Check if it is still a light weight lock, this is is true if we see
// the stack address of the basicLock in the markWord of the object.
Expand Down
2 changes: 1 addition & 1 deletion src/hotspot/cpu/ppc/c1_MacroAssembler_ppc.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@

// locking/unlocking
void lock_object (Register Rmark, Register Roop, Register Rbox, Register Rscratch, Label& slow_case);
void unlock_object(Register Rmark, Register Roop, Register Rbox, Label& slow_case);
void unlock_object(Register Rmark, Register Roop, Register Rbox, Label& slow_case, bool may_be_unordered);

void initialize_object(
Register obj, // result: pointer to object after successful allocation
Expand Down
8 changes: 2 additions & 6 deletions src/hotspot/cpu/ppc/interp_masm_ppc_64.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1127,16 +1127,12 @@ void InterpreterMacroAssembler::unlock_object(Register monitor) {
lwz(tmp, in_bytes(JavaThread::lock_stack_top_offset()), R16_thread);
cmplwi(CCR0, tmp, (unsigned)LockStack::start_offset());
ble(CCR0, slow_case);
// Then check if the top of the lock-stack matches the unlocked object.
addi(tmp, tmp, -oopSize);
ldx(tmp, tmp, R16_thread);
cmpd(CCR0, tmp, object);
bne(CCR0, slow_case);

ld(header, oopDesc::mark_offset_in_bytes(), object);
andi_(R0, header, markWord::monitor_value);
bne(CCR0, slow_case);
lightweight_unlock(object, header, tmp, slow_case);

lightweight_unlock(object, header, tmp, slow_case, true);
} else {
addi(object_mark_addr, object, oopDesc::mark_offset_in_bytes());

Expand Down
24 changes: 18 additions & 6 deletions src/hotspot/cpu/ppc/macroAssembler_ppc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2293,7 +2293,8 @@ void MacroAssembler::compiler_fast_lock_object(ConditionRegister flag, Register
}

void MacroAssembler::compiler_fast_unlock_object(ConditionRegister flag, Register oop, Register box,
Register temp, Register displaced_header, Register current_header) {
Register temp, Register displaced_header, Register current_header,
bool may_be_unordered) {
assert_different_registers(oop, box, temp, displaced_header, current_header);
assert(LockingMode != LM_LIGHTWEIGHT || flag == CCR0, "bad condition register");
Label success, failure, object_has_monitor, notRecursive;
Expand Down Expand Up @@ -2334,7 +2335,7 @@ void MacroAssembler::compiler_fast_unlock_object(ConditionRegister flag, Registe
b(success);
} else {
assert(LockingMode == LM_LIGHTWEIGHT, "must be");
lightweight_unlock(oop, current_header, /* temp */ displaced_header, failure);
lightweight_unlock(oop, current_header, /* temp */ displaced_header, failure, may_be_unordered);
b(success);
}

Expand Down Expand Up @@ -4032,7 +4033,7 @@ void MacroAssembler::lightweight_lock(Register obj, Register hdr, Register t1, L
//
// - obj: the object to be unlocked
// - hdr: the (pre-loaded) header of the object, will be destroyed
void MacroAssembler::lightweight_unlock(Register obj, Register hdr, Register t1, Label& slow) {
void MacroAssembler::lightweight_unlock(Register obj, Register hdr, Register t1, Label& slow, bool may_be_unordered) {
assert(LockingMode == LM_LIGHTWEIGHT, "only used with new lightweight locking");
assert_different_registers(obj, hdr);

Expand Down Expand Up @@ -4067,9 +4068,20 @@ void MacroAssembler::lightweight_unlock(Register obj, Register hdr, Register t1,

// Check if the top of the lock-stack matches the unlocked object.
addi(temp, temp, -oopSize);
ldx(R0, temp, R16_thread);
cmpd(CCR0, R0, obj);
bne(CCR0, slow);
if (may_be_unordered) {
ldx(R0, temp, R16_thread);
cmpd(CCR0, R0, obj);
bne(CCR0, slow);
} else {
#ifdef ASSERT
Label tos_ok;
ldx(R0, temp, R16_thread);
cmpd(CCR0, R0, obj);
beq(CCR0, tos_ok);
stop("Top of lock-stack does not match the unlocked object");
bind(tos_ok);
#endif
}

// Release the lock.
atomically_flip_locked_state(/* is_unlock */ true, obj, hdr, slow, MacroAssembler::MemBarRel);
Expand Down
4 changes: 2 additions & 2 deletions src/hotspot/cpu/ppc/macroAssembler_ppc.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -607,7 +607,7 @@ class MacroAssembler: public Assembler {
void dec_held_monitor_count(Register tmp);
void atomically_flip_locked_state(bool is_unlock, Register obj, Register tmp, Label& failed, int semantics);
void lightweight_lock(Register obj, Register hdr, Register t1, Label& slow);
void lightweight_unlock(Register obj, Register hdr, Register t1, Label& slow);
void lightweight_unlock(Register obj, Register hdr, Register t1, Label& slow, bool may_be_unordered);

// allocation (for C1)
void tlab_allocate(
Expand All @@ -626,7 +626,7 @@ class MacroAssembler: public Assembler {
Register tmp1, Register tmp2, Register tmp3);

void compiler_fast_unlock_object(ConditionRegister flag, Register oop, Register box,
Register tmp1, Register tmp2, Register tmp3);
Register tmp1, Register tmp2, Register tmp3, bool may_be_unoredered);

// Check if safepoint requested and if so branch
void safepoint_poll(Label& slow_path, Register temp, bool at_return, bool in_nmethod);
Expand Down
2 changes: 1 addition & 1 deletion src/hotspot/cpu/ppc/ppc.ad
Original file line number Diff line number Diff line change
Expand Up @@ -12168,7 +12168,7 @@ instruct cmpFastUnlock(flagsRegCR0 crx, iRegPdst oop, iRegPdst box, iRegPdst tmp
format %{ "FASTUNLOCK $oop, $box, $tmp1, $tmp2" %}
ins_encode %{
__ compiler_fast_unlock_object($crx$$CondRegister, $oop$$Register, $box$$Register,
$tmp1$$Register, $tmp2$$Register, $tmp3$$Register);
$tmp1$$Register, $tmp2$$Register, $tmp3$$Register, Compile::current()->is_osr_compilation());
// If unlocking was successful, crx should indicate 'EQ'.
// The compiler generates a branch to the runtime call to
// _complete_monitor_unlocking_Java for the case where crx is 'NE'.
Expand Down
2 changes: 1 addition & 1 deletion src/hotspot/cpu/ppc/sharedRuntime_ppc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2674,7 +2674,7 @@ nmethod *SharedRuntime::generate_native_wrapper(MacroAssembler *masm,
__ addi(r_box, R1_SP, lock_offset);

// Try fastpath for unlocking.
__ compiler_fast_unlock_object(CCR0, r_oop, r_box, r_temp_1, r_temp_2, r_temp_3);
__ compiler_fast_unlock_object(CCR0, r_oop, r_box, r_temp_1, r_temp_2, r_temp_3, false);
__ beq(CCR0, done);

// Save and restore any potential method result value around the unlocking operation.
Expand Down

0 comments on commit 2ad3283

Please sign in to comment.