RFR: 8319797: Recursive lightweight locking: Runtime implementation
Roman Kennke
rkennke at openjdk.org
Fri Nov 10 13:51:00 UTC 2023
On Fri, 10 Nov 2023 12:40:03 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.
Good work! Mostly looks good! I only have some minor comments and a question.
src/hotspot/share/runtime/lockStack.cpp line 47:
> 45: LockStack::LockStack(JavaThread* jt) :
> 46: _top(lock_stack_base_offset), _base() {
> 47: // Make sure the layout of the object is compatable with the emitted codes assumptions.
Typo: compatible -> compatible, codes -> code's (?)
src/hotspot/share/runtime/synchronizer.cpp line 530:
> 528: LockStack& lock_stack = current->lock_stack();
> 529: if (lock_stack.is_full()) {
> 530: // The emitted code always goes into the runtime incase the lock stack
Typo: incase -> in case
src/hotspot/share/runtime/synchronizer.cpp line 530:
> 528: LockStack& lock_stack = current->lock_stack();
> 529: if (lock_stack.is_full()) {
> 530: // The emitted code always goes into the runtime incase the lock stack
What is the rationale behind this block? Is it beneficial to inflate the top-most lock to make room for the new one, because that might be hotter? If so, then it may be even more useful to inflate the bottom-most entry instead?
-------------
Changes requested by rkennke (Reviewer).
PR Review: https://git.openjdk.org/jdk/pull/16606#pullrequestreview-1724787619
PR Review Comment: https://git.openjdk.org/jdk/pull/16606#discussion_r1389399785
PR Review Comment: https://git.openjdk.org/jdk/pull/16606#discussion_r1389412144
PR Review Comment: https://git.openjdk.org/jdk/pull/16606#discussion_r1389415768
More information about the hotspot-dev
mailing list