On Fri, 18 Nov 2022 03:42:39 GMT, Chris Plummer <cjplum...@openjdk.org> wrote:

>> Enabling the `notify_jvmti_events` is an optimization to avoid having this 
>> notification overhead with JVMTI virtual thread mount state transitions when 
>> it is not needed.
>> We need to enable it only once and never disable it if enabled.
>> The first attempt to enable it is at startup if there was any agent loaded 
>> with command line options.
>> In such a case, the get_jvmti_interface() is called in a context of 
>> `AgentOnLoad()` in unattached thread.
>> It only sets the `java_lang_VirtualThread::set_notify_jvmti_events(true)` 
>> The `init_static_notify_jvmti_events()` is called from the 
>> `javaClasses_init()`.
>> The agents that are loaded into running VM are initialized with the 
>> `AgentOnAttach()`.
>> In this case, we can't rely on the `javaClasses_init()` and so, have to 
>> explicitly call the `init_static_notify_jvmti_events()`.
>> I feels like this can be simplified. I keep thinking about the best way to 
>> do it.
>> Probably, the pair <set_notify_jvmti_events,  
>> init_static_notify_jvmti_events> can be replaced with just function. The 
>> problem is that we can't use the `ThreadInVMfromNative` helper for 
>> unattached thread.
>
> If `notify_jvmti_events()` is false, then you call 
> `set_notify_jvmti_events(true)`, which means you will never enter the `if` 
> block again. However, if the thread is not attached,  you do not call 
> `init_static_notify_jvmti_events()`. What happens if later there is an 
> attached thread that triggers this code? Is seem when that happens you should 
> call `init_static_notify_jvmti_events()`, but won't because 
> `notify_jvmti_events()` is true.

I think you need a flag that tells you if `init_static_notify_jvmti_events()` 
has been called.

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

PR: https://git.openjdk.org/jdk/pull/11204

Reply via email to