Java自带故障分析工具jmap工具使用说明

jmap

输出进程、核心文件或远程调试服务器的共享对象内存或者堆内存的相关信息。

语法

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

解释

  • executable

    产生核心转储的Java可执行文件

  • core

    打印内存信息的核心文件

  • remote-hostname-or-IP

    远程调试服务器的hostname或者IP地址。查看jsadebug

  • server-id

    远程服务器上有多个调试服务器时,提供的调式服务器唯一ID

  • 通过``-J-d64可以指定jmap`运行在64位JVM上

    jmap -J-d64 -heap pid

Options

<no option>

没有option参数,jmap命令输出共享对象映射信息。会输出JVM中所有共享对象的起始地址、映射大小、文件的全路径

$ jmap 5208
Attaching to process ID 5208, please wait...
Debugger attached successfully.
Server compiler detected.
JVM version is 25.40-b25
0x0000000056140000      8716K   D:\path\Java\java1.8\64_jdk1.8.0_40\jre\bin\server\jvm.dll
0x00000000569d0000      840K    D:\path\Java\java1.8\64_jdk1.8.0_40\jre\bin\msvcr100.dll
0x0000000056e10000      52K     D:\path\Java\java1.8\64_jdk1.8.0_40\jre\bin\management.dll
0x0000000056e20000      68K     D:\path\Java\java1.8\64_jdk1.8.0_40\jre\bin\nio.dll
0x0000000056e40000      104K    D:\path\Java\java1.8\64_jdk1.8.0_40\jre\bin\net.dll
0x0000000056e60000      88K     D:\path\Java\java1.8\64_jdk1.8.0_40\jre\bin\zip.dll

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

  • 将Java堆信息存入filename指定文件名的hprof二进制文件中;
  • live 是可选操作,指定live表示只保存活跃对象;
  • 使用jhat命令可以读取文件;
$ jmap -dump:live,format=b,file=test 5208
Dumping heap to C:\user\username\Desktop\test ...
Heap dump file created
$ jhat  C:\\Users\\username\\Desktop\\test
Reading from C:\Users\username\Desktop\test...
Dump file created Fri Dec 27 13:20:01 CST 2019
Snapshot read, resolving...
Resolving 502739 objects...
Chasing references, expect 100 dots....................................................................................................
Eliminating duplicate references....................................................................................................
Snapshot resolved.
Started HTTP server on port 7000
Server is ready.

访问localhost:7000可以查看文件具体内容

finalizerinfo

$ jmap -finalizerinfo 10864
Attaching to process ID 10864, please wait...
Debugger attached successfully.
Server compiler detected.
JVM version is 25.40-b25
Number of objects pending for finalization: 0

heap

输出堆垃圾回收的摘要信息,配置信息,各年代的堆使用信息以及 interned Strings的是数量和大小。

$ jmap -heap 10864
Attaching to process ID 10864, please wait...
Debugger attached successfully.
Server compiler detected.
JVM version is 25.40-b25

using thread-local object allocation.
Garbage-First (G1) GC with 4 thread(s)

Heap Configuration:
   MinHeapFreeRatio         = 40
   MaxHeapFreeRatio         = 70
   MaxHeapSize              = 1073741824 (1024.0MB)
   NewSize                  = 1363144 (1.2999954223632812MB)
   MaxNewSize               = 643825664 (614.0MB)
   OldSize                  = 5452592 (5.1999969482421875MB)
   NewRatio                 = 2
   SurvivorRatio            = 8
   MetaspaceSize            = 21807104 (20.796875MB)
   CompressedClassSpaceSize = 1073741824 (1024.0MB)
   MaxMetaspaceSize         = 268435456 (256.0MB)
   G1HeapRegionSize         = 1048576 (1.0MB)

Heap Usage:
G1 Heap:
   regions  = 1024
   capacity = 1073741824 (1024.0MB)
   used     = 402117216 (383.4888610839844MB)
   free     = 671624608 (640.5111389160156MB)
   37.45008409023285% used
G1 Young Generation:
Eden Space:
   regions  = 341
   capacity = 572522496 (546.0MB)
   used     = 357564416 (341.0MB)
   free     = 214958080 (205.0MB)
   62.45421245421245% used
Survivor Space:
   regions  = 31
   capacity = 32505856 (31.0MB)
   used     = 32505856 (31.0MB)
   free     = 0 (0.0MB)
   100.0% used
G1 Old Generation:
   regions  = 15
   capacity = 468713472 (447.0MB)
   used     = 10998368 (10.488861083984375MB)
   free     = 457715104 (436.5111389160156MB)
   2.34650136107033% used

22533 interned Strings occupying 2048048 bytes.

histo[:live]

  • 将堆信息以列表(histogram)的形式输出;
  • 输出每个类的信息:对象个数、内存字节数、全路径;
  • 如果指定live,只统计活跃对象信息(从以下输出可以看到对象数是不同的)
$ jmap -histo 10864

 num     #instances         #bytes  class name
----------------------------------------------
   1:        887212      198868312  [C
   2:        423381       89093320  [B
   3:         46645       26477944  [I
   4:        542764       13026336  java.lang.String
   5:        128620       12347520  sun.util.calendar.Gregorian$Date
   6:        128391       10271280  java.util.zip.ZipEntry
   7:         92913        4668984  [Ljava.lang.Object;
   8:        112727        2705448  java.util.Date
   9:         46899        2626344  java.util.stream.ReferencePipeline$Head
  10:         48749        1949960  java.security.AccessControlContext
  11:         82135        1814832  [Ljava.lang.Class;
  12:         14411        1632616  java.lang.Class
  13:         50674        1621568  java.util.HashMap$Node
  14:         46875        1500000  java.util.Spliterators$ArraySpliterator
  15:         16237        1314488  [Ljava.util.HashMap$Node;
  16:         14048        1236224  java.lang.reflect.Method
  17:         35411        1133152  java.util.concurrent.ConcurrentHashMap$Node
  18:         46864        1124736  java.util.stream.MatchOps$$Lambda$45/319558327
  19:         40542         973008  java.lang.StringBuilder
  20:         19482         935136  java.util.HashMap
  21:         26831         870296  [Ljava.security.ProtectionDomain;
  22:         33581         805944  org.apache.commons.collections.map.ListOrderedMap$ListOrderedMapEntry
  23:          9684         772896  [S
  24:         46864         749824  org.apache.jorphan.reflect.ClassFinder$ExtendsClassFilter$$Lambda$44/1397381784
  25:         20407         653024  java.util.ArrayList$Itr
  26:         10000         640000  java.awt.event.InvocationEvent
  27:         18944         606208  java.util.concurrent.locks.AbstractQueuedSynchronizer$Node
  28:         18127         580064  java.util.Hashtable$Entry
  29:         17336         554752  java.beans.PropertyChangeEvent
  30:         13686         547440  java.lang.ref.Finalizer
  31:         31829         509264  java.lang.Object
  32:         19459         467016  java.util.ArrayList
....................
3770:             1             16  sun.text.normalizer.NormalizerImpl$FCDTrieImpl
3771:             1             16  sun.text.normalizer.NormalizerImpl$NormTrieImpl
3772:             1             16  sun.util.CoreResourceBundleControl
3773:             1             16  sun.util.calendar.Gregorian
3774:             1             16  sun.util.locale.InternalLocaleBuilder$CaseInsensitiveChar
3775:             1             16  sun.util.locale.provider.AuxLocaleProviderAdapter$NullProvider
3776:             1             16  sun.util.locale.provider.CalendarDataUtility$CalendarFieldValueNamesMapGetter
3777:             1             16  sun.util.locale.provider.CalendarDataUtility$CalendarWeekParameterGetter
3778:             1             16  sun.util.locale.provider.CalendarNameProviderImpl$LengthBasedComparator
3779:             1             16  sun.util.locale.provider.SPILocaleProviderAdapter
3780:             1             16  sun.util.locale.provider.TimeZoneNameUtility$TimeZoneNameGetter
3781:             1             16  sun.util.resources.LocaleData
3782:             1             16  sun.util.resources.LocaleData$LocaleDataResourceBundleControl
Total       3659918      405059648
$ jmap -histo:live 10864

 num     #instances         #bytes  class name
----------------------------------------------
   1:          7681        6404584  [B
   2:         74426        6304912  [C
   3:         13259        4714608  [I
   4:         72674        1744176  java.lang.String
   5:         14411        1632616  java.lang.Class
   ......................
   3034:             1             16  sun.util.locale.provider.SPILocaleProviderAdapter
3035:             1             16  sun.util.locale.provider.TimeZoneNameUtility$TimeZoneNameGetter
3036:             1             16  sun.util.resources.LocaleData
3037:             1             16  sun.util.resources.LocaleData$LocaleDataResourceBundleControl
Total        561269       36751776

clstats

  • 输出Java堆中类加载器的统计信息;
  • 输出每个类加载器的信息:名称,状态,地址,父类加载器,已加载的类的数量和大小;
  • 统计会比较耗费时间;
$ jmap -clstats 10864
Attaching to process ID 10864, please wait...
Debugger attached successfully.
Server compiler detected.
JVM version is 25.40-b25
finding class loader instances ..done.
computing per loader stat ..done.
please wait.. computing liveness..........................................................liveness analysis may be inaccurate ...
class_loader    classes bytes   parent_loader   alive?  type

<bootstrap>     3835    6981748   null          live    <internal>
0x00000000c02ccba8      1       1471    0x00000000c02cc7b0      dead    sun/reflect/DelegatingClassLoader@0x0000000100009df8
0x00000000c1aa4420      1       878     0x00000000c02cc7b0      dead    sun/reflect/DelegatingClassLoader@0x0000000100009df8
0x00000000c02cd820      1       1472    0x00000000c02cc7b0      dead    sun/reflect/DelegatingClassLoader@0x0000000100009df8
0x00000000c202e190      1       878       null          dead    sun/reflect/DelegatingClassLoader@0x0000000100009df8
0x00000000c1c3e350      1       878       null          dead    sun/reflect/DelegatingClassLoader@0x0000000100009df8
0x00000000c1dbe048      1       1472    0x00000000c02cc7b0      dead    sun/reflect/DelegatingClassLoader@0x0000000100009df8
0x00000000c02ccd38      1       1472    0x00000000c02cc7b0      dead    sun/reflect/DelegatingClassLoader@0x0000000100009df8
0x00000000c134d6a0      1       1471    0x00000000c02cc7b0      dead    sun/reflect/DelegatingClassLoader@0x0000000100009df8
0x00000000c03acea0      1       1471      null          dead    sun/reflect/DelegatingClassLoader@0x0000000100009df8
0x00000000c02cc7b0      10587   13944043        0x00000000c0300be8      live    org/apache/jmeter/DynamicClassLoader@0x0000000100060218
0x00000000c1e0fe40      1       878     0x00000000c02cc7b0      dead    sun/reflect/DelegatingClassLoader@0x0000000100009df8
0x00000000c10256a0      1       1471    0x00000000c02cc7b0      dead    sun/reflect/DelegatingClassLoader@0x0000000100009df8
0x00000000c02cc888      1       1481      null          dead    sun/reflect/DelegatingClassLoader@0x0000000100009df8
0x00000000c19dc138      1       1471      null          dead    sun/reflect/DelegatingClassLoader@0x0000000100009df8
0x00000000c19dcb38      1       1473      null          dead    sun/reflect/DelegatingClassLoader@0x0000000100009df8
0x00000000c19e6fb8      1       1473      null          dead    sun/reflect/DelegatingClassLoader@0x0000000100009df8
0x00000000c19aa9b0      1       1473      null          dead    sun/reflect/DelegatingClassLoader@0x0000000100009df8
0x00000000c1aa5000      1       878       null          dead    sun/reflect/DelegatingClassLoader@0x0000000100009df8
0x00000000c02cce00      1       1472      null          dead    sun/reflect/DelegatingClassLoader@0x0000000100009df8
0x00000000c0fd55d0      12      37189   0x00000000c0300be8      live    sun/reflect/misc/MethodUtil@0x00000001001e1028
0x00000000c0ef5fc0      1       878       null          dead    sun/reflect/DelegatingClassLoader@0x0000000100009df8
0x00000000c02cca18      1       1472    0x00000000c02cc7b0      dead    sun/reflect/DelegatingClassLoader@0x0000000100009df8
0x00000000c0270990      0       0       0x00000000c0300be8      live    java/util/ResourceBundle$RBClassLoader@0x00000001000f2f58
0x00000000c0fd4ec0      1       878     0x00000000c02cc7b0      dead    sun/reflect/DelegatingClassLoader@0x0000000100009df8
0x00000000c0ef6450      1       1471    0x00000000c02cc7b0      dead    sun/reflect/DelegatingClassLoader@0x0000000100009df8
0x00000000c1025440      1       878       null          dead    sun/reflect/DelegatingClassLoader@0x0000000100009df8
0x00000000c02cd8e8      1       1472    0x00000000c02cc7b0      dead    sun/reflect/DelegatingClassLoader@0x0000000100009df8
0x00000000c037f870      1       1471    0x00000000c02ccec8      dead    sun/reflect/DelegatingClassLoader@0x0000000100009df8
0x00000000c1eac520      1       878       null          dead    sun/reflect/DelegatingClassLoader@0x0000000100009df8
0x00000000c1fb10b0      1       878     0x00000000c02cc7b0      dead    sun/reflect/DelegatingClassLoader@0x0000000100009df8
0x00000000c02ccae0      1       1472    0x00000000c02cc7b0      dead    sun/reflect/DelegatingClassLoader@0x0000000100009df8
0x00000000c03d5370      1       878       null          dead    sun/reflect/DelegatingClassLoader@0x0000000100009df8
0x00000000c10a22d8      1       1471      null          dead    sun/reflect/DelegatingClassLoader@0x0000000100009df8
0x00000000c23a9668      1       878       null          dead    sun/reflect/DelegatingClassLoader@0x0000000100009df8
0x00000000c0300be8      37      144387  0x00000000c02ccec8      live    sun/misc/Launcher$AppClassLoader@0x000000010000f668
0x00000000c02ccc70      1       1471    0x00000000c02cc7b0      dead    sun/reflect/DelegatingClassLoader@0x0000000100009df8
0x00000000c13df1e0      1       1472      null          dead    sun/reflect/DelegatingClassLoader@0x0000000100009df8
0x00000000c1522db0      1       1471      null          dead    sun/reflect/DelegatingClassLoader@0x0000000100009df8
0x00000000c202e8e0      1       878       null          dead    sun/reflect/DelegatingClassLoader@0x0000000100009df8
0x00000000c02ccec8      152     345291    null          live    sun/misc/Launcher$ExtClassLoader@0x000000010000fa10
0x00000000c20611e0      1       1471    0x00000000c02cc7b0      dead    sun/reflect/DelegatingClassLoader@0x0000000100009df8
0x00000000c0ef6108      1       878       null          dead    sun/reflect/DelegatingClassLoader@0x0000000100009df8
0x00000000c19e2e70      1       1473      null          dead    sun/reflect/DelegatingClassLoader@0x0000000100009df8
0x00000000c1fe6910      1       878     0x00000000c02cc7b0      dead    sun/reflect/DelegatingClassLoader@0x0000000100009df8
0x00000000c206a068      1       878     0x00000000c02cc7b0      dead    sun/reflect/DelegatingClassLoader@0x0000000100009df8
0x00000000c10a1ef8      1       878       null          dead    sun/reflect/DelegatingClassLoader@0x0000000100009df8
0x00000000c0fd5088      1       889     0x00000000c0fd55d0      dead    sun/reflect/DelegatingClassLoader@0x0000000100009df8
0x00000000c13d75c8      1       1473      null          dead    sun/reflect/DelegatingClassLoader@0x0000000100009df8
0x00000000c1e25298      1       1471    0x00000000c02cc7b0      dead    sun/reflect/DelegatingClassLoader@0x0000000100009df8
0x00000000c02cc950      1       1471    0x00000000c02cc7b0      dead    sun/reflect/DelegatingClassLoader@0x0000000100009df8
0x00000000c23c42c0      1       878     0x00000000c02cc7b0      dead    sun/reflect/DelegatingClassLoader@0x0000000100009df8

total = 52      14669   21509096            N/A         alive=6, dead=46            N/A

F

强制输出

  • 使用jmap -dump或者jmap -histo命令时,如果进程没有响应,可以使用-F强制输出;
  • live模式下不能使用-F强制输出;

h help

-h-help都是输出帮助信息的指令

-Jflag

flag信息传递给运行jamp命令的虚拟机

其他文章列表

spring web service系列1
spring web service系列2
spring web service系列3
maven配置文件settings.xml详解
Nginx转发请求过程解析
Nginx中的负载均衡算法
Nginx upstream指令配置说明
Nginx中虚拟服务器server指令配置说明
Nginx中proxy_pass/proxy_redirect/proxy_set_header配置说明
Nginx中ngx_http_core_module相关指令配置说明
Java自带JVM监控工具jstat使用详细说明
Java自带JVM监控工具jps使用详细说明
Java自带故障分析工具jhat工具使用说明

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 194,319评论 5 459
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 81,801评论 2 371
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 141,567评论 0 319
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 52,156评论 1 263
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 61,019评论 4 355
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 46,090评论 1 272
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 36,500评论 3 381
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 35,192评论 0 253
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 39,474评论 1 290
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 34,566评论 2 309
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 36,338评论 1 326
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 32,212评论 3 312
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 37,572评论 3 298
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 28,890评论 0 17
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 30,169评论 1 250
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 41,478评论 2 341
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 40,661评论 2 335