Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8338813

Implement JEP 491: Synchronize Virtual Threads without Pinning

XMLWordPrintable

    • Icon: CSR CSR
    • Resolution: Approved
    • Icon: P2 P2
    • 24
    • hotspot
    • None
    • behavioral
    • minimal
    • No compatibility concerns.
    • System or security property
    • Implementation

      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.

            alanb Alan Bateman
            alanb Alan Bateman
            David Holmes, Patricio Chilano Mateo
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: