JDK-8319796 : Recursive lightweight locking
  • Type: Enhancement
  • Component: hotspot
  • Sub-Component: runtime
  • Priority: P4
  • Status: Resolved
  • Resolution: Delivered
  • Submitted: 2023-11-09
  • Updated: 2024-04-30
  • Resolved: 2024-04-30
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
JDK 23
23Resolved
Related Reports
Duplicate :  
Relates :  
Relates :  
Relates :  
Relates :  
Relates :  
Sub Tasks
JDK-8319797 :  
JDK-8319799 :  
JDK-8319801 :  
JDK-8319900 :  
JDK-8319901 :  
Description
Add support for a limited set of recursive (reentrant) locking for LM_LIGHTWEIGHT.

The current implementation of LM_LIGHTWEIGHT must inflate the monitor for any recursive locking. 

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 entries 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 (0b01) 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 (0b01) 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.

The fundamental difference is that inflation must set the correct number of recursions when fixing the anonymous owner, and the lock stack must be checked for recursions when performing monitor exit to see if it is valid to transition the mark word to unlocked.
Comments
This umbrella RFE is completed in JDK23 except for two sub-tasks: JDK-8319947 Recursive lightweight locking: s390x implementation JDK-8319949 Recursive lightweight locking: arm implementation It is not clear whether JDK-8319947 or JDK-8319949 will be completed in time for the JDK23 code fork on 2024.06.06. Neither of those RFE sub-tasks have assigned engineers. There are a couple of options for managing this umbrella RFE: 1) Retarget this umbrella RFE to JDK24. 2) Convert JDK-8319947 and JDK-8319949 from sub-tasks of this umbrella RFE into standalone RFEs and resolve this umbrella RFE as delivered in JDK23. Of course, if both JDK-8319947 and JDK-8319949 happen to get fixed and integrated before 2024.06.06, then all is good and this umbrella RFE can be resolved as delivered in JDK23.
17-04-2024