The HotSpot Attach mechanism of note-taking, and the hotspotattach Mechanism
As mentioned in the previous article, JDK's built-in jstack is used.Dynamic AttachMechanism. The following describes the mechanism in the official documentation,
This is a Sun private mechanic that allows an external process to start a thread in HotSpot that can then be used to launch an agent to run in that HotSpot, and to send information about the state of HotSpot back to the external process.
Now the problem becomes the IPC problem between external process and target VM process. So what kind of IPC method is used,
On Linux and Solaris, the client creates a file named. Attach_pid<pid>
And sendsSIGQUITTo the target JVM process. The existence of this file causesSIGQUITHandler in HotSpot to start the attach listener thread. On Windows, the client uses the Win32CreateRemoteThreadFunction to create a new thread in the target process. The attach listener thread then communicates with the source JVM in an OS dependent manner:
- On Solaris,Doors IPCMechanic is used. The door is attached to a file in the file system so that clients can access it.
- On Linux,Unix domain socketIs used. This socket is bound to a file in the filesystem so that clients can access it.
- On Windows, the created thread is given the name ofPipeWhich is served by the client. The result of the operations are written to this pipe by the target JVM.
That is to say, the Linux platform is Chestnut and two IPC methods are used,
In this process, two files are created,
- . Attach_pid
<pid>
External process will create this file to trigger the creation of the Attach Listener thread, because the SIGQUIT signal is not sent only by external process. This file is used to tell target VM, the attach request has arrived. The relevant code is in LinuxVirtualMachine. java;
- . Java_pid
<pid>
, Target VM will create this file, this is because the implementation mechanism of Unix domain socket itself needs to create a file through this file for IPC. The related code is in attachListener_linux.cpp;
The<pid>
Are the target VM's pid.
References
- Http://openjdk.java.net/groups/hotspot/docs/Serviceability.html#battach