JEP 193: Enhanced Volatiles
Jeroen Frijters
jeroen at sumatra.nl
Wed Mar 5 07:40:49 UTC 2014
Brian Goetz wrote:
> Right now, the semantics of method calls in Java are simple --
> everything (primitives, object references) is passed by value. Adding
> pass-by-reference would add significant complexity. And method calls
> are not a niche feature; that added complexity will be borne by every
> developer, every day.
We'll just have to disagree on this. VB developers are not more sophisticated than Java developers and they've dealt with ByRef just fine (even though many don't understand it). In practice they don't run into it that often.
> My goal here is to make sure that expert users can get their job done
> somehow, *without* making the job of mainstream developers harder. The
> "add lvalues to Java so experts can write CAS-libraries" fails that test
> miserably.
Why not go for something far less intrusive then? Here's my straw man proposal:
Add an annotation that can be placed on native methods to synthesize atomic accessor methods.
Example usage:
@AtomicField("next")
private native boolean compareAndSet(Node expected, Node newValue);
@AtomicArray
private static native boolean compareAndSet(Node[] array, Node expected, Node newValue);
(Note that the method name is not significant, the operation can be derived from the signature, or explicit in the annotation, if necessary.)
This requires no changes to the language and adds only a slight burden on the developer (but it's very easy to add tooling support).
Regards,
Jeroen
More information about the core-libs-dev
mailing list