8016569: javac, add new flag for polymorphic method signatures
authorvromero
Fri, 14 Jun 2013 16:25:09 +0100
changeset 18389 a425d0819f36
parent 18388 7d67f9206d8f
child 18390 f5cad700f200
8016569: javac, add new flag for polymorphic method signatures Reviewed-by: jjg Contributed-by: maurizio.cimadamore@oracle.com
langtools/src/share/classes/com/sun/tools/javac/code/Flags.java
langtools/src/share/classes/com/sun/tools/javac/code/Symbol.java
langtools/src/share/classes/com/sun/tools/javac/code/Types.java
langtools/src/share/classes/com/sun/tools/javac/comp/Attr.java
langtools/src/share/classes/com/sun/tools/javac/comp/Check.java
langtools/src/share/classes/com/sun/tools/javac/comp/MemberEnter.java
langtools/src/share/classes/com/sun/tools/javac/comp/Resolve.java
langtools/src/share/classes/com/sun/tools/javac/jvm/ClassReader.java
--- a/langtools/src/share/classes/com/sun/tools/javac/code/Flags.java	Tue Jun 11 09:59:34 2013 +0100
+++ b/langtools/src/share/classes/com/sun/tools/javac/code/Flags.java	Fri Jun 14 16:25:09 2013 +0100
@@ -278,6 +278,11 @@
      */
     public static final long BAD_OVERRIDE = 1L<<45;
 
+    /**
+     * Flag that indicates a signature polymorphic method (292).
+     */
+    public static final long SIGNATURE_POLYMORPHIC = 1L<<46;
+
     /** Modifier masks.
      */
     public static final int
--- a/langtools/src/share/classes/com/sun/tools/javac/code/Symbol.java	Tue Jun 11 09:59:34 2013 +0100
+++ b/langtools/src/share/classes/com/sun/tools/javac/code/Symbol.java	Fri Jun 14 16:25:09 2013 +0100
@@ -1537,25 +1537,6 @@
                     getKind() == ElementKind.INSTANCE_INIT;
         }
 
-        /**
-         * A polymorphic signature method (JLS SE 7, 8.4.1) is a method that
-         * (i) is declared in the java.lang.invoke.MethodHandle class, (ii) takes
-         * a single variable arity parameter (iii) whose declared type is Object[],
-         * (iv) has a return type of Object and (v) is native.
-         */
-        public boolean isSignaturePolymorphic(Types types) {
-            List<Type> argtypes = type.getParameterTypes();
-            Type firstElemType = argtypes.nonEmpty() ?
-                    types.elemtype(argtypes.head) :
-                    null;
-            return owner == types.syms.methodHandleType.tsym &&
-                    argtypes.length() == 1 &&
-                    firstElemType != null &&
-                    types.isSameType(firstElemType, types.syms.objectType) &&
-                    types.isSameType(type.getReturnType(), types.syms.objectType) &&
-                    (flags() & NATIVE) != 0;
-        }
-
         public Attribute getDefaultValue() {
             return defaultValue;
         }
