How to simulate the Out Of memory : Requested array size exceeds VM limit(如何模拟内存不足:请求的数组大小超过 VM 限制)
问题描述
我使用了来自 sun 网站的 Out Of Memory 帮助一个>.它被引用的地方<块引用>
内存不足:请求的数组大小超过了 VM 限制
这表明应用程序试图分配一个大于堆大小的数组.为了例如,如果应用程序尝试分配一个 512MB 的数组,但最大堆大小为 256MB,那么这个错误将被抛出.在大多数情况下,问题可能是堆大小太大小或错误导致应用程序尝试创建一个数组,其大小计算为不正确.
我试图通过
来模拟这个import java.util.ArrayList;导入 java.util.List;公共类 JavaTest {公共静态无效主要(字符串[]参数){长[] ll = 新长[64*1024*1024];}}
在我的机器上
javac *.java;java -Xmx256m JavaTest
但上面的行正在生产
<上一页>线程主"java.lang.OutOfMemoryError 中的异常:Java 堆空间在 JavaTest.main(JavaTest.java:7)我错过了什么?
更新:我的java版本是
<上一页>$java -版本java版本1.6.0_15"Java(TM) SE 运行时环境 (build 1.6.0_15-b03)Java HotSpot(TM) 服务器虚拟机(build 14.1-b02,混合模式)
为了我
long[] l = new long[Integer.MAX_VALUE];
产生 线程main"java.lang.OutOfMemoryError 中的异常:请求的数组大小超过 VM 限制
PS:如果你需要产生异常来进行测试,你也可以自己throw new OutOfMemoryError("Requested array size超出VM limit")
.
I used the Out Of Memory help from sun's site. Where it is quoted as
Out Of Memory : Requested array size exceeds VM limit
This indicates that the application attempted to allocate an array that is larger than the heap size. For example, if an application tries to allocate an array of 512MB but the maximum heap size is 256MB, then this error will be thrown. In most cases the problem is likely to be either that the heap size is too small or that a bug results in the application attempting to create an array whose size is calculated to be incorrectly huge.
I tried to simulate this by
import java.util.ArrayList;
import java.util.List;
public class JavaTest {
public static void main(String[] args){
long[] ll = new long[64*1024*1024];
}
}
on my machine with
javac *.java;java -Xmx256m JavaTest
But the above line is producing
Exception in thread "main" java.lang.OutOfMemoryError: Java heap space at JavaTest.main(JavaTest.java:7)
What am I missing?
Update : My java version is
$java -version java version "1.6.0_15" Java(TM) SE Runtime Environment (build 1.6.0_15-b03) Java HotSpot(TM) Server VM (build 14.1-b02, mixed mode)
For me
long[] l = new long[Integer.MAX_VALUE];
yields Exception in thread "main" java.lang.OutOfMemoryError: Requested array size exceeds VM limit
PS: if you need to produce the exception for the purpose of testing, you could also just throw new OutOfMemoryError("Requested array size exceeds VM limit")
yourself.
这篇关于如何模拟内存不足:请求的数组大小超过 VM 限制的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:如何模拟内存不足:请求的数组大小超过 VM 限制


- Eclipse 插件更新错误日志在哪里? 2022-01-01
- C++ 和 Java 进程之间的共享内存 2022-01-01
- value & 是什么意思?0xff 在 Java 中做什么? 2022-01-01
- Spring Boot连接到使用仲裁器运行的MongoDB副本集 2022-01-01
- 从 finally 块返回时 Java 的奇怪行为 2022-01-01
- 如何使用WebFilter实现授权头检查 2022-01-01
- Java包名称中单词分隔符的约定是什么? 2022-01-01
- 将log4j 1.2配置转换为log4j 2配置 2022-01-01
- Jersey REST 客户端:发布多部分数据 2022-01-01
- Safepoint+stats 日志,输出 JDK12 中没有 vmop 操作 2022-01-01