JVM监控—jmap命令

语法:jmap [option]
option选项:
-heap  :显示堆详细信息
-histo[:live]  :显示堆中对象的统计信息,如果指定了live子选项,则只计算活动的对象
-dump:  :生成堆转储快照dump文件

1、jmap pid
查看进程的内存映像信息,使用的动态库
例子:jmap 5313

Attaching to process ID 5313, please wait...
Debugger attached successfully.
Server compiler detected.
JVM version is 25.231-b11
0x0000000000400000	8K	/appserver/jdk1.8.0_231/jre/bin/java
0x00007fdfd6b0b000	66K	/usr/lib64/libbz2.so.1.0.6
0x00007fdfd6d1b000	153K	/usr/lib64/liblzma.so.5.2.2
0x00007fdfd6f41000	88K	/usr/lib64/libz.so.1.2.7
0x00007fdfd7157000	97K	/usr/lib64/libelf-0.176.so
0x00007fdfd736f000	19K	/usr/lib64/libattr.so.1.1.0
0x00007fdfd7574000	330K	/usr/lib64/libdw-0.176.so
0x00007fdfd77c5000	19K	/usr/lib64/libcap.so.2.22
0x00007fdfd79ca000	84K	/usr/lib64/libnss_myhostname.so.2
0x00007fdfd7bdf000	107K	/usr/lib64/libresolv-2.17.so
0x00007fdfd7df9000	30K	/usr/lib64/libnss_dns-2.17.so
0x00007fe018348000	86K	/usr/lib64/libgcc_s-4.8.5-20150702.so.1
0x00007fe018563000	276K	/appserver/jdk1.8.0_231/jre/lib/amd64/libsunec.so
0x00007fe018acf000	50K	/appserver/jdk1.8.0_231/jre/lib/amd64/libmanagement.so
0x00007fe018de9000	110K	/appserver/jdk1.8.0_231/jre/lib/amd64/libnet.so
0x00007fe02c0ae000	91K	/appserver/jdk1.8.0_231/jre/lib/amd64/libnio.so
0x00007fe02f502000	124K	/appserver/jdk1.8.0_231/jre/lib/amd64/libzip.so
0x00007fe02f71e000	60K	/usr/lib64/libnss_files-2.17.so
0x00007fe02f931000	226K	/appserver/jdk1.8.0_231/jre/lib/amd64/libjava.so
0x00007fe02fb60000	64K	/appserver/jdk1.8.0_231/jre/lib/amd64/libverify.so
0x00007fe02fd6f000	42K	/usr/lib64/librt-2.17.so
0x00007fe02ff77000	1110K	/usr/lib64/libm-2.17.so
0x00007fe030279000	16650K	/appserver/jdk1.8.0_231/jre/lib/amd64/server/libjvm.so
0x00007fe031263000	2105K	/usr/lib64/libc-2.17.so
0x00007fe031631000	18K	/usr/lib64/libdl-2.17.so
0x00007fe031835000	106K	/appserver/jdk1.8.0_231/jre/lib/amd64/jli/libjli.so
0x00007fe031a4d000	138K	/usr/lib64/libpthread-2.17.so
0x00007fe031c69000	159K	/usr/lib64/ld-2.17.so

2、jmap -heap
例子:jmap -heap 5313

Attaching to process ID 5313, please wait...
Debugger attached successfully.
Server compiler detected.
JVM version is 25.231-b11

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

Heap Configuration:
   MinHeapFreeRatio         = 0
   MaxHeapFreeRatio         = 100
   MaxHeapSize              = 482344960 (460.0MB)
   NewSize                  = 10485760 (10.0MB)
   MaxNewSize               = 160432128 (153.0MB)
   OldSize                  = 20971520 (20.0MB)
   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 = 21495808 (20.5MB)
   used     = 1891648 (1.80401611328125MB)
   free     = 19604160 (18.69598388671875MB)
   8.80007860137195% used
From Space:
   capacity = 1572864 (1.5MB)
   used     = 1048576 (1.0MB)
   free     = 524288 (0.5MB)
   66.66666666666667% used
To Space:
   capacity = 1572864 (1.5MB)
   used     = 0 (0.0MB)
   free     = 1572864 (1.5MB)
   0.0% used
PS Old Generation
   capacity = 56098816 (53.5MB)
   used     = 43251320 (41.24767303466797MB)
   free     = 12847496 (12.252326965332031MB)
   77.09845427040742% used

29872 interned Strings occupying 2700008 bytes.

3、jmap -histo:live
例子:jmap -histo:live 5313 > /tmp/a.log
能显示对象的实例个数、占用的字节数、类的名称
cat a.log | head -n 20

 num     #instances         #bytes  class name
----------------------------------------------
   1:         85992        9718248  [C
   2:         84880        2037120  java.lang.String
   3:          3183        1875736  [B
   4:         12926        1661344  [Ljava.lang.Object;
   5:         46829        1498528  java.util.concurrent.ConcurrentHashMap$Node
   6:         15142        1332496  java.lang.reflect.Method
   7:         10866        1224384  java.lang.Class
   8:         25368         811776  java.util.HashMap$Node
   9:           311         538336  [Ljava.util.concurrent.ConcurrentHashMap$Node;
  10:          3546         371536  [Ljava.util.HashMap$Node;
  11:         11578         370496  java.lang.ref.WeakReference
  12:          5712         339960  [I
  13:         12847         308328  org.apache.catalina.loader.ResourceEntry
  14:           468         307008  io.netty.util.internal.shaded.org.jctools.queues.MpscArrayQueue
  15:         12102         290448  org.springframework.core.MethodClassKey
  16:         16414         262624  java.lang.Object
  17:          5437         217480  java.lang.ref.SoftReference

4、jmap -dump: pid
例子:jmap -dump:live,format=b,file=/tmp/b.dump 5313

Dumping heap to /tmp/b.dump ...
Heap dump file created

生成的是二进制文件,可以用jdk自带工具jvisualvm.exe打开分析,为什么这个对象数量很多,是由谁引用的,堆溢出一般是没有及时回收内存

参考资料:
https://www.cnblogs.com/kongzhongqijing/articles/3621163.html
 

你可能感兴趣的:(其它)