MethodHandles for Kawa and other functional languages?

John Rose john.r.rose at oracle.com
Wed Sep 29 18:08:59 PDT 2010


On Sep 29, 2010, at 5:00 PM, Per Bothner wrote:

> Fundamentally, the question is: When the Scheme programmer passes
> of function to a higher-level function (like map), what is the type
> of the object passed: A MethodHandle?  A Procedure?  Something else?
> There seem to be different kind of MethodHandles, so perhaps something
> is appropriate.  Is there some blog article or cookbook discussing this?

Quick answer to your next-to-last question:  The language-specific APIs should use their own interfaces or classes, so continue to use Procedure.  But if and when you go to JSR 292 API's you need to convert to the MH type.  The MethodHandleProvider (aka MethodHandleBox) interface is supposed to make this process more regular.

For example, an invokedynamic bootstrap method (binding a Scheme call site) needs to return either a CallSite wrapped around a method handle (if it is to be rebindable) or a MethodHandle (if not).  In either case, you'll want to convert your Procedure down to a MH when binding it to an invokedynamic call site.

Your internal field Procedure.mh field might be made lazy or even virtualized away, as long as MHP.asMethodHandle does something reasonable for every individual Procedure.  It depends on how or whether you want to use polymorphism in the Procedure type, or whether you want to do all the polymorphism through method handles.  At a minimum, you'll want to make out-calls to random Java methods through method handles, instead of through reflection or thousands of inner classes.

By the way, the usefulness (or not) of MHP is a matter of debate on the JSR 292 EG, so I'm eager for insights.

Also, I will read your message over in more detail.

-- John


More information about the mlvm-dev mailing list