Summary of HotSpot Attach mechanism

Source: Internet
Author: User
Tags unix domain socket

We have already mentioned in the previous article that the JDK Jstack is the Dynamic Attach mechanism used. The following is a description of the mechanism in the official documentation,

This was a Sun private mechanism that allows an external process to start a thread in HotSpot so can then was used to Laun Ch an agent to run in so hotspot, and to send information about the state of the hotspot back to the external process.

So 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 sends a Sigquit to the target JVM process. The existence of this file causes the sigquit handler in HotSpot to start the attach listener thread. On Windows, the client uses the Win32 createremotethread function to create a new thread in the target PR Ocess. The attach listener thread then communicates with the source JVM in an OS dependent manner:

    • On Solaris, the Doors IPC mechanism is used. The door is attached to a file of the file system so that clients can access it.
    • On Linux, a Unix domain sockets is used. This socket was bound to a file with the filesystem so, clients can access it.
    • On Windows, the created thread is given the name of a pipe which are served by the client. The result of the operations is written to this pipe by the target JVM.

In other words, using the Linux platform as Chestnut, two IPC methods are used,

    1. Signal mechanism. First external process will send a sigquit signal to the target VM Process,target VM will create a Attach Listener thread;
    2. Unix domain socket. The attach listener thread then connects to the external process through the UNIX domain socket and can then communicate based on the socket.

In this process, two files are created,

    • . Attach_pid <pid> , external process creates this file in order to trigger the creation of the attach listener thread, because the sigquit signal is not sent only by the external process. Through this file to tell the target VM, there is a attach request came over. The relevant code is in Linuxvirtualmachine.java;
    • . Java_pid <pid> , the target VM creates this file because the UNIX domain socket itself implements the mechanism to create a file that can be passed through the IPC. The relevant code is in Attachlistener_linux.cpp;

All of which <pid> are the PID of the target VM.

Resources
    • Http://openjdk.java.net/groups/hotspot/docs/Serviceability.html#battach

Summary of HotSpot Attach mechanism

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.