RFR: 8319797: Recursive lightweight locking: Runtime implementation [v6]
Daniel D. Daugherty
dcubed at openjdk.org
Wed Nov 22 21:36:09 UTC 2023
On Tue, 21 Nov 2023 14:45:23 GMT, Axel Boldt-Christmas <aboldtch at openjdk.org> wrote:
>> Implements the runtime part of JDK-8319796.
>> The different CPU implementations are/will be created as dependent pull requests.
>>
>> This enhancement proposes introducing the ability for LM_LIGHTWEIGHT to handle consecutive recursive monitor enter. Limiting the implementation to only consecutive monitor enters allows for more efficient emitted code which only needs to look at the two top most entires on the lock stack to determine what to do in a monitor exit.
>>
>> A high level overview:
>> * Locking is still performed on the mark word
>> * Unlocked (0b01) <=> Locked (0b00)
>> * Monitor enter on Obj with mark word Unlocked (0b01) is the same
>> * Transition Obj's mark word Unlocked (0b01) => Locked (0b00)
>> * Push Obj onto the lock stack
>> * Success
>> * Monitor enter on Obj with mark word Locked (0b00) will check the top entry on the lock stack
>> * If top entry is Obj
>> * Push Obj on the lock stack
>> * Success
>> * If top entry is not Obj
>> * Inflate and call ObjectMonitor::enter
>> * Monitor exit on Obj with mark word Locked (0b00) will check the two top entries on the lock stack
>> * If just the top entry is Obj
>> * Transition Obj's mark word Locked (0b00) => Unlocked (0b01)
>> * Pop the entry
>> * Success
>> * If both entries are Obj
>> * Pop the top entry
>> * Success
>> * Any other case only occurs for unstructured locking, then just inflate and call ObjectMonitor::exit
>> * If the monitor has been inflated for object Obj which is owned by the current thread
>> * All corresponding entries for Obj is removed from the lock stack
>> * The monitor recursions is set to the number of removed entries - 1
>> * The owner is changed from anonymous to the thread
>> * The regular ObjectMonitor::action is called.
>
> Axel Boldt-Christmas has updated the pull request with a new target base due to a merge or a rebase. The pull request now contains six commits:
>
> - Merge remote-tracking branch 'upstream_jdk/pr/16603' into JDK-8319797
> - Merge remote-tracking branch 'upstream_jdk/pr/16603' into JDK-8319797
> - Merge remote-tracking branch 'upstream_jdk/pr/16603' into JDK-8319797
> - Fix nit
> - Fix comment typos
> - 8319797: Recursive lightweight locking: Runtime implementation
I've done another review pass and added a few more comments.
I think I made only minor comments in both passes. Of course,
when I review one or more of the platform specific fixes, I may
have more to say about this "Runtime" portion.
src/hotspot/share/runtime/synchronizer.cpp line 1320:
> 1318: inf->set_owner_from_anonymous(current);
> 1319: size_t removed = JavaThread::cast(current)->lock_stack().remove(object);
> 1320: inf->set_recursions(removed - 1);
Hmmmm... so now I'm wondering how non-lightweight locking gets the
recursions count correct? IIRC, with LM_LEGACY we count the BasicLocks
on the stack in order to get a proper recursion count, but I could be wrong...
I don't see anything in the inflation code that's updating the recursion count
based on BasicLocks on the stack. Of course that would be impossible for a
Thread-A to do safely why inflating an ObjectMonitor for a lock held by a
Thread-B.
-------------
Marked as reviewed by dcubed (Reviewer).
PR Review: https://git.openjdk.org/jdk/pull/16606#pullrequestreview-1745354175
PR Review Comment: https://git.openjdk.org/jdk/pull/16606#discussion_r1402720113
More information about the hotspot-dev
mailing list