<i18n dev> RFR: 8287860: Revise usage of volatile in j.u.Locale
Сергей Цыпанов
duke at openjdk.java.net
Mon Jun 6 13:30:53 UTC 2022
On Mon, 6 Jun 2022 13:20:31 GMT, liach <duke at openjdk.java.net> wrote:
>> - cached hash code of `Locale` and `Locale$LanguageRange` shouldn't be volatile, even in case of race in the worst case it is recalculated at most once per thread
>> - `defaultLocale` field is read multiple times in `initDefault()`
>> - `isoLanguages` is accessed multiple times in `getISOLanguages()`
>> - `languageTag` is read twice in `toLanguageTag()`
>
> src/java.base/share/classes/java/util/Locale.java line 2260:
>
>> 2258: * Calculated hashcode
>> 2259: */
>> 2260: private transient volatile int hashCodeValue;
>
> We can additionally annotate such cache fields with `@Stable` so as to enable constant-folding optimizations from the hotspot JIT.
Shouldn't the fields annotated with `@Stable` be `final` as well?
-------------
PR: https://git.openjdk.java.net/jdk/pull/9041
More information about the i18n-dev
mailing list