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

Print this page
rev 5501 : imported patch io-trace

*** 32,41 **** --- 32,42 ---- import java.nio.channels.*; import java.util.ArrayList; import java.util.List; import java.security.AccessController; import sun.misc.Cleaner; + import sun.misc.IoTrace; import sun.security.action.GetPropertyAction; public class FileChannelImpl extends FileChannel {
*** 54,94 **** private final boolean append; // Required to prevent finalization of creating stream (immutable) private final Object parent; // Thread-safe set of IDs of native threads, for signalling private final NativeThreadSet threads = new NativeThreadSet(2); // Lock for operations involving position and size private final Object positionLock = new Object(); ! private FileChannelImpl(FileDescriptor fd, boolean readable, boolean writable, boolean append, Object parent) { this.fd = fd; this.readable = readable; this.writable = writable; this.append = append; this.parent = parent; this.nd = new FileDispatcherImpl(append); } // Used by FileInputStream.getChannel() and RandomAccessFile.getChannel() ! public static FileChannel open(FileDescriptor fd, boolean readable, boolean writable, Object parent) { ! return new FileChannelImpl(fd, readable, writable, false, parent); } // Used by FileOutputStream.getChannel ! public static FileChannel open(FileDescriptor fd, boolean readable, boolean writable, boolean append, Object parent) { ! return new FileChannelImpl(fd, readable, writable, append, parent); } private void ensureOpen() throws IOException { if (!isOpen()) throw new ClosedChannelException(); --- 55,99 ---- private final boolean append; // Required to prevent finalization of creating stream (immutable) private final Object parent; + // The path of the referenced file (null if the parent stream is created with a file descriptor) + private final String path; + // Thread-safe set of IDs of native threads, for signalling private final NativeThreadSet threads = new NativeThreadSet(2); // Lock for operations involving position and size private final Object positionLock = new Object(); ! private FileChannelImpl(FileDescriptor fd, String path, boolean readable, boolean writable, boolean append, Object parent) { this.fd = fd; this.readable = readable; this.writable = writable; this.append = append; this.parent = parent; + this.path = path; this.nd = new FileDispatcherImpl(append); } // Used by FileInputStream.getChannel() and RandomAccessFile.getChannel() ! public static FileChannel open(FileDescriptor fd, String path, boolean readable, boolean writable, Object parent) { ! return new FileChannelImpl(fd, path, readable, writable, false, parent); } // Used by FileOutputStream.getChannel ! public static FileChannel open(FileDescriptor fd, String path, boolean readable, boolean writable, boolean append, Object parent) { ! return new FileChannelImpl(fd, path, readable, writable, append, parent); } private void ensureOpen() throws IOException { if (!isOpen()) throw new ClosedChannelException();
*** 132,141 **** --- 137,147 ---- if (!readable) throw new NonReadableChannelException(); synchronized (positionLock) { int n = 0; int ti = -1; + Object traceContext = IoTrace.fileReadBegin(path); try { begin(); ti = threads.add(); if (!isOpen()) return 0;
*** 143,152 **** --- 149,159 ---- n = IOUtil.read(fd, dst, -1, nd, positionLock); } while ((n == IOStatus.INTERRUPTED) && isOpen()); return IOStatus.normalize(n); } finally { threads.remove(ti); + IoTrace.fileReadEnd(traceContext, n > 0 ? n : 0); end(n > 0); assert IOStatus.check(n); } } }
*** 160,169 **** --- 167,177 ---- if (!readable) throw new NonReadableChannelException(); synchronized (positionLock) { long n = 0; int ti = -1; + Object traceContext = IoTrace.fileReadBegin(path); try { begin(); ti = threads.add(); if (!isOpen()) return 0;
*** 171,180 **** --- 179,189 ---- n = IOUtil.read(fd, dsts, offset, length, nd); } while ((n == IOStatus.INTERRUPTED) && isOpen()); return IOStatus.normalize(n); } finally { threads.remove(ti); + IoTrace.fileReadEnd(traceContext, n > 0 ? n : 0); end(n > 0); assert IOStatus.check(n); } } }
*** 184,193 **** --- 193,203 ---- if (!writable) throw new NonWritableChannelException(); synchronized (positionLock) { int n = 0; int ti = -1; + Object traceContext = IoTrace.fileWriteBegin(path); try { begin(); ti = threads.add(); if (!isOpen()) return 0;
*** 196,205 **** --- 206,216 ---- } while ((n == IOStatus.INTERRUPTED) && isOpen()); return IOStatus.normalize(n); } finally { threads.remove(ti); end(n > 0); + IoTrace.fileWriteEnd(traceContext, n > 0 ? n : 0); assert IOStatus.check(n); } } }
*** 212,221 **** --- 223,233 ---- if (!writable) throw new NonWritableChannelException(); synchronized (positionLock) { long n = 0; int ti = -1; + Object traceContext = IoTrace.fileWriteBegin(path); try { begin(); ti = threads.add(); if (!isOpen()) return 0;
*** 223,232 **** --- 235,245 ---- n = IOUtil.write(fd, srcs, offset, length, nd); } while ((n == IOStatus.INTERRUPTED) && isOpen()); return IOStatus.normalize(n); } finally { threads.remove(ti); + IoTrace.fileWriteEnd(traceContext, n > 0 ? n : 0); end(n > 0); assert IOStatus.check(n); } } }
*** 663,672 **** --- 676,686 ---- if (!readable) throw new NonReadableChannelException(); ensureOpen(); int n = 0; int ti = -1; + Object traceContext = IoTrace.fileReadBegin(path); try { begin(); ti = threads.add(); if (!isOpen()) return -1;
*** 674,683 **** --- 688,698 ---- n = IOUtil.read(fd, dst, position, nd, positionLock); } while ((n == IOStatus.INTERRUPTED) && isOpen()); return IOStatus.normalize(n); } finally { threads.remove(ti); + IoTrace.fileReadEnd(traceContext, n > 0 ? n : 0); end(n > 0); assert IOStatus.check(n); } }
*** 689,698 **** --- 704,714 ---- if (!writable) throw new NonWritableChannelException(); ensureOpen(); int n = 0; int ti = -1; + Object traceContext = IoTrace.fileWriteBegin(path); try { begin(); ti = threads.add(); if (!isOpen()) return -1;
*** 701,710 **** --- 717,727 ---- } while ((n == IOStatus.INTERRUPTED) && isOpen()); return IOStatus.normalize(n); } finally { threads.remove(ti); end(n > 0); + IoTrace.fileWriteEnd(traceContext, n > 0 ? n : 0); assert IOStatus.check(n); } }