I am facing an issue when using the com.sun.tools.attach.VirtualMachine
Java API. My target application(Tomcat) is running using Oracle Hot Spot version 1.7.0_80. I am trying to connect that tomcat via dynamic attach from another Java program (on the same machine) which is using Open JDK 10.0.2. I am using the below code
...............
String agentPath = Agent.class.getProtectionDomain().getCodeSource().getLocation().getPath();
agentPath = convertFileSeparators(agentPath, File.separatorChar);
String agentInstallDir = agentPath.substring(0, agentPath.lastIndexOf(File.separator));
System.out.println("My Java agent installed on the location :"+agentPath);
StringBuilder sb = new StringBuilder();
sb.append("MY_RELIC_HOME").append("=").append(agentInstallDir);
if (agentArgs != null) {
sb.append(",").append(agentArgs);
}
com.sun.tools.attach.VirtualMachine virtualMachine = com.sun.tools.attach.VirtualMachine.attach(vmID);
virtualMachine.loadAgent(agentPath, sb.toString());
.........
I am able to attach successfully to the target application , but getting the below exception in my attach program (running open JDK 10.0.2) after attach.
com.sun.tools.attach.AgentLoadException: 0
at jdk.attach/sun.tools.attach.HotSpotVirtualMachine.loadAgentLibrary(HotSpotVirtualMachine.java:104)
at jdk.attach/sun.tools.attach.HotSpotVirtualMachine.loadAgentLibrary(HotSpotVirtualMachine.java:115)
at jdk.attach/sun.tools.attach.HotSpotVirtualMachine.loadAgent(HotSpotVirtualMachine.java:139)
at com.eg.agent.Agent.main(Agent.java:582)
The code on the line no 582 is virtualMachine.loadAgent(agentPath, sb.toString());
.
If i run my attach program using Java 7 or 8, there is no exception and attach is success.
Why com.sun.tools.attach.AgentLoadException: 0
exception occurs when using JDK 10 ?