VarAccessor - VarHandle alternative?

Rémi Forax forax at univ-mlv.fr
Sat Aug 8 11:08:23 UTC 2015


Yes,
that's a very good question !

I prefer your implemation too.

Rémi 


Le 8 août 2015 08:52:21 CEST, Christoph Engelbert <chris at hazelcast.com> a écrit :
>Hey Peter,
>
>That actually is a very interesting prototype and the implementation
>would be way easier than the current VarHandles. This kind of double
>dispatch on VarHandles (especially if you’re missing a specialization
>method in VarHandleGuards it kind of gets ugly).
>
>I really like your idea!
>
>Chris
>
>> Am 08.08.2015 um 02:28 schrieb Peter Levart <peter.levart at gmail.com>:
>> 
>> Hi,
>> 
>> @PolymorphicSignature methods in VarHandle (combined with generics in
>FieldHandle) are a way to expose an API that does not explode in the
>number of different public classes for different primitive types. But
>aren't any-fied (specialized) generics doing just the same? I know:
>VarHandles are  proposed for JDK9 and any-fied generics aren't there
>yet.
>> 
>> Anyway, I tried to see if current state of any-fied generics allows
>me to build an API that is similar in footprint as VarHandle but fully
>compile-time type safe:
>> 
>>
>http://cr.openjdk.java.net/~plevart/misc/valhala-hacks/vaccess/VarAccessor.java
>> 
>> With some tricks (type tokens and manual specialization by
>sub-classing), it can be done as a type-safe wrapper over Unsafe. This
>implementation is missing proper access checks. It's just a proof of
>concept.
>> 
>> While playing with this, I noticed a javac inconsistency. The
>following diamond:
>> 
>> public abstract class VarAccessor<T, any V> {
>> 
>>    private static final Map<Class<?>, BiFunction<Class<?>, String,
>VarAccessor<?, any>>> factories
>>        = new HashMap<>();
>> 
>> ... does not work. I had to re-specify the full types in the HashMap
>constructor:
>> 
>>    private static final Map<Class<?>, BiFunction<Class<?>, String,
>VarAccessor<?, any>>> factories
>>        = new HashMap<Class<?>, BiFunction<Class<?>, String,
>VarAccessor<?, any>>>();
>> 
>> 
>> Regards, Peter
>> 




More information about the valhalla-dev mailing list