RFR 8017540: Improve multi-threaded contention behavior of BigInteger.toString() radix conversion cache
Brian Burkhalter
brian.burkhalter at oracle.com
Wed Jun 26 18:13:18 UTC 2013
So do we have consensus on this version?
Thanks for the lively "conversation."
Brian
On Jun 26, 2013, at 12:05 AM, Aleksey Shipilev wrote:
> Yes, like that.
>
> -Aleksey
>
> On 26.06.2013, at 10:53, Dmitry Nadezhin <dmitry.nadezhin at gmail.com> wrote:
>
>>> We could check for the existing cacheLine.length right before installing
>> the new one
>>
>> Do you mean something like this ?
>>
>> 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 + 1; i++)
>> cacheLine[i] = cacheLine[i - 1].square();
>>
>> if (exponent >= powerCache[radix].length) { // volatile read again
>> BigInteger[][] pc = Arrays.copyOf(powerCache);
>> pc[radix] = cacheLine;
>> powerCache = pc; // volatile write, publish
>> }
>> return cacheLine[exponent];
>> }
More information about the core-libs-dev
mailing list