You can only inject (deploy) an agent either at start time of the JVM by passing the argument
-agentlib:<agent-lib-name>=<options>
or-agentpath:<path-to-agent>=<options>
.The other way is through Java itself. This depends heavily on the JVM, for that reason it is out of JVMTI specification scope. For instance if there is the
VirtualMachine
class through the methodloadAgentPath(agentPath, options)
. If you want to execute this from within the native JVMTI code you would need to do Bytecode instrumentation.I am not sure, similar to 1. you could run the Java
unload
method through Bytecode instrumentation. Ifdlclose()
works I do not see a problem in doing that.
As you see, you can pass data to the Java agent by using the options. Alternatively, if you want to pass data continuously between both instances you can open two sockets and write/read between them. I used Protobuf