@@ -0,0 +1,925 @@
+package sample.jcu.unsafe;%0A%0Aimport org.junit.Test;%0A%0A/**%0A * @author soyona%0A * @Package sample.jcu.unsafe%0A * @Desc: %E7%94%B3%E8%AF%B7Integer.MAX_VALUE%E5%86%85%E5%AD%98%EF%BC%8CVM %E8%BF%98%E6%98%AF direct byte buffers%0A * @date 2018/7/14 12:49%0A */%0Apublic class ArraySizeTest %7B%0A%0A    /**%0A     * allocate an array that has more than Integer.MAX_VALUE entries.%0A     *%0A     * You will get the exception: java.lang.OutOfMemoryError: Requested array size exceeds VM limit%0A     */%0A    @Test%0A    public void arrayInVMTest()%7B%0A        // 2%E7%9A%8431%E6%AC%A1%E5%B9%82-1%EF%BC%8C1Byte=8bit%EF%BC%8C1KByte = 1024Byte = 2%E7%9A%8410%E6%AC%A1Byte%0A        // 1MByte = 1024 * 1KByte = 2%E7%9A%8420%E6%AC%A1Byte%0A        // 1GByte = 1024 * 1MByte = 2%E7%9A%8430%E6%AC%A1Byte%0A        // 2GByte = 1GByte * 2    = 2%E7%9A%8431%E6%AC%A1Byte%0A        // Integer.MAX_VALUE%0A        long unit = 1L;%0A        long int_max = (unit %3C%3C 31) -1;%0A        System.out.println(int_max);%0A        System.out.println(Integer.MAX_VALUE);%0A        // %E5%A4%A7%E7%BA%A62G-1%E5%86%85%E5%AD%98%EF%BC%8C%E5%9C%A8%E5%A0%86%E4%B8%AD%E6%97%A0%E6%B3%95%E5%88%9B%E5%BB%BA%0A        byte%5B%5D strings = new byte%5BInteger.MAX_VALUE%5D;%0A    %7D%0A%7D%0A

Test for allocating an array that has more than Integer.MAX_VALUE entries.