jmap命令可以获取运行中的jvm的快照,从而离线分析,检查内存泄漏,检查一些严重影响性能的大对象的创建,检查系统中最多的对象,各种对象所占用的内存大小.可以使用jmap生成Heap Dump.
什么是堆Dump
堆Dump是反应Java堆使用情况的内存镜像,其中主要包含系统信息,虚拟机属性,完整的线程Dump,所有类和对象的状态等。一般,在内存不足,GC异常等情况下,我们就会怀疑内存泄漏,这个时候就可以制作堆(Dump)来查询具体情况。
常见的内存错误
> outOfMemoryError 年老代内存不足。
> outOfMemoryError:PermGen Space 永久代内存不足。
> outOfMemoryError:GC overhead limit exceed 垃圾回收时间占用系统运行时间的98%或以上。
jmap -heap pid
查看java堆信息
Attaching to process ID 18378, please wait...
Debugger attached successfully.
Server compiler detected.
JVM version is 25.261-b12
using thread-local object allocation.
Parallel GC with 4 thread(s)
Heap Configuration:
MinHeapFreeRatio = 0 # JVM最小空闲比率
MaxHeapFreeRatio = 100
MaxHeapSize = 4164943872 (3972.0MB)
NewSize = 87031808 (83.0MB)
MaxNewSize = 1388314624 (1324.0MB)
OldSize = 175112192 (167.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 = 1314914304 (1254.0MB)
used = 794405392 (757.6040191650391MB)
free = 520508912 (496.39598083496094MB)
60.41499355383087% used
From Space:
capacity = 36175872 (34.5MB)
used = 23758320 (22.657699584960938MB)
free = 12417552 (11.842300415039062MB)
65.6744915506114% used
To Space:
capacity = 37224448 (35.5MB)
used = 0 (0.0MB)
free = 37224448 (35.5MB)
0.0% use