On Thu, 16 Nov 2023 19:02:39 GMT, Patricio Chilano Mateo 
<pchilanom...@openjdk.org> wrote:

>> I'm suggesting to fix it this way for the unmounted case only:
>> 
>> @@ -1976,6 +1976,13 @@ JvmtiHandshake::execute(JvmtiUnitedHandshakeClosure* 
>> hs_cl, ThreadsListHandle* t
>>        return;
>>      }
>>      if (target_jt == nullptr) {    // unmounted virtual thread
>> +      // JvmtiVTMSTransitionDisabler can start after the vthread executed 
>> notifyJvmtiUnmount(), i.e.
>> +      // the vthread is already outside the transition, but before changing 
>> the state to TERMINATED.
>> +      // Changing the state to TERMINATED is racy, so we check if the 
>> continuation is done in advance.
>> +      oop cont = java_lang_VirtualThread::continuation(target_h());
>> +      if (jdk_internal_vm_Continuation::done(cont)) {
>> +        return;
>> +      }
>>        hs_cl->do_vthread(target_h); // execute handshake closure callback on 
>> current thread directly
>>      }
>>    }
>
> Sounds good. Is there a reason why not have the check inside 
> JvmtiEnvBase::is_vthread_alive()?

If it is a part of the `JvmtiEnvBase::is_vthread_alive()` then it is racy for 
mounted virtual threads.
It is not racy for unmounted virtual threads.

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

PR Review Comment: https://git.openjdk.org/jdk/pull/16460#discussion_r1396456207

Reply via email to