1 Reply Latest reply on Jun 19, 2013 6:41 AM by Woodbridge

    Allowing agents to attach to a running vm

      I am trying to use the attach api to load my native JVMTI agent into a running VM with .loadAgentPath(), however I am getting an AgentLoadException. Am I right in thinking that, in normal operation, the JVM isn't set up to enable JVMTI for performance reasons? I have had success in the past if the agent is started up with the vm using command-line flags or the browser properties (my app is running as an applet when its fully deployed, I only run from the command line for development purposes). If so, is there a way to enable these capabilities somehow so I can use attach? I thought that was what .setCapabilities was for, but I don't think I'm even getting that far, the agent is never loaded.

      Thanks, help is greatly appreciated.

      EDIT: I should point out that I have tried loading a bare minimum agent, that is, a dll that just exports Agent_OnAttach and attempts to notify me that it is attached - does not request any capabilities or attempt to perform any debugging. It raises an AgentLoadException.

      Edited by: Pizzey on Feb 11, 2010 6:37 PM
        • 1. Re: Allowing agents to attach to a running vm

          I met the similar problem (Under Windows, Java 7), I wrote a DLL in C/C++ as JVMTI agent and using the following code to load the agent (DLL) for a running Java program, but it doesn't work, no matter how I set the agentPath (absolute or relative file path), it doesn't work anyway, while using command-line flags the agent works fine.

          Did you guy find the solution for this issue? If yes, please kindly share it?




          VirtualMachine virtualMachine = com.sun.tools.attach.VirtualMachine.attach(pid); // I am sure the PID is correct, if this is wrong, it would cause another exception which did not occur

          virtualMachine.loadAgentPath(agentPath,null);  // even I set agentPath as null, it will get same exception: com.sun.tools.attach.AgentLoadException: Failed to load agent library