在cmd或者shell窗口输入jmap -h,输出如下结果:
Usage:
jmap [option] <pid>
(to connect to running process)
jmap [option] <executable <core>
(to connect to a core file)
jmap [option] [server_id@]<remote server IP or hostname>
(to connect to remote debug server)
where <option> is one of:
<none> to print same info as Solaris pmap
-heap to print java heap summary
-histo[:live] to print histogram of java object heap; if the "live"
suboption is specified, only count live objects
-clstats to print class loader statistics
-finalizerinfo to print information on objects awaiting finalization
-dump:<dump-options> to dump java heap in hprof binary format
dump-options:
live dump only live objects; if not specified,
all objects in the heap are dumped.
format=b binary format
file=<file> dump heap to <file>
Example: jmap -dump:live,format=b,file=heap.bin <pid>
-F force. Use with -dump:<dump-options> <pid> or -histo
to force a heap dump or histogram when <pid> does not
respond. The "live" suboption is not supported
in this mode.
-h | -help to print this help message
-J<flag> to pass <flag> directly to the runtime system查看java堆的信息以及垃圾回收算法等

可以看到堆的分代情况以及各区域的使用情况,垃圾收集器使用的是Parallel GC与java -XX:+PrintCommandLineFlags -version得到的结果一致:

打印当前java堆中所有对象的实例数和大小等,加了live选项则只打印存活的对象

打印class loader的统计信息
打印在等待执行finalize方法的对象
dump-options主要有:
把java堆中的对象dump到本地文件,然后使用第三方工具进行分析,如MAT,JProfile,IBM的分析工具等
与-dump 和-histo一起使用,强制执行后者 jmap -F -dump:live,format=b,file=heap.bin
attach 就是jvm提供一种jvm进程间通信的能力,能让一个进程传命令给另外一个进程,并让它执行内部的一些操作:
