8338897: Small startup regression remains after JDK-8309622 and JDK-8331932
Reviewed-by: liach, naoto
This commit is contained in:
parent
3d49fb8a17
commit
a98ecad0a9
@ -988,17 +988,23 @@ public final class Locale implements Cloneable, Serializable {
|
||||
if (locale != null) {
|
||||
return locale;
|
||||
}
|
||||
return LOCALE_CACHE.computeIfAbsent(baseloc, LOCALE_CREATOR);
|
||||
return LocaleCache.cache(baseloc);
|
||||
} else {
|
||||
LocaleKey key = new LocaleKey(baseloc, extensions);
|
||||
return LOCALE_CACHE.computeIfAbsent(key, LOCALE_CREATOR);
|
||||
return LocaleCache.cache(key);
|
||||
}
|
||||
}
|
||||
|
||||
private static final ReferencedKeyMap<Object, Locale> LOCALE_CACHE
|
||||
= ReferencedKeyMap.create(true, ReferencedKeyMap.concurrentHashMapSupplier());
|
||||
private static final class LocaleCache implements Function<Object, Locale> {
|
||||
private static final ReferencedKeyMap<Object, Locale> LOCALE_CACHE
|
||||
= ReferencedKeyMap.create(true, ReferencedKeyMap.concurrentHashMapSupplier());
|
||||
|
||||
private static final Function<Object, Locale> LOCALE_CREATOR = new LocaleCache();
|
||||
|
||||
public static Locale cache(Object key) {
|
||||
return LOCALE_CACHE.computeIfAbsent(key, LOCALE_CREATOR);
|
||||
}
|
||||
|
||||
private static final Function<Object, Locale> LOCALE_CREATOR = new Function<>() {
|
||||
@Override
|
||||
public Locale apply(Object key) {
|
||||
if (key instanceof BaseLocale base) {
|
||||
@ -1007,7 +1013,7 @@ public final class Locale implements Cloneable, Serializable {
|
||||
LocaleKey lk = (LocaleKey)key;
|
||||
return new Locale(lk.base, lk.exts);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
private static final class LocaleKey {
|
||||
|
||||
|
@ -38,7 +38,6 @@ import jdk.internal.util.StaticProperty;
|
||||
import jdk.internal.vm.annotation.Stable;
|
||||
|
||||
import java.util.StringJoiner;
|
||||
import java.util.function.UnaryOperator;
|
||||
|
||||
public final class BaseLocale {
|
||||
|
||||
@ -91,10 +90,6 @@ public final class BaseLocale {
|
||||
}
|
||||
}
|
||||
|
||||
// Interned BaseLocale cache
|
||||
private static final ReferencedKeySet<BaseLocale> CACHE =
|
||||
ReferencedKeySet.create(true, ReferencedKeySet.concurrentHashMapSupplier());
|
||||
|
||||
public static final String SEP = "_";
|
||||
|
||||
private final String language;
|
||||
@ -163,21 +158,16 @@ public final class BaseLocale {
|
||||
// Obtain the "interned" BaseLocale from the cache. The returned
|
||||
// "interned" instance can subsequently be used by the Locale
|
||||
// instance which guarantees the locale components are properly cased/interned.
|
||||
return CACHE.intern(new BaseLocale(language, script, region, variant),
|
||||
// Avoid lambdas since this may be on the bootstrap path in many locales
|
||||
INTERNER);
|
||||
}
|
||||
|
||||
public static final UnaryOperator<BaseLocale> INTERNER = new UnaryOperator<>() {
|
||||
@Override
|
||||
public BaseLocale apply(BaseLocale b) {
|
||||
return new BaseLocale(
|
||||
LocaleUtils.toLowerString(b.language).intern(),
|
||||
LocaleUtils.toTitleString(b.script).intern(),
|
||||
LocaleUtils.toUpperString(b.region).intern(),
|
||||
b.variant.intern());
|
||||
class InterningCache { // TODO: StableValue
|
||||
private static final ReferencedKeySet<BaseLocale> CACHE =
|
||||
ReferencedKeySet.create(true, ReferencedKeySet.concurrentHashMapSupplier());
|
||||
}
|
||||
};
|
||||
return InterningCache.CACHE.intern(new BaseLocale(
|
||||
language.intern(), // guaranteed to be lower-case
|
||||
LocaleUtils.toTitleString(script).intern(),
|
||||
region.intern(), // guaranteed to be upper-case
|
||||
variant.intern()));
|
||||
}
|
||||
|
||||
public static String convertOldISOCodes(String language) {
|
||||
return switch (language) {
|
||||
|
Loading…
Reference in New Issue
Block a user