8016569: javac, add new flag for polymorphic method signatures

Fri, 14 Jun 2013 16:25:09 +0100

author
vromero
date
Fri, 14 Jun 2013 16:25:09 +0100
changeset 1820
6b48ebae2569
parent 1819
7fe655cad9b1
child 1821
1936a884b290

8016569: javac, add new flag for polymorphic method signatures
Reviewed-by: jjg
Contributed-by: maurizio.cimadamore@oracle.com

src/share/classes/com/sun/tools/javac/code/Flags.java file | annotate | diff | comparison | revisions
src/share/classes/com/sun/tools/javac/code/Symbol.java file | annotate | diff | comparison | revisions
src/share/classes/com/sun/tools/javac/code/Types.java file | annotate | diff | comparison | revisions
src/share/classes/com/sun/tools/javac/comp/Attr.java file | annotate | diff | comparison | revisions
src/share/classes/com/sun/tools/javac/comp/Check.java file | annotate | diff | comparison | revisions
src/share/classes/com/sun/tools/javac/comp/MemberEnter.java file | annotate | diff | comparison | revisions
src/share/classes/com/sun/tools/javac/comp/Resolve.java file | annotate | diff | comparison | revisions
src/share/classes/com/sun/tools/javac/jvm/ClassReader.java file | annotate | diff | comparison | revisions
     1.1 --- a/src/share/classes/com/sun/tools/javac/code/Flags.java	Tue Jun 11 09:59:34 2013 +0100
     1.2 +++ b/src/share/classes/com/sun/tools/javac/code/Flags.java	Fri Jun 14 16:25:09 2013 +0100
     1.3 @@ -278,6 +278,11 @@
     1.4       */
     1.5      public static final long BAD_OVERRIDE = 1L<<45;
     1.6  
     1.7 +    /**
     1.8 +     * Flag that indicates a signature polymorphic method (292).
     1.9 +     */
    1.10 +    public static final long SIGNATURE_POLYMORPHIC = 1L<<46;
    1.11 +
    1.12      /** Modifier masks.
    1.13       */
    1.14      public static final int
     2.1 --- a/src/share/classes/com/sun/tools/javac/code/Symbol.java	Tue Jun 11 09:59:34 2013 +0100
     2.2 +++ b/src/share/classes/com/sun/tools/javac/code/Symbol.java	Fri Jun 14 16:25:09 2013 +0100
     2.3 @@ -1537,25 +1537,6 @@
     2.4                      getKind() == ElementKind.INSTANCE_INIT;
     2.5          }
     2.6  
     2.7 -        /**
     2.8 -         * A polymorphic signature method (JLS SE 7, 8.4.1) is a method that
     2.9 -         * (i) is declared in the java.lang.invoke.MethodHandle class, (ii) takes
    2.10 -         * a single variable arity parameter (iii) whose declared type is Object[],
    2.11 -         * (iv) has a return type of Object and (v) is native.
    2.12 -         */
    2.13 -        public boolean isSignaturePolymorphic(Types types) {
    2.14 -            List<Type> argtypes = type.getParameterTypes();
    2.15 -            Type firstElemType = argtypes.nonEmpty() ?
    2.16 -                    types.elemtype(argtypes.head) :
    2.17 -                    null;
    2.18 -            return owner == types.syms.methodHandleType.tsym &&
    2.19 -                    argtypes.length() == 1 &&
    2.20 -                    firstElemType != null &&
    2.21 -                    types.isSameType(firstElemType, types.syms.objectType) &&
    2.22 -                    types.isSameType(type.getReturnType(), types.syms.objectType) &&
    2.23 -                    (flags() & NATIVE) != 0;
    2.24 -        }
    2.25 -
    2.26          public Attribute getDefaultValue() {
    2.27              return defaultValue;
    2.28          }
     3.1 --- a/src/share/classes/com/sun/tools/javac/code/Types.java	Tue Jun 11 09:59:34 2013 +0100
     3.2 +++ b/src/share/classes/com/sun/tools/javac/code/Types.java	Fri Jun 14 16:25:09 2013 +0100
     3.3 @@ -951,6 +951,22 @@
     3.4      }
     3.5  
     3.6      /**
     3.7 +    * A polymorphic signature method (JLS SE 7, 8.4.1) is a method that
     3.8 +    * (i) is declared in the java.lang.invoke.MethodHandle class, (ii) takes
     3.9 +    * a single variable arity parameter (iii) whose declared type is Object[],
    3.10 +    * (iv) has a return type of Object and (v) is native.
    3.11 +    */
    3.12 +   public boolean isSignaturePolymorphic(MethodSymbol msym) {
    3.13 +       List<Type> argtypes = msym.type.getParameterTypes();
    3.14 +       return (msym.flags_field & NATIVE) != 0 &&
    3.15 +               msym.owner == syms.methodHandleType.tsym &&
    3.16 +               argtypes.tail.tail == null &&
    3.17 +               argtypes.head.hasTag(TypeTag.ARRAY) &&
    3.18 +               msym.type.getReturnType().tsym == syms.objectType.tsym &&
    3.19 +               ((ArrayType)argtypes.head).elemtype.tsym == syms.objectType.tsym;
    3.20 +   }
    3.21 +
    3.22 +    /**
    3.23       * Is t the same type as s?
    3.24       */
    3.25      public boolean isSameType(Type t, Type s) {
     4.1 --- a/src/share/classes/com/sun/tools/javac/comp/Attr.java	Tue Jun 11 09:59:34 2013 +0100
     4.2 +++ b/src/share/classes/com/sun/tools/javac/comp/Attr.java	Fri Jun 14 16:25:09 2013 +0100
     4.3 @@ -3405,7 +3405,7 @@
     4.4                       Env<AttrContext> env,
     4.5                       ResultInfo resultInfo) {
     4.6              boolean isPolymorhicSignature =
     4.7 -                sym.kind == MTH && ((MethodSymbol)sym.baseSymbol()).isSignaturePolymorphic(types);
     4.8 +                (sym.baseSymbol().flags() & SIGNATURE_POLYMORPHIC) != 0;
     4.9              return isPolymorhicSignature ?
    4.10                      checkSigPolyMethodId(tree, site, sym, env, resultInfo) :
    4.11                      checkMethodIdInternal(tree, site, sym, env, resultInfo);
     5.1 --- a/src/share/classes/com/sun/tools/javac/comp/Check.java	Tue Jun 11 09:59:34 2013 +0100
     5.2 +++ b/src/share/classes/com/sun/tools/javac/comp/Check.java	Fri Jun 14 16:25:09 2013 +0100
     5.3 @@ -909,7 +909,7 @@
     5.4                                    "unchecked.generic.array.creation",
     5.5                                    argtype);
     5.6              }
     5.7 -            if (!((MethodSymbol)sym.baseSymbol()).isSignaturePolymorphic(types)) {
     5.8 +            if ((sym.baseSymbol().flags() & SIGNATURE_POLYMORPHIC) == 0) {
     5.9                  TreeInfo.setVarargsElement(env.tree, types.elemtype(argtype));
    5.10              }
    5.11           }
     6.1 --- a/src/share/classes/com/sun/tools/javac/comp/MemberEnter.java	Tue Jun 11 09:59:34 2013 +0100
     6.2 +++ b/src/share/classes/com/sun/tools/javac/comp/MemberEnter.java	Fri Jun 14 16:25:09 2013 +0100
     6.3 @@ -560,6 +560,10 @@
     6.4              chk.setDeferredLintHandler(prevLintHandler);
     6.5          }
     6.6  
     6.7 +        if (types.isSignaturePolymorphic(m)) {
     6.8 +            m.flags_field |= SIGNATURE_POLYMORPHIC;
     6.9 +        }
    6.10 +
    6.11          // Set m.params
    6.12          ListBuffer<VarSymbol> params = new ListBuffer<VarSymbol>();
    6.13          JCVariableDecl lastParam = null;
     7.1 --- a/src/share/classes/com/sun/tools/javac/comp/Resolve.java	Tue Jun 11 09:59:34 2013 +0100
     7.2 +++ b/src/share/classes/com/sun/tools/javac/comp/Resolve.java	Fri Jun 14 16:25:09 2013 +0100
     7.3 @@ -2267,7 +2267,7 @@
     7.4                      sym = super.access(env, pos, location, sym);
     7.5                  } else if (allowMethodHandles) {
     7.6                      MethodSymbol msym = (MethodSymbol)sym;
     7.7 -                    if (msym.isSignaturePolymorphic(types)) {
     7.8 +                    if ((msym.flags() & SIGNATURE_POLYMORPHIC) != 0) {
     7.9                          return findPolymorphicSignatureInstance(env, sym, argtypes);
    7.10                      }
    7.11                  }
     8.1 --- a/src/share/classes/com/sun/tools/javac/jvm/ClassReader.java	Tue Jun 11 09:59:34 2013 +0100
     8.2 +++ b/src/share/classes/com/sun/tools/javac/jvm/ClassReader.java	Fri Jun 14 16:25:09 2013 +0100
     8.3 @@ -1985,6 +1985,9 @@
     8.4                                        syms.methodClass);
     8.5          }
     8.6          MethodSymbol m = new MethodSymbol(flags, name, type, currentOwner);
     8.7 +        if (types.isSignaturePolymorphic(m)) {
     8.8 +            m.flags_field |= SIGNATURE_POLYMORPHIC;
     8.9 +        }
    8.10          if (saveParameterNames)
    8.11              initParameterNames(m);
    8.12          Symbol prevOwner = currentOwner;

mercurial