On Mon, 6 Jun 2022 13:20:31 GMT, liach <d...@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

Reply via email to