1

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?

nail fei
  • 2,179
  • 3
  • 16
  • 36

1 Answers1

0

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.

apangin
  • 92,924
  • 10
  • 193
  • 247
  • but I encounter a condition that the Agent_OnUnload is called and the jvm is still running. For example, I have ATest.java,BTest.java...ZTest.java and the *execute order* maybe Agent_Onload *ATest.java BTest.java*... Agent_OnUnload ...*ZTest.java* that is to say, ***the Agent_OnUnload is called and jvm go runing *** – nail fei Oct 18 '16 at 01:47
  • @cainiaofei This means some class has called `System.exit()` or `Runtime.getRuntime().halt()` – apangin Oct 18 '16 at 02:35