<i18n dev> RFR: 8347949: Currency method to stream available Currencies [v5]

Roger Riggs rriggs at openjdk.org
Wed Jan 22 17:12:55 UTC 2025


On Tue, 21 Jan 2025 18:44:39 GMT, Justin Lu <jlu at openjdk.org> wrote:

>> src/java.base/share/classes/java/util/Currency.java line 469:
>> 
>>> 467: 
>>> 468:     // Initialize the set of available currencies if needed
>>> 469:     private static synchronized void initAvailableCurrencies() {
>> 
>> Should we make `available` volatile so we can avoid entering the monitor if the currencies are initialized?
>> 
>> (Note: We may get Stable Values very soon, at that point SV is a much better solution)
>
> Thanks Chen, made `available` volatile and implemented DCL in https://github.com/openjdk/jdk/pull/23165/commits/96e86c800f1d1af1c20bfee944c298f17b7e8860.
> Also added a duplicate elements test as you suggested.

I'm not sure how useful it is to optimize the performance of `availableCurrencies` access to "available", but adding volatile will slow every access down.
The computation of the available currencies is stable, so a race computing it is benign.
Except for the available hashSet being partially filled when read by the thread calling `getAvailableCurrencies()`.
That could be remedied by using a new local for the new HashSet in initAvailableCurrencies and assigning to available only when the set is completely initialized.
(And yes, this looks like a good fit for stable values.)

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

PR Review Comment: https://git.openjdk.org/jdk/pull/23165#discussion_r1925680680


More information about the i18n-dev mailing list