Few questions about invokeDynamic
forax at univ-mlv.fr
Sat Nov 6 08:13:45 PDT 2010
Le 06/11/2010 11:31, assembling signals a écrit :
> Hello, everyone!
> I couldn't find information about several issues, so I'll ask here for help:
> I'm using JDK7 b116.
> When using MethodHandle.invokeExact(...), I can only invoke a method,
> which signature is "Object (Object)", anything else fails with:
> WrongMethodTypeException: ()V cannot be called as ([Ljava/lang/Object;)Ljava/lang/Object;
MethodHandle unlike reflection doesn't require to box arguments in an array.
Moreover, invokeExact only works if the method handle's type is the same as
the one process by the compiler using the declared type of the parameter.
MethodHandle mh = ...
expects that mh.type is double(int,int).
You should use invokeGeneric instead of invokeExact if you want Java
> Doing it with invokeVarargs(...) works, but a benchmark showed that it is nearly as slow
> as good old Java reflection (Method.invoke(...)), which is around 50 times slower than normal method invocation.
Yes, it's as fast :)
> In contrast, using the language feature "InvokeDynamic.<void>anything();" is just 2.5 times slower
> than usual method invocation. So my assumption is just that invokeVarargs is slow because of varargs,
> and invokeExact should be as fast as InvokeDynamic.<...>(...) syntax, but since it fails, I can't know.
invokedynamic should be faster than MH.invokeExact because invokedynamic
to check the type at each invocation but once when you call
> So my questions are:
> 1) is that just a bug that invokeExact fails with anything but Object (Object)?
No, invokeExact require to be called with exactly the same signature
(bit to bit :)
that the signature of the method handle.
So if you create a method handle on a static method int foo(int,int),
takes two ints and returns an int.
(int)mh.invokeExact(2,3) will works.
Not that the cast is not a real cast but a hint to the compiler that it
will returns an int.
> 2) is my assumption correct that normally invokeExact should be as fast as InvokeDynamic.<...>(...)?
just a little slower. (see below)
> 3) Is there a tentative timeline about the progress of MLVM in JDK7, or at least when could
> one expect invokeExact to "work"?
it works :)
> Note: I can't use InvokeDynamic.<...>(...) for method-signatures known only at runtime,
> that's why I need invokeExact.
> Thank you very much in advance!
> Best regards,
> Ivan G S
More information about the mlvm-dev