Java jmap 命令详解

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/yx0628/article/details/80954652

jmap 命令如下:

[root@admin ~]# jmap --help
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

常用的 options 参数:
- heap 显示 Java 堆详细信息
- histo 显示堆中对象的统计信息
- permstat 显示堆永久区的类加载器的统计信息
- finalizerinfo 显示在 F-Queue 队列等待 Finalizer 线程执行 finalize 方法的对象
- dump 生成堆转储快照

例如,要生成堆快照文件:

[root@admin ~]# jmap -dump:live,format=b,file=/home/dump.hprof 43616
Dumping heap to /home/dump.hprof ...
Heap dump file created

如果要打印 heap 的概要信息,GC 算法等,可以使用 -heap :

[root@admin ~]# jmap -heap 43616
Attaching to process ID 43616, please wait...
Debugger attached successfully.
Server compiler detected.
JVM version is 24.45-b08

using thread-local object allocation.
Parallel GC with 4 thread(s)

Heap Configuration:
   MinHeapFreeRatio = 40
   MaxHeapFreeRatio = 70
   MaxHeapSize      = 3191865344 (3044.0MB)
   NewSize          = 1310720 (1.25MB)
   MaxNewSize       = 17592186044415 MB
   OldSize          = 5439488 (5.1875MB)
   NewRatio         = 2
   SurvivorRatio    = 8
   PermSize         = 21757952 (20.75MB)
   MaxPermSize      = 85983232 (82.0MB)
   G1HeapRegionSize = 0 (0.0MB)

Heap Usage:
PS Young Generation
Eden Space:
   capacity = 50855936 (48.5MB)
   used     = 2034448 (1.9402008056640625MB)
   free     = 48821488 (46.55979919433594MB)
   4.000414032297036% used
From Space:
   capacity = 7864320 (7.5MB)
   used     = 0 (0.0MB)
   free     = 7864320 (7.5MB)
   0.0% used
To Space:
   capacity = 7864320 (7.5MB)
   used     = 0 (0.0MB)
   free     = 7864320 (7.5MB)
   0.0% used
PS Old Generation
   capacity = 51380224 (49.0MB)
   used     = 473272 (0.45134735107421875MB)
   free     = 50906952 (48.54865264892578MB)
   0.9211170430086097% used
PS Perm Generation
   capacity = 22020096 (21.0MB)
   used     = 2571712 (2.45257568359375MB)
   free     = 19448384 (18.54742431640625MB)
   11.678931826636905% used

1453 interned Strings occupying 135688 bytes.

-finalizerinfo:

[root@admin ~]# jmap -finalizerinfo 43616
Attaching to process ID 43616, please wait...
Debugger attached successfully.
Server compiler detected.
JVM version is 24.45-b08
Number of objects pending for finalization: 0

看到当前并没有等待 finalize 的对象。

-histo:
显示堆中对象的统计信息。
-histo:live 这个命令执行,JVM会先触发gc,然后再统计信息。

[root@admin ~]# jmap -histo:live 43616 | more

 num     #instances         #bytes  class name
----------------------------------------------
   1:          5734         739488  <methodKlass>
   2:          5734         662424  <constMethodKlass>
   3:           380         453824  <constantPoolKlass>
   4:           349         279520  <constantPoolCacheKlass>
   5:          1834         264656  [C
   6:           380         257248  <instanceKlassKlass>
   7:           528          89504  [B
   8:           443          54200  java.lang.Class
   9:           627          41648  [[I
  10:          1683          40392  java.lang.String
  11:           580          35536  [S
  12:           785          31400  java.util.TreeMap$Entry
  13:            46          24656  <objArrayKlassKlass>
  14:           314          13184  [Ljava.lang.Object;
  15:           186           7584  [Ljava.lang.String;
  16:            13           6152  <methodDataKlass>
  17:             8           4288  <typeArrayKlassKlass>
  18:           112           3584  java.util.Hashtable$Entry
  19:            11           2288  <klassKlass>
  20:            61           1952  java.util.concurrent.ConcurrentHashMap$HashEntry
  21:            38           1824  sun.util.locale.LocaleObjectCache$CacheEntry

-permstat

[root@admin ~]# jmap -permstat 43616
Attaching to process ID 43616, please wait...
Debugger attached successfully.
Server compiler detected.
JVM version is 24.45-b08
finding class loader instances ..done.
computing per loader stat ..done.
please wait.. computing liveness...............................................................................done.
class_loader    classes bytes   parent_loader   alive?  type

<bootstrap>     377     2522712   null          live    <internal>
0x0000000741c00d98      0       0         null          live    sun/misc/Launcher$ExtClassLoader@0x000000073cbc1478
0x0000000741c00738      11      123552  0x0000000741c00d98      live    sun/misc/Launcher$AppClassLoader@0x000000073cc24c50

total = 3       388     2646264     N/A         alive=3, dead=0     N/A

猜你喜欢

转载自blog.csdn.net/yx0628/article/details/80954652