Generate Java dump when OUTOFMEMORY

I have a program that should eventually generate OUTOFMEMORY

public class VeryLargeObject implements Serializable {
    public static final int SIZE = 1 << 12;

    public String tag;
    public int[][] bigOne = new int[SIZE][SIZE];

    {
        // Initialize bigOne
        for(int i = 0; i < SIZE ; ++i) {
            for(int j = 0; j < SIZE; ++j) {
                bigOne[i][j] = (int) (Math.random() * 100);
            }
        }
    }

    public VeryLargeObject(String tag) {
        this.tag = tag;
    }

    public static void main(String args[]) {
        VeryLargeObject[] vla = new VeryLargeObject[1 << 12];
        for(int i = 0; i < Integer.MAX_VALUE; ++i) {
            vla[i] = new VeryLargeObject("aa");
        }
    }
}

I run the program with the following parameters:

java VeryLargeObject -Xms1024m -Xmx1024m -XX:+HeapDumpOnOutOfMemoryError -XX:HeapDumpPath="D:\workspace"

The program failed due to OUTOFMEMORY, but no dump file was generated Do you know why?

Exception in thread "main" java.lang.OutOfMemoryError: Java heap space
        at VeryLargeObject.<init>(VeryLargeObject.java:14)
        at VeryLargeObject.main(VeryLargeObject.java:32)

Solution

For the initiator, delete the XX option and any option before verylargeobject, otherwise you pass the parameters to the Java program instead of the JVM

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>