• Stars
    star
    378
  • Rank 113,272 (Top 3 %)
  • Language
    Java
  • Created almost 9 years ago
  • Updated about 2 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Dump classes from running JVM process.

Dumpclass

Dump classes from running JVM process by sa-jdi.jar.

  • Support wildcard match

  • Support multi classloader

Download dumpclass.jar

You can download dumpclass.jar from maven center.

http://search.maven.org/#search%7Cga%7C1%7Cdumpclass

wget http://search.maven.org/remotecontent?filepath=io/github/hengyunabc/dumpclass/0.0.2/dumpclass-0.0.2.jar -O dumpclass.jar

Usage

Usage:
 pattern                  : class name wildcard match pattern
 --noStat                 : do not print dump stat (default: false)
 --sensitive              : class name wildcard match sensitive. In mac os, try
                            this option. (default: false)
 -c (--classLoaderPrefix) : classLoaderPrefix (default: false)
 -o (--outputDir) VAL     : outputDir
 -p (--pid) N             : pid

Example:
  java -jar dumpclass.jar -p 4345 *StringUtils
  java -jar dumpclass.jar -p 4345 -o /tmp/dump *StringUtils
  java -jar dumpclass.jar -p 4345 -o /tmp/dump --classLoaderPrefix  *StringUtils
Use the specified sa-jdi.jar:
  java -cp './dumpclass.jar:$JAVA_HOME/lib/sa-jdi.jar' io.github.hengyunabc.dumpclass.DumpMain 4345 *StringUtils

Trouble

  • Try to use sudo
Error attaching to process: sun.jvm.hotspot.debugger.DebuggerException: Can't attach to the process. Could be caused by an incorrect pid or lack of privileges.
sun.jvm.hotspot.debugger.DebuggerException: sun.jvm.hotspot.debugger.DebuggerException: Can't attach to the process. Could be caused by an incorrect pid or lack of privileges.
	at sun.jvm.hotspot.debugger.bsd.BsdDebuggerLocal$BsdDebuggerLocalWorkerThread.execute(BsdDebuggerLocal.java:169)
	at sun.jvm.hotspot.debugger.bsd.BsdDebuggerLocal.attach(BsdDebuggerLocal.java:287)
	at sun.jvm.hotspot.HotSpotAgent.attachDebugger(HotSpotAgent.java:671)
	at sun.jvm.hotspot.HotSpotAgent.setupDebuggerDarwin(HotSpotAgent.java:659)
	at sun.jvm.hotspot.HotSpotAgent.setupDebugger(HotSpotAgent.java:341)
	at sun.jvm.hotspot.HotSpotAgent.go(HotSpotAgent.java:304)
	at sun.jvm.hotspot.HotSpotAgent.attach(HotSpotAgent.java:140)
	at sun.jvm.hotspot.tools.Tool.start(Tool.java:185)
	at sun.jvm.hotspot.tools.Tool.execute(Tool.java:118)
	at sun.jvm.hotspot.tools.jcore.ClassDump.main(ClassDump.java:180)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:498)
	at io.github.hengyunabc.dumpclass.DumpMain.run(DumpMain.java:132)
	at io.github.hengyunabc.dumpclass.DumpMain.doMain(DumpMain.java:68)
	at io.github.hengyunabc.dumpclass.DumpMain.main(DumpMain.java:61)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:498)
	at io.github.hengyunabc.dumpclass.DumpMain$2.run(DumpMain.java:184)
	at java.lang.Thread.run(Thread.java:745)
Caused by: sun.jvm.hotspot.debugger.DebuggerException: Can't attach to the process. Could be caused by an incorrect pid or lack of privileges.
	at sun.jvm.hotspot.debugger.bsd.BsdDebuggerLocal.attach0(Native Method)
	at sun.jvm.hotspot.debugger.bsd.BsdDebuggerLocal.access$100(BsdDebuggerLocal.java:65)
	at sun.jvm.hotspot.debugger.bsd.BsdDebuggerLocal$1AttachTask.doit(BsdDebuggerLocal.java:278)
	at sun.jvm.hotspot.debugger.bsd.BsdDebuggerLocal$BsdDebuggerLocalWorkerThread.run(BsdDebuggerLocal.java:144)
  • Make sure use the same jdk version.
Attaching to process ID 53577, please wait...
Exception in thread "main" java.lang.reflect.InvocationTargetException
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:497)
	at io.github.hengyunabc.dumpclass.DumpMain.main(DumpMain.java:101)
