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

Aleksey Shipilev aleksey.shipilev at oracle.com
Wed Jun 26 06:31:11 UTC 2013


On 26.06.2013, at 7:31, Dmitry Nadezhin <dmitry.nadezhin at gmail.com> wrote:

We have two versions after private discussion with Aleksey.

BigInteger getRadixConversionCache(int radix, int exponent) { BigInteger[][] pc = powerCache; // volatile read BigInteger[] cacheLine = pc[radix]; if (exponent < cacheLine.length) return cacheLine[exponent]; int oldSize = cacheLine.length; cacheLine = Arrays.copyOf(cacheLine, exponent + 1); for (int i = oldSize; i < exponent + 1; i++) cacheLine[i] = cacheLine[i - 1].square(); pc = Arrays.copyOf(powerCache); pc[radix] = cacheLine; powerCache = pc; // volatile write, publish return cacheLine[exponent]; }

Thanks, I like this version a lot better. We could check for the existing cacheLine.length right before installing the new one, so the opportunity to overwrite larger cacheLine would be minimal, but I do think the probability of unlucky timing is very low, and the argument is moot :) Let's keep it simple.

-Aleksey.



More information about the core-libs-dev mailing list