8055088: Optimization for locale resources loading isn't working

Reviewed-by: naoto
This commit is contained in:
Masayoshi Okutsu 2014-08-19 16:02:48 +09:00
parent 391a556d14
commit 46c981faef
6 changed files with 47 additions and 35 deletions

View File

@ -1,5 +1,5 @@
# #
# Copyright (c) 2011, 2013, Oracle and/or its affiliates. All rights reserved. # Copyright (c) 2011, 2014, Oracle and/or its affiliates. All rights reserved.
# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. # DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
# #
# This code is free software; you can redistribute it and/or modify it # This code is free software; you can redistribute it and/or modify it
@ -34,7 +34,8 @@ LOCALE_FILES := $(shell $(FIND) $(JDK_TOPDIR)/src/*/share/classes \
-name "TimeZoneNames_*.java" -o -name "TimeZoneNames_*.properties" -o \ -name "TimeZoneNames_*.java" -o -name "TimeZoneNames_*.properties" -o \
-name "LocaleNames_*.java" -o -name "LocaleNames_*.properties" -o \ -name "LocaleNames_*.java" -o -name "LocaleNames_*.properties" -o \
-name "CurrencyNames_*.java" -o -name "CurrencyNames_*.properties" -o \ -name "CurrencyNames_*.java" -o -name "CurrencyNames_*.properties" -o \
-name "CalendarData_*.java" -o -name "CalendarData_*.properties") -name "CalendarData_*.java" -o -name "CalendarData_*.properties" -o \
-name "BreakIteratorInfo_*.java" -o -name "BreakIteratorRules_*.java")
# Then translate the locale files into for example: FormatData_sv # Then translate the locale files into for example: FormatData_sv
LOCALE_RESOURCES := $(sort $(subst .properties,,$(subst .java,,$(notdir $(LOCALE_FILES))))) LOCALE_RESOURCES := $(sort $(subst .properties,,$(subst .java,,$(notdir $(LOCALE_FILES)))))
@ -86,6 +87,12 @@ $(eval $(call CaptureLocale,FormatData))
#sun.text.resources.CollationData #sun.text.resources.CollationData
$(eval $(call CaptureLocale,CollationData)) $(eval $(call CaptureLocale,CollationData))
#sun.text.resources.BreakIteratorInfo
$(eval $(call CaptureLocale,BreakIteratorInfo))
#sun.text.resources.BreakIteratorRules
$(eval $(call CaptureLocale,BreakIteratorRules))
#sun.util.resources.TimeZoneNames #sun.util.resources.TimeZoneNames
$(eval $(call CaptureLocale,TimeZoneNames)) $(eval $(call CaptureLocale,TimeZoneNames))

View File

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2012, 2014, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -30,6 +30,7 @@ import java.security.AccessController;
import java.security.PrivilegedAction; import java.security.PrivilegedAction;
import java.text.spi.BreakIteratorProvider; import java.text.spi.BreakIteratorProvider;
import java.text.spi.CollatorProvider; import java.text.spi.CollatorProvider;
import java.util.Collections;
import java.util.HashSet; import java.util.HashSet;
import java.util.Locale; import java.util.Locale;
import java.util.ResourceBundle; import java.util.ResourceBundle;
@ -102,6 +103,9 @@ public class CLDRLocaleProviderAdapter extends JRELocaleProviderAdapter {
@Override @Override
protected Set<String> createLanguageTagSet(String category) { protected Set<String> createLanguageTagSet(String category) {
ResourceBundle rb = ResourceBundle.getBundle("sun.util.cldr.CLDRLocaleDataMetaInfo", Locale.ROOT); ResourceBundle rb = ResourceBundle.getBundle("sun.util.cldr.CLDRLocaleDataMetaInfo", Locale.ROOT);
if (rb.containsKey(category)) {
return Collections.emptySet();
}
String supportedLocaleString = rb.getString(category); String supportedLocaleString = rb.getString(category);
Set<String> tagset = new HashSet<>(); Set<String> tagset = new HashSet<>();
StringTokenizer tokens = new StringTokenizer(supportedLocaleString); StringTokenizer tokens = new StringTokenizer(supportedLocaleString);

View File

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2012, 2014, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -34,6 +34,7 @@ import java.text.spi.DateFormatProvider;
import java.text.spi.DateFormatSymbolsProvider; import java.text.spi.DateFormatSymbolsProvider;
import java.text.spi.DecimalFormatSymbolsProvider; import java.text.spi.DecimalFormatSymbolsProvider;
import java.text.spi.NumberFormatProvider; import java.text.spi.NumberFormatProvider;
import java.util.Collections;
import java.util.HashSet; import java.util.HashSet;
import java.util.Locale; import java.util.Locale;
import java.util.Set; import java.util.Set;
@ -356,6 +357,9 @@ public class JRELocaleProviderAdapter extends LocaleProviderAdapter implements R
protected Set<String> createLanguageTagSet(String category) { protected Set<String> createLanguageTagSet(String category) {
String supportedLocaleString = LocaleDataMetaInfo.getSupportedLocaleString(category); String supportedLocaleString = LocaleDataMetaInfo.getSupportedLocaleString(category);
if (supportedLocaleString == null) {
return Collections.emptySet();
}
Set<String> tagset = new HashSet<>(); Set<String> tagset = new HashSet<>();
StringTokenizer tokens = new StringTokenizer(supportedLocaleString); StringTokenizer tokens = new StringTokenizer(supportedLocaleString);
while (tokens.hasMoreTokens()) { while (tokens.hasMoreTokens()) {

View File

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2005, 2013, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2005, 2014, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -57,6 +57,12 @@ public class LocaleDataMetaInfo {
resourceNameToLocales.put("CollationData", resourceNameToLocales.put("CollationData",
" #CollationData_ENLocales# | #CollationData_NonENLocales# "); " #CollationData_ENLocales# | #CollationData_NonENLocales# ");
resourceNameToLocales.put("BreakIteratorInfo",
" #BreakIteratorInfo_ENLocales# | #BreakIteratorInfo_NonENLocales# ");
resourceNameToLocales.put("BreakIteratorRules",
" #BreakIteratorRules_ENLocales# | #BreakIteratorRules_NonENLocales# ");
resourceNameToLocales.put("TimeZoneNames", resourceNameToLocales.put("TimeZoneNames",
" #TimeZoneNames_ENLocales# | #TimeZoneNames_NonENLocales# "); " #TimeZoneNames_ENLocales# | #TimeZoneNames_NonENLocales# ");

View File

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2012, 2014, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -295,7 +295,7 @@ public abstract class LocaleProviderAdapter {
* A utility method for implementing the default LocaleServiceProvider.isSupportedLocale * A utility method for implementing the default LocaleServiceProvider.isSupportedLocale
* for the JRE, CLDR, and FALLBACK adapters. * for the JRE, CLDR, and FALLBACK adapters.
*/ */
static boolean isSupportedLocale(Locale locale, LocaleProviderAdapter.Type type, Set<String> langtags) { public static boolean isSupportedLocale(Locale locale, LocaleProviderAdapter.Type type, Set<String> langtags) {
assert type == Type.JRE || type == Type.CLDR || type == Type.FALLBACK; assert type == Type.JRE || type == Type.CLDR || type == Type.FALLBACK;
if (Locale.ROOT.equals(locale)) { if (Locale.ROOT.equals(locale)) {
return true; return true;

View File

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 1996, 2013, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 1996, 2014, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -48,8 +48,11 @@ import java.util.List;
import java.util.Locale; import java.util.Locale;
import java.util.MissingResourceException; import java.util.MissingResourceException;
import java.util.ResourceBundle; import java.util.ResourceBundle;
import java.util.Set;
import sun.util.locale.provider.JRELocaleProviderAdapter;
import sun.util.locale.provider.LocaleDataMetaInfo; import sun.util.locale.provider.LocaleDataMetaInfo;
import sun.util.locale.provider.LocaleProviderAdapter; import sun.util.locale.provider.LocaleProviderAdapter;
import static sun.util.locale.provider.LocaleProviderAdapter.Type.CLDR;
import static sun.util.locale.provider.LocaleProviderAdapter.Type.JRE; import static sun.util.locale.provider.LocaleProviderAdapter.Type.JRE;
/** /**
@ -204,35 +207,23 @@ public class LocaleData {
@Override @Override
public List<Locale> getCandidateLocales(String baseName, Locale locale) { public List<Locale> getCandidateLocales(String baseName, Locale locale) {
List<Locale> candidates = super.getCandidateLocales(baseName, locale); List<Locale> candidates = super.getCandidateLocales(baseName, locale);
/* Get the locale string list from LocaleDataMetaInfo class. */ // Weed out Locales which are known to have no resource bundles
String localeString = LocaleDataMetaInfo.getSupportedLocaleString(baseName); int lastDot = baseName.lastIndexOf('.');
String category = (lastDot >= 0) ? baseName.substring(lastDot + 1) : baseName;
if (localeString != null && localeString.length() != 0) { LocaleProviderAdapter.Type type = baseName.contains(DOTCLDR) ? CLDR : JRE;
for (Iterator<Locale> l = candidates.iterator(); l.hasNext();) { LocaleProviderAdapter adapter = LocaleProviderAdapter.forType(type);
Locale loc = l.next(); Set<String> langtags = ((JRELocaleProviderAdapter)adapter).getLanguageTagSet(category);
String lstr; if (!langtags.isEmpty()) {
if (loc.getScript().length() > 0) { for (Iterator<Locale> itr = candidates.iterator(); itr.hasNext();) {
lstr = loc.toLanguageTag().replace('-', '_'); if (!LocaleProviderAdapter.isSupportedLocale(itr.next(), type, langtags)) {
} else { itr.remove();
lstr = loc.toString();
int idx = lstr.indexOf("_#");
if (idx >= 0) {
lstr = lstr.substring(0, idx);
}
}
/* Every locale string in the locale string list returned from
the above getSupportedLocaleString is enclosed
within two white spaces so that we could check some locale
such as "en".
*/
if (lstr.length() != 0 && localeString.indexOf(" " + lstr + " ") == -1) {
l.remove();
} }
} }
} }
// Force fallback to Locale.ENGLISH for CLDR time zone names support // Force fallback to Locale.ENGLISH for CLDR time zone names support
if (locale.getLanguage() != "en" if (locale.getLanguage() != "en"
&& baseName.contains(CLDR) && baseName.endsWith("TimeZoneNames")) { && type == CLDR && category.equals("TimeZoneNames")) {
candidates.add(candidates.size() - 1, Locale.ENGLISH); candidates.add(candidates.size() - 1, Locale.ENGLISH);
} }
return candidates; return candidates;
@ -254,7 +245,7 @@ public class LocaleData {
return null; return null;
} }
private static final String CLDR = ".cldr"; private static final String DOTCLDR = ".cldr";
/** /**
* Changes baseName to its per-language package name and * Changes baseName to its per-language package name and
@ -275,8 +266,8 @@ public class LocaleData {
assert JRE.getUtilResourcesPackage().length() assert JRE.getUtilResourcesPackage().length()
== JRE.getTextResourcesPackage().length(); == JRE.getTextResourcesPackage().length();
int index = JRE.getUtilResourcesPackage().length(); int index = JRE.getUtilResourcesPackage().length();
if (baseName.indexOf(CLDR, index) > 0) { if (baseName.indexOf(DOTCLDR, index) > 0) {
index += CLDR.length(); index += DOTCLDR.length();
} }
newBaseName = baseName.substring(0, index + 1) + lang newBaseName = baseName.substring(0, index + 1) + lang
+ baseName.substring(index); + baseName.substring(index);