src/share/classes/sun/nio/ch/FileChannelImpl.java
Print this page
rev 6052 : [mq]: jdk.patch
*** 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 there is no file)
+ 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 traceHandle = IoTrace.fileReadBegin(path);
try {
begin();
ti = threads.add();
if (!isOpen())
return 0;
*** 144,153 ****
--- 150,160 ----
} while ((n == IOStatus.INTERRUPTED) && isOpen());
return IOStatus.normalize(n);
} finally {
threads.remove(ti);
end(n > 0);
+ IoTrace.fileReadEnd(traceHandle, IOStatus.normalize(n));
assert IOStatus.check(n);
}
}
}
*** 160,169 ****
--- 167,177 ----
if (!readable)
throw new NonReadableChannelException();
synchronized (positionLock) {
long n = 0;
int ti = -1;
+ Object traceHandle = IoTrace.fileReadBegin(path);
try {
begin();
ti = threads.add();
if (!isOpen())
return 0;
*** 172,181 ****
--- 180,190 ----
} while ((n == IOStatus.INTERRUPTED) && isOpen());
return IOStatus.normalize(n);
} finally {
threads.remove(ti);
end(n > 0);
+ IoTrace.fileReadEnd(traceHandle, IOStatus.normalize(n));
assert IOStatus.check(n);
}
}
}
*** 184,193 ****
--- 193,203 ----
if (!writable)
throw new NonWritableChannelException();
synchronized (positionLock) {
int n = 0;
int ti = -1;
+ Object traceHandle = 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(traceHandle, IOStatus.normalize(n));
assert IOStatus.check(n);
}
}
}
*** 212,221 ****
--- 223,233 ----
if (!writable)
throw new NonWritableChannelException();
synchronized (positionLock) {
long n = 0;
int ti = -1;
+ Object traceHandle = IoTrace.fileWriteBegin(path);
try {
begin();
ti = threads.add();
if (!isOpen())
return 0;
*** 224,233 ****
--- 236,246 ----
} while ((n == IOStatus.INTERRUPTED) && isOpen());
return IOStatus.normalize(n);
} finally {
threads.remove(ti);
end(n > 0);
+ IoTrace.fileWriteEnd(traceHandle, IOStatus.normalize(n));
assert IOStatus.check(n);
}
}
}
*** 663,672 ****
--- 676,686 ----
if (!readable)
throw new NonReadableChannelException();
ensureOpen();
int n = 0;
int ti = -1;
+ Object traceHandle = IoTrace.fileReadBegin(path);
try {
begin();
ti = threads.add();
if (!isOpen())
return -1;
*** 675,684 ****
--- 689,699 ----
} while ((n == IOStatus.INTERRUPTED) && isOpen());
return IOStatus.normalize(n);
} finally {
threads.remove(ti);
end(n > 0);
+ IoTrace.fileReadEnd(traceHandle, IOStatus.normalize(n));
assert IOStatus.check(n);
}
}
public int write(ByteBuffer src, long position) throws IOException {
*** 689,698 ****
--- 704,714 ----
if (!writable)
throw new NonWritableChannelException();
ensureOpen();
int n = 0;
int ti = -1;
+ Object traceHandle = 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(traceHandle, IOStatus.normalize(n));
assert IOStatus.check(n);
}
}