Search code examples
javadlljvmjvmti

when execute Agent_UnLoad() method about "java -agentpath:c:/tool.dll javaClass


I just start learning JVM TI. About the java command: java -agentpath:../tool.dll javaClass, I know that there is a Agent_OnLoad() method in dll and maybe it set some event callback method. And I know the jvm execute Agent_OnLoad() first and then execute javaClass.And the Agent_OnUnLoad() is also called by jvm.


Then the problem comes, how the jvm know when call Agent_OnUnLoad() method . At First, I think that after javaClass is executed jvm will calls Agent_OnUnload(), but then I discard this thought because at this time, maybe the dll is doing sth e.g. writing data to disk.


So how jvm know it is the right time to call Agent_OnUnLoad() method?


Solution

  • There is no standard mechanism defined to unload agent libraries. Agent_OnUnload will be called only before the VM termination, when all Shutdown hooks are completed.