RFR: 8319773: Avoid inflating monitors when installing hash codes for LM_LIGHTWEIGHT
David Holmes
dholmes at openjdk.org
Mon Nov 13 00:57:57 UTC 2023
On Fri, 10 Nov 2023 12:18:29 GMT, Axel Boldt-Christmas <aboldtch at openjdk.org> wrote:
> LM_LIGHTWEIGHT only uses the lock bits for its locking. This leaves the hashCode bits free when a monitor is not inflated. So instead of inflating when installing the hashCode on a fast locked object it can simply use the hashCode bits in the markWord.
>
> The mark word transitions Unlocked (0b01) <=> Locked (0b00) are done by retrying the CAS if it fails due to non-lock bit changes.
> The mark word transitions Monitor (0b10) <=> Locked/Unlocked (0b0X) are the same as before, inflation already handles hash codes. This change does not interact with the mark word if it is in a Monitor (0b10) state, so the strong CAS which is used for deflation are still valid, and will not fail to any other reason than the cooperative race to help transition the mark word during deflation.
>
> This is dependent on JDK-8319778 simply because JDK-8319797 is dependent on both this and JDK-8319778.
Seems reasonable - though more complex than I had envisaged. One query below and a change requested for the test.
Thanks
src/hotspot/share/runtime/synchronizer.cpp line 582:
> 580: // It can only have installed an anonymously locked monitor at this point.
> 581: // Fetch that monitor, set owner correctly to this thread, and
> 582: // exit it (allowing waiting threads to enter).
I don't understand why the anonymous owner case is no longer being checked. ??
test/hotspot/jtreg/runtime/whitebox/TestWBDeflateIdleMonitors.java line 69:
> 67: obj = new Object();
> 68: synchronized (obj) {
> 69: if (LockingMode != LM_LIGHTWEIGHT) {
I don't think we need to make this test behave differently because of implementation details of different locking modes. Just use `wait(1)` unconditionally. Thanks.
-------------
Changes requested by dholmes (Reviewer).
PR Review: https://git.openjdk.org/jdk/pull/16603#pullrequestreview-1726397913
PR Review Comment: https://git.openjdk.org/jdk/pull/16603#discussion_r1390528029
PR Review Comment: https://git.openjdk.org/jdk/pull/16603#discussion_r1390529012
More information about the hotspot-dev
mailing list