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

LambdaMetafactory: standardize supported type conversions

    Details

      Description

      The conversions allowed by LambdaMetafactory on parameter and return types are ad hoc and inconsistent with the specification.

      Propose standardizing on the conversions supported by MethodHandle.asType, which are similar but a little more flexible.

      Specifically:

      invokedType.parameterType(i) --> implMethod.type().parameterType(i)
      Currently: same type (but receiver can be a subtype)
      Change: allow any 'asType' conversion, including boxing & unboxing

      instantiatedMethodType.parameterType(i) --> implMethod.type().parameterType(j)
      Currently: ref subtype, prim widening, or box/unbox followed by these (but receiver can't be boxed)
      Change: allow conversion between arbitrary refs; allow narrowing from a supertype before unbox; allow receiver to be boxed

      samMethodType.parameterType(i) --> instantiatedMethodType.parameterType(i)
      Currently: ref supertype, prim same
      Change: allow any 'asType' conversion, including boxing & unboxing

      implMethod.type().returnType() --> instantiatedMethodType.returnType()
      Currently: any type targeting void, arbitrary refs, prim widening, box+widening, unbox+widening*
      Change: allow void to target a non-void type; allow narrowing from a supertype before unbox

      instantiatedMethodType.returnType() --> samMethodType.returnType()
      Currently: void->void, ref subtype, prim widening, box+widening, unbox+widening
      Change: allow either to be void; allow conversion between arbitrary refs; allow narrowing from a supertype before unbox

      (*Current implementation allows any reference-typed implMethod return to be compatible with any expected primitive type, as long as the reference type is not a box type (if it is a box type, unbox+widening applies). This is probably a bug.)

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                dlsmith Dan Smith
                Reporter:
                dlsmith Dan Smith
              • Votes:
                0 Vote for this issue
                Watchers:
                3 Start watching this issue

                Dates

                • Created:
                  Updated: