< prev index next >

src/java.base/share/classes/java/nio/MappedMemoryUtils.java

Print this page

 81         // no need to load a sync mapped buffer
 82         if (isSync) {
 83             return;
 84         }
 85         if ((address == 0) || (size == 0))
 86             return;
 87         long offset = mappingOffset(address);
 88         long length = mappingLength(offset, size);
 89         unload0(mappingAddress(address, offset), length);
 90     }
 91 
 92     static void force(FileDescriptor fd, long address, boolean isSync, long index, long length) {
 93         if (isSync) {
 94             // simply force writeback of associated cache lines
 95             Unsafe.getUnsafe().writebackMemory(address + index, length);
 96         } else {
 97             // force writeback via file descriptor
 98             long offset = mappingOffset(address, index);
 99             long mappingAddress = mappingAddress(address, offset, index);
100             long mappingLength = mappingLength(offset, length);
101             long comp = Blocker.begin();
102             try {
103                 force0(fd, mappingAddress, mappingLength);
104             } catch (IOException cause) {
105                 throw new UncheckedIOException(cause);
106             } finally {
107                 Blocker.end(comp);
108             }
109         }
110     }
111 
112     // native methods
113 
114     private static native boolean isLoaded0(long address, long length, long pageCount);
115     private static native void load0(long address, long length);
116     private static native void unload0(long address, long length);
117     private static native void force0(FileDescriptor fd, long address, long length) throws IOException;
118 
119     // utility methods
120 
121     // Returns the distance (in bytes) of the buffer start from the
122     // largest page aligned address of the mapping less than or equal
123     // to the start address.
124     private static long mappingOffset(long address) {
125         return mappingOffset(address, 0);
126     }
127 

 81         // no need to load a sync mapped buffer
 82         if (isSync) {
 83             return;
 84         }
 85         if ((address == 0) || (size == 0))
 86             return;
 87         long offset = mappingOffset(address);
 88         long length = mappingLength(offset, size);
 89         unload0(mappingAddress(address, offset), length);
 90     }
 91 
 92     static void force(FileDescriptor fd, long address, boolean isSync, long index, long length) {
 93         if (isSync) {
 94             // simply force writeback of associated cache lines
 95             Unsafe.getUnsafe().writebackMemory(address + index, length);
 96         } else {
 97             // force writeback via file descriptor
 98             long offset = mappingOffset(address, index);
 99             long mappingAddress = mappingAddress(address, offset, index);
100             long mappingLength = mappingLength(offset, length);
101             boolean attempted = Blocker.begin();
102             try {
103                 force0(fd, mappingAddress, mappingLength);
104             } catch (IOException cause) {
105                 throw new UncheckedIOException(cause);
106             } finally {
107                 Blocker.end(attempted);
108             }
109         }
110     }
111 
112     // native methods
113 
114     private static native boolean isLoaded0(long address, long length, long pageCount);
115     private static native void load0(long address, long length);
116     private static native void unload0(long address, long length);
117     private static native void force0(FileDescriptor fd, long address, long length) throws IOException;
118 
119     // utility methods
120 
121     // Returns the distance (in bytes) of the buffer start from the
122     // largest page aligned address of the mapping less than or equal
123     // to the start address.
124     private static long mappingOffset(long address) {
125         return mappingOffset(address, 0);
126     }
127 
< prev index next >