首页  

JVM Attach机制     所属分类 jvm 浏览量 1449
jvm进程间通信 
jstack PID
线程dump

Attach Listener 
Signal Dispatcher 

UNIX进程间通信 IPC

UNIX Domain Socket
UNIX Domain Socket是全双工的,API接口语义丰富,相比其它IPC机制有明显的优越性,已成为使用最广泛的IPC机制


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. 

The attach listener thread then communicates with the source JVM in an OS dependent manner

On Linux, a Unix domain socket is used. This socket is bound to a file in the filesystem so that clients can access it.

Linux平台使用了两种IPC方式

信号机制,external process先发送一个SIGQUIT信号给target VM process,target VM创建一个Attach Listener线程
Unix domain socket,Attach Listener线程会通过Unix domain socket与external process建立连接,之后基于这个socket进行通信


两个文件被创建

.attach_pid$pid,external process创建这个文件,触发Attach Listener线程的创建,相关代码 LinuxVirtualMachine.java 
.java_pid$pid ,target VM 创建这个文件, Unix domain socket ,通过这个文件进行IPC ,相关代码 attachListener_linux.cpp


Attach 用途

内存dump
线程dump
类信息统计 
动态加载agent 
动态设置vm flag 
打印vm flag
获取系统属性等


Attach API

This is a Sun private mechanism 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.


com.sun.tools.attach.VirtualMachine

attach
loadAgentXXX
detach


AttachProvider


JConsole 本地连接

List< VirtualMachineDescriptor> list = VirtualMachine.list(); 
for (VirtualMachineDescriptor vmd : list) { 
    System.out.println("pid:" + vmd.id() + ":" + vmd.displayName()); 
}


Attach到特定进程的JVM上,并加载Agent
sun.tools.jconsole.LocalVirtualMachine

上一篇     下一篇
linux sort 命令

Java黑科技VirtualMachine

Spring JMX

arthas原理简介

OLAP引擎介绍及比较

clickhouse MergeTree 和 Distributed 存储引擎