On 01/30/2011 09:08 AM, John Rose wrote:
On Jan 29, 2011, at 11:40 PM, Kirill Shirokov wrote:
The invokedynamic instruction requires a MethodHandle constant pool
entry for a bootstrap method.
This MH CP entry can be one of 9 REF_xxx types.
Questions:
Q1. Which types are valid in the case of bootstrap method?
Any CONSTANT_MethodHandle for which the resulting MH can accept an
invokeGeneric call on the specified methods, which returns a CallSite.
Q2. What happens if I try to use invalid types?
The MH will be materialized for the BSM, and the invokeGeneric call
will fail, either with WMTE or CCE. This is an implication of the
specification. Some of the details are spelled out here in the javadoc:
After resolution, the linkage process may fail in a variety of ways.
All failures are reported by an BootstrapMethodError, which is thrown
as the abnormal termination of the dynamic call site execution.
The following circumstances will cause this:
• the index to the bootstrap method specifier is out of range
• the bootstrap method cannot be resolved
• the MethodType to pass to the bootstrap method cannot be resolved
• a static argument to the bootstrap method cannot be resolved (i.e.,
a CONSTANT_Class, CONSTANT_MethodType, orCONSTANT_MethodHandle argument cannot
be linked)
• the bootstrap method has the wrong arity, causing invokeGeneric to
throw WrongMethodTypeException
• the bootstrap method has a wrong argument or return type
• the bootstrap method invocation completes abnormally
• the result from the bootstrap invocation is not a reference to an
object of type CallSite
• the target of the CallSite does not have a target of the
expected MethodType
I could not find answers in the current specification.
Since we're editing it furiously, maybe you looked at an earlier spec.
which didn't have the language above.
I guess that the correct answers would be:
A1. The valid types are: REF_getStatic, REF_invokeStatic (? and maybe
REF_newInvokeSpecial). All others are invalid for bootstraping.
Not getstatic. That is always a zero-arity method, which will not
accept the 3 or more arguments passed to the BSM.
Yes, invokestatic and newinvokespecial are the key use cases.
Since the Lookup object comes first in the list, if the Lookup class
had a method which could accept a name and type and then return a call
site, that would work also, as a REF_invokevirtual. But there is no
such method.
And Lookup is final.
A2. If the type is invalid, JVM throws an exception (and doesn't try to
call bootstrap MH taking arguments from Java stack)
It tries to call the MH, and immediately fails. The failure is
wrapped in a bootstrap method error, which is thrown.
If the failure is an error (a subtype of Error), should it wrapped too ?
The backport doesn't wrap errors.
Good questions. Thanks.
-- John
Rémi
_______________________________________________
mlvm-dev mailing list
[email protected]
http://mail.openjdk.java.net/mailman/listinfo/mlvm-dev