本系列笔记主要基于《深入理解Java虚拟机:JVM高级特性与最佳实践 第2版》,是这本书的读书笔记。

jmap 命令用来生成内存堆转储快照,一般称为heapdump或dump文件。
除了使用 jmap 命令,还以通过一些JVM参数让虚拟机在内存溢出时自动dump出快照文件。

参数 说明
-XX:+HeapDumpOnOutOfMemoryError 内存溢出时自动导出内存快照
-XX:HeapDumpPath=E:/dumps/ 导出内存快照时保存的路径

所有的JDK工具都可以在Oracle官网的 Java Tools Reference 文档中找到使用说明,这是主要参考,包括命令格式、参数内容、输出信息等等。

jmap 命令格式:

jmap [ options ] pid
jmap [ options ] executable core
jmap [ options ] [ pid ] server-id@ ] remote-hostname-or-IP

jmap 帮助信息:


jmap -dump

jmap 命令使用-dump参数生成内存快照,-dump参数格式如下:

-dump:[live,] format=b, file=filename


jmap -dump:format=b,file=/dumps/jmap.hprof 21060




jmap -heap

jmap 命令使用-heap参数查看堆内存的配置信息,以及堆中各个区域的使用情况,如新生代的Eden和Survivor区,还有老年代。


jmap -heap 21060




jmap 命令还有很多其他参数,可以参考 Java Tools Reference 文档,列举如下:

<no option>
    When no option is used, the jmap command prints shared object mappings. For each shared object loaded in the target JVM, the start address, size of the mapping, and the full path of the shared object file are printed. This behavior is similar to the Oracle Solaris pmap utility.
-dump:[live,] format=b, file=filename
    Dumps the Java heap in hprof binary format to filename. The live suboption is optional, but when specified, only the active objects in the heap are dumped. To browse the heap dump, you can use the jhat(1) command to read the generated file.
    Prints information about objects that are awaiting finalization.
    Prints a heap summary of the garbage collection used, the head configuration, and generation-wise heap usage. In addition, the number and size of interned Strings are printed.

    Prints a histogram of the heap. For each Java class, the number of objects, memory size in bytes, and the fully qualified class names are printed. The JVM internal class names are printed with an asterisk (*) prefix. If the live suboption is specified, then only active objects are counted.

    Prints class loader wise statistics of Java heap. For each class loader, its name, how active it is, address, parent class loader, and the number and size of classes it has loaded are printed.

    Force. Use this option with the jmap -dump or jmap -histo option when the pid does not respond. The live suboption is not supported in this mode.

    Prints a help message.
    Prints a help message.
    Passes flag to the Java Virtual Machine where the jmap command is running.
posted @ 2020-01-11 09:53  Cellei  阅读(310)  评论(0编辑  收藏