changeset 2987:47035395abad

Avoid unnecessary (and possibly specialization-dependent) erasure calls in ClassReader.
author mcimadamore
date Fri, 24 Apr 2015 18:53:45 +0100
parents 8e0403b17db9
children 58e78a090947
files src/jdk.compiler/share/classes/com/sun/tools/javac/jvm/ClassReader.java
diffstat 1 files changed, 20 insertions(+), 8 deletions(-) [+]
line wrap: on
line diff
--- a/src/jdk.compiler/share/classes/com/sun/tools/javac/jvm/ClassReader.java	Fri Apr 24 18:51:52 2015 +0100
+++ b/src/jdk.compiler/share/classes/com/sun/tools/javac/jvm/ClassReader.java	Fri Apr 24 18:53:45 2015 +0100
@@ -427,7 +427,7 @@
         case CONSTANT_InterfaceMethodref: {
             ClassSymbol owner = readClassSymbol(getChar(index + 1));
             NameAndType nt = readNameAndType(getChar(index + 3));
-            poolObj[i] = new MethodSymbol(0, nt.name, nt.uniqueType.type, owner);
+            poolObj[i] = new ReaderMethodSymbol(0, nt.name, nt.uniqueType.type, owner);
             break;
         }
         case CONSTANT_NameandType:
@@ -1310,7 +1310,7 @@
         MethodType type = nt.uniqueType.type.asMethodType();
 
         for (Symbol sym : scope.getSymbolsByName(nt.name)) {
-            if (sym.kind == MTH && isSameBinaryType(sym.type.asMethodType(), type))
+            if (sym.kind == MTH && isSameBinaryType(asDescriptorType((MethodSymbol)sym).asMethodType(), type))
                 return (MethodSymbol)sym;
         }
 
@@ -1333,14 +1333,17 @@
         // Try searching again
         return findMethod(nt, scope, flags);
     }
+    //where
+        private Type asDescriptorType(MethodSymbol msym) {
+            return (msym instanceof ReaderMethodSymbol) ?
+                    ((ReaderMethodSymbol)msym).descriptor : types.erasure(msym.type.asMethodType());
+        }
 
     /** Similar to Types.isSameType but avoids completion
-     * Todo: it is not true anymore that this doesn't cause completion, as now erasure completes
      * supertypes recursively. This is causing a failure in testgetallmembers test.
      */
     private boolean isSameBinaryType(MethodType mt1, MethodType mt2) {
-        List<Type> types1 = types.erasure(mt1.getParameterTypes())
-            .prepend(types.erasure(mt1.getReturnType()));
+        List<Type> types1 = mt1.getParameterTypes().prepend(mt1.getReturnType());
         List<Type> types2 = mt2.getParameterTypes().prepend(mt2.getReturnType());
         while (!types1.isEmpty() && !types2.isEmpty()) {
             if (types1.head.tsym != types2.head.tsym)
@@ -1885,7 +1888,7 @@
                                            syms.botType,
                                            List.<Type>nil(),
                                            syms.methodClass);
-            return new MethodSymbol(PUBLIC | ABSTRACT, name, mt, container.tsym);
+            return new ReaderMethodSymbol(PUBLIC | ABSTRACT, name, mt, container.tsym);
         }
 
         Attribute result;
@@ -2123,7 +2126,7 @@
                                       type.getThrownTypes(),
                                       syms.methodClass);
         }
-        MethodSymbol m = new MethodSymbol(flags, name, type, currentOwner);
+        MethodSymbol m = new ReaderMethodSymbol(flags, name, type, currentOwner);
         if (types.isSignaturePolymorphic(m)) {
             m.flags_field |= SIGNATURE_POLYMORPHIC;
         }
@@ -2153,6 +2156,15 @@
 
         return m;
     }
+    //where
+        class ReaderMethodSymbol extends MethodSymbol {
+            Type descriptor;
+
+            ReaderMethodSymbol(long flags, Name name, Type type, Symbol owner) {
+                super(flags, name, type, owner);
+                this.descriptor = type;
+            }
+        }
 
     private List<Type> adjustMethodParams(long flags, List<Type> args) {
         boolean isVarargs = (flags & VARARGS) != 0;
@@ -2381,7 +2393,7 @@
                 if ((flags & STATIC) == 0) {
                     ((ClassType)member.type).setEnclosingType(outer.type);
                     if (member.erasure_field != null)
-                        ((ClassType)member.erasure_field).setEnclosingType(types.erasure(outer.type));
+                        ((ClassType)member.erasure_field).setEnclosingType(outer.type.tsym.erasure(types));
                 }
                 if (c == outer) {
                     member.flags_field = flags;