JDK-8308750 : Release Note: Warning Printed when an Agent Is Loaded into a Running VM
  • Type: Sub-task
  • Component: core-svc
  • Sub-Component: tools
  • Affected Version: 21
  • Priority: P4
  • Status: Resolved
  • Resolution: Delivered
  • Submitted: 2023-05-24
  • Updated: 2023-08-25
  • Resolved: 2023-06-07
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
JDK 21
21Resolved
Description
The Java Virtual Machine (JVM) now prints a warning to standard error when a JVM Tool Interface (JVM TI) agent or Java Agent is dynamically loaded into a running JVM. The warning is intended to prepare for a future release that disallows, by default, dynamic loading of agent code into a running JVM.

Agents are programs that run in the JVM process and make use of powerful JVM TI or `java.lang.instrument` APIs. These APIs are designed to support tooling such as profilers and debuggers. Agents are started via a command line option, for example `-agentlib` or `-javaagent`, or they can be started into a running VM using the JDK specific `com.sun.tools.attach` API or the `jcmd` command. Agents loaded into a running VM will now print a warning. There is no warning for agents that are loaded at startup via command line options.

The HotSpot VM option `EnableDynamicAgentLoading` controls dynamic loading of agents. This option has existed since JDK 9. The default, since JDK 9, is to allow dynamic loading of agents. Running with `-XX:+EnableDynamicAgentLoading` on the command line serves as an explicit  "opt-in" that allows agent code to be loaded into a running VM and thus suppresses the warning. Running with  `-XX:-EnableDynamicAgentLoading` disallows agent code from being loaded into a running VM and can be used to test possible future behavior.

In addition, the system property `jdk.instrument.traceUsage` can be used to trace uses of the `java.lang.instrument` API. Running with `-Djdk.instrument.traceUsage` or `-Djdk.instrument.traceUsage=true` causes usages of the API to print a trace message and stack trace. This can be used to identify agents that are dynamically loaded instead of being started on the command line with `-javaagent`.

More information on this change can be found in [JEP 451](https://openjdk.org/jeps/451).