RFR: 8309622: Re-examine the cache mechanism in BaseLocale [v2]

Andrey Turbanov aturbanov at openjdk.org
Tue Jun 13 13:14:54 UTC 2023


On Mon, 12 Jun 2023 17:33:11 GMT, Naoto Sato <naoto at openjdk.org> wrote:

>> This is stemming from the PR: https://github.com/openjdk/jdk/pull/14211 where aggressive GC can cause NPE in `BaseLocale$Key` class. I refactored the in-house cache with WeakHashMap, and removed the Key class as it is no longer needed (thus the original NPE will no longer be possible). Also with the new JMH test case, it gains some performance improvement:
>> 
>> (w/o fix)
>> 
>> Benchmark                       Mode  Cnt      Score     Error  Units
>> LocaleCache.testForLanguageTag  avgt   20   5781.275 ± 569.580  ns/op
>> LocaleCache.testLocaleOf        avgt   20  62564.079 ± 406.697  ns/op
>> 
>> (w/ fix)
>> Benchmark                       Mode  Cnt      Score     Error  Units
>> LocaleCache.testForLanguageTag  avgt   20   4801.175 ± 371.830  ns/op
>> LocaleCache.testLocaleOf        avgt   20  60394.652 ± 352.471  ns/op
>
> Naoto Sato has updated the pull request incrementally with one additional commit since the last revision:
> 
>   Addressing comments (test grouping, synchronization), minor optimization on loop lookup

test/micro/org/openjdk/bench/java/util/LocaleCache.java line 58:

> 56:                 throw new RuntimeException("Different Locale was created");
> 57:             }
> 58:             previous =  l;

Suggestion:

            previous = l;

test/micro/org/openjdk/bench/java/util/LocaleCache.java line 70:

> 68:                 throw new RuntimeException("Different Locale was created");
> 69:             }
> 70:             previous =  l;

Suggestion:

            previous = l;

-------------

PR Review Comment: https://git.openjdk.org/jdk/pull/14404#discussion_r1228106882
PR Review Comment: https://git.openjdk.org/jdk/pull/14404#discussion_r1228109502


More information about the core-libs-dev mailing list