8213406: (fs) More than one instance of built-in FileSystem observed in heap

Reviewed-by: alanb, cushon, weijun
This commit is contained in:
Martin Buchholz 2018-11-28 14:28:28 -08:00
parent 978c78f7fc
commit 7212bf0a77
14 changed files with 106 additions and 53 deletions

View file

@ -32,7 +32,7 @@ import java.io.IOException;
* AIX implementation of FileSystemProvider
*/
public class AixFileSystemProvider extends UnixFileSystemProvider {
class AixFileSystemProvider extends UnixFileSystemProvider {
public AixFileSystemProvider() {
super();
}

View file

@ -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();
}
}

View file

@ -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();
}
}

View file

@ -36,7 +36,7 @@ import jdk.internal.util.StaticProperty;
* Linux implementation of FileSystemProvider
*/
public class LinuxFileSystemProvider extends UnixFileSystemProvider {
class LinuxFileSystemProvider extends UnixFileSystemProvider {
public LinuxFileSystemProvider() {
super();
}

View file

@ -31,7 +31,7 @@ import java.io.IOException;
* Bsd implementation of FileSystemProvider
*/
public class BsdFileSystemProvider extends UnixFileSystemProvider {
class BsdFileSystemProvider extends UnixFileSystemProvider {
public BsdFileSystemProvider() {
super();
}

View file

@ -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();
}
}

View file

@ -34,7 +34,7 @@ import sun.security.action.GetPropertyAction;
* MacOSX implementation of FileSystemProvider
*/
public class MacOSXFileSystemProvider extends BsdFileSystemProvider {
class MacOSXFileSystemProvider extends BsdFileSystemProvider {
public MacOSXFileSystemProvider() {
super();
}

View file

@ -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 @@ public final class FilePermission extends Permission implements Serializable {
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 @@ public final class FilePermission extends Permission implements Serializable {
if (name.equals("<<ALL FILES>>")) {
allFiles = true;
npath = builtInFS.getPath("");
npath = EMPTY_PATH;
// other fields remain default
return;
}
@ -351,7 +349,7 @@ public final class FilePermission extends Permission implements Serializable {
npath = npath.getParent();
}
if (npath == null) {
npath = builtInFS.getPath("");
npath = EMPTY_PATH;
}
invalid = false;
} catch (InvalidPathException ipe) {

View file

@ -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.ServiceConfigurationError;
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 @@ import jdk.internal.misc.VM;
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 @@ public final class FileSystems {
// 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 @@ public final class FileSystems {
if (VM.isModuleSystemInited()) {
return DefaultFileSystemHolder.defaultFileSystem;
} else {
return BuiltinFileSystemHolder.builtinFileSystem;
// always use the platform's default file system during startup
return DefaultFileSystemProvider.theFileSystem();
}
}

View file

@ -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();
}
}

View file

@ -36,7 +36,7 @@ import sun.security.action.GetPropertyAction;
* Solaris implementation of FileSystemProvider
*/
public class SolarisFileSystemProvider extends UnixFileSystemProvider {
class SolarisFileSystemProvider extends UnixFileSystemProvider {
public SolarisFileSystemProvider() {
super();
}

View file

@ -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 @@ public abstract class UnixFileSystemProvider
theFileSystem = newFileSystem(userDir);
}
UnixFileSystem theFileSystem() {
return theFileSystem;
}
/**
* Constructs a new file system using the given default directory.
*/

View file

@ -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();
}
}

View file

@ -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.WindowsNativeDispatcher.*;
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 @@ public class WindowsFileSystemProvider
theFileSystem = new WindowsFileSystem(this, StaticProperty.userDir());
}
WindowsFileSystem theFileSystem() {
return theFileSystem;
}
@Override
public String getScheme() {
return "file";