--- old/src/java.base/share/classes/sun/nio/ch/FileChannelImpl.java 2018-07-19 11:59:00.932311536 +0100 +++ new/src/java.base/share/classes/sun/nio/ch/FileChannelImpl.java 2018-07-19 11:59:00.108309055 +0100 @@ -934,6 +934,23 @@ public MappedByteBuffer map(MapMode mode, long position, long size) throws IOException { + return map_internal(mode, position, size, false); + } + + public MappedByteBuffer map_persistent(MapMode mode, long position, long size) + throws IOException + { + if (mode == MapMode.PRIVATE) { + throw new IllegalArgumentException("Mode private is not allowed for persistent_map"); + } + return map_internal(mode, position, size, true); + } + + private MappedByteBuffer map_internal(MapMode mode, + long position, long size, + boolean isPersistent) + throws IOException + { ensureOpen(); if (mode == null) throw new NullPointerException("Mode is null"); @@ -951,8 +968,9 @@ imode = MAP_RO; else if (mode == MapMode.READ_WRITE) imode = MAP_RW; - else if (mode == MapMode.PRIVATE) + else if (mode == MapMode.PRIVATE) { imode = MAP_PV; + } assert (imode >= 0); if ((mode != MapMode.READ_ONLY) && !writable) throw new NonWritableChannelException(); @@ -995,9 +1013,9 @@ // a valid file descriptor is not required FileDescriptor dummy = new FileDescriptor(); if ((!writable) || (imode == MAP_RO)) - return Util.newMappedByteBufferR(0, 0, dummy, null); + return Util.newMappedByteBufferR(0, 0, dummy, null, isPersistent); else - return Util.newMappedByteBuffer(0, 0, dummy, null); + return Util.newMappedByteBuffer(0, 0, dummy, null, isPersistent); } pagePosition = (int)(position % allocationGranularity); @@ -1005,7 +1023,7 @@ mapSize = size + pagePosition; try { // If map0 did not throw an exception, the address is valid - addr = map0(imode, mapPosition, mapSize); + addr = map0(imode, mapPosition, mapSize, isPersistent); } catch (OutOfMemoryError x) { // An OutOfMemoryError may indicate that we've exhausted // memory so force gc and re-attempt map @@ -1016,7 +1034,7 @@ Thread.currentThread().interrupt(); } try { - addr = map0(imode, mapPosition, mapSize); + addr = map0(imode, mapPosition, mapSize, isPersistent); } catch (OutOfMemoryError y) { // After a second OOME, fail throw new IOException("Map failed", y); @@ -1042,12 +1060,14 @@ return Util.newMappedByteBufferR(isize, addr + pagePosition, mfd, - um); + um, + isPersistent); } else { return Util.newMappedByteBuffer(isize, addr + pagePosition, mfd, - um); + um, + isPersistent); } } finally { threads.remove(ti); @@ -1201,7 +1221,7 @@ // -- Native methods -- // Creates a new mapping - private native long map0(int prot, long position, long length) + private native long map0(int prot, long position, long length, boolean isPersistent) throws IOException; // Removes an existing mapping