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