JVM调优小工具之jmap

简介

jmap(Java Memory Map)可用于获取堆转储快照、查询呢finalize队列、查询堆和方法区详细信息(如:空间使用率、垃圾收集器类型)。

使用方法(出现异常,参考这里解决)

jmap [ options ] pid :对本地虚拟机进程执行操作。
jmap [ options ] executable core :对可执行Core File执行操作。
jmap [ options ] [ pid ] server-id@ ] remote-hostname-or-IP :对远程服务执行操作。

options :

options 作用
打印共享对象映射。对于目标JVM中加载的每个共享对象将打印共享对象文件的起始地址、映射大小和完整路径
-dump 生成堆转储快照。命令格式为 -dump:[live,] format=b, file=filename 加上[live,]选项,则只会dump出存活对象
-finalizerinfo 显示在F-Quene中等待finalizer线程执行finalize()方法的对象,只在Linux、Solaris系统下有效
-heap 显示堆信息,如参数配置、分代情况、垃圾回收器等。除此以外还会显示常量池中字符串数量和占用空间大小
-histo[:live] 显示堆中对象统计信息。包括类、对象数量、占用内存(byte)、类全限定名。加上[:live]则只会统计存活对象
-clstats 打印类加载器相关的信息。对于每个类加载器,将打印其名称、活动程度、地址、父类加载器、以及已加载类的数量和大小
-F 强制执行。在jmap -dump 或 jmap -histo没有响应时使用-F强制执行(这种模式下live选项会失效)
-J 向JVM传递参数
使用示例
  1. jmap 14508:打印共享对象映射。
david@UX501:~$ jmap 14508
Attaching to process ID 14508, please wait...
Debugger attached successfully.
Server compiler detected.
JVM version is 25.212-b01
0x000055c84251e000	6K	/usr/lib/jvm/java-8-openjdk-amd64/jre/bin/java
0x00007f520c1ff000	34K	/usr/lib/jvm/java-8-openjdk-amd64/jre/lib/amd64/libzip.so
0x00007f520c410000	183K	/usr/lib/jvm/java-8-openjdk-amd64/jre/lib/amd64/libjava.so
0x00007f520c63e000	66K	/usr/lib/jvm/java-8-openjdk-amd64/jre/lib/amd64/libverify.so
0x00007f520c84f000	34K	/usr/lib/x86_64-linux-gnu/librt-2.28.so
0x00007f520c95a000	98K	/usr/lib/x86_64-linux-gnu/libgcc_s.so.1
0x00007f520c974000	1542K	/usr/lib/x86_64-linux-gnu/libm-2.28.so
0x00007f520caf7000	1533K	/usr/lib/x86_64-linux-gnu/libstdc++.so.6.0.25
0x00007f520cc7b000	13500K	/usr/lib/jvm/java-8-openjdk-amd64/jre/lib/amd64/server/libjvm.so
0x00007f520dbcf000	1781K	/usr/lib/x86_64-linux-gnu/libc-2.28.so
0x00007f520dd90000	14K	/usr/lib/x86_64-linux-gnu/libdl-2.28.so
0x00007f520dd95000	54K	/usr/lib/jvm/java-8-openjdk-amd64/jre/lib/amd64/jli/libjli.so
0x00007f520dfa3000	110K	/usr/lib/x86_64-linux-gnu/libz.so.1.2.11
0x00007f520dfc0000	143K	/usr/lib/x86_64-linux-gnu/libpthread-2.28.so
0x00007f520dfe8000	54K	/usr/lib/x86_64-linux-gnu/libnss_files-2.28.so
0x00007f520e001000	161K	/usr/lib/x86_64-linux-gnu/ld-2.28.so
  1. jmap -dump:live,format=b,file=/home/david/Desktop/dump-20200706.hprof 14508:生成dump文件
david@UX501:~$ jmap -dump:live,format=b,file=/home/david/Desktop/dump-20200706.hprof 14508
Dumping heap to /home/david/Desktop/dump-20200706.hprof ...
Heap dump file created
david@UX501:~$
  1. jmap -finalizerinfo 14508:查看正在等待执行finalize()方法的对象
david@UX501:~$ jmap -finalizerinfo 14508
Attaching to process ID 14508, please wait...
Debugger attached successfully.
Server compiler detected.
JVM version is 25.212-b01
Number of objects pending for finalization: 0
  1. jmap -heap 14508:查看与堆相关的信息
david@UX501:~$ jmap -heap 14508
Attaching to process ID 14508, please wait...
Debugger attached successfully.
Server compiler detected.
JVM version is 25.212-b01

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

Heap Configuration:
   MinHeapFreeRatio         = 0
   MaxHeapFreeRatio         = 100
   MaxHeapSize              = 3131047936 (2986.0MB)
   NewSize                  = 65536000 (62.5MB)
   MaxNewSize               = 1043333120 (995.0MB)
   OldSize                  = 131596288 (125.5MB)
   NewRatio                 = 2
   SurvivorRatio            = 8
   MetaspaceSize            = 21807104 (20.796875MB)
   CompressedClassSpaceSize = 1073741824 (1024.0MB)
   MaxMetaspaceSize         = 17592186044415 MB
   G1HeapRegionSize         = 0 (0.0MB)

Heap Usage:
PS Young Generation
Eden Space:
   capacity = 49807360 (47.5MB)
   used     = 3984688 (3.8000946044921875MB)
   free     = 45822672 (43.69990539550781MB)
   8.000199167351974% 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 = 55574528 (53.0MB)
   used     = 5688328 (5.424812316894531MB)
   free     = 49886200 (47.57518768310547MB)
   10.235494937536851% used

688 interned Strings occupying 46272 bytes.

  1. jmap -histo:live 14508:查看对象统计信息
david@UX501:~$ jmap -histo:live 14508

 num     #instances         #bytes  class name
----------------------------------------------
   1:         95004        3040128  java.util.HashMap$Node
   2:        189966        3039456  java.lang.Integer
   3:            12         525248  [Ljava.util.HashMap$Node;
   4:           930          82496  [C
   5:           478          54504  java.lang.Class
   6:           531          26840  [Ljava.lang.Object;
   7:            21          25288  [B
   8:           918          22032  java.lang.String
   9:            94           3760  java.lang.ref.SoftReference
  10:            91           3584  [I
  11:           111           3552  java.util.Hashtable$Entry
  12:             8           3008  java.lang.Thread
  1. jmap -clstats 14508:查看类加载器相关的信息
david@UX501:~$ jmap -clstats 14508
Attaching to process ID 14508, please wait...
Debugger attached successfully.
Server compiler detected.
JVM version is 25.212-b01
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>	411	794860	  null  	live	<internal>
0x0000000705601aa0	1	893	0x0000000705604d68	live	sun/misc/Launcher$AppClassLoader@0x00000007c000f298
0x0000000705604d68	0	0	  null  	live	sun/misc/Launcher$ExtClassLoader@0x00000007c000f630

total = 3	412	795753	    N/A    	alive=3, dead=0	    N/A  

未经授权,禁止转载。

你可能感兴趣的:(java,java,jvm)