87 nioAccess.unload(min, unmapper.isSync(), length);
88 }
89
90 @Override
91 public boolean isLoaded() {
92 return nioAccess.isLoaded(min, unmapper.isSync(), length);
93 }
94
95 @Override
96 public void force() {
97 nioAccess.force(unmapper.fileDescriptor(), min, unmapper.isSync(), 0, length);
98 }
99
100 // factories
101
102 public static MappedMemorySegment makeMappedSegment(Path path, long bytesSize, FileChannel.MapMode mapMode) throws IOException {
103 if (bytesSize <= 0) throw new IllegalArgumentException("Requested bytes size must be > 0.");
104 try (FileChannelImpl channelImpl = (FileChannelImpl)FileChannel.open(path, openOptions(mapMode))) {
105 UnmapperProxy unmapperProxy = channelImpl.mapInternal(mapMode, 0L, bytesSize);
106 MemoryScope scope = new MemoryScope(null, unmapperProxy::unmap);
107 return new MappedMemorySegmentImpl(unmapperProxy.address(), unmapperProxy, bytesSize,
108 defaultAccessModes(bytesSize), Thread.currentThread(), scope);
109 }
110 }
111
112 private static OpenOption[] openOptions(FileChannel.MapMode mapMode) {
113 if (mapMode == FileChannel.MapMode.READ_ONLY) {
114 return new OpenOption[] { StandardOpenOption.READ };
115 } else if (mapMode == FileChannel.MapMode.READ_WRITE || mapMode == FileChannel.MapMode.PRIVATE) {
116 return new OpenOption[] { StandardOpenOption.READ, StandardOpenOption.WRITE };
117 } else {
118 throw new UnsupportedOperationException("Unsupported map mode: " + mapMode);
119 }
120 }
121 }
|
87 nioAccess.unload(min, unmapper.isSync(), length);
88 }
89
90 @Override
91 public boolean isLoaded() {
92 return nioAccess.isLoaded(min, unmapper.isSync(), length);
93 }
94
95 @Override
96 public void force() {
97 nioAccess.force(unmapper.fileDescriptor(), min, unmapper.isSync(), 0, length);
98 }
99
100 // factories
101
102 public static MappedMemorySegment makeMappedSegment(Path path, long bytesSize, FileChannel.MapMode mapMode) throws IOException {
103 if (bytesSize <= 0) throw new IllegalArgumentException("Requested bytes size must be > 0.");
104 try (FileChannelImpl channelImpl = (FileChannelImpl)FileChannel.open(path, openOptions(mapMode))) {
105 UnmapperProxy unmapperProxy = channelImpl.mapInternal(mapMode, 0L, bytesSize);
106 MemoryScope scope = new MemoryScope(null, unmapperProxy::unmap);
107 int modes = defaultAccessModes(bytesSize);
108 if (mapMode == FileChannel.MapMode.READ_ONLY) {
109 modes &= ~WRITE;
110 }
111 return new MappedMemorySegmentImpl(unmapperProxy.address(), unmapperProxy, bytesSize,
112 modes, Thread.currentThread(), scope);
113 }
114 }
115
116 private static OpenOption[] openOptions(FileChannel.MapMode mapMode) {
117 if (mapMode == FileChannel.MapMode.READ_ONLY) {
118 return new OpenOption[] { StandardOpenOption.READ };
119 } else if (mapMode == FileChannel.MapMode.READ_WRITE || mapMode == FileChannel.MapMode.PRIVATE) {
120 return new OpenOption[] { StandardOpenOption.READ, StandardOpenOption.WRITE };
121 } else {
122 throw new UnsupportedOperationException("Unsupported map mode: " + mapMode);
123 }
124 }
125 }
|