[9] RFR (S): 8036117: MethodHandles.catchException doesn't handle VarargsCollector right (8034120 failed)

Christian Thalinger christian.thalinger at oracle.com
Sat Mar 8 00:51:17 UTC 2014

Seems good to me.  I’d like to have another name for this method:

+     private static Object invokeCustom(MethodHandle target, Object... args) throws Throwable {

On Mar 4, 2014, at 12:00 PM, Vladimir Ivanov <vladimir.x.ivanov at oracle.com> wrote:

> http://cr.openjdk.java.net/~vlivanov/8036117/webrev.00/
> https://bugs.openjdk.java.net/browse/JDK-8036117
> 84 lines changed: 74 ins; 3 del; 7 mod
> I have to revert a cleanup I did for 8027827. 
> MethodHandle.invokeWithArguments (and generic invocation) has unpleasant 
> peculiarity in behavior when used with VarargsCollector. So, 
> unfortunately, invokeWithArguments is not an option there.
> Looking at the API (excerpts from javadoc [1] [2]), the following 
> condition doesn't hold in that case:
>   "trailing parameter type of the caller is a reference type identical 
> to or assignable to the trailing parameter type of the adapter".
> Example:
>   target.invokeWithArguments((Object[])args)
>   =>
>   target.invoke((Object)o1,(Object)o2,(Object)o3)
>   =/>
>   target.invokeExact((Object)o1, (Object)o2, (Object[])o3)
> because Object !<: Object[].
> The fix is to skip unnecessary conversion when invoking a method handle 
> and just do a pairwise type conversion.
> Testing: failing test case, nashorn w/ experimental features (octane)
> Thanks!
> Best regards,
> Vladimir Ivanov
> [1] MethodHandle.invokeWithArguments
> "Performs a variable arity invocation, ..., as if via an inexact invoke 
> from a call site which mentions only the type Object, and whose arity is 
> the length of the argument array."
> [2] MethodHandle.asVarargsCollector
> "When called with plain, inexact invoke, if the caller type is the same 
> as the adapter, the adapter invokes the target as with invokeExact. 
> (This is the normal behavior for invoke when types match.)
> Otherwise, if the caller and adapter arity are the same, and the 
> trailing parameter type of the caller is a reference type identical to 
> or assignable to the trailing parameter type of the adapter, the 
> arguments and return values are converted pairwise, as if by asType on a 
> fixed arity method handle.
> Otherwise, the arities differ, or the adapter's trailing parameter type 
> is not assignable from the corresponding caller type. In this case, the 
> adapter replaces all trailing arguments from the original trailing 
> argument position onward, by a new array of type arrayType, whose 
> elements comprise (in order) the replaced arguments."
> _______________________________________________
> mlvm-dev mailing list
> mlvm-dev at openjdk.java.net
> http://mail.openjdk.java.net/mailman/listinfo/mlvm-dev

More information about the core-libs-dev mailing list