Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8024761

JSR 292 improve performance of generic invocation

    XMLWordPrintable

Details

    • b112
    • Not verified

    Description

      The performance of MethodHandle.invoke is very slow when the call site type differs from the method handle type. When the types differ, the invocation is defined to proceed as if two steps were taken:

      1. the target method handle is first adjusted to the call site type, by MethodHandles.asType

      2. the type-adjusted method handle is invoked directly, by MethodHandles.invokeExact

      The existing code (from JDK 7) awkwardly performs the type adjustment on every call. But performing the type analysis and adapter creation on every call is inherently slow. A good fix is to cache the result of step 1 (MethodHandles.asType), since step 2 is already reasonably fast.

      For most applications, a one-element cache on each individual method handle is a reasonable choice. It has the particular advantage of speeding up invocations of non-varargs bootstrap methods. To benefit from this, the bootstrap methods themselves need to be uniquified across multiple class files, so this work will also include a cache to benefit commonly-used bootstrap methods, such as JDK 8's LambdaMetafactory.metafactory.

      Additional caches could be based on the call site, the call site type, the target type, or the target's MH.form.

      Attachments

        Issue Links

          Activity

            People

              jrose John Rose
              jrose John Rose
              Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: