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.