RFR: 8296324: JVMTI GetStackTrace truncates vthread stack trace for agents loaded into running VM [v2]

Chris Plummer cjplummer at openjdk.org
Fri Nov 18 05:23:20 UTC 2022


On Fri, 18 Nov 2022 04:55:10 GMT, Serguei Spitsyn <sspitsyn at openjdk.org> wrote:

>> I think you need a flag that tells you if `init_static_notify_jvmti_events()` has been called.
>
> A part of the initialization sequence we need to know is:
> 
> create_vm()  {
>   . . .
>   // Launch -agentlib/-agentpath and converted -Xrun agents
>   if (Arguments::init_agents_at_startup()) {
>     create_vm_init_agents();  =>  {
>        <loads all agents and calls AgentOnLoad entry points>  =>
>         get_jvmti_interface() => set_notify_jvmti_events(true)
>   }
>   . . .
>   init_globals() => javaClasses_init() => java_lang_VirtualThread::init_static_notify_jvmti_events()
> 
> The `create_vm_init_agents()` is called in the context of unattaching thread.
> In this context a call to `java_lang_VirtualThread::init_static_notify_jvmti_events()` is guaranteed to happen after all the agents were successfully loaded at startup and executed their `AgentOnLoad` entree points which make calls to `vm->GetEnv()` that transitively call to `get_jvmti_interface()` and `java_lang_VirtualThread::set_notify_jvmti_events(true)`.
> 
> The conclusion is that the `java_lang_VirtualThread::init_static_notify_jvmti_events()` is always called at startup (single-threaded execution mode) after load of all the agents.
> In opposite, all calls to `get_jvmti_interface()` from the `AgentOnAttach` entry points have to in context of attached threads. I'm thinking if we could add an assert to ensure it is always the case.
> We can add a comment on this but I'm puzzled on how to make it clear and simple.

If there are no command line agents, then on startup `vthread_notify_jvmti_events` is not set true. Because it is not true, when `javaClasses_init()` calls `init_static_notify_jvmti_events()`, it does nothing. The whole point of the code we are reviewing here is to make sure `init_static_notify_jvmti_events()` is called while `vthread_notify_jvmti_events == true` so it actually does something. However, the code here does not bother calling `init_static_notify_jvmti_events()` if the current thread is detached, but it does still set `vthread_notify_jvmti_events = true`. This means that if this code gets called a second time, this time with the current thread attached, it will not call `init_static_notify_jvmti_events()` due to `vthread_notify_jvmti_events == true`, but it seems it should be calling it.

What I believe to be the flaw here is that you call `set_notify_jvmti_events(true)` even if you don't call `init_static_notify_jvmti_events()`.

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

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


More information about the serviceability-dev mailing list