> 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 fall > through to an outer invocation. > - Environment creation ...
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 ------------- Changes: https://git.openjdk.org/jdk/pull/33700/files Webrev: https://webrevs.openjdk.org/?repo=jdk&pr=33700&range=04 Stats: 6969 lines in 63 files changed: 5722 ins; 1052 del; 195 mod Patch: https://git.openjdk.org/jdk/pull/33700.diff Fetch: git fetch https://git.openjdk.org/jdk.git pull/33700/head:pull/33700 PR: https://git.openjdk.org/jdk/pull/33700
