Java本机直接内存溢出
JVM配置
-XX:MaxDirectMemorySize=100M -XX:+HeapDumpOnOutOfMemoryError -XX:+PrintGCDetails
测试代码
package com.example.oom; import sun.misc.Unsafe; import java.lang.reflect.Field; public class DirectMemoryOOM { private static 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); } } }
测试结果
Exception in thread "main" java.lang.OutOfMemoryError at sun.misc.Unsafe.allocateMemory(Native Method) at com.example.oom.DirectMemoryOOM.main(DirectMemoryOOM.java:16)
也没有dump,因为这个不是队内oom
作者:iBrake
本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利.