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

Avoid rebinds in MethodHandle.viewAsType

    XMLWordPrintable

Details

    Description

      In the current implementation MethodHandle.viewAsType eagerly rebinds when creating a view of a method type as an alternative type:

          MethodHandle viewAsType(MethodType newType, boolean strict) {
              MethodHandle mh = rebind();
              return this.copyWith(newType, mh.form);
          }

      This prevents exposing uncrackable DMHs, ie, ones where calling Lookup.revealDirect(mh) would not produce a correct MethodHandleInfo.

      If we restructure this so that crackability is a property on the DMH, we can avoid the rebinds:

      http://cr.openjdk.java.net/~redestad/scratch/constructor_withType.03/

      This improves overhead slightly when calling MH.asType with a "viewable" type (one where all parameters in the new type can be assigned without transforms to parameters in the old; and return in the old can be assigned without transforms in the new).

      Since the Hidden Classes JEP this means a small startup gain for capturing lambdas. Might also benefit VarHandle bootstrap costs.

      Attachments

        Activity

          People

            redestad Claes Redestad
            redestad Claes Redestad
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: