RFR: 8319801: Recursive lightweight locking: aarch64 implementation [v6]
Roman Kennke
rkennke at openjdk.org
Wed Jan 24 11:34:32 UTC 2024
On Tue, 23 Jan 2024 16:30:48 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 with a new target base due to a merge or a rebase. The incremental webrev excludes the unrelated changes brought in by the merge/rebase. The pull request contains 10 additional commits since the last revision:
>
> - Merge remote-tracking branch 'upstream_jdk/pr/16606' into JDK-8319801
> - Switch to CAS over LXSX
> - Fix missing $
> - Merge remote-tracking branch 'upstream_jdk/pr/16606' into JDK-8319801
> - Merge remote-tracking branch 'upstream_jdk/pr/16606' into JDK-8319801
> - Merge remote-tracking branch 'upstream_jdk/pr/16606' into JDK-8319801
> - Merge remote-tracking branch 'upstream_jdk/pr/16606' into JDK-8319801
> - Merge remote-tracking branch 'upstream_jdk/pr/16606' into JDK-8319801
> - 8319801: Recursive lightweight locking: aarch64 implementation
> - Cleanup: C2 fast_lock/fast_unlock aarch64
Nice work! I've only got some minor issues.
src/hotspot/cpu/aarch64/c2_MacroAssembler_aarch64.cpp line 230:
> 228: Register t2, Register t3) {
> 229: assert(LockingMode == LM_LIGHTWEIGHT, "must be");
> 230: // TODO: Current implementation does not use the box, consider removing.
If it's not used, then please remove it? Maybe it can help to allocate one less register, which may be useful performance-wise when register pressure is high?
src/hotspot/cpu/aarch64/c2_MacroAssembler_aarch64.cpp line 339:
> 337: Register t2) {
> 338: assert(LockingMode == LM_LIGHTWEIGHT, "must be");
> 339: // TODO: Current implementation uses box only as a TEMP, consider renaming.
Yeah, please rename the register.
src/hotspot/cpu/aarch64/macroAssembler_aarch64.cpp line 68:
> 66: #endif
> 67:
> 68: #include <sys/types.h>
Is that import even used? I can't spot it.
-------------
Changes requested by rkennke (Reviewer).
PR Review: https://git.openjdk.org/jdk/pull/16608#pullrequestreview-1841154137
PR Review Comment: https://git.openjdk.org/jdk/pull/16608#discussion_r1464774323
PR Review Comment: https://git.openjdk.org/jdk/pull/16608#discussion_r1464775022
PR Review Comment: https://git.openjdk.org/jdk/pull/16608#discussion_r1464776683
More information about the hotspot-dev
mailing list