Few questions about invokeDynamic
Rémi Forax
forax at univ-mlv.fr
Mon Nov 8 14:46:50 PST 2010
Le 08/11/2010 20:52, assembling signals a écrit :
> Ok, I extended my "benchmark" to support a method handle with spread args,
> and this part slower than everything else :(
>
No chance.
> Note: I use Object[] for spread arguments, because in my real-world scenario,
> as mentioned before, I would need any possible method signature to work.
>
You can also use invokedynamic and linked to the spread
version of the method handle.
But sadly, it crashes the VM.
The test case below reproduces the bug.
Rémi
-------------------------------------------------------------------------------
import java.dyn.CallSite;
import java.dyn.InvokeDynamic;
import java.dyn.Linkage;
import java.dyn.MethodHandle;
import java.dyn.MethodHandles;
import java.dyn.MethodType;
public class IndySpreadBug {
public static void main(String[] args) throws Throwable {
for(int i=0; i<1000000; i++) {
InvokeDynamic.foo(new Object[]{2,3});
}
}
private static void foo(int i, int j) {
//System.out.println(i + " " + j);
}
private static CallSite bootstrap(Class<?> declaring, String name,
MethodType type) throws Throwable {
CallSite cs = new CallSite();
MethodHandle mh =
MethodHandles.lookup().findStatic(IndySpreadBug.class, "foo",
MethodType.methodType(void.class, int.class, int.class));
mh = MethodHandles.spreadArguments(mh, type);
cs.setTarget(mh);
return cs;
}
static {
Linkage.registerBootstrapMethod("bootstrap");
}
}
More information about the mlvm-dev
mailing list