On Fri, 27 Nov 2026 12:52:37 GMT, Markus Grönlund <[email protected]> wrote:
>> Greetings, >> >> Please review this change to improve JFR’s reporting of JVMTI agents and, >> for better separation of concerns, the responsibilities and lifetimes of >> JVMTI agents. >> >> ## Problem >> >> Tools commonly reuse `Agent_OnAttach` as a control channel—for example, to >> start and stop profiling. Previously, each successful startup invocation was >> counted as a new agent instance, producing duplicate and misleading JFR >> reporting. >> >> This change associates reporting with JVMTI environment lifetimes >> established during agent startup, while separating those lifetimes from >> library lookup and `Agent_OnUnload` notifications. >> >> For further details and a before-and-after profiling demonstration, see >> [JDK-8392584](https://bugs.openjdk.org/browse/JDK-8392584). >> >> ## Model and responsibilities >> >> This design keeps each agent’s state separate from shared library details, >> startup tracking, and entry-point calls. >> >> - `JvmtiAgent` stores the agent’s identity, options, a reference to the >> `JvmtiAgentLibrary`, and a link to the JVMTI environment. Startup, JVMTI >> environment association, and timing have separate state models. >> - `JvmtiAgentManager` creates new `JvmtiAgent` objects, manages agent >> startup and selects agents for retention or discarding. It handles JVMTI >> environment disposal and `VMInit` timing, agent iteration, and diagnostic >> info. >> - `JvmtiAgentLibrary` represents a loaded OS library. It includes the >> library’s handle, static-agent identity, file path, and resolution of JVMTI >> entry points. More than one agent can use the same library. >> - `JvmtiAgentLibraryManager` loads and tracks `JvmtiAgentLibrary` objects >> and manages native lookups and `Agent_OnUnload` eligibility. The identity >> and lifetime of a library are separate from any `JvmtiAgent`. >> - `JvmtiAgentInvoker` resolves and invokes exported JVMTI entry points like >> `Agent_OnLoad` and `Agent_OnAttach`, handling thread-state changes and >> results. It also handles legacy `XRUN` conversion and runtime agent >> attachment timing. >> >> ## JVMTI environment association and retention >> >> The first successfully created JVMTI environment on the startup thread is >> associated with the innermost executing startup invocation. This environment >> becomes the `JvmtiAgent`'s identity over its lifetime. >> >> The association has some constraints: >> >> - Disposing the associated environment does not make the `JvmtiAgent` >> eligible for reassociation. >> - Additional environments created by an inner startup invocation do not ... > > Markus Grönlund has updated the pull request with a new target base due to a > merge or a rebase. The pull request now contains seven commits: > > - Merge upstream master into 8392584 > - streamlining > - Decomposition > - Remove unrelated JFR tests > - start() instead of startup() and updated test > - line break > - 8392584 I see an older description was lost during restructuring: "For JFR attribution, provenance is exact only within JVM-initiated startup callbacks. A scoped startup request associates a GetEnv- created environment with the active startup invocation. This covers the normal Agent_OnLoad and Agent_OnAttach paths without relying on native stack inspection. 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." ------------- PR Comment: https://git.openjdk.org/jdk/pull/33700#issuecomment-7276326487
