Crash with invokeDynamic on MethodMissing attempt

John Rose 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:  
> Bound[<unknown>(java.lang.String)java.lang.String]
> 	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)  
=> String.

That type is derived from MissingHandle.INVOKE minus the initial  
argument.  This is determined by the super call:
       super(INVOKE);

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  
property.

With your posted code, this call:
       site.setTarget(target);

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);

to this:
     CallSite site = new CallSite(caller, name, type);

your code runs (at least for me it does).

-- John
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.openjdk.java.net/pipermail/mlvm-dev/attachments/20090518/010433fd/attachment.html 


More information about the mlvm-dev mailing list