Java黑科技VirtualMachine
所属分类 java
浏览量 2416
https://docs.oracle.com/javase/8/docs/jdk/api/attach/spec/com/sun/tools/attach/VirtualMachine.html
static VirtualMachine attach(String id)
Attaches to a Java virtual machine.
static VirtualMachine attach(VirtualMachineDescriptor vmd)
Attaches to a Java virtual machine.
abstract void detach()
Detach from the virtual machine.
abstract Properties getAgentProperties()
Returns the current agent properties in the target virtual machine.
abstract Properties getSystemProperties()
Returns the current system properties in the target virtual machine.
static List list()
Return a list of Java virtual machines.
void loadAgent(String agent)
Loads an agent.
在运行时动态加载 java agent
abstract void loadAgent(String agent, String options)
Loads an agent.
void loadAgentLibrary(String agentLibrary)
Loads an agent library.
abstract void loadAgentLibrary(String agentLibrary, String options)
Loads an agent library.
void loadAgentPath(String agentPath)
Load a native agent library by full pathname.
abstract void loadAgentPath(String agentPath, String options)
Load a native agent library by full pathname.
attach DIY
ShowClassAgent
MyAttachTest
Agent-Class dyyx.agent.attach.ShowClassAgent
mvn install -f pom-attach-agent.xml
java -cp .:jvmtools-1.0.jar dyyx.agent.attach.MyAttachTest 60295 jvmtools-1.0.jar
Caused by: java.lang.ClassNotFoundException: com.sun.tools.attach.VirtualMachine
java -cp .:jvmtools-1.0.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_121.jdk/Contents/Home/lib/tools.jar dyyx.agent.attach.MyAttachTest 60295 jvmtools-1.0.jar
Exception in thread "main" com.sun.tools.attach.AgentLoadException: Agent JAR not found or no Agent-Class attribute
java -cp .:jvmtools-1.0.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_121.jdk/Contents/Home/lib/tools.jar dyyx.agent.attach.MyAttachTest 60295 /Users/dugang/work/demos/jvmtools/target/jvmtools-1.0.jar
agent jar 使用 全路径
目标JVM进程 (PID 60295) 控制台输出 加载的类名
完整代码
https://gitee.com/dyyx/demos/tree/master/jvmtools/src/main/java/dyyx/agent/attach
java代码获取所有jvm进程
jvm外挂工具揭秘
javaagent机制
java debug 原理简介
javaagent两种加载方式及实例
上一篇
下一篇
zookeeper集群搭建
互联网广告术语解释
linux sort 命令
Spring JMX
JVM Attach机制
arthas原理简介