RFR: 8254354: Add an asExact() VarHandle combinator [v2]
Jorn Vernee
jvernee at openjdk.java.net
Mon Oct 26 18:57:44 UTC 2020
On Mon, 26 Oct 2020 17:13:05 GMT, Rémi Forax <github.com+828220+forax at openjdk.org> wrote:
>> We can clarify the new methods and tie them closer to method handle semantics. I suggest the names `asExactInvoker` and `asInvoker`, referencing `MethodHandles.exactInvoker` and `MethodHandles.invoker` respectively. (The term "generic" is really reserved for erased method types, and otherwise used internally as the generic invoker.)
>>
>> The `VarHandle` documentation already specifies that:
>>
>> * <p>
>> * Invocation of an access mode method behaves as if an invocation of
>> * {@link MethodHandle#invoke}, where the receiving method handle accepts the
>> * VarHandle instance as the leading argument. More specifically, the
>> * following, where {@code {access-mode}} corresponds to the access mode method
>> * name:
>> * <pre> {@code
>> * VarHandle vh = ..
>> * R r = (R) vh.{access-mode}(p1, p2, ..., pN);
>> * }</pre>
>> * behaves as if:
>> * <pre> {@code
>> * VarHandle vh = ..
>> * VarHandle.AccessMode am = VarHandle.AccessMode.valueFromMethodName("{access-mode}");
>> * MethodHandle mh = MethodHandles.varHandleExactInvoker(
>> * am,
>> * vh.accessModeType(am));
>> *
>> * R r = (R) mh.invoke(vh, p1, p2, ..., pN)
>> * }</pre>
>> * (modulo access mode methods do not declare throwing of {@code Throwable}).
>> ...
>>
>> We will need to adjust this section, i can help, but first let us reach agreement on this approach.
>
> Paul,
> an invoker has the MethodHandle (resp. VarHandle) as first argument so it's not the same semantics.
I've updated the implementation of accessModeType to work with the ordinal directly. Note that it was using the AccessType ordinal though, so I also had to change the parameter type of accessModeTypeUncached, and the respective implementations, to use AccessType directly (luckily this was possible, since the current implementations all just used the AccessType).
-------------
PR: https://git.openjdk.java.net/jdk/pull/843
More information about the core-libs-dev
mailing list