JDK-8338813 : Implement JEP 491: Synchronize Virtual Threads without Pinning
  • Type: CSR
  • Component: hotspot
  • Sub-Component: runtime
  • Priority: P2
  • Status: Closed
  • Resolution: Approved
  • Fix Versions: 24
  • Submitted: 2024-08-22
  • Updated: 2024-11-04
  • Resolved: 2024-11-04
Related Reports
CSR :  
Description
Summary
-------

Improve the scalability of Java code that uses `synchronized` methods and statements by arranging for virtual threads that block on object monitors to release their carrier for use by other virtual threads.


Problem
-------

At this time, a virtual thread cannot unmount when it blocks inside `synchronized ` methods or blocks, when it blocks entering a `synchronized ` method/block, or when it waits in `Object.wait`. These cases currently "pin" the carrier which can harm the scalability and performance. In some cases it can lead to starvation, even deadlock, where no virtual threads can execute because all platform threads available to the JDK's virtual thread scheduler are pinned by a virtual thread.

Solution
--------

Change the HotSpot VM's implementation of object monitors so that virtual threads can acquire, hold, and release monitors, independently of their carriers.

As part of the change:

- Remove the diagnostic option to detect pinning that was enabled with `-Djdk.tracePinnedThreads`. This option has proven very problematic and no longer useful.

- Expand the scenarios where the JDK Flight Recorder event `jdk.VirtualThreadPinned` is recorded. It will now be recorded when a virtual threads parks, blocks on monitor enter, or waits in Object.waits while pinned due to a native or VM frame. This includes blocking during class loading while executing a class initializer. A JFR event is also recorded when waiting in the VM for another thread to initialize a class.


Specification
-------------

There are no specification changes.
Comments
Moving to Approved.
04-11-2024

There is no "compatibility risk" description at present.
18-10-2024

Moving to Provisional, not Approved.
03-10-2024