I'm writing a Java agent to interact with JVMTI. For reasons I won't get into, I need to use JVMTI (the C interface inside the java
process) rather than the Java APIs like java.lang.instrument
or JDI. I would like to be able to do a couple of things which appear not to be supported directly.
- Is there a way to load an agent after the Java process has already started?
- Is there a way to unload a Java agent (short of killing the whole Java process) either from inside the JVMTI code or from outside the process? For instance, could I safely call
dlclose()
from the JVMTI code if I can find the handle for the dynamically-loaded module?
If these operations can't be done, is there a way to pass data to a Java agent after it's loaded? Is there a normal way to do this through some Java command-line utility? If not, can I safely create a thread and have it listen to a socket using the standard C or C++ library calls within the code for my agent?
If it helps, don't worry about supporting Windows with your answer - I'm undertaking this project to extend a Unix-only debugging tool.
Note: I've already seen this but thought there might be some normal way to do it that isn't in the JVMTI standard.