常規(guī)方法1: gcore或jmap -F 強(qiáng)行dump舔株;
?常規(guī)方法2:jinfo/jcmd 增加?HeapDumpBeforeFullGC/HeapDumpAfterFullGC flag
常規(guī)方法3:重啟 設(shè)置 JVM 參數(shù) -XX:+UseHeapDumpBeforeFullGC
常規(guī)方法4:jmx删铃,mxbean直接動(dòng)態(tài)修改,比如去Jconsole里setVmOption稿存,直接將HeapDumpBeforeFullGC和HeapDumpAfterFullGC設(shè)置成true;
非常規(guī)方法:無限FGC時(shí)用
先用ps -ef|grep java 到j(luò)vm進(jìn)程,gdb attach上去, 例如gdb -p 34567
通過p命令顯示HeapDumpBeforeFullGC變量的地址(默認(rèn)是false)
(gdb) p &HeapDumpBeforeFullGC
$1 = ( *) 0x10f35754f
runtime設(shè)置這個(gè)變量為true(1)
(gdb) set *0x10f35754f=1
(gdb) p HeapDumpBeforeFullGC
$2 = 1
下次FullGC觸發(fā)前瞭空,就會(huì)自動(dòng)HeapDump了到默認(rèn)的 java_pidxxx.hprof了。
有了dump文件后要恢復(fù)flag回去
(gdb) p HeapDumpBeforeFullGC
$1 = 1
(gdb) p &HeapDumpBeforeFullGC
$2 = ( *) 0x10f35754f
(gdb) set *0x10f35754f=0
(gdb) p HeapDumpBeforeFullGC
$3 = 0