On 12/08/2025 16:27, Cay Horstmann wrote:
I was asked when specifically a thread is pinned/unpinned. Following https://openjdk.org/jeps/444#Pinning, I had assumed that a thread is pinned when it calls a foreign/native method, or prior to JEP 491, when it enters a synchronized block/method.

On the other hand, there is this sentence in JEP 491: "In particular, if a virtual thread calls native code, either through a native method or the Foreign Function & Memory API, and that native code calls back to Java code that performs a blocking operation or blocks on a monitor, then the virtual thread *will be pinned*."

In the JEP 444 sense, it would have already been pinned when calling the native code, but it seems that in the JEP 491 sense, that only happens upon performing a blocking operation in the callback.

A virtual thread is pinned to its carrier when executing native code or when calling through native code (and back to Java). The limitations listed in JEP 444 includes the case where a virtual thread is executing native code. JEP 444 doesn't go into the scenario of a virtual threads calling through native code (so native frames on the stack) and attempts to block. The cited text in JEP 491 is from the section on diagnosing further cases of pinning and I think is okay.

-Alan


Reply via email to