import sun.misc.Unsafe;
import java.lang.reflect.Field;

/**
 * VM Args:
 *  -XX:MaxDirectMemorySize=10M
 * @author 献
 * @company Goochine-深圳古辰创智科技有限公司
 * @website www.goochine.com
 * @tel 18271840547
 * @date 2017/4/24
 */
public class TestDirectOOM {
    public static void main(String[] args) throws IllegalAccessException {
        Field field = Unsafe.class.getDeclaredFields()[0];

        field.setAccessible(true);

        Unsafe unsafe = (Unsafe) field.get(null);
        while (true) {
            // 1MB
            unsafe.allocateMemory(1024 * 1024);
        }
    }
}
