RFR: 8319773: Avoid inflating monitors when installing hash codes for LM_LIGHTWEIGHT [v4]

Daniel D. Daugherty dcubed at openjdk.org
Thu Nov 16 18:20:57 UTC 2023


On Thu, 16 Nov 2023 10:04:11 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.
>
> Axel Boldt-Christmas has updated the pull request incrementally with one additional commit since the last revision:
> 
>   Move is_lock_owned closer to its only use

src/hotspot/share/runtime/synchronizer.cpp line 521:

> 519:           const markWord new_mark = mark.set_fast_locked();
> 520:           const markWord old_mark = mark;
> 521:           mark = obj()->cas_set_mark(new_mark, old_mark);

I'm having trouble seeing how this change is related to hash codes.
The previous code did not loop and if the calling thread's attempt to
lightweight lock the object lost a race, then we simply fell thru down
to the inflate-enter loop...

I don't see any explanation for this change in the bug report or in the
PR anywhere. Perhaps I'll figure it out as I reason thru the changes...

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

PR Review Comment: https://git.openjdk.org/jdk/pull/16603#discussion_r1396154763


More information about the hotspot-dev mailing list