I just came across an Hotspot internals wiki on MethodHandles and invokedynamic
It makes a few interesting points that answer these questions (and a few more).
- What is called compiler-generated overloads in the question, the java guys call signature polymorphic.
MethodHandle.invokeExact
and friends are unique, being the only signature polymorphic methods.- On the HotSpot VM, the
invokevirtual
bytecode for MethodHandle.invoke* is secretly converted to aninvokehandle
instruction.invokehandle
is likeinvokedynamic
; a few internals are different, and where eachinvokedynamic
instruction must point to it's own Constant Pool Cache Entry (CPCE),invokehandle
s can share CPCEs.
invokedynamic
uses the non-publicMethodHandle.invokeBasic
on the HotSpot VMMethodHandle.invokeBasic
is like invokeExact but more loose; for one it does not check the types of at the call-site with those of the callee.
- Hot method handles (including
invokedynamic
) can be JIT-compiled
Additionally, lambda expressions will be implemented via invokedynamic
. (Got that from Edwin Dalorzo's answer.) This means lambda expressions
- will indirectly use
MethodHandle.invokeBasic
on the HotSpot VM (see above), and - are eligible to be JIT-compiled