Caused by: java.lang.InternalError: void* type hasn't been seen when parsing int*
	at sun.jvm.hotspot.HotSpotTypeDataBase.recursiveCreateBasicPointerType(HotSpotTypeDataBase.java:721)
	at sun.jvm.hotspot.HotSpotTypeDataBase.lookupType(HotSpotTypeDataBase.java:134)
	at sun.jvm.hotspot.HotSpotTypeDataBase.lookupOrCreateClass(HotSpotTypeDataBase.java:631)
	at sun.jvm.hotspot.HotSpotTypeDataBase.createType(HotSpotTypeDataBase.java:751)
	at sun.jvm.hotspot.HotSpotTypeDataBase.readVMTypes(HotSpotTypeDataBase.java:195)
	at sun.jvm.hotspot.HotSpotTypeDataBase.<init>(HotSpotTypeDataBase.java:89)
	at sun.jvm.hotspot.HotSpotAgent.setupVM(HotSpotAgent.java:403)
	at sun.jvm.hotspot.HotSpotAgent.go(HotSpotAgent.java:305)
	at sun.jvm.hotspot.HotSpotAgent.attach(HotSpotAgent.java:140)
	at sun.jvm.hotspot.tools.Tool.start(Tool.java:185)
	at sun.jvm.hotspot.tools.Tool.execute(Tool.java:118)
	at sun.jvm.hotspot.tools.jcore.ClassDump.main(ClassDump.java:180)
	... 5 more
  • One class loaded by multi ClassLoader

Try to use HSDB. After attach java process, "Tools", "Class Browser".

sudo java -classpath "$JAVA_HOME/lib/sa-jdi.jar" sun.jvm.hotspot.HSDB

complie dumpclass.jar

mvn clean package
ls -alh target

License

Apache License V2

More Repositories

1

xdiamond

全局配置中心
Java
576
star
2

redis-id-generator

distributed id generator based on redis.
Java
463
star
3

spring-boot-inside

spring boot技术细节的相关demo
Java
218
star
4

zabbix-api

zabbix-api for java
Java
91
star
5

dubbo-arthas-demo

演示Arthas排查Dubbo问题的Demo
Java
87
star
6

zabbix-sender

java zabbix-sender
Java
75
star
7

zpush

Apple APNs java client.
Java
44
star
8

executable-embeded-tomcat-sample

executable-embeded-tomcat-sample, support traditional web.xml.
Java
43
star
9

dubbo-apache-commons-collections-bug

演示dubbo rpc Apache commons collections 的Java序列化漏洞
Shell
42
star
10

metrics-kafka

Dropwizard Metrics reporter for kafka.
Java
35
star
11

arthas-mybatis-demo

Java
26
star
12

jenkins-ansible-supervisor-deploy

Use jenkins, ansible, supervisor to deploy java application.
Shell
25
star
13

spring-boot-fat-jar-jsp-sample

Java
25
star
14

metrics-zabbix

metrics-zabbix. Report dropwizard/metrics data to zabbix.
Java
24
star
15

xsession

A java web servlet filter for distributed session cached . 分布式Java Web Session缓存。
Java
24
star
16

springboot-classchecker

A tool to find incompatible classes between spring boot 1 and spring boot 2, help upgrade from spring boot 1 to spring boot 2.
Shell
19
star
17

spring-boot-utils

Spring boot 1 and spring boot 2 compatible utils.
Java
17
star
18

maven-repo

My personal maven repository.
12
star
19

spring-config

spring config switch with dev, test, product environment.
Java
11
star
20

kafka-zabbix

Consumer metrics from kafka, then send to zabbix.
Java
10
star
21

mybatis-ehcache-spring

Mybatis ehcache with spring. Mybatis cache metrics.
Java
6
star
22

dubbo-spring-boot-demo

http://start.dubbo.io/
Java
6
star
23

hengyunabc.github.io

HTML
6
star
24

jmh-demo

Java Microbenchmark Demo
Java
5
star
25

lite-jdk

5
star
26

java-telnet-client-demo

A pure java telnet client demo, connect to remote telnet server.
Java
4
star
27

spring-boot-demo

spring boot demo project.
Shell
4
star
28

jpms-tools

Java
4
star
29

telnetd-x

Automatically exported from code.google.com/p/telnetd-x
Java
3
star
30

dubbo-initializr

Java
3
star
31

simple-redis-ratelimiter

A very simple redis ratelimiter.
Java
3
star
32

database-test

测试以db为消息队列的存储的性能
Java
2
star
33

arthas-repackage-deps

Java
2
star
34

netty-grpc-web-proxy

Java
2
star
35

spring-boot-prometheus-grafana-demo

Spring Boot应用集成k8s prometheus grafana demo
Java
2
star
36

endpoints-spring-boot-starter

Show all spring boot endpoints mappings url.
Java
2
star
37

skywalking-error-demo

Java
1
star
38

java9-guide

Java
1
star
39

classpath-demo

演示ClassaPath相关知识的demo
Java
1
star
40

katacoda-scenarios

Katacoda Scenarios
Shell
1
star
41

java-syntax-highlighter

Automatically exported from code.google.com/p/java-syntax-highlighter
Java
1
star
42

xqwizard-code

Visual Basic
1
star