8213406: (fs) More than one instance of built-in FileSystem observed in heap
Reviewed-by: alanb, cushon, weijun
--- a/src/java.base/aix/classes/sun/nio/fs/AixFileSystemProvider.java Wed Nov 28 16:05:48 2018 -0500
+++ b/src/java.base/aix/classes/sun/nio/fs/AixFileSystemProvider.java Wed Nov 28 14:28:28 2018 -0800
@@ -32,7 +32,7 @@
* AIX implementation of FileSystemProvider
*/
-public class AixFileSystemProvider extends UnixFileSystemProvider {
+class AixFileSystemProvider extends UnixFileSystemProvider {
public AixFileSystemProvider() {
super();
}
--- a/src/java.base/aix/classes/sun/nio/fs/DefaultFileSystemProvider.java Wed Nov 28 16:05:48 2018 -0500
+++ b/src/java.base/aix/classes/sun/nio/fs/DefaultFileSystemProvider.java Wed Nov 28 14:28:28 2018 -0800
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2017, 2018, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@@ -25,19 +25,29 @@
package sun.nio.fs;
-import java.nio.file.spi.FileSystemProvider;
+import java.nio.file.FileSystem;
/**
* Creates this platform's default FileSystemProvider.
*/
public class DefaultFileSystemProvider {
+ private static final AixFileSystemProvider INSTANCE
+ = new AixFileSystemProvider();
+
private DefaultFileSystemProvider() { }
/**
- * Returns the default FileSystemProvider.
+ * Returns the platform's default file system provider.
*/
- public static FileSystemProvider create() {
- return new AixFileSystemProvider();
+ public static AixFileSystemProvider instance() {
+ return INSTANCE;
+ }
+
+ /**
+ * Returns the platform's default file system.
+ */
+ public static FileSystem theFileSystem() {
+ return INSTANCE.theFileSystem();
}
}
--- a/src/java.base/linux/classes/sun/nio/fs/DefaultFileSystemProvider.java Wed Nov 28 16:05:48 2018 -0500
+++ b/src/java.base/linux/classes/sun/nio/fs/DefaultFileSystemProvider.java Wed Nov 28 14:28:28 2018 -0800
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2017, 2018, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@@ -25,19 +25,29 @@
package sun.nio.fs;
-import java.nio.file.spi.FileSystemProvider;
+import java.nio.file.FileSystem;
/**
* Creates this platform's default FileSystemProvider.
*/
public class DefaultFileSystemProvider {
+ private static final LinuxFileSystemProvider INSTANCE
+ = new LinuxFileSystemProvider();
+
private DefaultFileSystemProvider() { }
/**
- * Returns the default FileSystemProvider.
+ * Returns the platform's default file system provider.
*/
- public static FileSystemProvider create() {
- return new LinuxFileSystemProvider();
+ public static LinuxFileSystemProvider instance() {
+ return INSTANCE;
+ }
+
+ /**
+ * Returns the platform's default file system.
+ */
+ public static FileSystem theFileSystem() {
+ return INSTANCE.theFileSystem();
}
}
--- a/src/java.base/linux/classes/sun/nio/fs/LinuxFileSystemProvider.java Wed Nov 28 16:05:48 2018 -0500
+++ b/src/java.base/linux/classes/sun/nio/fs/LinuxFileSystemProvider.java Wed Nov 28 14:28:28 2018 -0800
@@ -36,7 +36,7 @@
* Linux implementation of FileSystemProvider
*/
-public class LinuxFileSystemProvider extends UnixFileSystemProvider {
+class LinuxFileSystemProvider extends UnixFileSystemProvider {
public LinuxFileSystemProvider() {
super();
}
--- a/src/java.base/macosx/classes/sun/nio/fs/BsdFileSystemProvider.java Wed Nov 28 16:05:48 2018 -0500
+++ b/src/java.base/macosx/classes/sun/nio/fs/BsdFileSystemProvider.java Wed Nov 28 14:28:28 2018 -0800
@@ -31,7 +31,7 @@
* Bsd implementation of FileSystemProvider
*/
-public class BsdFileSystemProvider extends UnixFileSystemProvider {
+class BsdFileSystemProvider extends UnixFileSystemProvider {
public BsdFileSystemProvider() {
super();
}
--- a/src/java.base/macosx/classes/sun/nio/fs/DefaultFileSystemProvider.java Wed Nov 28 16:05:48 2018 -0500
+++ b/src/java.base/macosx/classes/sun/nio/fs/DefaultFileSystemProvider.java Wed Nov 28 14:28:28 2018 -0800
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2017, 2018, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@@ -25,19 +25,29 @@
package sun.nio.fs;
-import java.nio.file.spi.FileSystemProvider;
+import java.nio.file.FileSystem;
/**
* Creates this platform's default FileSystemProvider.
*/
public class DefaultFileSystemProvider {
+ private static final MacOSXFileSystemProvider INSTANCE
+ = new MacOSXFileSystemProvider();
+
private DefaultFileSystemProvider() { }
/**
- * Returns the default FileSystemProvider.
+ * Returns the platform's default file system provider.
*/
- public static FileSystemProvider create() {
- return new MacOSXFileSystemProvider();
+ public static MacOSXFileSystemProvider instance() {
+ return INSTANCE;
+ }
+
+ /**
+ * Returns the platform's default file system.
+ */
+ public static FileSystem theFileSystem() {
+ return INSTANCE.theFileSystem();
}
}
--- a/src/java.base/macosx/classes/sun/nio/fs/MacOSXFileSystemProvider.java Wed Nov 28 16:05:48 2018 -0500
+++ b/src/java.base/macosx/classes/sun/nio/fs/MacOSXFileSystemProvider.java Wed Nov 28 14:28:28 2018 -0800
@@ -34,7 +34,7 @@
* MacOSX implementation of FileSystemProvider
*/
-public class MacOSXFileSystemProvider extends BsdFileSystemProvider {
+class MacOSXFileSystemProvider extends BsdFileSystemProvider {
public MacOSXFileSystemProvider() {
super();
}
--- a/src/java.base/share/classes/java/io/FilePermission.java Wed Nov 28 16:05:48 2018 -0500
+++ b/src/java.base/share/classes/java/io/FilePermission.java Wed Nov 28 14:28:28 2018 -0800
@@ -25,7 +25,6 @@
package java.io;
-import java.net.URI;
import java.nio.file.*;
import java.security.*;
import java.util.Enumeration;
@@ -199,12 +198,11 @@
private static final long serialVersionUID = 7930732926638008763L;
/**
- * Always use the internal default file system, in case it was modified
- * with java.nio.file.spi.DefaultFileSystemProvider.
+ * Use the platform's default file system to avoid recursive initialization
+ * issues when the VM is configured to use a custom file system provider.
*/
private static final java.nio.file.FileSystem builtInFS =
- DefaultFileSystemProvider.create()
- .getFileSystem(URI.create("file:///"));
+ DefaultFileSystemProvider.theFileSystem();
private static final Path here = builtInFS.getPath(
GetPropertyAction.privilegedGetProperty("user.dir"));
@@ -326,7 +324,7 @@
if (name.equals("<<ALL FILES>>")) {
allFiles = true;
- npath = builtInFS.getPath("");
+ npath = EMPTY_PATH;
// other fields remain default
return;
}
@@ -351,7 +349,7 @@
npath = npath.getParent();
}
if (npath == null) {
- npath = builtInFS.getPath("");
+ npath = EMPTY_PATH;
}
invalid = false;
} catch (InvalidPathException ipe) {
--- a/src/java.base/share/classes/java/nio/file/FileSystems.java Wed Nov 28 16:05:48 2018 -0500
+++ b/src/java.base/share/classes/java/nio/file/FileSystems.java Wed Nov 28 14:28:28 2018 -0800
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2007, 2017, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2007, 2018, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@@ -37,6 +37,7 @@
import java.util.ServiceLoader;
import jdk.internal.misc.VM;
+import sun.nio.fs.DefaultFileSystemProvider;
/**
* Factory methods for file systems. This class defines the {@link #getDefault
@@ -88,16 +89,6 @@
public final class FileSystems {
private FileSystems() { }
- // Built-in file system provider
- private static final FileSystemProvider builtinFileSystemProvider =
- sun.nio.fs.DefaultFileSystemProvider.create();
-
- // built-in file system
- private static class BuiltinFileSystemHolder {
- static final FileSystem builtinFileSystem =
- builtinFileSystemProvider.getFileSystem(URI.create("file:///"));
- }
-
// lazy initialization of default file system
private static class DefaultFileSystemHolder {
static final FileSystem defaultFileSystem = defaultFileSystem();
@@ -118,7 +109,8 @@
// returns default provider
private static FileSystemProvider getDefaultProvider() {
- FileSystemProvider provider = builtinFileSystemProvider;
+ // start with the platform's default file system provider
+ FileSystemProvider provider = DefaultFileSystemProvider.instance();
// if the property java.nio.file.spi.DefaultFileSystemProvider is
// set then its value is the name of the default provider (or a list)
@@ -189,7 +181,8 @@
if (VM.isModuleSystemInited()) {
return DefaultFileSystemHolder.defaultFileSystem;
} else {
- return BuiltinFileSystemHolder.builtinFileSystem;
+ // always use the platform's default file system during startup
+ return DefaultFileSystemProvider.theFileSystem();
}
}
--- a/src/java.base/solaris/classes/sun/nio/fs/DefaultFileSystemProvider.java Wed Nov 28 16:05:48 2018 -0500
+++ b/src/java.base/solaris/classes/sun/nio/fs/DefaultFileSystemProvider.java Wed Nov 28 14:28:28 2018 -0800
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2017, 2018, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@@ -25,19 +25,29 @@
package sun.nio.fs;
-import java.nio.file.spi.FileSystemProvider;
+import java.nio.file.FileSystem;
/**
* Creates this platform's default FileSystemProvider.
*/
public class DefaultFileSystemProvider {
+ private static final SolarisFileSystemProvider INSTANCE
+ = new SolarisFileSystemProvider();
+
private DefaultFileSystemProvider() { }
/**
- * Returns the default FileSystemProvider.
+ * Returns the platform's default file system provider.
*/
- public static FileSystemProvider create() {
- return new SolarisFileSystemProvider();
+ public static SolarisFileSystemProvider instance() {
+ return INSTANCE;
+ }
+
+ /**
+ * Returns the platform's default file system.
+ */
+ public static FileSystem theFileSystem() {
+ return INSTANCE.theFileSystem();
}
}
--- a/src/java.base/solaris/classes/sun/nio/fs/SolarisFileSystemProvider.java Wed Nov 28 16:05:48 2018 -0500
+++ b/src/java.base/solaris/classes/sun/nio/fs/SolarisFileSystemProvider.java Wed Nov 28 14:28:28 2018 -0800
@@ -36,7 +36,7 @@
* Solaris implementation of FileSystemProvider
*/
-public class SolarisFileSystemProvider extends UnixFileSystemProvider {
+class SolarisFileSystemProvider extends UnixFileSystemProvider {
public SolarisFileSystemProvider() {
super();
}
--- a/src/java.base/unix/classes/sun/nio/fs/UnixFileSystemProvider.java Wed Nov 28 16:05:48 2018 -0500
+++ b/src/java.base/unix/classes/sun/nio/fs/UnixFileSystemProvider.java Wed Nov 28 14:28:28 2018 -0800
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2008, 2013, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2008, 2018, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@@ -56,6 +56,10 @@
theFileSystem = newFileSystem(userDir);
}
+ UnixFileSystem theFileSystem() {
+ return theFileSystem;
+ }
+
/**
* Constructs a new file system using the given default directory.
*/
--- a/src/java.base/windows/classes/sun/nio/fs/DefaultFileSystemProvider.java Wed Nov 28 16:05:48 2018 -0500
+++ b/src/java.base/windows/classes/sun/nio/fs/DefaultFileSystemProvider.java Wed Nov 28 14:28:28 2018 -0800
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2008, 2009, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2008, 2018, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@@ -25,14 +25,28 @@
package sun.nio.fs;
-import java.nio.file.spi.FileSystemProvider;
+import java.nio.file.FileSystem;
/**
- * Creates default provider on Windows
+ * Creates this platform's default FileSystemProvider.
*/
public class DefaultFileSystemProvider {
+ private static final WindowsFileSystemProvider INSTANCE
+ = new WindowsFileSystemProvider();
+
private DefaultFileSystemProvider() { }
- public static FileSystemProvider create() {
- return new WindowsFileSystemProvider();
+
+ /**
+ * Returns the platform's default file system provider.
+ */
+ public static WindowsFileSystemProvider instance() {
+ return INSTANCE;
+ }
+
+ /**
+ * Returns the platform's default file system.
+ */
+ public static FileSystem theFileSystem() {
+ return INSTANCE.theFileSystem();
}
}
--- a/src/java.base/windows/classes/sun/nio/fs/WindowsFileSystemProvider.java Wed Nov 28 16:05:48 2018 -0500
+++ b/src/java.base/windows/classes/sun/nio/fs/WindowsFileSystemProvider.java Wed Nov 28 14:28:28 2018 -0800
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2008, 2013, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2008, 2018, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@@ -42,7 +42,7 @@
import static sun.nio.fs.WindowsSecurity.*;
import static sun.nio.fs.WindowsConstants.*;
-public class WindowsFileSystemProvider
+class WindowsFileSystemProvider
extends AbstractFileSystemProvider
{
private static final Unsafe unsafe = Unsafe.getUnsafe();
@@ -53,6 +53,10 @@
theFileSystem = new WindowsFileSystem(this, StaticProperty.userDir());
}
+ WindowsFileSystem theFileSystem() {
+ return theFileSystem;
+ }
+
@Override
public String getScheme() {
return "file";