[9] RFR(S): 8005873: JRuby test_respond_to.rb asserts with: MT-unsafe modification of inline cache
Paul Sandoz
paul.sandoz at oracle.com
Thu May 15 08:53:37 UTC 2014
On May 14, 2014, at 10:50 PM, Vladimir Ivanov <vladimir.x.ivanov at oracle.com> wrote:
>>>> Or perhaps use Unsafe.CAS directly within setCachedLambdaForm?
>>> Yes, Unsafe is another option here. But since cache updates should be
>>> rare, Unsafe is an overkill here IMO - locking should be fine.
>>
>> I don't get it, AtomicReferenceArray.CAS implementation uses Unsafe.CAS
> By overkill I meant code complexity - it increases for no benefit.
>
> If we use Unsafe directly, we need to duplicate offset calculation logic from AtomicReferenceArray.
>
While i find that simple [*], i tend to agree that a lock in setCachedLambdaForm is simpler for this case (and cachedLambdaForm could be left as is).
Paul.
[*] There are constants on Unsafe, Unsafe.ARRAY_OBJECT_BASE_OFFSET and Unsafe.ARRAY_OBJECT_INDEX_SCALE, although commonly one would prefer to do address = (i << shift) + base, rather than address = i * scale + base:
boolean r = Unsafe.compareAndSwapObject(lambdaForms,
which * Unsafe.ARRAY_OBJECT_INDEX_SCALE + Unsafe.ARRAY_OBJECT_BASE_OFFSET,
null, form);
return r ? form : lambdaForms[which]; // always returns non-null value
More information about the hotspot-dev
mailing list