RFR: 8319801: Recursive lightweight locking: aarch64 implementation

Axel Boldt-Christmas aboldtch at openjdk.org
Wed Nov 15 07:41:29 UTC 2023


On Fri, 10 Nov 2023 13:23:37 GMT, Andrew Haley <aph 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.
>
> src/hotspot/cpu/aarch64/macroAssembler_aarch64.cpp line 6344:
> 
>> 6342: 
>> 6343:   // Try to lock. Transition lock bits 0b01 => 0b00
>> 6344:   assert(oopDesc::mark_offset_in_bytes() == 0, "required to avoid lea");
> 
> It might be cleaner just to put in the `lea`. I believe that nothing will be emitted if the addend is zero. It's up to you.

It is only a nop if we load it into obj. And the current contract is that we do not change the value in obj. So we would still have to assert that the mark offset it 0 or we break the contract.

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

PR Review Comment: https://git.openjdk.org/jdk/pull/16608#discussion_r1393771857


More information about the hotspot-dev mailing list