天天看點

利用jamp和jhat檢視系統對象配置設定情況

利用jamp和jhat檢視系統對象配置設定情況

1. jamp

root@node131:~/bes_seeyon_logs# jmap -heap 32051
Attaching to process ID 32051, please wait...
Debugger attached successfully.
Server compiler detected.
JVM version is 25.71-b00

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

Heap Configuration:
   MinHeapFreeRatio         = 40
   MaxHeapFreeRatio         = 70
   MaxHeapSize              = 16777216000 (16000.0MB)
   NewSize                  = 1363144 (1.2999954223632812MB)
   MaxNewSize               = 5591007232 (5332.0MB)
   OldSize                  = 5452592 (5.1999969482421875MB)
   NewRatio                 = 2
   SurvivorRatio            = 8
   MetaspaceSize            = 4194304000 (4000.0MB)
   CompressedClassSpaceSize = 1073741824 (1024.0MB)
   MaxMetaspaceSize         = 4194304000 (4000.0MB)
   G1HeapRegionSize         = 4194304 (4.0MB)

Heap Usage:
Exception in thread "main" java.lang.reflect.InvocationTargetException
   at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
   at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
   at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
   at java.lang.reflect.Method.invoke(Method.java:498)
   at sun.tools.jmap.JMap.runTool(JMap.java:201)
   at sun.tools.jmap.JMap.main(JMap.java:130)
Caused by: java.lang.RuntimeException: unknown CollectedHeap type : class sun.jvm.hotspot.gc_interface.CollectedHeap
   at sun.jvm.hotspot.tools.HeapSummary.run(HeapSummary.java:144)
   at sun.jvm.hotspot.tools.Tool.startInternal(Tool.java:260)
   at sun.jvm.hotspot.tools.Tool.start(Tool.java:223)
   at sun.jvm.hotspot.tools.Tool.execute(Tool.java:118)
   at sun.jvm.hotspot.tools.HeapSummary.main(HeapSummary.java:49)
   ... 6 more      

它可以列印出 Eden區總容量 、已使用的容量、剩餘的空間容量、兩個Survivor區的總容量、已使用的容量和剩餘的空間容量、老年代的總容量、已使用的容量和剩餘的容量。但是 一般不用jmap指令,原因有2個 :1 沒有jstat 顯示的全 2 沒有GC相關統計。

# 該指令了解目前jvm中對象占用情況,它會按照對象占用空間大小降序排列,這樣就可以快速了解到那個對象占用了大量記憶體
root@node131:~/bes_seeyon_logs# jmap -histo 32051 
num     #instances         #bytes  class name
----------------------------------------------
   1:      24122377     2122532560  [C
   2:       5169030      782332368  [B
   3:        467896      338246792  [I
   4:      13109748      314633952  java.lang.String
   5:       5465828      131179872  java.lang.StringBuilder
   6:       2668662      106746480  java.io.ObjectStreamField
   7:       2201879       97641048  [Ljava.lang.Object;
   8:        938397       82578936  java.lang.reflect.Method
   9:        607426       63172304  java.io.ObjectStreamClass
  10:       1703416       54509312  java.util.concurrent.locks.AbstractQueuedSynchronizer$Node
  11:       1272133       40708256  java.util.HashMap$Node
  12:       1288689       30928536  java.lang.Long
  13:       1059702       25432848  java.util.ArrayList
  14:        458851       24076192  [Ljava.util.HashMap$Node;
  15:        475831       22839888  java.util.HashMap
  16:        434167       17366680  java.util.TreeMap$Entry
  17:        511656       16372992  java.util.concurrent.ConcurrentHashMap$Node
  18:        507610       16243520  java.io.File
  19:        500892       16028544  java.lang.ref.WeakReference
  20:        249458       15965312  java.io.ObjectInputStream
  21:        270501       15800704  [Ljava.io.ObjectInputStream$HandleTable$HandleList;
  22:        282202       15316888  [Ljava.io.ObjectStreamField;
  23:        354535       14601512  [Ljava.lang.String;
  24:        260206       14571536  java.io.ObjectInputStream$BlockDataInputStream
  ....      

2. jamp 生成目前堆記憶體快照

# 使用jmap 指令生成個堆記憶體快照到一個檔案當中,因dump.hprof是二進制檔案,不可直接打開
root@node131:~/bes_seeyon_logs# jmap -dump:live,format=b,file=dump.hprof 32051
Dumping heap to /data/BES952/Node/10.XX.XX.XX/instances/ins13/logs/dump.hprof ...
Heap dump file created
root@node131:~/bes_seeyon_logs# sz dump.hprof      

3. 利用jhat 在浏覽器中分析堆轉出快照

C:\Users\test\Desktop>jhat -port 7000  dump.hprof
Reading from dump.hprof...
Dump file created Fri Sep 24 17:17:07 CST 2021
Snapshot read, resolving...
Resolving 18466626 objects...
Chasing references, expect 3693 dots.............................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................
Eliminating duplicate references.............................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................
Snapshot resolved.
Started HTTP server on port 7000      

4. jhat的用法

C:\Users\test>jhat -h
Usage:  jhat [-stack <bool>] [-refs <bool>] [-port <port>] [-baseline <file>] [-debug <int>] [-version] [-h|-help] <file>

        -J<flag>          Pass <flag> directly to the runtime system. For
                          example, -J-mx512m to use a maximum heap size of 512MB
        -stack false:     Turn off tracking object allocation call stack.
        -refs false:      Turn off tracking of references to objects
        -port <port>:     Set the port for the HTTP server.  Defaults to 7000
        -exclude <file>:  Specify a file that lists data members that should
                          be excluded from the reachableFrom query.
        -baseline <file>: Specify a baseline object dump.  Objects in
                          both heap dumps with the same ID and same class will
                          be marked as not being "new".
        -debug <int>:     Set debug level.
                            0:  No debug output
                            1:  Debug hprof file parsing
                            2:  Debug hprof file parsing, no server
        -version          Report version number
        -h|-help          Print this help and exit
        <file>            The file to read

For a dump file that contains multiple heap dumps,
you may specify which dump in the file
by appending "#<number>" to the file name, i.e. "foo.hprof#3".

All boolean options default to "true"