Skip to content

Commit 7212bf0

Browse files
author
Martin Buchholz
committed
8213406: (fs) More than one instance of built-in FileSystem observed in heap
Reviewed-by: alanb, cushon, weijun
1 parent 978c78f commit 7212bf0

14 files changed

Lines changed: 106 additions & 53 deletions

File tree

src/java.base/aix/classes/sun/nio/fs/AixFileSystemProvider.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
* AIX implementation of FileSystemProvider
3333
*/
3434

35-
public class AixFileSystemProvider extends UnixFileSystemProvider {
35+
class AixFileSystemProvider extends UnixFileSystemProvider {
3636
public AixFileSystemProvider() {
3737
super();
3838
}

src/java.base/aix/classes/sun/nio/fs/DefaultFileSystemProvider.java

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2017, 2018, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -25,19 +25,29 @@
2525

2626
package sun.nio.fs;
2727

28-
import java.nio.file.spi.FileSystemProvider;
28+
import java.nio.file.FileSystem;
2929

3030
/**
3131
* Creates this platform's default FileSystemProvider.
3232
*/
3333

3434
public class DefaultFileSystemProvider {
35+
private static final AixFileSystemProvider INSTANCE
36+
= new AixFileSystemProvider();
37+
3538
private DefaultFileSystemProvider() { }
3639

3740
/**
38-
* Returns the default FileSystemProvider.
41+
* Returns the platform's default file system provider.
42+
*/
43+
public static AixFileSystemProvider instance() {
44+
return INSTANCE;
45+
}
46+
47+
/**
48+
* Returns the platform's default file system.
3949
*/
40-
public static FileSystemProvider create() {
41-
return new AixFileSystemProvider();
50+
public static FileSystem theFileSystem() {
51+
return INSTANCE.theFileSystem();
4252
}
4353
}

src/java.base/linux/classes/sun/nio/fs/DefaultFileSystemProvider.java

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2017, 2018, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -25,19 +25,29 @@
2525

2626
package sun.nio.fs;
2727

28-
import java.nio.file.spi.FileSystemProvider;
28+
import java.nio.file.FileSystem;
2929

3030
/**
3131
* Creates this platform's default FileSystemProvider.
3232
*/
3333

3434
public class DefaultFileSystemProvider {
35+
private static final LinuxFileSystemProvider INSTANCE
36+
= new LinuxFileSystemProvider();
37+
3538
private DefaultFileSystemProvider() { }
3639

3740
/**
38-
* Returns the default FileSystemProvider.
41+
* Returns the platform's default file system provider.
42+
*/
43+
public static LinuxFileSystemProvider instance() {
44+
return INSTANCE;
45+
}
46+
47+
/**
48+
* Returns the platform's default file system.
3949
*/
40-
public static FileSystemProvider create() {
41-
return new LinuxFileSystemProvider();
50+
public static FileSystem theFileSystem() {
51+
return INSTANCE.theFileSystem();
4252
}
4353
}

src/java.base/linux/classes/sun/nio/fs/LinuxFileSystemProvider.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
* Linux implementation of FileSystemProvider
3737
*/
3838

39-
public class LinuxFileSystemProvider extends UnixFileSystemProvider {
39+
class LinuxFileSystemProvider extends UnixFileSystemProvider {
4040
public LinuxFileSystemProvider() {
4141
super();
4242
}

src/java.base/macosx/classes/sun/nio/fs/BsdFileSystemProvider.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
* Bsd implementation of FileSystemProvider
3232
*/
3333

34-
public class BsdFileSystemProvider extends UnixFileSystemProvider {
34+
class BsdFileSystemProvider extends UnixFileSystemProvider {
3535
public BsdFileSystemProvider() {
3636
super();
3737
}

src/java.base/macosx/classes/sun/nio/fs/DefaultFileSystemProvider.java

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2017, 2018, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -25,19 +25,29 @@
2525

2626
package sun.nio.fs;
2727

28-
import java.nio.file.spi.FileSystemProvider;
28+
import java.nio.file.FileSystem;
2929

3030
/**
3131
* Creates this platform's default FileSystemProvider.
3232
*/
3333

3434
public class DefaultFileSystemProvider {
35+
private static final MacOSXFileSystemProvider INSTANCE
36+
= new MacOSXFileSystemProvider();
37+
3538
private DefaultFileSystemProvider() { }
3639

3740
/**
38-
* Returns the default FileSystemProvider.
41+
* Returns the platform's default file system provider.
42+
*/
43+
public static MacOSXFileSystemProvider instance() {
44+
return INSTANCE;
45+
}
46+
47+
/**
48+
* Returns the platform's default file system.
3949
*/
40-
public static FileSystemProvider create() {
41-
return new MacOSXFileSystemProvider();
50+
public static FileSystem theFileSystem() {
51+
return INSTANCE.theFileSystem();
4252
}
4353
}

src/java.base/macosx/classes/sun/nio/fs/MacOSXFileSystemProvider.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
* MacOSX implementation of FileSystemProvider
3535
*/
3636

37-
public class MacOSXFileSystemProvider extends BsdFileSystemProvider {
37+
class MacOSXFileSystemProvider extends BsdFileSystemProvider {
3838
public MacOSXFileSystemProvider() {
3939
super();
4040
}

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

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525

2626
package java.io;
2727

28-
import java.net.URI;
2928
import java.nio.file.*;
3029
import java.security.*;
3130
import java.util.Enumeration;
@@ -199,12 +198,11 @@ public final class FilePermission extends Permission implements Serializable {
199198
private static final long serialVersionUID = 7930732926638008763L;
200199

201200
/**
202-
* Always use the internal default file system, in case it was modified
203-
* with java.nio.file.spi.DefaultFileSystemProvider.
201+
* Use the platform's default file system to avoid recursive initialization
202+
* issues when the VM is configured to use a custom file system provider.
204203
*/
205204
private static final java.nio.file.FileSystem builtInFS =
206-
DefaultFileSystemProvider.create()
207-
.getFileSystem(URI.create("file:///"));
205+
DefaultFileSystemProvider.theFileSystem();
208206

209207
private static final Path here = builtInFS.getPath(
210208
GetPropertyAction.privilegedGetProperty("user.dir"));
@@ -326,7 +324,7 @@ private void init(int mask) {
326324

327325
if (name.equals("<<ALL FILES>>")) {
328326
allFiles = true;
329-
npath = builtInFS.getPath("");
327+
npath = EMPTY_PATH;
330328
// other fields remain default
331329
return;
332330
}
@@ -351,7 +349,7 @@ private void init(int mask) {
351349
npath = npath.getParent();
352350
}
353351
if (npath == null) {
354-
npath = builtInFS.getPath("");
352+
npath = EMPTY_PATH;
355353
}
356354
invalid = false;
357355
} catch (InvalidPathException ipe) {

src/java.base/share/classes/java/nio/file/FileSystems.java

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2007, 2017, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2007, 2018, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -37,6 +37,7 @@
3737
import java.util.ServiceLoader;
3838

3939
import jdk.internal.misc.VM;
40+
import sun.nio.fs.DefaultFileSystemProvider;
4041

4142
/**
4243
* Factory methods for file systems. This class defines the {@link #getDefault
@@ -88,16 +89,6 @@
8889
public final class FileSystems {
8990
private FileSystems() { }
9091

91-
// Built-in file system provider
92-
private static final FileSystemProvider builtinFileSystemProvider =
93-
sun.nio.fs.DefaultFileSystemProvider.create();
94-
95-
// built-in file system
96-
private static class BuiltinFileSystemHolder {
97-
static final FileSystem builtinFileSystem =
98-
builtinFileSystemProvider.getFileSystem(URI.create("file:///"));
99-
}
100-
10192
// lazy initialization of default file system
10293
private static class DefaultFileSystemHolder {
10394
static final FileSystem defaultFileSystem = defaultFileSystem();
@@ -118,7 +109,8 @@ public FileSystemProvider run() {
118109

119110
// returns default provider
120111
private static FileSystemProvider getDefaultProvider() {
121-
FileSystemProvider provider = builtinFileSystemProvider;
112+
// start with the platform's default file system provider
113+
FileSystemProvider provider = DefaultFileSystemProvider.instance();
122114

123115
// if the property java.nio.file.spi.DefaultFileSystemProvider is
124116
// set then its value is the name of the default provider (or a list)
@@ -189,7 +181,8 @@ public static FileSystem getDefault() {
189181
if (VM.isModuleSystemInited()) {
190182
return DefaultFileSystemHolder.defaultFileSystem;
191183
} else {
192-
return BuiltinFileSystemHolder.builtinFileSystem;
184+
// always use the platform's default file system during startup
185+
return DefaultFileSystemProvider.theFileSystem();
193186
}
194187
}
195188

src/java.base/solaris/classes/sun/nio/fs/DefaultFileSystemProvider.java

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2017, 2018, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -25,19 +25,29 @@
2525

2626
package sun.nio.fs;
2727

28-
import java.nio.file.spi.FileSystemProvider;
28+
import java.nio.file.FileSystem;
2929

3030
/**
3131
* Creates this platform's default FileSystemProvider.
3232
*/
3333

3434
public class DefaultFileSystemProvider {
35+
private static final SolarisFileSystemProvider INSTANCE
36+
= new SolarisFileSystemProvider();
37+
3538
private DefaultFileSystemProvider() { }
3639

3740
/**
38-
* Returns the default FileSystemProvider.
41+
* Returns the platform's default file system provider.
42+
*/
43+
public static SolarisFileSystemProvider instance() {
44+
return INSTANCE;
45+
}
46+
47+
/**
48+
* Returns the platform's default file system.
3949
*/
40-
public static FileSystemProvider create() {
41-
return new SolarisFileSystemProvider();
50+
public static FileSystem theFileSystem() {
51+
return INSTANCE.theFileSystem();
4252
}
4353
}

0 commit comments

Comments
 (0)