On invoke dynamic and method handles
Iulian Dragos
jaguarul at gmail.com
Wed Dec 17 10:44:14 PST 2008
I noticed several differences between what JSR 292
(http://jcp.org/en/jsr/detail?id=292) says and the current
implementation. I know this is work in progress, but at least one
difference seems small enough to be an oversight.
The signature of the bootstrap method is defined as Object(CallSite
cs, Object... args) in code, but the JSR lists it as Object(CallSite
cs, Object receiver, Object... args). The latter has a great
advantage: the arguments are already prepared for a reflective call.
The contract of 'bootstrap' is that it makes the call and returns a
value, possibly setting a target for future calls. In the current
implementation, one would have to create a new array and strip the
first element:
cs.setTarget(mh);
Object[] args1 = new Object[args.length - 1];
System.arraycopy(args, 1, args1, 0, args.length - 1);
return rm.invoke(args[0], args1);
I find this to be a typical scenario, so I wonder why this deviation
from the JSR.
A second question: Is there a way to invoke a method handle
generically? That means by passing an Object array, as done above
using java.lang.reflect.Method. In other words, could method handles
be used in the bootstrap method instead of reflect.Method?
Thanks,
Iulian
--
« Je déteste la montagne, ça cache le paysage »
Alphonse Allais
More information about the mlvm-dev
mailing list