Crash with invokeDynamic on MethodMissing attempt
John.Rose at Sun.COM
Mon May 18 15:05:25 PDT 2009
On May 18, 2009, at 2:22 PM, Yehuda Katz wrote:
> I had tried that before; when I do that, I get:
> Exception in thread "main" java.dyn.WrongMethodTypeException:
> at java.dyn.CallSite.checkTarget(CallSite.java:149)
> at java.dyn.CallSite.setTarget(CallSite.java:142)
> at Main$MissingHandle.<init>(Main.java:29)
> at Main.bootstrapDynamic(Main.java:46)
> at sun.dyn.CallSiteImpl.makeSite(CallSiteImpl.java:64)
> at Main.main(Main.java:15)
OK. That's saying that your MissingHandle handle's type is (String)
That type is derived from MissingHandle.INVOKE minus the initial
argument. This is determined by the super call:
But the indy site has a type of (DynamicTester, String) => String:
String ret = InvokeDynamic.<String>unknown(tester, "EXTRA");
So your call site target (whatever it ends up to be) needs to accept a
DynamicTester argument as well. Neither 'this' nor 'target' has that
With your posted code, this call:
should have raised a WMT reporting that target has too many arguments,
not too few, since the target is the static methodNotFound. Its type
is (DynamicTester, String, String) => String, which does not match the
call site either.
It is a bug that this mismatch was not detected by checkTarget, and
the call site was linked to methodNotFound. This will certainly cause
crashy behavior. Note in the backtrace that the call goes through to
your ultimate target (methodNotFound, with three arguments) but only
two of those arguments were stacked by the call site.
In any case, to correct your logic, use setTarget(this), and add the
required DynamicTester argument to MissingHandle.invoke.
Finally (and here's where the crasher bug is) your bootstrap method
which creates a call site for JVM hands it one of the wrong type.
Change this line:
CallSite site = new CallSite(caller, name, newType);
CallSite site = new CallSite(caller, name, type);
your code runs (at least for me it does).
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the mlvm-dev