-XX:[+|-]YieldPinnedVirtualThreads
This option enables or disables the yielding of CPU time by pinned continuations for virtual threads. You can control virtual thread scheduling behavior, especially in the case of applications that frequently encounter pinning scenarios.
The -XX:+YieldPinnedVirtualThreads option is the default setting.
Syntax
-XX:[+|-]YieldPinnedVirtualThreads
| Setting | Effect | Default |
|---|---|---|
-XX:+YieldPinnedVirtualThreads |
Enable | yes |
-XX:-YieldPinnedVirtualThreads |
Disable |
Explanation
When a virtual thread is created, it is associated with a data structure called continuation that represents the execution state of a virtual thread. Continuation saves and restores the current state of a virtual thread. For example, when a virtual thread unmounts, continuation saves the current state and when it remounts on an available carrier thread, continuation restores that state.
In some scenarios, such as executing native code or some VM internal operations, the continuation is pinned. When pinned, a virtual thread cannot unmount its carrier thread even if it encounters a blocking operation. It also holds onto CPU time, thus preventing other virtual threads from using that carrier thread.
A VM maintains a limited pool of carrier threads. Virtual threads are supposed to unmount when blocked, freeing carriers for other virtual threads to use. You can use the -XX:+YieldPinnedVirtualThreads option to enable the pinned virtual thread to yield CPU time to OS scheduler. A pinned virtual thread cannot unmount its carrier thread but the yielding option helps by at least allowing sharing of CPU time even when carrier thread sharing is impossible.
You can use the -XX:-YieldPinnedVirtualThreads option to disable this yielding of CPU time feature.
For more information about pinning of virtual threads, see JEP 491: Synchronize Virtual Threads without Pinning.
