Quick observation: 261 private BaseLocale getBaseLocale() { 262 return (holder == null) ? holderRef.get() : holder; 263 } This method can return null if the soft ref has been cleared. But you don’t check in equals: 270 if (obj instanceof Key && this.hash == ((Key)obj).hash) { 271 BaseLocale other = ((Key) obj).getBaseLocale(); 272 BaseLocale locale = this.getBaseLocale(); 273 if (LocaleUtils.caseIgnoreMatch(other.getLanguage(), locale.getLanguage()) Paul.
On Feb 6, 2018, at 9:51 AM, Claes Redestad <claes.redestad@oracle.com> wrote:
Hi,
we can refactor sun.util.locale.BaseLocale+LocaleObjectCache to minimize the number of SoftReferences created in Locale::<clinit> and when looking up already defined BaseLocales inside the Locale constructor.
http://cr.openjdk.java.net/~redestad/8196869/jdk.00/
This is mainly a tiny startup optimization, dropping executed bytecode during startup by a few thousand and reducing the minimum retained heap by a few Kb, but also speeds up microbenchmarks repeatedly calling the Locale constructor by ~1.25x. Tests stressing that dereferenced Locales are disposed of promptly remain happy.
Thanks!
/Claes