Skip to content

Commit b48dbf6

Browse files
committed
8316181: Move the fast locking implementation out of the .ad files
Reviewed-by: thartmann, rkennke, fyang
1 parent 8f4dfc4 commit b48dbf6

6 files changed

+435
-417
lines changed

src/hotspot/cpu/aarch64/aarch64.ad

+6-198
Original file line numberDiff line numberDiff line change
@@ -3816,202 +3816,6 @@ encode %{
38163816
__ br(target_reg);
38173817
%}
38183818

3819-
enc_class aarch64_enc_fast_lock(iRegP object, iRegP box, iRegP tmp, iRegP tmp2) %{
3820-
C2_MacroAssembler _masm(&cbuf);
3821-
Register oop = as_Register($object$$reg);
3822-
Register box = as_Register($box$$reg);
3823-
Register disp_hdr = as_Register($tmp$$reg);
3824-
Register tmp = as_Register($tmp2$$reg);
3825-
Label cont;
3826-
Label object_has_monitor;
3827-
Label count, no_count;
3828-
3829-
assert_different_registers(oop, box, tmp, disp_hdr);
3830-
3831-
// Load markWord from object into displaced_header.
3832-
__ ldr(disp_hdr, Address(oop, oopDesc::mark_offset_in_bytes()));
3833-
3834-
if (DiagnoseSyncOnValueBasedClasses != 0) {
3835-
__ load_klass(tmp, oop);
3836-
__ ldrw(tmp, Address(tmp, Klass::access_flags_offset()));
3837-
__ tstw(tmp, JVM_ACC_IS_VALUE_BASED_CLASS);
3838-
__ br(Assembler::NE, cont);
3839-
}
3840-
3841-
// Check for existing monitor
3842-
__ tbnz(disp_hdr, exact_log2(markWord::monitor_value), object_has_monitor);
3843-
3844-
if (LockingMode == LM_MONITOR) {
3845-
__ tst(oop, oop); // Set NE to indicate 'failure' -> take slow-path. We know that oop != 0.
3846-
__ b(cont);
3847-
} else if (LockingMode == LM_LEGACY) {
3848-
// Set tmp to be (markWord of object | UNLOCK_VALUE).
3849-
__ orr(tmp, disp_hdr, markWord::unlocked_value);
3850-
3851-
// Initialize the box. (Must happen before we update the object mark!)
3852-
__ str(tmp, Address(box, BasicLock::displaced_header_offset_in_bytes()));
3853-
3854-
// Compare object markWord with an unlocked value (tmp) and if
3855-
// equal exchange the stack address of our box with object markWord.
3856-
// On failure disp_hdr contains the possibly locked markWord.
3857-
__ cmpxchg(oop, tmp, box, Assembler::xword, /*acquire*/ true,
3858-
/*release*/ true, /*weak*/ false, disp_hdr);
3859-
__ br(Assembler::EQ, cont);
3860-
3861-
assert(oopDesc::mark_offset_in_bytes() == 0, "offset of _mark is not 0");
3862-
3863-
// If the compare-and-exchange succeeded, then we found an unlocked
3864-
// object, will have now locked it will continue at label cont
3865-
3866-
// Check if the owner is self by comparing the value in the
3867-
// markWord of object (disp_hdr) with the stack pointer.
3868-
__ mov(rscratch1, sp);
3869-
__ sub(disp_hdr, disp_hdr, rscratch1);
3870-
__ mov(tmp, (address) (~(os::vm_page_size()-1) | markWord::lock_mask_in_place));
3871-
// If condition is true we are cont and hence we can store 0 as the
3872-
// displaced header in the box, which indicates that it is a recursive lock.
3873-
__ ands(tmp/*==0?*/, disp_hdr, tmp); // Sets flags for result
3874-
__ str(tmp/*==0, perhaps*/, Address(box, BasicLock::displaced_header_offset_in_bytes()));
3875-
__ b(cont);
3876-
} else {
3877-
assert(LockingMode == LM_LIGHTWEIGHT, "must be");
3878-
__ lightweight_lock(oop, disp_hdr, tmp, rscratch1, no_count);
3879-
__ b(count);
3880-
}
3881-
3882-
// Handle existing monitor.
3883-
__ bind(object_has_monitor);
3884-
3885-
// The object's monitor m is unlocked iff m->owner == NULL,
3886-
// otherwise m->owner may contain a thread or a stack address.
3887-
//
3888-
// Try to CAS m->owner from NULL to current thread.
3889-
__ add(tmp, disp_hdr, (in_bytes(ObjectMonitor::owner_offset())-markWord::monitor_value));
3890-
__ cmpxchg(tmp, zr, rthread, Assembler::xword, /*acquire*/ true,
3891-
/*release*/ true, /*weak*/ false, rscratch1); // Sets flags for result
3892-
3893-
if (LockingMode != LM_LIGHTWEIGHT) {
3894-
// Store a non-null value into the box to avoid looking like a re-entrant
3895-
// lock. The fast-path monitor unlock code checks for
3896-
// markWord::monitor_value so use markWord::unused_mark which has the
3897-
// relevant bit set, and also matches ObjectSynchronizer::enter.
3898-
__ mov(tmp, (address)markWord::unused_mark().value());
3899-
__ str(tmp, Address(box, BasicLock::displaced_header_offset_in_bytes()));
3900-
}
3901-
__ br(Assembler::EQ, cont); // CAS success means locking succeeded
3902-
3903-
__ cmp(rscratch1, rthread);
3904-
__ br(Assembler::NE, cont); // Check for recursive locking
3905-
3906-
// Recursive lock case
3907-
__ increment(Address(disp_hdr, in_bytes(ObjectMonitor::recursions_offset()) - markWord::monitor_value), 1);
3908-
// flag == EQ still from the cmp above, checking if this is a reentrant lock
3909-
3910-
__ bind(cont);
3911-
// flag == EQ indicates success
3912-
// flag == NE indicates failure
3913-
__ br(Assembler::NE, no_count);
3914-
3915-
__ bind(count);
3916-
__ increment(Address(rthread, JavaThread::held_monitor_count_offset()));
3917-
3918-
__ bind(no_count);
3919-
%}
3920-
3921-
enc_class aarch64_enc_fast_unlock(iRegP object, iRegP box, iRegP tmp, iRegP tmp2) %{
3922-
C2_MacroAssembler _masm(&cbuf);
3923-
Register oop = as_Register($object$$reg);
3924-
Register box = as_Register($box$$reg);
3925-
Register disp_hdr = as_Register($tmp$$reg);
3926-
Register tmp = as_Register($tmp2$$reg);
3927-
Label cont;
3928-
Label object_has_monitor;
3929-
Label count, no_count;
3930-
3931-
assert_different_registers(oop, box, tmp, disp_hdr);
3932-
3933-
if (LockingMode == LM_LEGACY) {
3934-
// Find the lock address and load the displaced header from the stack.
3935-
__ ldr(disp_hdr, Address(box, BasicLock::displaced_header_offset_in_bytes()));
3936-
3937-
// If the displaced header is 0, we have a recursive unlock.
3938-
__ cmp(disp_hdr, zr);
3939-
__ br(Assembler::EQ, cont);
3940-
}
3941-
3942-
// Handle existing monitor.
3943-
__ ldr(tmp, Address(oop, oopDesc::mark_offset_in_bytes()));
3944-
__ tbnz(tmp, exact_log2(markWord::monitor_value), object_has_monitor);
3945-
3946-
if (LockingMode == LM_MONITOR) {
3947-
__ tst(oop, oop); // Set NE to indicate 'failure' -> take slow-path. We know that oop != 0.
3948-
__ b(cont);
3949-
} else if (LockingMode == LM_LEGACY) {
3950-
// Check if it is still a light weight lock, this is is true if we
3951-
// see the stack address of the basicLock in the markWord of the
3952-
// object.
3953-
3954-
__ cmpxchg(oop, box, disp_hdr, Assembler::xword, /*acquire*/ false,
3955-
/*release*/ true, /*weak*/ false, tmp);
3956-
__ b(cont);
3957-
} else {
3958-
assert(LockingMode == LM_LIGHTWEIGHT, "must be");
3959-
__ lightweight_unlock(oop, tmp, box, disp_hdr, no_count);
3960-
__ b(count);
3961-
}
3962-
3963-
assert(oopDesc::mark_offset_in_bytes() == 0, "offset of _mark is not 0");
3964-
3965-
// Handle existing monitor.
3966-
__ bind(object_has_monitor);
3967-
STATIC_ASSERT(markWord::monitor_value <= INT_MAX);
3968-
__ add(tmp, tmp, -(int)markWord::monitor_value); // monitor
3969-
3970-
if (LockingMode == LM_LIGHTWEIGHT) {
3971-
// If the owner is anonymous, we need to fix it -- in an outline stub.
3972-
Register tmp2 = disp_hdr;
3973-
__ ldr(tmp2, Address(tmp, ObjectMonitor::owner_offset()));
3974-
// We cannot use tbnz here, the target might be too far away and cannot
3975-
// be encoded.
3976-
__ tst(tmp2, (uint64_t)ObjectMonitor::ANONYMOUS_OWNER);
3977-
C2HandleAnonOMOwnerStub* stub = new (Compile::current()->comp_arena()) C2HandleAnonOMOwnerStub(tmp, tmp2);
3978-
Compile::current()->output()->add_stub(stub);
3979-
__ br(Assembler::NE, stub->entry());
3980-
__ bind(stub->continuation());
3981-
}
3982-
3983-
__ ldr(disp_hdr, Address(tmp, ObjectMonitor::recursions_offset()));
3984-
3985-
Label notRecursive;
3986-
__ cbz(disp_hdr, notRecursive);
3987-
3988-
// Recursive lock
3989-
__ sub(disp_hdr, disp_hdr, 1u);
3990-
__ str(disp_hdr, Address(tmp, ObjectMonitor::recursions_offset()));
3991-
__ cmp(disp_hdr, disp_hdr); // Sets flags for result
3992-
__ b(cont);
3993-
3994-
__ bind(notRecursive);
3995-
__ ldr(rscratch1, Address(tmp, ObjectMonitor::EntryList_offset()));
3996-
__ ldr(disp_hdr, Address(tmp, ObjectMonitor::cxq_offset()));
3997-
__ orr(rscratch1, rscratch1, disp_hdr); // Will be 0 if both are 0.
3998-
__ cmp(rscratch1, zr); // Sets flags for result
3999-
__ cbnz(rscratch1, cont);
4000-
// need a release store here
4001-
__ lea(tmp, Address(tmp, ObjectMonitor::owner_offset()));
4002-
__ stlr(zr, tmp); // set unowned
4003-
4004-
__ bind(cont);
4005-
// flag == EQ indicates success
4006-
// flag == NE indicates failure
4007-
__ br(Assembler::NE, no_count);
4008-
4009-
__ bind(count);
4010-
__ decrement(Address(rthread, JavaThread::held_monitor_count_offset()));
4011-
4012-
__ bind(no_count);
4013-
%}
4014-
40153819
%}
40163820

