mirror of
https://github.com/openjdk/jdk.git
synced 2025-08-27 14:54:52 +02:00
8286709: (fc) FileChannel/FileChannelImpl cleanup
Reviewed-by: alanb
This commit is contained in:
parent
7eb15593e1
commit
7cb368b34d
2 changed files with 57 additions and 53 deletions
|
@ -1211,8 +1211,10 @@ public class FileChannelImpl
|
|||
Objects.requireNonNull(session, "Session is null");
|
||||
MemorySessionImpl sessionImpl = MemorySessionImpl.toSessionImpl(session);
|
||||
sessionImpl.checkValidStateSlow();
|
||||
if (offset < 0) throw new IllegalArgumentException("Requested bytes offset must be >= 0.");
|
||||
if (size < 0) throw new IllegalArgumentException("Requested bytes size must be >= 0.");
|
||||
if (offset < 0)
|
||||
throw new IllegalArgumentException("Requested bytes offset must be >= 0.");
|
||||
if (size < 0)
|
||||
throw new IllegalArgumentException("Requested bytes size must be >= 0.");
|
||||
|
||||
boolean isSync = isSync(mode);
|
||||
int prot = toProt(mode);
|
||||
|
@ -1222,14 +1224,17 @@ public class FileChannelImpl
|
|||
modes |= MAP_MEM_SEG_READ_ONLY;
|
||||
}
|
||||
if (unmapper != null) {
|
||||
AbstractMemorySegmentImpl segment = new MappedMemorySegmentImpl(unmapper.address(), unmapper, size,
|
||||
modes, session);
|
||||
sessionImpl.addOrCleanupIfFail(new MemorySessionImpl.ResourceList.ResourceCleanup() {
|
||||
@Override
|
||||
public void cleanup() {
|
||||
unmapper.unmap();
|
||||
}
|
||||
});
|
||||
AbstractMemorySegmentImpl segment =
|
||||
new MappedMemorySegmentImpl(unmapper.address(), unmapper, size,
|
||||
modes, session);
|
||||
MemorySessionImpl.ResourceList.ResourceCleanup resource =
|
||||
new MemorySessionImpl.ResourceList.ResourceCleanup() {
|
||||
@Override
|
||||
public void cleanup() {
|
||||
unmapper.unmap();
|
||||
}
|
||||
};
|
||||
sessionImpl.addOrCleanupIfFail(resource);
|
||||
return segment;
|
||||
} else {
|
||||
return new MappedMemorySegmentImpl.EmptyMappedMemorySegmentImpl(modes, session);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue