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

Brian Burkhalter brian.burkhalter at oracle.com
Thu Jun 27 18:29:01 UTC 2013


On Jun 27, 2013, at 4:18 AM, Aleksey Shipilev wrote:

> 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.

Are there any objections to this version (as included above)?

Brian


More information about the core-libs-dev mailing list