RFR: 8319801: Recursive lightweight locking: aarch64 implementation [v9]

Coleen Phillimore coleenp at openjdk.org
Wed Jan 24 17:39:31 UTC 2024


On Wed, 24 Jan 2024 16:06:49 GMT, Axel Boldt-Christmas <aboldtch at openjdk.org> wrote:

>> Implements the aarch64 port of JDK-8319796.
>> 
>> There are two major parts for the port implementation. The C2 part, and the part shared by the interpreter, C1 and the native call wrapper.
>> 
>> The biggest change for both parts is that we check the lock stack first and if it is a recursive lightweight [un]lock and in that case simply pop/push and finish successfully.
>> 
>> Only if the recursive lightweight [un]lock fails does it look at the mark word. 
>> 
>> For the shared part if it is an unstructured exit, the monitor is inflated or the mark word transition fails it calls into the runtime.
>> 
>> The C2 operates under a few more assumptions, that the locking is structured and balanced. This means that some checks can be elided. 
>> 
>> First this means that in C2 unlock if the obj is not on the top of the lock stack, it must be inflated. And reversely if we reach the inflated C2 unlock the obj is not on the lock stack. This second property makes it possible to avoid reading the owner (and checking if it is anonymous). Instead it can either just do an un-contended unlock by writing null to the owner, or if contention happens, simply write the thread to the owner and jump to the runtime. 
>> 
>> The aarch64 C2 port tries to avoid stronger memory semantics where ever possible. In C2 lock it first does a relaxed load of the mark word to check for inflation. Both lock and unlock uses a load/store exclusive register pair to transition the mark word.
>
> Axel Boldt-Christmas has updated the pull request incrementally with two additional commits since the last revision:
> 
>  - Preloads markWord unconditionally
>  - Revert "Add preload_mark to MacroAssembler::lightweight_lock"
>    
>    This reverts commit 8950f503aa5dba0e203613bd9737ea0d50388ca3.

I have some minor questions and random thoughts, but this looks good.

src/hotspot/cpu/aarch64/c2_MacroAssembler_aarch64.cpp line 381:

> 379:     assert(oopDesc::mark_offset_in_bytes() == 0, "required to avoid lea");
> 380:     orr(t, mark, markWord::unlocked_value);
> 381:     // Release to satisfy the JMM.

I don't know what this comment is trying to say.
in the cmpxchg, is 't' the address of the markWord?

src/hotspot/cpu/aarch64/c2_MacroAssembler_aarch64.cpp line 434:

> 432:     sub(recursions, recursions, 1u);
> 433:     str(recursions, Address(monitor, ObjectMonitor::recursions_offset()));
> 434:     // Set flag == EQ

Thanks for this comment.

src/hotspot/cpu/aarch64/c2_MacroAssembler_aarch64.cpp line 455:

> 453:     // The owner may be anonymous and we removed the last obj entry in
> 454:     // the lock-stack. This loses the information about the owner.
> 455:     // Write the thread to the owner field so the runtime knows the owner.

Is this necessary here also?  Previous checks and slow path code in the runtime has already set the owner, if I understand correctly.

-------------

Marked as reviewed by coleenp (Reviewer).

PR Review: https://git.openjdk.org/jdk/pull/16608#pullrequestreview-1841976962
PR Review Comment: https://git.openjdk.org/jdk/pull/16608#discussion_r1465304035
PR Review Comment: https://git.openjdk.org/jdk/pull/16608#discussion_r1465306973
PR Review Comment: https://git.openjdk.org/jdk/pull/16608#discussion_r1465311272


More information about the hotspot-dev mailing list