8080225: FileInput/OutputStream/FileChannel cleanup should be improved

Reviewed-by: mchung, plevart, bpb
This commit is contained in:
Roger Riggs 2017-12-01 16:40:08 -05:00
parent b93586c51e
commit f29e21abb1
23 changed files with 1104 additions and 261 deletions

View file

@ -114,6 +114,7 @@ class FileDispatcherImpl extends FileDispatcher {
FileDescriptor result = new FileDescriptor();
long handle = duplicateHandle(fdAccess.getHandle(fd));
fdAccess.setHandle(result, handle);
fdAccess.registerCleanup(result);
return result;
}

View file

@ -139,7 +139,7 @@ public class WindowsAsynchronousFileChannelImpl
invalidateAllLocks();
// close the file
close0(handle);
nd.close(fdObj);
// waits until all I/O operations have completed
ioCache.close();
@ -728,8 +728,6 @@ public class WindowsAsynchronousFileChannelImpl
private static native int lockFile(long handle, long position, long size,
boolean shared, long overlapped) throws IOException;
private static native void close0(long handle);
static {
IOUtil.load();
}

View file

@ -216,8 +216,7 @@ class WindowsChannelFactory {
} catch (IOException x) {
// IOException is thrown if the file handle cannot be associated
// with the completion port. All we can do is close the file.
long handle = fdAccess.getHandle(fdObj);
CloseHandle(handle);
fdAccess.close(fdObj);
throw x;
}
}
@ -347,6 +346,7 @@ class WindowsChannelFactory {
FileDescriptor fdObj = new FileDescriptor();
fdAccess.setHandle(fdObj, handle);
fdAccess.setAppend(fdObj, flags.append);
fdAccess.registerCleanup(fdObj);
return fdObj;
}
}