The HotSpot Attach mechanism of note-taking, and the hotspotattach Mechanism

Source: Internet
Author: User
Tags unix domain socket

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

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.