Inserting pre and post-call logic around a handle?

Charles Oliver Nutter headius at headius.com
Thu May 19 14:08:56 PDT 2011


On Thu, May 19, 2011 at 3:53 PM, John Rose <john.r.rose at oracle.com> wrote:
> If you do a fold with a void return, nothing gets inserted into the argument list.
>
> The doc for this needs to be fixed, but the implementation should work now.

Hah...the original subject of my email was "foldArguments with void
return possible?" but I generalized it to get thoughts on the general
structure of my sketch. Excellent, that's what I hoped.

> Your sketch seems good, except that you cannot handle both the return value and the thrown exception in one place.  (API limitation.)  So if your post logic wants to see the return value, you have more work to do.

It should not need to see the return value, but perhaps catchException
will only return what's in the handler as the result of the whole
call? The logic in pre and post is almost completely divorced from the
actual target; it's just twiddling some thread-local state on the way
in and out.

> Suggestion:  Make the direct MH be a free variable, by doing the fancy transform on MethodHandles.exactInvoker(dmh.type()).  That is, instead of mh = T(dmh); mh.invoke(a*); do inv = T(exactInvoker(dmh.type()));  if (?) inv.invokeExact(dmh, a*) else { mh = inv.bindTo(dmh); mh.invoke(a*); }.

I'm not using MethodHandle#invoke* anywhere in JRuby at the
moment...this is all bound through invokedynamic. Let me try to
dissect what you're suggesting here...

My goal in using all handles from call site to target is to get the
whole thing to inline. Are you suggesting doing the above logic in
Java code and binding that as the target, with the MH bound as an
argument to it on a site-by-site basis? That won't inline through the
above logic all the way back to the call site in polymorphic cases,
will it?

Basically, I want the MH chain to contain all pre/post logic in a
try/finally form wrapped around the eventual direct handle, since
ping-ponging through a generalized piece of code for many different
targets would produce a polymorphic MethodHandle#invoke*
call...wouldn't it?

- Charlie


More information about the mlvm-dev mailing list