RFR: 8373367: interp-only mechanism fails to work for carrier threads in a corner case [v3]

David Holmes dholmes at openjdk.org
Mon Feb 2 02:14:06 UTC 2026


On Fri, 30 Jan 2026 07:45:04 GMT, Serguei Spitsyn <sspitsyn at openjdk.org> wrote:

>> The `interp-only` mechanism is based on the `JavaThread` objects. Carrier and virtual threads can temporary share the same `JavaThread`. The `java_thread->jvmti_thread_state()` is re-linked to a virtual thread at `mount` and to the carrier thread at `unmount`. The `JvmtiThreadState` has a back link to the `JavaThread` which is also set for virtual thread at a `mount` and carrier thread at an `unmount`. Just one of these two links at the same time is set to the `JavaThread`, the other one has to be set to `nullptr`. The `interp-only` mechanism needs this invariant.
>> However, there is a corner case when this invariant is broken. It happens when the `JvmtiThreadState` for carrier thread has just been created. In such case, the link to `JavaThread` is always `non-nullptr` even though a virtual thread is currently mounted on a carrier thread. This simple update fixes the issue in the  `JvmtiThreadState` ctor.
>> 
>> Testing:
>>  - TBD: Mach5 tiers 1-6
>
> Serguei Spitsyn has updated the pull request incrementally with one additional commit since the last revision:
> 
>   review: moved and extended comment in JvmtiThreadState ctor

I appreciate the expanded comments but I still don't fully understand what `_thread` and `_saved_thread` point to at different times. The lifecycle of these fields really needs to be clearly described somewhere.

A couple of typos are present - see below. Thanks

src/hotspot/share/prims/jvmtiThreadState.cpp line 61:

> 59: 
> 60:   // The _thread field is a link to the JavaThread associated with JvmtiThreadState.
> 61:   // The _thread_saved field is used for carrier threads only when a virtual thread,

Suggestion:

  // The _thread_saved field is used for carrier threads only when a virtual thread

src/hotspot/share/prims/jvmtiThreadState.cpp line 65:

> 63:   // Carrier and virtual threads can temporarily share same JavaThread. In such a case,
> 64:   // only virtual _thread should have a link from JvmtiThreadState to JavaThread.
> 65:   // The carrier thread _thread filed is set to nullptr if a virtual thread is monted.

Suggestion:

  // The carrier thread _thread field is set to nullptr if a virtual thread is mounted.

-------------

Changes requested by dholmes (Reviewer).

PR Review: https://git.openjdk.org/jdk/pull/29436#pullrequestreview-3737008826
PR Review Comment: https://git.openjdk.org/jdk/pull/29436#discussion_r2752276119
PR Review Comment: https://git.openjdk.org/jdk/pull/29436#discussion_r2752275470


More information about the hotspot-dev mailing list