RFR: 8341470: BigDecimal.stripTrailingZeros() optimization [v12]
Archie Cobbs
acobbs at openjdk.org
Fri Oct 4 17:14:36 UTC 2024
On Fri, 4 Oct 2024 17:03:38 GMT, fabioromano1 <duke at openjdk.org> wrote:
>> 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...
@fabioromano1, this is a static method manipulating static fields that are shared by all instances; whether individual instances are thread safe is a separate and unrelated issue.
-------------
PR Review Comment: https://git.openjdk.org/jdk/pull/21323#discussion_r1788027181
More information about the core-libs-dev
mailing list