Closed buuuuuuug closed 5 months ago
It looks like the root cause of this is that the thread is actually not getting pinned in Native Image. When I debug this, isPinned0
is negative and the thread will yield (while it doesn't in regular Java). I'm not 100% sure why there is a difference in vthread pinning behaviour between Native Image and Java, but perhaps its related to monitors always being inflated. In Java mode, the pin reason is MONITOR
. Since stack locking does not exist as an optimization in NI, maybe vthreads don't need to pin while holding a monitor. Maybe @peter-hofer could explain more?
@roberttoyonaga Our implementation of monitors doesn't need to pin virtual threads. Pinning happens only with native code on the stack, while holding a monitor that was acquired via JNI's MonitorEnter
function, or while executing a class initializer in a virtual thread.
Describe the issue As descibed in issue5410, graalvm jdk21 should have supported
jdk.VirtualThreadPinned
event in native-image mode. However it does not!Steps to reproduce the issue Please include both build steps as well as run steps
JfrVirtualThreadPinnedEventHandler.class
.Describe GraalVM and your environment:
More details build log
Following the steps above, the first time to run
curl --request POST --url 'http://localhost:8080/pinning
will get the log as below:but, when running as native-image, you get no pin log