我有一个应该最终生成的程序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");
}
}
}
Run Code Online (Sandbox Code Playgroud)
我用以下参数运行程序:
java VeryLargeObject -Xms1024m -Xmx1024m -XX:+HeapDumpOnOutOfMemoryError -XX:HeapDumpPath="D:\workspace"
Run Code Online (Sandbox Code Playgroud)
程序因OutOfMemory失败,但未生成转储文件.你知道为什么吗?
Exception in thread "main" java.lang.OutOfMemoryError: Java heap space
at VeryLargeObject.<init>(VeryLargeObject.java:14)
at VeryLargeObject.main(VeryLargeObject.java:32)
Run Code Online (Sandbox Code Playgroud)
Ral*_*lph 16
问题是-XX:HeapDumpPathspefies文件而不是路径.
-Xms1024m -Xmx1024m -XX:+HeapDumpOnOutOfMemoryError -XX:HeapDumpPath="c:\temp\dump2.hprof"
Run Code Online (Sandbox Code Playgroud)
添加:
和bestsss也是对的,所以你需要修复两个"错误":
java -Xms1024m -Xmx1024m -XX:+HeapDumpOnOutOfMemoryError -XX:HeapDumpPath="c:\temp\dump2.hprof" VeryLargeObject
Run Code Online (Sandbox Code Playgroud)
我怀疑jvm无法写入路径并无声地失败.例如,这必须是存在的目录中的文件名.如果您有一个目录D:\workspace,它将失败.如果你有D:\workspace\heap.hprof它可能会工作.首先尝试创建该名称的空白文件,以便您可以执行此操作.
| 归档时间: |
|
| 查看次数: |
18716 次 |
| 最近记录: |