Implementing VarHandle

Paul Sandoz paul.sandoz at oracle.com
Mon Apr 20 09:06:42 UTC 2015


Hi Peter, 

We did consider supporting field and method literals in 9, leveraging the same syntax as for method references combined with target typing. But, we have currently concluded it would be best to punt it to post-9. 

As a result there is currently no compelling need to support VarHandles in the constant pool, which, while not particular hard AFAICT (famous last words!), is a welcome reduction in work.

Paul.

On Apr 20, 2015, at 10:41 AM, Peter Levart <peter.levart at gmail.com> wrote:
>> The thing that pushed us over the edge is that value types are coming.  With value types, one can create type-safe, zero-cost, specialized wrappers for {Static,Instance,Array,Native}VarHandle<T> that wrap an underlying VH; because these wrappers can be values, they can provide type safety with no indirection or footprint costs.  So it seemed better to provide a simple, clean, low-level API now that doesn’t make any assumptions, let the early adopters (mostly us) deal with the fact that type safety comes at runtime (just as with MHs), and later provide a clean set of value wrappers on top of it.  
> 
> This seems like a good plan for post-JDK9 times. But I still miss one thing in this picture - the syntax. If purely API approach is taken, then we will still be using Strings to identify fields and do the caching of VarHandles ourselves. Are there any plans for specifying syntax for constant [Method|Var] handles in Java or is this being reserved for post-JDK9 times where the syntax will be used to produce type-safe wrappers (similar to approach taken with MethodHandles vs. Lambdas)?
> 
> Regards, Peter
> 


More information about the valhalla-dev mailing list