jmap

打印出某个java进程(使用pid)内存内的,所有‘对象’的情况(如:产生那些对象,及其数量)。

语法

  1. jmap [ option ] pid
  2. jmap [ option ] executable core
  3. jmap [ option ] [server-id@]remote-hostname-or-IP
  • -dump:[live,]format=b,file=<filename> 使用hprof二进制形式,输出jvm的heap内容到文件=. live子选项是可选的,假如指定live选项,那么只输出活的对象到文件.
  • -finalizerinfo 打印正等候回收的对象的信息.
  • -heap 打印heap的概要信息,GC使用的算法,heap的配置及wise heap的使用情况.
  • -histo[:live] 打印每个class的实例数目,内存占用,类全名信息. VM的内部类名字开头会加上前缀”*”. 如果live子参数加上后,只统计活的对象数量.
  • -permstat 打印classload和jvm heap长久层的信息. 包含每个classloader的名字,活泼性,地址,父classloader和加载的class数量. 另外,内部String的数量和占用内存数也会打印出来.
  • -F 强迫.在pid没有相应的时候使用-dump或者-histo参数. 在这个模式下,live子参数无效.
  • -h | -help打印辅助信息
  • -J 传递参数给jmap启动的jvm.

    常用参数

    -histo

    jmap -histo pid 展示class的内存情况 ```shell $ jmap -histo 17948 Picked up JAVA_TOOL_OPTIONS: -Dfile.encoding=UTF-8

    num #instances #bytes class name


1: 41173 17906640 [B 2: 457459 14638688 java.util.concurrent.locks.AbstractQueuedSynchronizer$Node 3: 98229 11211472 [C 4: 10284 11136880 [I 5: 155842 8727152 java.util.concurrent.ConcurrentHashMap$KeyIterator 6: 253325 8106400 java.util.ArrayList$Itr 7: 155935 6237400 java.util.HashMap$KeyIterator 8: 194915 4677960 java.util.LinkedList$Node 9: 194699 4672776 com.intellij.rt.debugger.agent.CaptureStorage$HardKey 10: 156076 3745824 java.util.Collections$UnmodifiableCollection$1 11: 79073 3162920 java.util.TreeMap$Entry 12: 62396 2495840 java.util.HashMap$ValueIterator 13: 78240 1877760 java.util.concurrent.CopyOnWriteArrayList$COWIterator ….

  1. <a name="weFBP"></a>
  2. #### -finalizerinfo
  3. 打印等待回收的对象信息
  4. ```shell
  5. $ jmap -finalizerinfo 17948
  6. Picked up JAVA_TOOL_OPTIONS: -Dfile.encoding=UTF-8
  7. Attaching to process ID 17948, please wait...
  8. Debugger attached successfully.
  9. Server compiler detected.
  10. JVM version is 25.45-b02
  11. Number of objects pending for finalization: 0

-heap

jmap -heap pid 展示pid的整体堆信息

  1. $ jmap -heap 17948
  2. Picked up JAVA_TOOL_OPTIONS: -Dfile.encoding=UTF-8
  3. Attaching to process ID 17948, please wait...
  4. Debugger attached successfully.
  5. Server compiler detected.
  6. JVM version is 25.45-b02
  7. using thread-local object allocation.
  8. Parallel GC with 8 thread(s)
  9. Heap Configuration:
  10. MinHeapFreeRatio = 0 #-XX:MinHeapFreeRatio设置JVM堆最小空闲比率
  11. MaxHeapFreeRatio = 100 #-XX:MaxHeapFreeRatio设置JVM堆最大空闲比率
  12. MaxHeapSize = 4271898624 (4074.0MB) #-XX:MaxHeapSize=设置JVM堆的最大大小
  13. NewSize = 89128960 (85.0MB) #-XX:NewSize=设置JVM堆的‘新生代’的默认大小
  14. MaxNewSize = 1423966208 (1358.0MB) #-XX:MaxNewSize=设置JVM堆的‘新生代’的最大大小
  15. OldSize = 179306496 (171.0MB) #-XX:OldSize=设置JVM堆的‘老生代’的大小
  16. NewRatio = 2 #-XX:NewRatio=:‘新生代’和‘老生代’的大小比率
  17. SurvivorRatio = 8 #-XX:SurvivorRatio=设置年轻代中Eden区与Survivor区的大小比值
  18. MetaspaceSize = 21807104 (20.796875MB)
  19. CompressedClassSpaceSize = 1073741824 (1024.0MB)
  20. MaxMetaspaceSize = 17592186044415 MB
  21. G1HeapRegionSize = 0 (0.0MB)
  22. Heap Usage:
  23. PS Young Generation
  24. Eden Space: :#Eden区内存分布
  25. capacity = 123207680 (117.5MB)
  26. used = 104699296 (99.84902954101562MB)
  27. free = 18508384 (17.650970458984375MB)
  28. 84.97789748171543% used
  29. From Space: #其中一个Survivor区的内存分布
  30. capacity = 8388608 (8.0MB)
  31. used = 7976216 (7.606712341308594MB)
  32. free = 412392 (0.39328765869140625MB)
  33. 95.08390426635742% used
  34. To Space: #另一个Survivor区的内存分布
  35. capacity = 11010048 (10.5MB)
  36. used = 0 (0.0MB)
  37. free = 11010048 (10.5MB)
  38. 0.0% used
  39. PS Old Generation #当前的Old区内存分布
  40. capacity = 83886080 (80.0MB)
  41. used = 5990344 (5.712837219238281MB)
  42. free = 77895736 (74.28716278076172MB)
  43. 7.141046524047852% used
  44. 13040 interned Strings occupying 1135008 bytes.