• Home
    • View
    • Login
    This page
    • Normal
    • Export PDF
    • Page Information

    Loading...
  1. Dashboard
  2. Undefined Space
  3. HotSpot
  4. Method handle invocation

Method handle invocation

  • Created by John Rose, last modified on Aug 12, 2013

Method handle invocation

Method handles have several modes of invocation, involving various degrees of type checking and conversion.

Every method handle invocation takes into account two independent sources of type information.  The caller (whose call site is invoking the method handle) specifies the caller method type implicitly by the choice of the call descriptor in the call site bytecode.  The callee (i.e., the method handle being invoked) has its own callee method type, which is simply its MethodHandle.type property.

The possible modes of method handle invocation include:

  • Exact invocation:  The invokeExact method requires the caller and callee method types to have identical components.  This method is public, safe, and signature-polymorphic.
  • Generic invocation: The generic invoke method allows the caller and callee method types to differ, as long as the callee can be viewed under the caller type, using the asType method.  As a consequence, this mode offers on-the-fly argument and return conversions. This method is public, safe, and signature-polymorphic.
  • Varargs invocation: The overloaded invokeWithArguments method allow an arbitrary varargs array or list of untyped arguments to be applied to a callee, and the call succeeds as long as the callee can be viewed under an implied caller type determined as if by MethodType.genericType.  This method is public.
  • Basic invocation: The invokeBasic method requires that the caller and callee method types have corresponding components, but uses "basic type" matching, which allows any reference to match any other reference.  Because there is no runtime check for matching types, this method must be used carefully.  It is used by trusted code to implement the other invocation modes.  This method is non-public and signature-polymorphic.  The JVM implementation treats it very specially.
  • Invokedynamic invocation: The invokedynamic instruction implicitly performs an exact invocation on the target of its resolved call site.  (Unlike the other modes, the callee is not visible as a receiver on the JVM expression stack.)  Because the system ensures that all call site targets have pre-checked callee method types, the system may use basic invocation as an implementation option.

In addition, method handles can be viewed by various transforms that change their apparent type, and hence their acceptable invocation types and modes:

  • Retyping view: A method handle can be viewed as a range of other compatible callee method types.  The view methods, asType and explicitCastArguments, are public.  Allowable conversions are drawn from those natural either to the Java language (on erased types only) or to the JVM itself.  The explicitCastArguments view allows some conversions not permitted by the asType view, such as narrowing primitive casts.
  • Spread view: A method handle can be viewed as if it accepts a varargs-like array of trailing arguments.  The view method, asSpreader, is public.  The array can be of any element type.
  • Collecting view: A method handle which accepts a trailing array argument can be viewed as if it takes those arguments positionally.  Either a fixed or variable number of positional arguments are acceptable.  The view methods, asCollector and asVarargsCollector, are public.  The array can be of any element type.
  • Other transforms, such as for argument permutation or binding, may also be considered as method handle views.

Exact invocation

discuss

Generic invocation

discuss

Varargs invocation

discuss

Basic invocation

discuss

Overview
Content Tools
ThemeBuilder
  • No labels

Terms of Use
• License: GPLv2
• Privacy • Trademarks • Contact Us

Powered by a free Atlassian Confluence Open Source Project License granted to https://www.atlassian.com/software/views/opensource-community-additional-license-offer. Evaluate Confluence today.

  • Kolekti ThemeBuilder Powered by Atlassian Confluence 8.5.21
  • Kolekti ThemeBuilder printed.by.atlassian.confluence
  • Report a bug
  • Atlassian News
Atlassian
Kolekti ThemeBuilder EngineAtlassian Confluence
{"serverDuration": 173, "requestCorrelationId": "36bfb4aa0704e557"}