40173821
//----------FRAME--------------------------------------------------------------
@@ -16626,7 +16430,9 @@ instruct cmpFastLock(rFlagsReg cr, iRegP object, iRegP box, iRegPNoSp tmp, iRegP
1662616430
ins_cost(5 * INSN_COST);
1662716431
format %{ "fastlock $object,$box\t! kills $tmp,$tmp2" %}
1662816432

16629-
ins_encode(aarch64_enc_fast_lock(object, box, tmp, tmp2));
16433+
ins_encode %{
16434+
__ fast_lock($object$$Register, $box$$Register, $tmp$$Register, $tmp2$$Register);
16435+
%}
1663016436

1663116437
ins_pipe(pipe_serial);
1663216438
%}
@@ -16639,7 +16445,9 @@ instruct cmpFastUnlock(rFlagsReg cr, iRegP object, iRegP box, iRegPNoSp tmp, iRe
1663916445
ins_cost(5 * INSN_COST);
1664016446
format %{ "fastunlock $object,$box\t! kills $tmp, $tmp2" %}
1664116447

16642-
ins_encode(aarch64_enc_fast_unlock(object, box, tmp, tmp2));
16448+
ins_encode %{
16449+
__ fast_unlock($object$$Register, $box$$Register, $tmp$$Register, $tmp2$$Register);
16450+
%}
1664316451

1664416452
ins_pipe(pipe_serial);
1664516453
%}

0 commit comments

Comments
 (0)