尝试分配大于 256 MB 的缓冲区大小时出现 Java 分段错误

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/6151398/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-30 14:34:03  来源:igfitidea点击:

Java Segmentation fault when try to allocate buffer sizes larger than 256 MB

javasegmentation-faultnio

提问by suleman

I am using a 64-bit JVM (Oracle), when i try to allocate buffer sizes larger than 256 MB it complains and throws a "segmentation fault" error. I and allocation direct memory buffers using java NIO, and transferring and receiving these objects to and from a RMI client program on same machine (Linux 64 bit).

我使用的是 64 位 JVM (Oracle),当我尝试分配大于 256 MB 的缓冲区大小时,它会抱怨并引发“分段错误”错误。我和使用 java NIO 分配直接内存缓冲区,并在同一台机器(Linux 64 位)上与 RMI 客户端程序传输和接收这些对象。

Any idea?

任何的想法?

回答by djhaskin987

Segmentation Faults happen in programs (such as the JVM) due to memory errors. Either the JVM has a bug in it that makes it try to use the wrong section of memory on the computer when its cranked up to use that much buffer space, or it tries to allocate 256M of memory and in the process it uses more space than the computer gave it. In short, it sounds to me like the 64 bit JVM wasn't built to allocate that much space with its current settings. Perhaps you could try to configure the JVM so that it asks for more memory from the computer before it starts up. jtahlborn's comment on your asking what the max heap setting is on the JVM is also a question you should ask before you run the program again.

由于内存错误,程序(例如 JVM)中会发生分段错误。JVM 中存在一个错误,使其在启动以使用那么多缓冲区空间时尝试使用计算机上错误的内存部分,或者它尝试分配 256M 的内存并在此过程中使用的空间超过电脑给了。简而言之,在我看来,64 位 JVM 的构建并不是为了使用其当前设置分配那么多空间。也许您可以尝试配置 JVM,以便它在启动之前从计算机请求更多内存。jtahlborn 关于您询问 JVM 上的最大堆设置的评论也是您在再次运行程序之前应该问的问题。

回答by Zian Choy

Have you tried the following workaround from the bug report?

您是否尝试过错误报告中的以下解决方法?

Run System.gc() before ByteBuffer.allocateDirect()...

在 ByteBuffer.allocateDirect() 之前运行 System.gc()...