RFR: 8319799: Recursive lightweight locking: x86 implementation
Axel Boldt-Christmas
aboldtch at openjdk.org
Fri Nov 10 13:05:10 UTC 2023
Implements the x86 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 x86 C2 port also has some extra oddities.
The mark word read is done early as it showed better scaling in hyper-threaded scenarios on certain intel hardware, and no noticeable downside on other tested x86 hardware.
The fast path is written to avoid going through conditional branches. This in combination with keeping the ZF output correct, the code does some actions eagerly, decrementing the held monitor count, popping from the lock stack. And jumps to a code stub if a slow path is required which restores the thread local state to a correct state before jumping to the runtime.
The contended unlock was also moved to the code stub.
-------------
Depends on: https://git.openjdk.org/jdk/pull/16606
Commit messages:
- 8319799: Recursive lightweight locking: x86 implementation
- Cleanup: C2 fast_lock/fast_unlock x86
Changes: https://git.openjdk.org/jdk/pull/16607/files
Webrev: https://webrevs.openjdk.org/?repo=jdk&pr=16607&range=00
Issue: https://bugs.openjdk.org/browse/JDK-8319799
Stats: 576 lines in 13 files changed: 463 ins; 57 del; 56 mod
Patch: https://git.openjdk.org/jdk/pull/16607.diff
Fetch: git fetch https://git.openjdk.org/jdk.git pull/16607/head:pull/16607
PR: https://git.openjdk.org/jdk/pull/16607
More information about the hotspot-dev
mailing list