On Mon, 30 Nov 2026 10:31:19 GMT, Markus Grönlund <[email protected]> wrote:

> An "agent" is now equated with its jvmtiEnv, that is, its runtime identity, 
> just like JVMTI handles agents internally.

If it is the plan, it looks fine. I agree defining an agent through `jvmtiEnv` 
makes sense. It is probably not the most useful definition from the user's 
perspective, but it is somewhat consistent. However, from what I can see, this 
PR does something different, it does _not_ equate `jvmtiEnv` with an agent.

The were a few examples in my previous message. Another example is an agent 
that allocates a temporary `jvmtiEnv` for some preliminary work, then disposes 
that env and allocates a persistent `jvmtiEnv` (within the same invocation) for 
the agent's main activity. JFR will incorrectly report the agent just once as 
disposed and will no longer track it. I would prefer that JFR didn't lie to the 
user.

So, to make `NativeAgent` reports reliable, why not associate agents with 
`jvmtiEnv` for real? I mean, to establish unconditional 1:1 relationship 
between them? E.g., if some library allocates two JVMTI environments (by 
whatever means), JFR will always report them as two `NativeAgent` events. If it 
is possible to associate the agent with a native library, `path` will contain 
the `.so` path. Otherwise, `path` can be empty.

I agree that invocation of `Agent_OnAttach` is not an agent as such. But it is 
a useful event on its own, and it's the function where `options` come from. I 
think it was an oversight to make `NativeAgent` event periodic in the first 
place, and it's the root cause of the original issue. As a momentary event, 
invocation of `Agent_OnLoad`/`Agent_OnAttach` makes total sense, and it 
provides more information to the user comparing to jvmtiEnv-based alternative. 
The cleanest solution would be probably to make two separate events: one 
periodic (jvmtiEnv-based) and one momentary (invocation-based).

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

PR Comment: https://git.openjdk.org/jdk/pull/33700#issuecomment-7299351299

Reply via email to