8209837: Avoid initializing ExpiringCache during bootstrap

Reviewed-by: sundar, forax
This commit is contained in:
Claes Redestad 2018-08-24 14:04:34 +02:00
parent 9ec15cedd0
commit 5ddac96c10
3 changed files with 39 additions and 21 deletions

View file

@ -231,18 +231,16 @@ abstract class FileSystem {
// Flags for enabling/disabling performance optimizations for file // Flags for enabling/disabling performance optimizations for file
// name canonicalization // name canonicalization
static boolean useCanonCaches; static final boolean useCanonCaches;
static boolean useCanonPrefixCache; static final boolean useCanonPrefixCache;
private static boolean getBooleanProperty(String prop, boolean defaultVal) { private static boolean getBooleanProperty(String prop, boolean defaultVal) {
return Boolean.parseBoolean(System.getProperty(prop, String value = System.getProperty(prop);
String.valueOf(defaultVal))); return (value != null) ? Boolean.parseBoolean(value) : defaultVal;
} }
static { static {
useCanonCaches = getBooleanProperty("sun.io.useCanonCaches", useCanonCaches = getBooleanProperty("sun.io.useCanonCaches", false);
useCanonCaches); useCanonPrefixCache = useCanonCaches && getBooleanProperty("sun.io.useCanonPrefixCache", false);
useCanonPrefixCache = getBooleanProperty("sun.io.useCanonPrefixCache",
useCanonPrefixCache);
} }
} }

View file

@ -44,6 +44,8 @@ class UnixFileSystem extends FileSystem {
colon = props.getProperty("path.separator").charAt(0); colon = props.getProperty("path.separator").charAt(0);
javaHome = StaticProperty.javaHome(); javaHome = StaticProperty.javaHome();
userDir = StaticProperty.userDir(); userDir = StaticProperty.userDir();
cache = useCanonCaches ? new ExpiringCache() : null;
javaHomePrefixCache = useCanonPrefixCache ? new ExpiringCache() : null;
} }
@ -145,11 +147,11 @@ class UnixFileSystem extends FileSystem {
// same directory, and must not create results differing from the true // same directory, and must not create results differing from the true
// canonicalization algorithm in canonicalize_md.c. For this reason the // canonicalization algorithm in canonicalize_md.c. For this reason the
// prefix cache is conservative and is not used for complex path names. // prefix cache is conservative and is not used for complex path names.
private ExpiringCache cache = new ExpiringCache(); private final ExpiringCache cache;
// On Unix symlinks can jump anywhere in the file system, so we only // On Unix symlinks can jump anywhere in the file system, so we only
// treat prefixes in java.home as trusted and cacheable in the // treat prefixes in java.home as trusted and cacheable in the
// canonicalization algorithm // canonicalization algorithm
private ExpiringCache javaHomePrefixCache = new ExpiringCache(); private final ExpiringCache javaHomePrefixCache;
public String canonicalize(String path) throws IOException { public String canonicalize(String path) throws IOException {
if (!useCanonCaches) { if (!useCanonCaches) {
@ -158,7 +160,7 @@ class UnixFileSystem extends FileSystem {
String res = cache.get(path); String res = cache.get(path);
if (res == null) { if (res == null) {
String dir = null; String dir = null;
String resDir = null; String resDir;
if (useCanonPrefixCache) { if (useCanonPrefixCache) {
// Note that this can cause symlinks that should // Note that this can cause symlinks that should
// be resolved to a destination directory to be // be resolved to a destination directory to be
@ -266,8 +268,12 @@ class UnixFileSystem extends FileSystem {
// (i.e., only remove/update affected entries) but probably // (i.e., only remove/update affected entries) but probably
// not worth it since these entries expire after 30 seconds // not worth it since these entries expire after 30 seconds
// anyway. // anyway.
if (useCanonCaches) {
cache.clear(); cache.clear();
}
if (useCanonPrefixCache) {
javaHomePrefixCache.clear(); javaHomePrefixCache.clear();
}
return delete0(f); return delete0(f);
} }
private native boolean delete0(File f); private native boolean delete0(File f);
@ -279,8 +285,12 @@ class UnixFileSystem extends FileSystem {
// (i.e., only remove/update affected entries) but probably // (i.e., only remove/update affected entries) but probably
// not worth it since these entries expire after 30 seconds // not worth it since these entries expire after 30 seconds
// anyway. // anyway.
if (useCanonCaches) {
cache.clear(); cache.clear();
}
if (useCanonPrefixCache) {
javaHomePrefixCache.clear(); javaHomePrefixCache.clear();
}
return rename0(f1, f2); return rename0(f1, f2);
} }
private native boolean rename0(File f1, File f2); private native boolean rename0(File f1, File f2);

View file

@ -51,6 +51,8 @@ class WinNTFileSystem extends FileSystem {
semicolon = props.getProperty("path.separator").charAt(0); semicolon = props.getProperty("path.separator").charAt(0);
altSlash = (this.slash == '\\') ? '/' : '\\'; altSlash = (this.slash == '\\') ? '/' : '\\';
userDir = normalize(props.getProperty("user.dir")); userDir = normalize(props.getProperty("user.dir"));
cache = useCanonCaches ? new ExpiringCache() : null;
prefixCache = useCanonPrefixCache ? new ExpiringCache() : null;
} }
private boolean isSlash(char c) { private boolean isSlash(char c) {
@ -387,8 +389,8 @@ class WinNTFileSystem extends FileSystem {
// same directory, and must not create results differing from the true // same directory, and must not create results differing from the true
// canonicalization algorithm in canonicalize_md.c. For this reason the // canonicalization algorithm in canonicalize_md.c. For this reason the
// prefix cache is conservative and is not used for complex path names. // prefix cache is conservative and is not used for complex path names.
private ExpiringCache cache = new ExpiringCache(); private final ExpiringCache cache;
private ExpiringCache prefixCache = new ExpiringCache(); private final ExpiringCache prefixCache;
@Override @Override
public String canonicalize(String path) throws IOException { public String canonicalize(String path) throws IOException {
@ -568,8 +570,12 @@ class WinNTFileSystem extends FileSystem {
// (i.e., only remove/update affected entries) but probably // (i.e., only remove/update affected entries) but probably
// not worth it since these entries expire after 30 seconds // not worth it since these entries expire after 30 seconds
// anyway. // anyway.
if (useCanonCaches) {
cache.clear(); cache.clear();
}
if (useCanonPrefixCache) {
prefixCache.clear(); prefixCache.clear();
}
return delete0(f); return delete0(f);
} }
@ -582,8 +588,12 @@ class WinNTFileSystem extends FileSystem {
// (i.e., only remove/update affected entries) but probably // (i.e., only remove/update affected entries) but probably
// not worth it since these entries expire after 30 seconds // not worth it since these entries expire after 30 seconds
// anyway. // anyway.
if (useCanonCaches) {
cache.clear(); cache.clear();
}
if (useCanonPrefixCache) {
prefixCache.clear(); prefixCache.clear();
}
return rename0(f1, f2); return rename0(f1, f2);
} }