Tag: mmap

导致VM故障的Java map / nio / NFS问题:“在编译的Java代码中最近的不安全内存访问操作中发生了故障”

我已经为特定的二进制格式编写了一个解析器类( nfdump,如果有人感兴趣的话),它使用java.nio的MappedByteBuffer来读取每个几GB的文件。 二进制格式只是一系列标题和大多数固定大小的二进制记录,它们通过调用nextRecord()输出到被调用者,后者推送状态机,完成时返回null。 它表现很好。 它适用于开发机器。 在我的生产主机上,它可以运行几分钟或几小时,但似乎总是抛出“java.lang.InternalError:在编译的Java代码中最近的一个不安全的内存访问操作中发生了一个错误”,指法其中一个Map.getInt ,getShort方法,即地图中的读取操作。 设置地图的无争议(?)代码是这样的: /** Set up the map from the given filename and position */ protected void open() throws IOException { // Set up buffer, is this all the flexibility we’ll need? channel = new FileInputStream(file).getChannel(); MappedByteBuffer map1 = channel.map(FileChannel.MapMode.READ_ONLY, 0, channel.size()); map1.load(); // we want the whole thing, plus […]

为什么人们说MappedByteBuffer的mmap更快?

我认为mmap并不像使用虚拟内存那么快,它仍然具有硬盘I / O. 但互联网上的很多人都说它很快,但没有理由。 在我的测试中,我使用BufferedReader和MappedByteBuffer读取文件,第一个更快。

如何在Java中存储映射(mmap)linux块设备(例如/ dev / sdb)?

我可以使用java.nio读取/编写带有Java的linux块设备。 以下代码有效: Path fp = FileSystems.getDefault().getPath(“/dev”, “sdb”); FileChannel fc = null; try { fc = FileChannel.open(fp, EnumSet.of(StandardOpenOption.READ, StandardOpenOption.WRITE)); } catch (Exception e) { System.out.println(“Error opening file: ” + e.getMessage()); } ByteBuffer buf = ByteBuffer.allocate(50); try { if(fc != null) fc.write(buf); } catch (Exception e) { System.out.println(“Error writing to file: ” + e.getMessage()); } 但是,内存映射不起作用。 以下代码失败 […]

Java OutOfMemoryexception:加载zip文件时出现mmap错误

我使用JVM参数在生产环境(rhel 5.2 x64,oracle jre 1.7_05,tomcat 7.0.28)上运行我的应用程序: -Xms8192m -Xmx8192m -XX:MaxPermSize=1024m -Doracle.net.tns_admin=/var/ora_net -XX:ReservedCodeCacheSize=512m -XX:+AggressiveOpts -XX:+UseFastAccessorMethods -XX:+UseStringCache -XX:+OptimizeStringConcat -XX:+UseCompressedOops -XX:+UseG1GC -Dcom.sun.management.jmxremote -Dcom.sun.management.jmxremote.port=9026 -Dcom.sun.management.jmxremote.ssl=false -Dcom.sun.management.jmxremote.authenticate=false 经过几次,我有像这样的堆栈跟踪: Java HotSpot(TM) 64-Bit Server VM warning: Attempt to deallocate stack guard pages failed. Java HotSpot(TM) 64-Bit Server VM warning: Attempt to allocate stack guard pages failed. mmap failed for CEN and END part […]