On Tue, 19 Dec 2023 21:34:10 GMT, Alex Menkov <amen...@openjdk.org> wrote:

> I mean race between virtual thread state change and the thread stack switch 
> (to/from carrier).

I'm not sure if I understand you correctly or if we can call it a race. Alan 
will correct me if I'm wrong.
You are talking about thread state change. At least, mount state transition 
happens on the same JavaThread (it seems, you call it thread state switch). 
Mount state transition can go over a safepoint. But it should not progress 
while in a safepoint. David pointed out, "this was all happening at a global 
safepoint". My understanding is this assumption is correct. Then your approach 
`to identify that a virtual thread is mounted or not` should work in general. 
The condition `java_lang_VirtualThread::carrier_thread(vt) != nullptr` should 
indicate that the `vt` is mounted or is being in mount or unmount transition.
If the `vt` is in mount or unmount transition then (it is a gray zone) the way 
we identify mounted state should match the way we did it when dumped mounted 
virtual threads.
It is done this way: `oop mounted_vt = thread->is_vthread_mounted() ? 
thread->vthread() : nullptr;`
So, it seems any of yous suggestion should work here. Though, it would be nice 
to simplify it a little if possible. Again, to be consistent, a `vt` in mount 
state transition just have to be identified as mounted or unmounted in both 
fragments in a similar way .

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

PR Review Comment: https://git.openjdk.org/jdk/pull/17134#discussion_r1434006417

Reply via email to