RFR: 8309622: Re-examine the cache mechanism in BaseLocale

Naoto Sato naoto at openjdk.org
Fri Jun 9 23:34:44 UTC 2023


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

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

Commit messages:
 - minor comment fix
 - equals/hash fix, constructor simplification
 - Removed Key
 - minor fixup
 - Use WeakHashMap
 - Modified JMH test
 - Added a test variation for the issue
 - added microbenchmark
 - 8309622: Re-examine the cache mechanism in BaseLocale

Changes: https://git.openjdk.org/jdk/pull/14404/files
 Webrev: https://webrevs.openjdk.org/?repo=jdk&pr=14404&range=00
  Issue: https://bugs.openjdk.org/browse/JDK-8309622
  Stats: 244 lines in 3 files changed: 104 ins; 117 del; 23 mod
  Patch: https://git.openjdk.org/jdk/pull/14404.diff
  Fetch: git fetch https://git.openjdk.org/jdk.git pull/14404/head:pull/14404

PR: https://git.openjdk.org/jdk/pull/14404


More information about the core-libs-dev mailing list