[9, 8u40] RFR (M): 8057020: LambdaForm caches should support eviction
Paul Sandoz
paul.sandoz at oracle.com
Mon Dec 8 16:19:29 UTC 2014
On Dec 6, 2014, at 1:30 PM, Peter Levart <peter.levart at gmail.com> wrote:
> Now what scares me (might be that I don't have an intimacy with LambdaForm class like you do). There is a situation where you publish LambdaForm instances via data race.
>
> One form of LambdaForm.transformCache is an array of Transform objects (the other two forms are not problematic). Transform class has all fields final except the 'referent' field of SoftReference, which holds a LambdaForm instance. In the following line:
>
> 377 ta[idx] = key;
>
>
> ...you publish Transform object to an element of array with relaxed write, and in the following lines:
>
> 271 } else {
> 272 Transform[] ta = (Transform[])c;
> 273 for (int i = 0; i < ta.length; i++) {
> 274 Transform t = ta[i];
> 275 if (t == null) break;
> 276 if (t.equals(key)) { k = t; break; }
> 277 }
> 278 }
> 279 assert(k == null || key.equals(k));
> 280 return (k != null) ? k.get() : null;
>
>
> ...you obtain the element of the array with no synchronization and a relaxed read and might return a non-null referent (the LambdaForm) which is then returned as an interned instance.
>
Transform still has final fields, thus when constructing a Transform using "key.withResult(form))" i don't think hotspot will reorder the store of the referent, or dependent stores, so that they occur after publication of the key element into the Transform[] array.
So i think things are also are ok between putInCache and getInCache.
> So can LambdaForm instances be published via data races without fear that they would appear half-initialized?
>
AFAICT yes. LambdaForm has final/stable fields and i presume it does not leak in the constructor (even when compiling on construction). See also MethodHandle.updateForm for rare cases where the lambda form of a MethodHandle is updated.
Paul.
> That's what I didn't know when I used a lazySet coupled with volatile get to access array elements in my version:
>
> http://cr.openjdk.java.net/~plevart/misc/LambdaFormEditor.WeakCache/webrev.01/
>
>
> Regards, Peter
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 841 bytes
Desc: Message signed with OpenPGP using GPGMail
URL: <http://mail.openjdk.java.net/pipermail/mlvm-dev/attachments/20141208/8ea89339/signature-0001.asc>
More information about the mlvm-dev
mailing list