RFR 8017540: Improve multi-threaded contention behavior of BigInteger.toString() radix conversion cache (original) (raw)

Aleksey Shipilev aleksey.shipilev at oracle.com
Thu Jun 27 11🔞02 UTC 2013


On 06/27/2013 10:37 AM, Peter Levart wrote:

Hi,

This version seems correct. Maybe just replace double volatile read at length re-check with a single one:

private static BigInteger getRadixConversionCache(int radix, int exponent) { BigInteger[] cacheLine = powerCache[radix]; // volatile read if (exponent < cacheLine.length)_ _return cacheLine[exponent];_ _int oldLength = cacheLine.length;_ _cacheLine = Arrays.copyOf(cacheLine, exponent + 1);_ _for (int i = oldLength; i <= exponent; i++)_ _cacheLine[i] = cacheLine[i - 1].pow(2);_ _BigInteger[][] pc = powerCache; // volatile read again_ _if (exponent >= pc[radix].length) { pc = pc.clone(); pc[radix] = cacheLine; powerCache = pc; // volatile write, publish } return cacheLine[exponent]; }

Yes, I'm voting for this one. All other improvements Peter had suggested, while interesting, seem to not to worth the trouble.

-Aleksey.



More information about the core-libs-dev mailing list