0

I'm trying to figure out how does the VirtualMachine.loadAgentPath works in a native way, Because of some difficulties I can't use the java code to perform my agent loading and have to make it with native code.

I looked into the implementations of HotSpotVirtualMachine and saw that it is calling some execute method to perform the loading

private void loadAgentLibrary(String agentLibrary, boolean isAbsolute, String options) 
    throws AgentLoadException, AgentInitializationException, IOException {
    InputStream in = execute("load", agentLibrary, isAbsolute ? "true" : "false", options);
    try {
        int result = readInt(in);
        if (result != 0) {
            throw new AgentInitializationException("Agent_OnAttach failed", result);
        }
    } finally {
        in.close();
    }
}

But I can't figure out how I can call that execute or load method Has anyone tried that before?

Thanks

Pierre
  • 2,552
  • 5
  • 26
  • 47
stylo
  • 496
  • 4
  • 12
  • The `execute` method is platform-dependent. Did you have a look at its code? – RealSkeptic May 27 '15 at 13:21
  • I couldn't find it, all I could find is the abstract form of it – stylo May 27 '15 at 13:32
  • Well, here's a tip: if you run into such a case in GrepCode, go to the hierarchy section. It usually shows appropriate subclasses if they exist. [Here](http://grepcode.com/file/repository.grepcode.com/java/root/jdk/openjdk/7u40-b43/sun/tools/attach/LinuxVirtualMachine.java?av=h#LinuxVirtualMachine) is a link to the Linux implementation. – RealSkeptic May 27 '15 at 13:37
  • I looked at the WindowsVirtualMachine.java code that implements it, and I can see that it calls some enqueue function to queue the command to the remote process. now where the hell is enqueue :S – stylo May 27 '15 at 13:43
  • well, found enqueue and realized that it also an exported function within attach.dll that inject code into the remote java process and do all kinds of stuff.. I really don't want to try and implement my own enqueue cuz it looks pretty damn hard and messy. any way to call it with the right arguments? – stylo May 27 '15 at 14:22

0 Answers0