Skip to content

Commit 27bcdb0

Browse files
committed
8302209: [Lilliput] Optimize fix-anon monitor owner path
Reviewed-by: stuefe
1 parent a4b8dbb commit 27bcdb0

File tree

5 files changed

+66
-8
lines changed

5 files changed

+66
-8
lines changed

src/hotspot/cpu/aarch64/aarch64.ad

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3934,13 +3934,16 @@ encode %{
39343934
__ add(tmp, tmp, -(int)markWord::monitor_value); // monitor
39353935

39363936
if (UseFastLocking) {
3937-
// If the owner is anonymous, we need to fix it -- in the slow-path.
3938-
__ ldr(disp_hdr, Address(tmp, ObjectMonitor::owner_offset_in_bytes()));
3939-
// We cannot use tbnz here: tbnz would leave the condition flags untouched,
3940-
// but we want to carry-over the NE condition to the exit at the cont label,
3941-
// in order to take the slow-path.
3942-
__ tst(disp_hdr, (uint64_t)(intptr_t) ANONYMOUS_OWNER);
3943-
__ br(Assembler::NE, no_count);
3937+
// If the owner is anonymous, we need to fix it -- in an outline stub.
3938+
Register tmp2 = disp_hdr;
3939+
__ ldr(tmp2, Address(tmp, ObjectMonitor::owner_offset_in_bytes()));
3940+
// We cannot use tbnz here, the target might be too far away and cannot
3941+
// be encoded.
3942+
__ tst(tmp2, (uint64_t)(intptr_t) ANONYMOUS_OWNER);
3943+
C2HandleAnonOMOwnerStub* stub = new (Compile::current()->comp_arena()) C2HandleAnonOMOwnerStub(tmp, tmp2);
3944+
Compile::current()->output()->add_stub(stub);
3945+
__ br(Assembler::NE, stub->entry());
3946+
__ bind(stub->continuation());
39443947
}
39453948

39463949
__ ldr(disp_hdr, Address(tmp, ObjectMonitor::recursions_offset_in_bytes()));

src/hotspot/cpu/aarch64/c2_CodeStubs_aarch64.cpp

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,27 @@ void C2CheckLockStackStub::emit(C2_MacroAssembler& masm) {
7575
__ b(continuation());
7676
}
7777

78+
int C2HandleAnonOMOwnerStub::max_size() const {
79+
return 20;
80+
}
81+
82+
void C2HandleAnonOMOwnerStub::emit(C2_MacroAssembler& masm) {
83+
__ bind(entry());
84+
Register mon = monitor();
85+
Register t = tmp();
86+
assert(t != noreg, "need tmp register");
87+
88+
// Fix owner to be the current thread.
89+
__ str(rthread, Address(mon, ObjectMonitor::owner_offset_in_bytes()));
90+
91+
// Pop owner object from lock-stack.
92+
__ ldr(t, Address(rthread, JavaThread::lock_stack_current_offset()));
93+
__ sub(t, t, oopSize);
94+
__ str(t, Address(rthread, JavaThread::lock_stack_current_offset()));
95+
96+
__ b(continuation());
97+
}
98+
7899
int C2LoadNKlassStub::max_size() const {
79100
return 8;
80101
}

src/hotspot/cpu/x86/c2_CodeStubs_x86.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,18 @@ void C2CheckLockStackStub::emit(C2_MacroAssembler& masm) {
8585
}
8686

8787
#ifdef _LP64
88+
int C2HandleAnonOMOwnerStub::max_size() const {
89+
return 17;
90+
}
91+
92+
void C2HandleAnonOMOwnerStub::emit(C2_MacroAssembler& masm) {
93+
__ bind(entry());
94+
Register mon = monitor();
95+
__ movptr(Address(mon, OM_OFFSET_NO_MONITOR_VALUE_TAG(owner)), r15_thread);
96+
__ subptr(Address(r15_thread, JavaThread::lock_stack_current_offset()), oopSize);
97+
__ jmp(continuation());
98+
}
99+
88100
int C2LoadNKlassStub::max_size() const {
89101
return 10;
90102
}

src/hotspot/cpu/x86/c2_MacroAssembler_x86.cpp

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -812,9 +812,18 @@ void C2_MacroAssembler::fast_unlock(Register objReg, Register boxReg, Register t
812812
#endif
813813
jccb(Assembler::zero, Stacked);
814814
if (UseFastLocking) {
815-
// If the owner is ANONYMOUS, we need to fix it - in the slow-path.
815+
// If the owner is ANONYMOUS, we need to fix it.
816816
testb(Address(tmpReg, OM_OFFSET_NO_MONITOR_VALUE_TAG(owner)), (int32_t) (intptr_t) ANONYMOUS_OWNER);
817+
#ifdef _LP64
818+
C2HandleAnonOMOwnerStub* stub = new (Compile::current()->comp_arena()) C2HandleAnonOMOwnerStub(tmpReg);
819+
Compile::current()->output()->add_stub(stub);
820+
jcc(Assembler::notEqual, stub->entry());
821+
bind(stub->continuation());
822+
#else
823+
// We can't easily implement this optimization on 32 bit because we don't have a thread register.
824+
// Call the slow-path instead.
817825
jcc(Assembler::notEqual, NO_COUNT);
826+
#endif
818827
}
819828
}
820829

src/hotspot/share/opto/c2_CodeStubs.hpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,19 @@ class C2CheckLockStackStub : public C2CodeStub {
9595
};
9696

9797
#ifdef _LP64
98+
class C2HandleAnonOMOwnerStub : public C2CodeStub {
99+
private:
100+
Register _monitor;
101+
Register _tmp;
102+
public:
103+
C2HandleAnonOMOwnerStub(Register monitor, Register tmp = noreg) : C2CodeStub(),
104+
_monitor(monitor), _tmp(tmp) {}
105+
Register monitor() { return _monitor; }
106+
Register tmp() { return _tmp; }
107+
int max_size() const;
108+
void emit(C2_MacroAssembler& masm);
109+
};
110+
98111
class C2LoadNKlassStub : public C2CodeStub {
99112
private:
100113
Register _dst;

0 commit comments

Comments
 (0)