--- a/langtools/src/share/classes/com/sun/tools/javac/code/Types.java	Tue Jun 11 09:59:34 2013 +0100
+++ b/langtools/src/share/classes/com/sun/tools/javac/code/Types.java	Fri Jun 14 16:25:09 2013 +0100
@@ -951,6 +951,22 @@
     }
 
     /**
+    * A polymorphic signature method (JLS SE 7, 8.4.1) is a method that
+    * (i) is declared in the java.lang.invoke.MethodHandle class, (ii) takes
+    * a single variable arity parameter (iii) whose declared type is Object[],
+    * (iv) has a return type of Object and (v) is native.
+    */
+   public boolean isSignaturePolymorphic(MethodSymbol msym) {
+       List<Type> argtypes = msym.type.getParameterTypes();
+       return (msym.flags_field & NATIVE) != 0 &&
+               msym.owner == syms.methodHandleType.tsym &&
+               argtypes.tail.tail == null &&
+               argtypes.head.hasTag(TypeTag.ARRAY) &&
+               msym.type.getReturnType().tsym == syms.objectType.tsym &&
+               ((ArrayType)argtypes.head).elemtype.tsym == syms.objectType.tsym;
+   }
+
+    /**
      * Is t the same type as s?
      */
     public boolean isSameType(Type t, Type s) {
--- a/langtools/src/share/classes/com/sun/tools/javac/comp/Attr.java	Tue Jun 11 09:59:34 2013 +0100
+++ b/langtools/src/share/classes/com/sun/tools/javac/comp/Attr.java	Fri Jun 14 16:25:09 2013 +0100
@@ -3405,7 +3405,7 @@
                      Env<AttrContext> env,
                      ResultInfo resultInfo) {
             boolean isPolymorhicSignature =
-                sym.kind == MTH && ((MethodSymbol)sym.baseSymbol()).isSignaturePolymorphic(types);
+                (sym.baseSymbol().flags() & SIGNATURE_POLYMORPHIC) != 0;
             return isPolymorhicSignature ?
                     checkSigPolyMethodId(tree, site, sym, env, resultInfo) :
                     checkMethodIdInternal(tree, site, sym, env, resultInfo);
--- a/langtools/src/share/classes/com/sun/tools/javac/comp/Check.java	Tue Jun 11 09:59:34 2013 +0100
+++ b/langtools/src/share/classes/com/sun/tools/javac/comp/Check.java	Fri Jun 14 16:25:09 2013 +0100
@@ -909,7 +909,7 @@
                                   "unchecked.generic.array.creation",
                                   argtype);
             }
-            if (!((MethodSymbol)sym.baseSymbol()).isSignaturePolymorphic(types)) {
+            if ((sym.baseSymbol().flags() & SIGNATURE_POLYMORPHIC) == 0) {
                 TreeInfo.setVarargsElement(env.tree, types.elemtype(argtype));
             }
          }
--- a/langtools/src/share/classes/com/sun/tools/javac/comp/MemberEnter.java	Tue Jun 11 09:59:34 2013 +0100
+++ b/langtools/src/share/classes/com/sun/tools/javac/comp/MemberEnter.java	Fri Jun 14 16:25:09 2013 +0100
@@ -560,6 +560,10 @@
             chk.setDeferredLintHandler(prevLintHandler);
         }
 
+        if (types.isSignaturePolymorphic(m)) {
+            m.flags_field |= SIGNATURE_POLYMORPHIC;
+        }
+
         // Set m.params
         ListBuffer<VarSymbol> params = new ListBuffer<VarSymbol>();
         JCVariableDecl lastParam = null;
--- a/langtools/src/share/classes/com/sun/tools/javac/comp/Resolve.java	Tue Jun 11 09:59:34 2013 +0100
+++ b/langtools/src/share/classes/com/sun/tools/javac/comp/Resolve.java	Fri Jun 14 16:25:09 2013 +0100
@@ -2267,7 +2267,7 @@
                     sym = super.access(env, pos, location, sym);
                 } else if (allowMethodHandles) {
                     MethodSymbol msym = (MethodSymbol)sym;
-                    if (msym.isSignaturePolymorphic(types)) {
+                    if ((msym.flags() & SIGNATURE_POLYMORPHIC) != 0) {
                         return findPolymorphicSignatureInstance(env, sym, argtypes);
                     }
                 }
--- a/langtools/src/share/classes/com/sun/tools/javac/jvm/ClassReader.java	Tue Jun 11 09:59:34 2013 +0100
+++ b/langtools/src/share/classes/com/sun/tools/javac/jvm/ClassReader.java	Fri Jun 14 16:25:09 2013 +0100
@@ -1985,6 +1985,9 @@
                                       syms.methodClass);
         }
         MethodSymbol m = new MethodSymbol(flags, name, type, currentOwner);
+        if (types.isSignaturePolymorphic(m)) {
+            m.flags_field |= SIGNATURE_POLYMORPHIC;
+        }
         if (saveParameterNames)
             initParameterNames(m);
         Symbol prevOwner = currentOwner;