Draft JEP on enhanced volatiles
Brian Goetz
brian.goetz at oracle.com
Sat Feb 8 17:52:14 UTC 2014
> can you be a little more specific and provide the way
> foo.volatile.compareAndSet is compiled with this example:
Hey, the JEP isn't even out of draft yet! Stop asking hard questions.
The current strawman, though, is to expose direct (CP-ready) MH forms
(Lookup API / constant pool format TBD) for field get/set with fence,
array element get/set with fence, field CAS, and array element CAS.
Then the static compiler translates
foo.volatile.cAS(n,m)
as
LDC #MH[lookupFieldCASer(foo)]
aload n
aload m
invokevirtual "invokeExact"
> class Linked {
> volatile Node head;
>
> public void add(String element) {
> for(;;) {
> Node oldHead = head.volatile.get();
> Node newNode = new Node(element, oldHead);
> if (head.volatile.compareAndSet(oldHead, newNode)) {
> return;
> }
> }
> }
> }
>
> I will be very happy to see how you solve the different issues because
> i've also spent some times thinking on how the .volatile syntax can be
> implemented:
> - what is the signature of the method compareAndSet, and how you
> fight the generics erasure ?
> - how do you remove the extra-level of indirection if head is a
> VolatileXXX,
> because accessing to the value is this.head.payload and not
> this.head ?
> - what LinkedClass.class.getDeclaredField("head").getType() returns ?
>
> regards,
> Rémi
>
More information about the core-libs-dev
mailing list