8033917: Keep track of file paths in file streams and channels for instrumentation purposes
Reviewed-by: alanb, dsamersoff
--- a/jdk/src/share/classes/java/io/FileInputStream.java Thu Feb 06 10:30:18 2014 -0800
+++ b/jdk/src/share/classes/java/io/FileInputStream.java Mon Feb 10 12:59:31 2014 +0100
@@ -51,6 +51,12 @@
/* 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();
@@ -128,6 +134,7 @@
}
fd = new FileDescriptor();
fd.attach(this);
+ path = name;
open(name);
}
@@ -164,6 +171,7 @@
security.checkRead(fdObj);
}
fd = fdObj;
+ path = null;
/*
* FileDescriptor is being shared by streams.
@@ -345,7 +353,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;
}
--- a/jdk/src/share/classes/java/io/FileOutputStream.java Thu Feb 06 10:30:18 2014 -0800
+++ b/jdk/src/share/classes/java/io/FileOutputStream.java Mon Feb 10 12:59:31 2014 +0100
@@ -67,6 +67,12 @@
*/
private FileChannel channel;
+ /**
+ * The path of the referenced file
+ * (null if the stream is created with a file descriptor)
+ */
+ private final String path;
+
private final Object closeLock = new Object();
private volatile boolean closed = false;
@@ -202,6 +208,7 @@
this.fd = new FileDescriptor();
fd.attach(this);
this.append = append;
+ this.path = name;
open(name, append);
}
@@ -239,6 +246,7 @@
}
this.fd = fdObj;
this.append = false;
+ this.path = null;
fd.attach(this);
}
@@ -376,7 +384,7 @@
public FileChannel getChannel() {
synchronized (this) {
if (channel == null) {
- channel = FileChannelImpl.open(fd, false, true, append, this);
+ channel = FileChannelImpl.open(fd, path, false, true, append, this);
}
return channel;
}
--- a/jdk/src/share/classes/java/io/RandomAccessFile.java Thu Feb 06 10:30:18 2014 -0800
+++ b/jdk/src/share/classes/java/io/RandomAccessFile.java Mon Feb 10 12:59:31 2014 +0100
@@ -62,6 +62,12 @@
private FileChannel channel = null;
private boolean rw;
+ /**
+ * The path of the referenced file
+ * (null if the stream is created with a file descriptor)
+ */
+ private final String path;
+
private Object closeLock = new Object();
private volatile boolean closed = false;
@@ -233,6 +239,7 @@
}
fd = new FileDescriptor();
fd.attach(this);
+ path = name;
open(name, imode);
}
@@ -272,7 +279,7 @@
public final FileChannel getChannel() {
synchronized (this) {
if (channel == null) {
- channel = FileChannelImpl.open(fd, true, rw, this);
+ channel = FileChannelImpl.open(fd, path, true, rw, this);
}
return channel;
}
--- a/jdk/src/share/classes/sun/nio/ch/FileChannelImpl.java Thu Feb 06 10:30:18 2014 -0800
+++ b/jdk/src/share/classes/sun/nio/ch/FileChannelImpl.java Mon Feb 10 12:59:31 2014 +0100
@@ -29,10 +29,20 @@
import java.io.IOException;
import java.nio.ByteBuffer;
import java.nio.MappedByteBuffer;
-import java.nio.channels.*;
+import java.nio.channels.ClosedByInterruptException;
+import java.nio.channels.ClosedChannelException;
+import java.nio.channels.FileChannel;
+import java.nio.channels.FileLock;
+import java.nio.channels.FileLockInterruptionException;
+import java.nio.channels.NonReadableChannelException;
+import java.nio.channels.NonWritableChannelException;
+import java.nio.channels.OverlappingFileLockException;
+import java.nio.channels.ReadableByteChannel;
+import java.nio.channels.WritableByteChannel;
+import java.security.AccessController;
import java.util.ArrayList;
import java.util.List;
-import java.security.AccessController;
+
import sun.misc.Cleaner;
import sun.security.action.GetPropertyAction;
@@ -56,13 +66,17 @@
// 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, boolean readable,
+ private FileChannelImpl(FileDescriptor fd, String path, boolean readable,
boolean writable, boolean append, Object parent)
{
this.fd = fd;
@@ -70,23 +84,24 @@
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,
+ public static FileChannel open(FileDescriptor fd, String path,
boolean readable, boolean writable,
Object parent)
{
- return new FileChannelImpl(fd, readable, writable, false, parent);
+ return new FileChannelImpl(fd, path, readable, writable, false, parent);
}
// Used by FileOutputStream.getChannel
- public static FileChannel open(FileDescriptor fd,
+ public static FileChannel open(FileDescriptor fd, String path,
boolean readable, boolean writable,
boolean append, Object parent)
{
- return new FileChannelImpl(fd, readable, writable, append, parent);
+ return new FileChannelImpl(fd, path, readable, writable, append, parent);
}
private void ensureOpen() throws IOException {
--- a/jdk/src/solaris/classes/sun/nio/fs/SolarisUserDefinedFileAttributeView.java Thu Feb 06 10:30:18 2014 -0800
+++ b/jdk/src/solaris/classes/sun/nio/fs/SolarisUserDefinedFileAttributeView.java Mon Feb 10 12:59:31 2014 +0100
@@ -149,7 +149,7 @@
int afd = openat(fd, nameAsBytes(file,name), (O_RDONLY|O_XATTR), 0);
// wrap with channel
- FileChannel fc = UnixChannelFactory.newFileChannel(afd, true, false);
+ FileChannel fc = UnixChannelFactory.newFileChannel(afd, file.toString(), true, false);
// read to EOF (nothing we can do if I/O error occurs)
try {
@@ -190,7 +190,7 @@
UnixFileModeAttribute.ALL_PERMISSIONS);
// wrap with channel
- FileChannel fc = UnixChannelFactory.newFileChannel(afd, false, true);
+ FileChannel fc = UnixChannelFactory.newFileChannel(afd, file.toString(), false, true);
// write value (nothing we can do if I/O error occurs)
try {
--- a/jdk/src/solaris/classes/sun/nio/fs/UnixChannelFactory.java Thu Feb 06 10:30:18 2014 -0800
+++ b/jdk/src/solaris/classes/sun/nio/fs/UnixChannelFactory.java Mon Feb 10 12:59:31 2014 +0100
@@ -100,10 +100,10 @@
/**
* Constructs a file channel from an existing (open) file descriptor
*/
- static FileChannel newFileChannel(int fd, boolean reading, boolean writing) {
+ static FileChannel newFileChannel(int fd, String path, boolean reading, boolean writing) {
FileDescriptor fdObj = new FileDescriptor();
fdAccess.set(fdObj, fd);
- return FileChannelImpl.open(fdObj, reading, writing, null);
+ return FileChannelImpl.open(fdObj, path, reading, writing, null);
}
/**
@@ -134,7 +134,7 @@
throw new IllegalArgumentException("APPEND + TRUNCATE_EXISTING not allowed");
FileDescriptor fdObj = open(dfd, path, pathForPermissionCheck, flags, mode);
- return FileChannelImpl.open(fdObj, flags.read, flags.write, flags.append, null);
+ return FileChannelImpl.open(fdObj, path.toString(), flags.read, flags.write, flags.append, null);
}
/**
--- a/jdk/src/windows/classes/sun/nio/fs/WindowsChannelFactory.java Thu Feb 06 10:30:18 2014 -0800
+++ b/jdk/src/windows/classes/sun/nio/fs/WindowsChannelFactory.java Mon Feb 10 12:59:31 2014 +0100
@@ -25,19 +25,22 @@
package sun.nio.fs;
-import java.nio.file.*;
-import java.nio.channels.*;
import java.io.FileDescriptor;
import java.io.IOException;
-import java.util.*;
+import java.nio.channels.AsynchronousFileChannel;
+import java.nio.channels.FileChannel;
+import java.nio.file.LinkOption;
+import java.nio.file.OpenOption;
+import java.nio.file.StandardOpenOption;
+import java.util.Set;
import com.sun.nio.file.ExtendedOpenOption;
+import sun.misc.JavaIOFileDescriptorAccess;
+import sun.misc.SharedSecrets;
import sun.nio.ch.FileChannelImpl;
import sun.nio.ch.ThreadPool;
import sun.nio.ch.WindowsAsynchronousFileChannelImpl;
-import sun.misc.SharedSecrets;
-import sun.misc.JavaIOFileDescriptorAccess;
import static sun.nio.fs.WindowsNativeDispatcher.*;
import static sun.nio.fs.WindowsConstants.*;
@@ -157,7 +160,7 @@
throw new IllegalArgumentException("APPEND + TRUNCATE_EXISTING not allowed");
FileDescriptor fdObj = open(pathForWindows, pathToCheck, flags, pSecurityDescriptor);
- return FileChannelImpl.open(fdObj, flags.read, flags.write, flags.append, null);
+ return FileChannelImpl.open(fdObj, pathForWindows, flags.read, flags.write, flags.append, null);
}
/**