无法使用 VM 选项获取转储文件:堆转储内存不足时引发 OOM 异常时出错



首先,我将Intelli Ideas用作IDE来运行旨在导致OOM异常的应用程序。VM选项:-XMX20M -XX:MaxDirectMemorySize = 10M -XX: HEAPDUMPONOUTOFMEMORYERROR -XX:HEAPDUMPPATH = C: USERS CHAO.ZHANG1 desktop desktop aaa.hprof

应用程序: 进口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 users chao.zhang1 desktop '例外。

其次,我尝试另一种方法来避免IDE的影响,我在CMD命令行中运行此命令:Java DirectMemoryoom -XMX20M -XX:MaxDirectMemorySize = 10M -XX: HEAPDUMPONOUTOFMEMORYERROR -XX:heapdumppath = c: users users chao.zhang1 desktop desktop aaa.hprof 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 Ideas Console输出:

#
# 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.69apache-tomcat-7.0.69binhs_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'的客户端版本上默认不启用Minidumps,Windows系统可能未正确配置用于转储文件。我还试图通过高级系统设置启用迷你销售 -> startup&恢复 ->设置 ->选择"小内存转储"。但是什么都没有改变。谁能提供一些建设性的建议?thx!

在系统设置中启用的内容是在蓝色屏幕的情况下,即在内核模式下发生异常时。这与Java无关。

如果您想要用于java的客户端版本的Minidumps,请在命令行中添加-XX:+CreateMinidumpOnCrash

事实证明,我没有按正确的顺序放置JVM选项。错误的版本是:java directMemoryoom -xmx20m -xx:maxDirectMemorysize = 10m -xx: heapdumponoutofmemoryerror -xx:heapdumppath = c: users users chao.zhang1在这样的申请类课程之前:Java -xmx20m -xx:MaxDirectMemorySize = 10m -XX: heapDumponOutofMemoryError -xx:heapdumppath = c: users users chao.zhang1 desktop desktop desktop aaa.haa.hprof directmemoroom

最新更新