RFR: 8341470: BigDecimal.stripTrailingZeros() optimization [v12]

fabioromano1 duke at openjdk.org
Fri Oct 4 17:06:41 UTC 2024


On Thu, 3 Oct 2024 17:15:34 GMT, Archie Cobbs <acobbs at openjdk.org> wrote:

>> fabioromano1 has updated the pull request incrementally with one additional commit since the last revision:
>> 
>>   Code simplification
>
> src/java.base/share/classes/java/math/BigDecimal.java line 5238:
> 
>> 5236:             BigInteger pow = FIVE_TO_2_TO[FIVE_TO_2_TO_LEN - 1];
>> 5237:             for (int i = FIVE_TO_2_TO_LEN; i <= n; i++)
>> 5238:                 FIVE_TO_2_TO[i] = pow = pow.multiply(pow);
> 
> Drive-by comment... apologies if I'm missing some subtle context. Doesn't this raciness create a bug? The field `FIVE_TO_2_TO_LEN` is read multiple times, and other threads could be incrementing it while this code executes, which would lead to an incorrect value for `pow`, etc.

@archiecobbs AFAIK, the documentation of `BigDecimal` does not specify that the class is thread-safe, but I could be wrong...

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

PR Review Comment: https://git.openjdk.org/jdk/pull/21323#discussion_r1788012854


More information about the core-libs-dev mailing list