Java性能调优工具——Jmap

一、命令说明

jmap(Java Memory Map)用于用于生成堆转储快照,有时候也用于查看内存内存使用情况。

二、参数说明

C:\Users\Administrator>jmap
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

三、使用示例

1 . jmap -heap : 打印Java内存使用统计信息

C:\Users\Administrator>jmap -heap 7364
Attaching to process ID 7364, please wait...
Debugger attached successfully.
Server compiler detected.
JVM version is 25.77-b03

using parallel threads in the new generation.
using thread-local object allocation.
Concurrent Mark-Sweep GC

Heap Configuration:
   MinHeapFreeRatio         = 40
   MaxHeapFreeRatio         = 70
   MaxHeapSize              = 4294967296 (4096.0MB
   NewSize                  = 1073741824 (1024.0MB
   MaxNewSize               = 1073741824 (1024.0MB
   OldSize                  = 1073741824 (1024.0MB
   NewRatio                 = 2
   SurvivorRatio            = 8
   MetaspaceSize            = 21807104 (20.796875M
   CompressedClassSpaceSize = 1073741824 (1024.0MB
   MaxMetaspaceSize         = 2147483648 (2048.0MB
   G1HeapRegionSize         = 0 (0.0MB)

Heap Usage:
New Generation (Eden + 1 Survivor Space): //---------------新生代
   capacity = 966393856 (921.625MB)
   used     = 360977320 (344.25479888916016MB)
   free     = 605416536 (577.3702011108398MB)
   37.35302307219966% used
Eden Space: //-----------------伊甸区
   capacity = 859045888 (819.25MB)
   used     = 360977320 (344.25479888916016MB)
   free     = 498068568 (474.99520111083984MB)
   42.02072613843883% used
From Space: //----------------第一幸存区
   capacity = 107347968 (102.375MB)
   used     = 0 (0.0MB)
   free     = 107347968 (102.375MB)
   0.0% used
To Space: //-----------------第二幸存区
   capacity = 107347968 (102.375MB)
   used     = 0 (0.0MB)
   free     = 107347968 (102.375MB)
   0.0% used
concurrent mark-sweep generation:
   capacity = 1073741824 (1024.0MB)
   used     = 590955568 (563.5791473388672MB)
   free     = 482786256 (460.4208526611328MB)
   55.03702610731125% used

156040 interned Strings occupying 14738896 bytes.

2 . jmap -histo[:live] : 打印每个类的实例数以及所占空间的统计信息

 jmap -histo 7364 > c:\Users\Administrator\Desktop\2.txt
 num     #instances         #bytes  class name
----------------------------------------------
   1:       3393365      348565536  [C
   2:        631117      100897704  [B
   3:        117043       68459672  [I
   4:       2724434       65386416  java.lang.String
   5:        538821       47416248  java.lang.reflect.Method
   6:        371571       18602096  [Ljava.lang.Object;
   7:        426426       17057040  java.util.TreeMap$Entry
   8:          2070       16797336  [J
   9:        473146       15140672  java.util.concurrent.ConcurrentHashMap$Node
  10:        465948       14910336  java.util.HashMap$Node
  11:        439728       14071296  java.lang.ref.WeakReference
  12:        417987       10968376  [Ljava.lang.String;
  13:        122936       10818368  com.seeyon.ctp.common.i18n.domain.ResourceInfo
//只打印出存活对象
jmap -histo:live 7364 > c:\Users\Administrator\Desktop\2.txt
 num     #instances         #bytes  class name
----------------------------------------------
   1:       1991718      197879544  [C
   2:       1984202       47620848  java.lang.String
   3:        527284       46400992  java.lang.reflect.Method
   4:          1201       16776160  [J
   5:        339593       16602976  [Ljava.lang.Object;
   6:         18450       15985840  [B
   7:        466136       14916352  java.util.concurrent.ConcurrentHashMap$Node
   8:        440931       14109792  java.util.HashMap$Node
   9:        437902       14012864  java.lang.ref.WeakReference
  10:         84851       12626640  [I

附 - jmap输出中class name非自定义类的说明:

BaseType CharacterType
Bbyte
Cchar
Ddouble
Ffloat
Iint
Jlong
L引用对象
Sshort
Zboolean
[数组引用对象

3 .jmap -finalizerinfo : 打印等待回收的对象信息

C:\Users\Administrator>jmap -finalizerinfo 7364
Attaching to process ID 7364, please wait...
Debugger attached successfully.
Server compiler detected.
JVM version is 25.77-b03
Number of objects pending for finalization: 0

4 . jmap -dump : dump内存信息到磁盘

``` jmap -dump:live,format=b,file=c:\users\Administrator\Desktop\test.bin 7364 ``` 注意:导出来的文件可以使用Jprofiler或者MemoryAnalyzer进行分析了

四、参考链接

  1. JVM调优命令-jmap
  2. jmap查看内存使用情况与生成heapdump
  3. jmap - Memory Map
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值