[jep-334] Asymmetric method types of MHD vs MH
Michael van Acken
michael.van.acken at gmail.com
Tue Nov 20 12:06:25 UTC 2018
While tracking down unexpected behavior in my compiler, I noticed that
MethodHandleDesc and MethodHandle differ in what they list in their
method type. I was expecting that the MHD matches the MH, in that
the receiver of a virtual method is included in the parameter list.
Instead,
it is omitted. (See below for a jshell example.)
As a compiler writer, I find the MH's unified view on static and virtual
method types very helpful. The current implementation's MHD class
does not mirror this view, which means I would have to special case the
method types for some operations.
My mental model of the descriptor classes is, that they are one-to-one
symbolic representations of their handle counterparts. I am very confused
by the difference in structure, with the receiver dropping out of the
method type.
| Welcome to JShell -- Version 12-internal
| For an introduction type: /help intro
jshell> import java.lang.invoke.*
jshell> import java.lang.constant.*
jshell> var l = MethodHandles.lookup()
l ==>
jshell> var mt = MethodType.methodType(Void.TYPE)
mt ==> ()void
jshell> var mh = l.findVirtual(java.io.PrintStream.class, "println", mt)
mh ==> MethodHandle(PrintStream)void
jshell> mh.type()
$6 ==> (PrintStream)void
jshell> mh.type().parameterCount()
$7 ==> 1
jshell> var mhd = (MethodHandleDesc)mh.describeConstable().get()
mhd ==> MethodHandleDesc[VIRTUAL/PrintStream::println()void]
jshell> mhd.methodType()
$9 ==> MethodTypeDesc[()void]
jshell> mhd.methodType().parameterCount()
$10 ==> 0
Regards,
Michael van Acken
More information about the amber-dev
mailing list