首先,我使用Intelli Idea作爲IDE來運行旨在導致OOM異常的應用程序。 VM選項: -Xmx20M -XX:MaxDirectMemorySize = 10M -XX:+ HeapDumpOnOutOfMemoryError -XX:HeapDumpPath = C:\用戶\ chao.zhang1 \桌面\ aaa.hprof無法使用VM選項獲取轉儲文件:引發OOM異常時的HeapDumpOnOutOfMemoryError
應用: 進口sun.misc.Unsafe ;
import java.lang.reflect.Field;
public class DirectMemoryOOM{
private static final int _1MB=1024*1024;
public static void main(String[]args)throws Exception{
Field unsafeField=Unsafe.class.getDeclaredFields()[0];
unsafeField.setAccessible(true);
Unsafe unsafe=(Unsafe)unsafeField.get(null);
while(true){
unsafe.allocateMemory(_1MB);
}
}
}
拋出異常後,目錄'C:\ Users \ chao.zhang1 \ Desktop \'中不存在轉儲文件。
其次,我嘗試另一種方法來避免IDE的影響,我運行在CMD命令行命令: 的java DirectMemoryOOM -Xmx20M -XX:MaxDirectMemorySize = 10M -XX:+ HeapDumpOnOutOfMemoryError -XX:HeapDumpPath = C:\ Users \ chao.zhang1 \ Desktop \ aaa.hprof 仍然沒有創建轉儲文件。
日誌在控制檯是:
Exception in thread "main" java.lang.OutOfMemoryError
at sun.misc.Unsafe.allocateMemory(Native Method)
at DirectMemoryOOM.main(DirectMemoryOOM.java:12)
更新2017年2月23日:今天我 運行到另一個JVM崩潰時Intelli想法控制檯輸出:
#
# A fatal error has been detected by the Java Runtime Environment:
#
# Internal Error (javaCalls.cpp:62), pid=11864, tid=13164
# guarantee(thread->is_Java_thread()) failed: crucial check - the VM thread cannot and must not escape to Java code
#
# JRE version: Java(TM) SE Runtime Environment (7.0_79-b15) (build 1.7.0_79-b15)
# Java VM: Java HotSpot(TM) 64-Bit Server VM (24.79-b02 mixed mode windows-amd64 compressed oops)
# Failed to write core dump. Minidumps are not enabled by default on client versions of Windows
#
# An error report file with more information is saved as:
# E:\apache-tomcat-7.0.69\apache-tomcat-7.0.69\bin\hs_err_pid11864.log
#
# If you would like to submit a bug report, please visit:
# http://bugreport.java.com/bugreport/crash.jsp
#
Disconnected from the target VM, address: '127.0.0.1:58121', transport: 'socket'
我想知道如果與'無法寫入核心轉儲'有關。在客戶端版本的Windows上,默認情況下未啓用「小型轉儲」,是否有可能未正確配置Windows系統以便轉儲文件。 我也嘗試通過高級系統設置啓用迷你轉儲 - >啓動&恢復 - >設置 - >選擇'小內存轉儲'。但沒有任何改變。 任何人都可以提出一些建設性的意見嗎?謝謝!
今天我碰到了jvm crash : –
如果OutOfMemoryError的原因是堆空間不足,則設置HeapDumpOnOutOfMemoryError標誌只會導致寫入堆轉儲。在其他情況下,如果堆不是內存泄漏的地方,那麼在堆中轉儲就沒有多少意義。 –
不錯的問題。提示:您不會將這些解決方案納入評論。有兩種選擇:如果你認爲這是一個非常特殊的問題;然後考慮刪除問題。但是如果你認爲你的問題+你的解決方案可能對別人有幫助;只需寫下你自己的答案。接受這個答案甚至是合法的。 – GhostCat