源码位于 JMap.java at jdk8-b120,可以看到对参数的解析以及对实际命令的调用。如果是堆转储会调用至 attachListener.cpp at jdk8-b120:
1 | // Implementation of "dumpheap" command. |
可以看出如果指定了 live
选项,则会在堆转储前执行一次 Full GC 以降低堆转储的大小,便于分析。在 jmap 中也有提到:
The live suboption is optional, but when specified, only the active objects in the heap are dumped.
值得注意的是在堆转储文件中的 int[]
部分来源于 GC、TLAB 等填充的内存空间,如 collectedHeap.cpp at jdk8-b120 中的 fill_with_object
方法:
1 | void CollectedHeap::fill_with_object(HeapWord* start, size_t words, bool zap) |
fill_with_object
方法被不少 GC 收集器调用,也被 ThreadLocalAllocBuffer
调用,如 threadLocalAllocBuffer.cpp at jdk8-b120:
1 | // Fills the current tlab with a dummy filler array to create |
Reference
jdk/HeapHprofBinWriter.java at jdk8-b120 · openjdk/jdk · GitHub
Can jmap -histo trigger full garbage collection? - Stack Overflow