--- old/src/share/classes/java/io/FileInputStream.java 2012-11-13 10:47:48.000000000 +0100 +++ new/src/share/classes/java/io/FileInputStream.java 2012-11-13 10:47:47.000000000 +0100 @@ -27,6 +27,8 @@ import java.nio.channels.FileChannel; import sun.nio.ch.FileChannelImpl; +import sun.misc.IoTrace; +import sun.misc.IoTraceContext; /** @@ -51,6 +53,9 @@ /* File Descriptor - handle to the open file */ private final FileDescriptor fd; + /* The path of the referenced file (null if the stream is created with a file descriptor) */ + private final String path; + private FileChannel channel = null; private final Object closeLock = new Object(); @@ -125,6 +130,7 @@ } fd = new FileDescriptor(); fd.attach(this); + this.path = name; open(name); } @@ -161,6 +167,7 @@ security.checkRead(fdObj); } fd = fdObj; + path = null; /* * FileDescriptor is being shared by streams. @@ -183,7 +190,18 @@ * file is reached. * @exception IOException if an I/O error occurs. */ - public native int read() throws IOException; + public int read() throws IOException { + IoTraceContext traceContext = IoTrace.fileReadBegin(path); + int b = 0; + try { + b = read0(); + } finally { + IoTrace.fileReadEnd(traceContext, b == -1 ? 0 : 1); + } + return b; + } + + private native int read0() throws IOException; /** * Reads a subarray as a sequence of bytes. @@ -206,7 +224,14 @@ * @exception IOException if an I/O error occurs. */ public int read(byte b[]) throws IOException { - return readBytes(b, 0, b.length); + IoTraceContext traceContext = IoTrace.fileReadBegin(path); + int bytesRead = 0; + try { + bytesRead = readBytes(b, 0, b.length); + } finally { + IoTrace.fileReadEnd(traceContext, bytesRead); + } + return bytesRead; } /** @@ -228,7 +253,14 @@ * @exception IOException if an I/O error occurs. */ public int read(byte b[], int off, int len) throws IOException { - return readBytes(b, off, len); + IoTraceContext traceContext = IoTrace.fileReadBegin(path); + int bytesRead = 0; + try { + bytesRead = readBytes(b, off, len); + } finally { + IoTrace.fileReadEnd(traceContext, bytesRead); + } + return bytesRead; } /** @@ -339,7 +371,7 @@ public FileChannel getChannel() { synchronized (this) { if (channel == null) { - channel = FileChannelImpl.open(fd, true, false, this); + channel = FileChannelImpl.open(fd, path, true, false, this); } return channel; }