< prev index next >

src/java.base/share/classes/sun/nio/ch/FileChannelImpl.java

Print this page

        

*** 932,941 **** --- 932,958 ---- private static final int MAP_PV = 2; 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"); if (position < 0L) throw new IllegalArgumentException("Negative position");
*** 949,960 **** int imode = -1; if (mode == MapMode.READ_ONLY) imode = MAP_RO; else if (mode == MapMode.READ_WRITE) imode = MAP_RW; ! else if (mode == MapMode.PRIVATE) imode = MAP_PV; assert (imode >= 0); if ((mode != MapMode.READ_ONLY) && !writable) throw new NonWritableChannelException(); if (!readable) throw new NonReadableChannelException(); --- 966,978 ---- int imode = -1; if (mode == MapMode.READ_ONLY) imode = MAP_RO; else if (mode == MapMode.READ_WRITE) imode = MAP_RW; ! else if (mode == MapMode.PRIVATE) { imode = MAP_PV; + } assert (imode >= 0); if ((mode != MapMode.READ_ONLY) && !writable) throw new NonWritableChannelException(); if (!readable) throw new NonReadableChannelException();
*** 993,1024 **** if (size == 0) { addr = 0; // a valid file descriptor is not required FileDescriptor dummy = new FileDescriptor(); if ((!writable) || (imode == MAP_RO)) ! return Util.newMappedByteBufferR(0, 0, dummy, null); else ! return Util.newMappedByteBuffer(0, 0, dummy, null); } pagePosition = (int)(position % allocationGranularity); long mapPosition = position - pagePosition; mapSize = size + pagePosition; try { // If map0 did not throw an exception, the address is valid ! addr = map0(imode, mapPosition, mapSize); } catch (OutOfMemoryError x) { // An OutOfMemoryError may indicate that we've exhausted // memory so force gc and re-attempt map System.gc(); try { Thread.sleep(100); } catch (InterruptedException y) { Thread.currentThread().interrupt(); } try { ! addr = map0(imode, mapPosition, mapSize); } catch (OutOfMemoryError y) { // After a second OOME, fail throw new IOException("Map failed", y); } } --- 1011,1042 ---- if (size == 0) { addr = 0; // a valid file descriptor is not required FileDescriptor dummy = new FileDescriptor(); if ((!writable) || (imode == MAP_RO)) ! return Util.newMappedByteBufferR(0, 0, dummy, null, isPersistent); else ! return Util.newMappedByteBuffer(0, 0, dummy, null, isPersistent); } pagePosition = (int)(position % allocationGranularity); long mapPosition = position - pagePosition; mapSize = size + pagePosition; try { // If map0 did not throw an exception, the address is valid ! 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 System.gc(); try { Thread.sleep(100); } catch (InterruptedException y) { Thread.currentThread().interrupt(); } try { ! addr = map0(imode, mapPosition, mapSize, isPersistent); } catch (OutOfMemoryError y) { // After a second OOME, fail throw new IOException("Map failed", y); } }
*** 1040,1055 **** Unmapper um = new Unmapper(addr, mapSize, isize, mfd); if ((!writable) || (imode == MAP_RO)) { return Util.newMappedByteBufferR(isize, addr + pagePosition, mfd, ! um); } else { return Util.newMappedByteBuffer(isize, addr + pagePosition, mfd, ! um); } } finally { threads.remove(ti); endBlocking(IOStatus.checkAll(addr)); } --- 1058,1075 ---- Unmapper um = new Unmapper(addr, mapSize, isize, mfd); if ((!writable) || (imode == MAP_RO)) { return Util.newMappedByteBufferR(isize, addr + pagePosition, mfd, ! um, ! isPersistent); } else { return Util.newMappedByteBuffer(isize, addr + pagePosition, mfd, ! um, ! isPersistent); } } finally { threads.remove(ti); endBlocking(IOStatus.checkAll(addr)); }
*** 1199,1209 **** } // -- Native methods -- // Creates a new mapping ! private native long map0(int prot, long position, long length) throws IOException; // Removes an existing mapping private static native int unmap0(long address, long length); --- 1219,1229 ---- } // -- Native methods -- // Creates a new mapping ! private native long map0(int prot, long position, long length, boolean isPersistent) throws IOException; // Removes an existing mapping private static native int unmap0(long address, long length);
< prev index next >