Monday 15 April 2013

JVMTI native agent (DLL) can not be loaded to a runing Java program - AgentLoadException -


I struggled on this issue for a few days, but have not yet received the correct answer.

Here's a description of the problem: I wrote a general Java program (program A), and with a Windows-based native agent (* .dll) with Agent_OnLoad, Agent_OnAttach, Agent_OnUnload , Written in C / C ++) method, which works fine using the Java Command-Line Flag (-GenTalib), then I have another Java to attach the native agent to run Java program A Program written (down to VM Attach and Load agent) See new code fragments), but I found an exception:

  com sun. Tools. Attack Agent Load: Expansion: Failed to load the agent library   

I tried to change agentpath (absolute or relative file path) or in such a way, none of these works did I do this work Need to try some more ways? What do I need to do is attach a native agent instead of using a command-line flag on a running Java program.

Does anyone know a clue for the root cause or solution?

Classpath ... ./ tools.jar com.xxx.TestAgentVMAttacher ... VirtualMachine VirtualMatchin = ComSun.Tovals.Tach.VirtualMachinTatch (PID); // Note: This code line is executed normally, I'm sure pid is correct ... agentPath = theFilePath + "/myagent.dll"; // Note: I'm sure the dll file path is true virtual Mitchine.loadAgentPath (agentPath, null); // Note: As I mentioned above, this code line will be the reason for the exception (agent loadexception), whether I set up agent path, even I set it blank, the only exception

Environment related information:
- OS: Windows XP - Java version: Java (TM) SE runtime environment (Build 1.7.0-B 147) Finally, I got an answer to my question, I used the wrong method in the agent Name ( 'Ajent_atchha') I / P>

. The CPP file should be the correct one, 'Agent_OnAttach', with this fix, my agent Ob (.dl) can now be loaded in the Java program running.

No comments:

Post a Comment