src/java.base/share/classes/java/io/File.java

Print this page
rev 12972 : 8140606: Update library code to use internal Unsafe
Reviewed-by: duke


2167      * readObject is called to restore this filename.
2168      * The original separator character is read.  If it is different
2169      * than the separator character on this system, then the old separator
2170      * is replaced by the local separator.
2171      */
2172     private synchronized void readObject(java.io.ObjectInputStream s)
2173          throws IOException, ClassNotFoundException
2174     {
2175         ObjectInputStream.GetField fields = s.readFields();
2176         String pathField = (String)fields.get("path", null);
2177         char sep = s.readChar(); // read the previous separator char
2178         if (sep != separatorChar)
2179             pathField = pathField.replace(sep, separatorChar);
2180         String path = fs.normalize(pathField);
2181         UNSAFE.putObject(this, PATH_OFFSET, path);
2182         UNSAFE.putIntVolatile(this, PREFIX_LENGTH_OFFSET, fs.prefixLength(path));
2183     }
2184 
2185     private static final long PATH_OFFSET;
2186     private static final long PREFIX_LENGTH_OFFSET;
2187     private static final sun.misc.Unsafe UNSAFE;
2188     static {
2189         try {
2190             sun.misc.Unsafe unsafe = sun.misc.Unsafe.getUnsafe();
2191             PATH_OFFSET = unsafe.objectFieldOffset(
2192                     File.class.getDeclaredField("path"));
2193             PREFIX_LENGTH_OFFSET = unsafe.objectFieldOffset(
2194                     File.class.getDeclaredField("prefixLength"));
2195             UNSAFE = unsafe;
2196         } catch (ReflectiveOperationException e) {
2197             throw new Error(e);
2198         }
2199     }
2200 
2201 
2202     /** use serialVersionUID from JDK 1.0.2 for interoperability */
2203     private static final long serialVersionUID = 301077366599181567L;
2204 
2205     // -- Integration with java.nio.file --
2206 
2207     private transient volatile Path filePath;
2208 
2209     /**
2210      * Returns a {@link Path java.nio.file.Path} object constructed from the




2167      * readObject is called to restore this filename.
2168      * The original separator character is read.  If it is different
2169      * than the separator character on this system, then the old separator
2170      * is replaced by the local separator.
2171      */
2172     private synchronized void readObject(java.io.ObjectInputStream s)
2173          throws IOException, ClassNotFoundException
2174     {
2175         ObjectInputStream.GetField fields = s.readFields();
2176         String pathField = (String)fields.get("path", null);
2177         char sep = s.readChar(); // read the previous separator char
2178         if (sep != separatorChar)
2179             pathField = pathField.replace(sep, separatorChar);
2180         String path = fs.normalize(pathField);
2181         UNSAFE.putObject(this, PATH_OFFSET, path);
2182         UNSAFE.putIntVolatile(this, PREFIX_LENGTH_OFFSET, fs.prefixLength(path));
2183     }
2184 
2185     private static final long PATH_OFFSET;
2186     private static final long PREFIX_LENGTH_OFFSET;
2187     private static final jdk.internal.misc.Unsafe UNSAFE;
2188     static {
2189         try {
2190             jdk.internal.misc.Unsafe unsafe = jdk.internal.misc.Unsafe.getUnsafe();
2191             PATH_OFFSET = unsafe.objectFieldOffset(
2192                     File.class.getDeclaredField("path"));
2193             PREFIX_LENGTH_OFFSET = unsafe.objectFieldOffset(
2194                     File.class.getDeclaredField("prefixLength"));
2195             UNSAFE = unsafe;
2196         } catch (ReflectiveOperationException e) {
2197             throw new Error(e);
2198         }
2199     }
2200 
2201 
2202     /** use serialVersionUID from JDK 1.0.2 for interoperability */
2203     private static final long serialVersionUID = 301077366599181567L;
2204 
2205     // -- Integration with java.nio.file --
2206 
2207     private transient volatile Path filePath;
2208 
2209     /**
2210      * Returns a {@link Path java.nio.file.Path} object constructed from the