ICode9

精准搜索请尝试: 精确搜索
首页 > 系统相关> 文章详细

JVM探秘:jmap生成内存堆转储快照

2020-01-11 10:07:35  阅读:259  来源: 互联网

标签:快照 JVM dump 转储 内存 heap Java jmap


本系列笔记主要基于《深入理解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 帮助信息:

image

jmap -dump

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

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

举例如下:

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

输出如下:

image

可见,在指定目录dumps下面生成了堆快照文件。

jmap -heap

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

-heap参数举例如下:

jmap -heap 21060

输出如下:

image

其他参数

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.
    
-finalizerinfo
    Prints information about objects that are awaiting finalization.
    
-heap
    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.

-histo[:live]
    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.

-clstats
    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.

-F
    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.

-h
    Prints a help message.
    
-help
    Prints a help message.
    
-Jflag
    Passes flag to the Java Virtual Machine where the jmap command is running.

标签:快照,JVM,dump,转储,内存,heap,Java,jmap
来源: https://www.cnblogs.com/cellei/p/12179079.html

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有