On Tue, 1 Dec 2026 03:07:32 GMT, Andrei Pangin <[email protected]> wrote:

> "There 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 just answered that it is provably hard to do:

"Environments created outside that explicit scope are deliberately not 
automatically attributed. JNI/JVMTI GetEnv carries no owning-
library identity, and inferring it from a caller PC or native stack is not 
provably correct: inlining and tail-call optimization can
remove or alter the relevant call frame. Avoiding that inference favors 
incomplete attribution over incorrect JFR attribution."

You can't safely infer a native caller's identity from GetEnv. A GetEnv 
additionally does not carry any agent options, some kind of name, or any of the 
event attributes - i.e., any data that would make attribution possible and give 
some assistance to the end user.

> 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.

How can you say that? JFR periodic is the only way JFR can report historical 
events in the future, including for new recordings not yet started.

An instant event would be lost forever, except for a recording that happened to 
run right then and there (if any).

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

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

Reply via email to