RFC: Refactoring SystemABI
Jorn Vernee
jbvernee at xs4all.nl
Fri Nov 23 14:14:17 UTC 2018
> What you describe is possible, but requires a field access/method call
> on every upcall (to get the method handle).
I'm not sure what you mean? We get the target MethodHandle as an
argument and then we create the prefixed MethodHandle like:
prefixed = collectArguments(INVOKE.bindTo(this), 0,
UPCALL_CONTEXT_CONSTRUCTOR);
Where INVOKE is the invoke method of the used UpcallHandler, and
UPCALL_CONTEXT_CONSTRUCTOR is the constructor of
UniversalUpcallHandler.UpcallContext.
The prefix and original target are both stored in @Stable fields, and
the UniversalUpcallHandler code calls the original target like it's
doing now (but dropping the receiver argument of course). So there
should be no change there.
What changes on the native side is; instead of calling the static
UniversalUpcallHandler::invoke, which creates a an UpcallContext and
then calls the virtual UniversalUpcallHandler::invoke method. It calls
the prefixed MethodHandle instead. You go from a static call to a
virtual call on the native side, but a virtual call was already
happening any ways just on the Java side, so it's just moved.
> So, with regular API this cannot be done, although I suspect Hotspot
> gurus might have some internal way to do this (?)
I was wondering as well how that works work with invokeExact since
that's @SignaturePolymorphic. But surely there is a way to call method
handles from VM code as well?
Jorn
Maurizio Cimadamore schreef op 2018-11-23 14:59:
> On 23/11/2018 13:51, Maurizio Cimadamore wrote:
>> plus I'm not sure how we can effectively invoke a MH from native code.
>
> Some excerpts from JDK javadocs on MethodHandle::invokeXYZ methods
>
> * When this method is observed via the Core Reflection API,
> * it will appear as a single native method, taking an object
> array and returning an object.
> * If this native method is invoked directly via
> * {@link java.lang.reflect.Method#invoke
> java.lang.reflect.Method.invoke}, via JNI,
> * or indirectly via {@link
> java.lang.invoke.MethodHandles.Lookup#unreflect Lookup.unreflect},
> * it will throw an {@code UnsupportedOperationException}.
>
> So, with regular API this cannot be done, although I suspect Hotspot
> gurus might have some internal way to do this (?)
>
> Maurizio
More information about the panama-dev
mailing list