1.1 --- a/src/share/classes/com/sun/tools/javac/code/Types.java Tue Oct 28 08:56:23 2014 +0100 1.2 +++ b/src/share/classes/com/sun/tools/javac/code/Types.java Tue Oct 28 14:59:42 2014 +0000 1.3 @@ -1892,7 +1892,12 @@ 1.4 * Mapping to take element type of an arraytype 1.5 */ 1.6 private Mapping elemTypeFun = new Mapping ("elemTypeFun") { 1.7 - public Type apply(Type t) { return elemtype(t); } 1.8 + public Type apply(Type t) { 1.9 + while (t.hasTag(TYPEVAR)) { 1.10 + t = t.getUpperBound(); 1.11 + } 1.12 + return elemtype(t); 1.13 + } 1.14 }; 1.15 1.16 /** 1.17 @@ -3521,40 +3526,46 @@ 1.18 } 1.19 1.20 /** 1.21 - * Return the least upper bound of pair of types. if the lub does 1.22 + * Return the least upper bound of list of types. if the lub does 1.23 * not exist return null. 1.24 */ 1.25 - public Type lub(Type t1, Type t2) { 1.26 - return lub(List.of(t1, t2)); 1.27 + public Type lub(List<Type> ts) { 1.28 + return lub(ts.toArray(new Type[ts.length()])); 1.29 } 1.30 1.31 /** 1.32 * Return the least upper bound (lub) of set of types. If the lub 1.33 * does not exist return the type of null (bottom). 1.34 */ 1.35 - public Type lub(List<Type> ts) { 1.36 + public Type lub(Type... ts) { 1.37 + final int UNKNOWN_BOUND = 0; 1.38 final int ARRAY_BOUND = 1; 1.39 final int CLASS_BOUND = 2; 1.40 - int boundkind = 0; 1.41 - for (Type t : ts) { 1.42 + 1.43 + int[] kinds = new int[ts.length]; 1.44 + 1.45 + int boundkind = UNKNOWN_BOUND; 1.46 + for (int i = 0 ; i < ts.length ; i++) { 1.47 + Type t = ts[i]; 1.48 switch (t.getTag()) { 1.49 case CLASS: 1.50 - boundkind |= CLASS_BOUND; 1.51 + boundkind |= kinds[i] = CLASS_BOUND; 1.52 break; 1.53 case ARRAY: 1.54 - boundkind |= ARRAY_BOUND; 1.55 + boundkind |= kinds[i] = ARRAY_BOUND; 1.56 break; 1.57 case TYPEVAR: 1.58 do { 1.59 t = t.getUpperBound(); 1.60 } while (t.hasTag(TYPEVAR)); 1.61 if (t.hasTag(ARRAY)) { 1.62 - boundkind |= ARRAY_BOUND; 1.63 + boundkind |= kinds[i] = ARRAY_BOUND; 1.64 } else { 1.65 - boundkind |= CLASS_BOUND; 1.66 + boundkind |= kinds[i] = CLASS_BOUND; 1.67 } 1.68 break; 1.69 default: 1.70 + kinds[i] = UNKNOWN_BOUND; 1.71 if (t.isPrimitive()) 1.72 return syms.errType; 1.73 } 1.74 @@ -3565,15 +3576,16 @@ 1.75 1.76 case ARRAY_BOUND: 1.77 // calculate lub(A[], B[]) 1.78 - List<Type> elements = Type.map(ts, elemTypeFun); 1.79 - for (Type t : elements) { 1.80 - if (t.isPrimitive()) { 1.81 + Type[] elements = new Type[ts.length]; 1.82 + for (int i = 0 ; i < ts.length ; i++) { 1.83 + Type elem = elements[i] = elemTypeFun.apply(ts[i]); 1.84 + if (elem.isPrimitive()) { 1.85 // if a primitive type is found, then return 1.86 // arraySuperType unless all the types are the 1.87 // same 1.88 - Type first = ts.head; 1.89 - for (Type s : ts.tail) { 1.90 - if (!isSameType(first, s)) { 1.91 + Type first = ts[0]; 1.92 + for (int j = 1 ; j < ts.length ; j++) { 1.93 + if (!isSameType(first, ts[j])) { 1.94 // lub(int[], B[]) is Cloneable & Serializable 1.95 return arraySuperType(); 1.96 } 1.97 @@ -3588,13 +3600,20 @@ 1.98 1.99 case CLASS_BOUND: 1.100 // calculate lub(A, B) 1.101 - while (!ts.head.hasTag(CLASS) && !ts.head.hasTag(TYPEVAR)) { 1.102 - ts = ts.tail; 1.103 + int startIdx = 0; 1.104 + for (int i = 0; i < ts.length ; i++) { 1.105 + Type t = ts[i]; 1.106 + if (t.hasTag(CLASS) || t.hasTag(TYPEVAR)) { 1.107 + break; 1.108 + } else { 1.109 + startIdx++; 1.110 + } 1.111 } 1.112 - Assert.check(!ts.isEmpty()); 1.113 + Assert.check(startIdx < ts.length); 1.114 //step 1 - compute erased candidate set (EC) 1.115 - List<Type> cl = erasedSupertypes(ts.head); 1.116 - for (Type t : ts.tail) { 1.117 + List<Type> cl = erasedSupertypes(ts[startIdx]); 1.118 + for (int i = startIdx + 1 ; i < ts.length ; i++) { 1.119 + Type t = ts[i]; 1.120 if (t.hasTag(CLASS) || t.hasTag(TYPEVAR)) 1.121 cl = intersect(cl, erasedSupertypes(t)); 1.122 } 1.123 @@ -3603,9 +3622,9 @@ 1.124 //step 3 - for each element G in MEC, compute lci(Inv(G)) 1.125 List<Type> candidates = List.nil(); 1.126 for (Type erasedSupertype : mec) { 1.127 - List<Type> lci = List.of(asSuper(ts.head, erasedSupertype.tsym)); 1.128 - for (Type t : ts) { 1.129 - lci = intersect(lci, List.of(asSuper(t, erasedSupertype.tsym))); 1.130 + List<Type> lci = List.of(asSuper(ts[startIdx], erasedSupertype.tsym)); 1.131 + for (int i = startIdx + 1 ; i < ts.length ; i++) { 1.132 + lci = intersect(lci, List.of(asSuper(ts[i], erasedSupertype.tsym))); 1.133 } 1.134 candidates = candidates.appendList(lci); 1.135 } 1.136 @@ -3616,9 +3635,9 @@ 1.137 default: 1.138 // calculate lub(A, B[]) 1.139 List<Type> classes = List.of(arraySuperType()); 1.140 - for (Type t : ts) { 1.141 - if (!t.hasTag(ARRAY)) // Filter out any arrays 1.142 - classes = classes.prepend(t); 1.143 + for (int i = 0 ; i < ts.length ; i++) { 1.144 + if (kinds[i] != ARRAY_BOUND) // Filter out any arrays 1.145 + classes = classes.prepend(ts[i]); 1.146 } 1.147 // lub(A, B[]) is lub(A, arraySuperType) 1.148 return lub(classes);