What interprocess communication mechanism does the Java Attach API use?

I am trying to figure out the mechanism of interaction between processes used by the Java Attach API for the main operating systems, but I can not find many links to the main mechanism.

The only mention I found was here where it refers to the DOORS process communication mechanism developed some time ago by Sun. But I doubt it is used on Windows or Mac. Most articles describe the Java Attach API and how shared libraries / DLLs are loaded, but do not dwell on how the connection between jvisualvm and the local JVM process actually works.

There is a mention here that tools.jar and libattach.so (on Unix systems) or attach.dll (on Windows) are responsible for supporting the Attach API, but I could not find many details about how they work inside .

So, how does process communication for the Java Attach API work on each of the major operating systems? That is, Windows, Mac OSX, and Linux.

+6
source share
2 answers

This seems to be implemented on top of the Java Platform debugger architecture ( JPDA ) (as Elliott Frisch pointed out).

Windows uses a shared memory transport.

Linux-based systems use the Socket transport.

More information can be found here .

+2
source

The Java Attach API has a pluggable provider architecture. The dynamic join provider is specific to the target virtual machine. In the case of Oracle or OpenJDK, the JVM is responsible for the Sun provider. This provider uses various methods, depending on the operating system. The protocol also supports other facilities (for example, jcmd )

For Linux, it uses the following protocol:

  • compile the pid of the target JVM and create flaffile /tmp/.attach_pid%d
  • send SIGQUIT to the target JVM
  • in the target JVM, the signal handler will start attaching a listener thread if the flag file exists.
  • A socket of the domain /tmp/.java_pid%d unix will be created in the attachment listener thread and will listen to this socket for commands
  • a typical load command that tells the target JVM to load an agent implementation. This is implied in shared attachListener.cpp and loads the JVMTI agent.

The method used for JMX is "load", which loads the specified JVMTI agent and then connects regularly through RMI.

Older versions of Java use java.io.tmpdir or even environment-related temporary directories, for later versions / tmp, however, are hard-coded.

Solaris uses IPC Door instead of a unix domain socket. Windows uses CreateRemoteThread with the name of the named pipe for this bootstrap.

This is described here: http://openjdk.java.net/groups/hotspot/docs/Serviceability.html#tattach (I did not check, but I would expect the HP port to use the Linux engine, OpenJDK AIX port).

The IBM JDK uses a similar mechanism (with a larger configuration): https://www.ibm.com/support/knowledgecenter/en/SSYKE2_7.0.0/com.ibm.java.win.70.doc/user/attachapi.html

0
source

All Articles