RFR: 8196869: Optimize Locale creation

Claes Redestad claes.redestad at oracle.com
Wed Feb 7 14:23:36 UTC 2018


On 2018-02-07 13:55, Peter Levart wrote:
> Would making CacheEntry extend jdk.internal.ref.SoftCleanable instead 
> of SoftReference help here? You could remove the cleanStaleEntries 
> method entirely and just remove the Map entry in SoftCleanable's 
> performCleanup method.

possible, but that'd be a larger change than I'm comfortable with for now.

As Locale is initialized on bootstrap, a Cleaner-based impl. would mean 
an innocuous thread unconditionally, which would defeat the intent to 
the minimal time to bootstrap the JVM. If we could tease things apart 
even further
so that a SoftCleanable and Cleaners are only set up when initializing any
non-constant Locale then I think we should contemplate this as a follow up.

Updated webrev:


- use map.remove(entry.getKey(), entry) instead of 
- for most Locales, Locale$LocaleKey.exts is null, so using the 
BaseLocale as key
   directly in Locale allows us to avoid loading Locale$LocaleKey except 
in exceptional
- use map.replace to safely update the entry when putIfAbsent returns an 
   but it points to a cleared value, so that (benign) races to create 
new Locale objects
   will canonicalize


More information about the core-libs-dev mailing list