Fri, 31 Oct 2014 20:19:04 -0700
Merge
1.1 --- a/src/share/classes/com/sun/tools/javac/code/Types.java Wed Oct 29 10:50:43 2014 -0700 1.2 +++ b/src/share/classes/com/sun/tools/javac/code/Types.java Fri Oct 31 20:19:04 2014 -0700 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);
2.1 --- a/src/share/classes/com/sun/tools/javac/comp/Attr.java Wed Oct 29 10:50:43 2014 -0700 2.2 +++ b/src/share/classes/com/sun/tools/javac/comp/Attr.java Fri Oct 31 20:19:04 2014 -0700 2.3 @@ -1010,8 +1010,12 @@ 2.4 // parameters have already been entered 2.5 env.info.scope.enter(tree.sym); 2.6 } else { 2.7 - memberEnter.memberEnter(tree, env); 2.8 - annotate.flush(); 2.9 + try { 2.10 + annotate.enterStart(); 2.11 + memberEnter.memberEnter(tree, env); 2.12 + } finally { 2.13 + annotate.enterDone(); 2.14 + } 2.15 } 2.16 } else { 2.17 if (tree.init != null) {
3.1 --- a/src/share/classes/com/sun/tools/javac/comp/MemberEnter.java Wed Oct 29 10:50:43 2014 -0700 3.2 +++ b/src/share/classes/com/sun/tools/javac/comp/MemberEnter.java Fri Oct 31 20:19:04 2014 -0700 3.3 @@ -575,51 +575,46 @@ 3.4 3.5 Env<AttrContext> localEnv = methodEnv(tree, env); 3.6 3.7 - annotate.enterStart(); 3.8 + DiagnosticPosition prevLintPos = deferredLintHandler.setPos(tree.pos()); 3.9 try { 3.10 - DiagnosticPosition prevLintPos = deferredLintHandler.setPos(tree.pos()); 3.11 - try { 3.12 - // Compute the method type 3.13 - m.type = signature(m, tree.typarams, tree.params, 3.14 - tree.restype, tree.recvparam, 3.15 - tree.thrown, 3.16 - localEnv); 3.17 - } finally { 3.18 - deferredLintHandler.setPos(prevLintPos); 3.19 - } 3.20 + // Compute the method type 3.21 + m.type = signature(m, tree.typarams, tree.params, 3.22 + tree.restype, tree.recvparam, 3.23 + tree.thrown, 3.24 + localEnv); 3.25 + } finally { 3.26 + deferredLintHandler.setPos(prevLintPos); 3.27 + } 3.28 3.29 - if (types.isSignaturePolymorphic(m)) { 3.30 - m.flags_field |= SIGNATURE_POLYMORPHIC; 3.31 - } 3.32 + if (types.isSignaturePolymorphic(m)) { 3.33 + m.flags_field |= SIGNATURE_POLYMORPHIC; 3.34 + } 3.35 3.36 - // Set m.params 3.37 - ListBuffer<VarSymbol> params = new ListBuffer<VarSymbol>(); 3.38 - JCVariableDecl lastParam = null; 3.39 - for (List<JCVariableDecl> l = tree.params; l.nonEmpty(); l = l.tail) { 3.40 - JCVariableDecl param = lastParam = l.head; 3.41 - params.append(Assert.checkNonNull(param.sym)); 3.42 - } 3.43 - m.params = params.toList(); 3.44 + // Set m.params 3.45 + ListBuffer<VarSymbol> params = new ListBuffer<VarSymbol>(); 3.46 + JCVariableDecl lastParam = null; 3.47 + for (List<JCVariableDecl> l = tree.params; l.nonEmpty(); l = l.tail) { 3.48 + JCVariableDecl param = lastParam = l.head; 3.49 + params.append(Assert.checkNonNull(param.sym)); 3.50 + } 3.51 + m.params = params.toList(); 3.52 3.53 - // mark the method varargs, if necessary 3.54 - if (lastParam != null && (lastParam.mods.flags & Flags.VARARGS) != 0) 3.55 - m.flags_field |= Flags.VARARGS; 3.56 + // mark the method varargs, if necessary 3.57 + if (lastParam != null && (lastParam.mods.flags & Flags.VARARGS) != 0) 3.58 + m.flags_field |= Flags.VARARGS; 3.59 3.60 - localEnv.info.scope.leave(); 3.61 - if (chk.checkUnique(tree.pos(), m, enclScope)) { 3.62 - enclScope.enter(m); 3.63 - } 3.64 + localEnv.info.scope.leave(); 3.65 + if (chk.checkUnique(tree.pos(), m, enclScope)) { 3.66 + enclScope.enter(m); 3.67 + } 3.68 3.69 - annotateLater(tree.mods.annotations, localEnv, m, tree.pos()); 3.70 - // Visit the signature of the method. Note that 3.71 - // TypeAnnotate doesn't descend into the body. 3.72 - typeAnnotate(tree, localEnv, m, tree.pos()); 3.73 + annotateLater(tree.mods.annotations, localEnv, m, tree.pos()); 3.74 + // Visit the signature of the method. Note that 3.75 + // TypeAnnotate doesn't descend into the body. 3.76 + typeAnnotate(tree, localEnv, m, tree.pos()); 3.77 3.78 - if (tree.defaultValue != null) 3.79 - annotateDefaultValueLater(tree.defaultValue, localEnv, m); 3.80 - } finally { 3.81 - annotate.enterDone(); 3.82 - } 3.83 + if (tree.defaultValue != null) 3.84 + annotateDefaultValueLater(tree.defaultValue, localEnv, m); 3.85 } 3.86 3.87 /** Create a fresh environment for method bodies. 3.88 @@ -647,54 +642,49 @@ 3.89 localEnv.info.staticLevel++; 3.90 } 3.91 DiagnosticPosition prevLintPos = deferredLintHandler.setPos(tree.pos()); 3.92 - annotate.enterStart(); 3.93 try { 3.94 - try { 3.95 - if (TreeInfo.isEnumInit(tree)) { 3.96 - attr.attribIdentAsEnumType(localEnv, (JCIdent)tree.vartype); 3.97 - } else { 3.98 - attr.attribType(tree.vartype, localEnv); 3.99 - if (TreeInfo.isReceiverParam(tree)) 3.100 - checkReceiver(tree, localEnv); 3.101 - } 3.102 - } finally { 3.103 - deferredLintHandler.setPos(prevLintPos); 3.104 + if (TreeInfo.isEnumInit(tree)) { 3.105 + attr.attribIdentAsEnumType(localEnv, (JCIdent)tree.vartype); 3.106 + } else { 3.107 + attr.attribType(tree.vartype, localEnv); 3.108 + if (TreeInfo.isReceiverParam(tree)) 3.109 + checkReceiver(tree, localEnv); 3.110 } 3.111 + } finally { 3.112 + deferredLintHandler.setPos(prevLintPos); 3.113 + } 3.114 3.115 - if ((tree.mods.flags & VARARGS) != 0) { 3.116 - //if we are entering a varargs parameter, we need to 3.117 - //replace its type (a plain array type) with the more 3.118 - //precise VarargsType --- we need to do it this way 3.119 - //because varargs is represented in the tree as a 3.120 - //modifier on the parameter declaration, and not as a 3.121 - //distinct type of array node. 3.122 - ArrayType atype = (ArrayType)tree.vartype.type.unannotatedType(); 3.123 - tree.vartype.type = atype.makeVarargs(); 3.124 + if ((tree.mods.flags & VARARGS) != 0) { 3.125 + //if we are entering a varargs parameter, we need to 3.126 + //replace its type (a plain array type) with the more 3.127 + //precise VarargsType --- we need to do it this way 3.128 + //because varargs is represented in the tree as a 3.129 + //modifier on the parameter declaration, and not as a 3.130 + //distinct type of array node. 3.131 + ArrayType atype = (ArrayType)tree.vartype.type.unannotatedType(); 3.132 + tree.vartype.type = atype.makeVarargs(); 3.133 + } 3.134 + Scope enclScope = enter.enterScope(env); 3.135 + VarSymbol v = 3.136 + new VarSymbol(0, tree.name, tree.vartype.type, enclScope.owner); 3.137 + v.flags_field = chk.checkFlags(tree.pos(), tree.mods.flags, v, tree); 3.138 + tree.sym = v; 3.139 + if (tree.init != null) { 3.140 + v.flags_field |= HASINIT; 3.141 + if ((v.flags_field & FINAL) != 0 && 3.142 + needsLazyConstValue(tree.init)) { 3.143 + Env<AttrContext> initEnv = getInitEnv(tree, env); 3.144 + initEnv.info.enclVar = v; 3.145 + v.setLazyConstValue(initEnv(tree, initEnv), attr, tree); 3.146 } 3.147 - Scope enclScope = enter.enterScope(env); 3.148 - VarSymbol v = 3.149 - new VarSymbol(0, tree.name, tree.vartype.type, enclScope.owner); 3.150 - v.flags_field = chk.checkFlags(tree.pos(), tree.mods.flags, v, tree); 3.151 - tree.sym = v; 3.152 - if (tree.init != null) { 3.153 - v.flags_field |= HASINIT; 3.154 - if ((v.flags_field & FINAL) != 0 && 3.155 - needsLazyConstValue(tree.init)) { 3.156 - Env<AttrContext> initEnv = getInitEnv(tree, env); 3.157 - initEnv.info.enclVar = v; 3.158 - v.setLazyConstValue(initEnv(tree, initEnv), attr, tree); 3.159 - } 3.160 - } 3.161 - if (chk.checkUnique(tree.pos(), v, enclScope)) { 3.162 - chk.checkTransparentVar(tree.pos(), v, enclScope); 3.163 - enclScope.enter(v); 3.164 - } 3.165 - annotateLater(tree.mods.annotations, localEnv, v, tree.pos()); 3.166 - typeAnnotate(tree.vartype, env, v, tree.pos()); 3.167 - v.pos = tree.pos; 3.168 - } finally { 3.169 - annotate.enterDone(); 3.170 } 3.171 + if (chk.checkUnique(tree.pos(), v, enclScope)) { 3.172 + chk.checkTransparentVar(tree.pos(), v, enclScope); 3.173 + enclScope.enter(v); 3.174 + } 3.175 + annotateLater(tree.mods.annotations, localEnv, v, tree.pos()); 3.176 + typeAnnotate(tree.vartype, env, v, tree.pos()); 3.177 + v.pos = tree.pos; 3.178 } 3.179 // where 3.180 void checkType(JCTree tree, Type type, String diag) { 3.181 @@ -1030,189 +1020,194 @@ 3.182 JCClassDecl tree = (JCClassDecl)env.tree; 3.183 boolean wasFirst = isFirst; 3.184 isFirst = false; 3.185 + try { 3.186 + annotate.enterStart(); 3.187 3.188 - JavaFileObject prev = log.useSource(env.toplevel.sourcefile); 3.189 - DiagnosticPosition prevLintPos = deferredLintHandler.setPos(tree.pos()); 3.190 - try { 3.191 - // Save class environment for later member enter (2) processing. 3.192 - halfcompleted.append(env); 3.193 + JavaFileObject prev = log.useSource(env.toplevel.sourcefile); 3.194 + DiagnosticPosition prevLintPos = deferredLintHandler.setPos(tree.pos()); 3.195 + try { 3.196 + // Save class environment for later member enter (2) processing. 3.197 + halfcompleted.append(env); 3.198 3.199 - // Mark class as not yet attributed. 3.200 - c.flags_field |= UNATTRIBUTED; 3.201 + // Mark class as not yet attributed. 3.202 + c.flags_field |= UNATTRIBUTED; 3.203 3.204 - // If this is a toplevel-class, make sure any preceding import 3.205 - // clauses have been seen. 3.206 - if (c.owner.kind == PCK) { 3.207 - memberEnter(env.toplevel, env.enclosing(TOPLEVEL)); 3.208 - todo.append(env); 3.209 + // If this is a toplevel-class, make sure any preceding import 3.210 + // clauses have been seen. 3.211 + if (c.owner.kind == PCK) { 3.212 + memberEnter(env.toplevel, env.enclosing(TOPLEVEL)); 3.213 + todo.append(env); 3.214 + } 3.215 + 3.216 + if (c.owner.kind == TYP) 3.217 + c.owner.complete(); 3.218 + 3.219 + // create an environment for evaluating the base clauses 3.220 + Env<AttrContext> baseEnv = baseEnv(tree, env); 3.221 + 3.222 + if (tree.extending != null) 3.223 + typeAnnotate(tree.extending, baseEnv, sym, tree.pos()); 3.224 + for (JCExpression impl : tree.implementing) 3.225 + typeAnnotate(impl, baseEnv, sym, tree.pos()); 3.226 + annotate.flush(); 3.227 + 3.228 + // Determine supertype. 3.229 + Type supertype = 3.230 + (tree.extending != null) 3.231 + ? attr.attribBase(tree.extending, baseEnv, true, false, true) 3.232 + : ((tree.mods.flags & Flags.ENUM) != 0) 3.233 + ? attr.attribBase(enumBase(tree.pos, c), baseEnv, 3.234 + true, false, false) 3.235 + : (c.fullname == names.java_lang_Object) 3.236 + ? Type.noType 3.237 + : syms.objectType; 3.238 + ct.supertype_field = modelMissingTypes(supertype, tree.extending, false); 3.239 + 3.240 + // Determine interfaces. 3.241 + ListBuffer<Type> interfaces = new ListBuffer<Type>(); 3.242 + ListBuffer<Type> all_interfaces = null; // lazy init 3.243 + Set<Type> interfaceSet = new HashSet<Type>(); 3.244 + List<JCExpression> interfaceTrees = tree.implementing; 3.245 + for (JCExpression iface : interfaceTrees) { 3.246 + Type i = attr.attribBase(iface, baseEnv, false, true, true); 3.247 + if (i.hasTag(CLASS)) { 3.248 + interfaces.append(i); 3.249 + if (all_interfaces != null) all_interfaces.append(i); 3.250 + chk.checkNotRepeated(iface.pos(), types.erasure(i), interfaceSet); 3.251 + } else { 3.252 + if (all_interfaces == null) 3.253 + all_interfaces = new ListBuffer<Type>().appendList(interfaces); 3.254 + all_interfaces.append(modelMissingTypes(i, iface, true)); 3.255 + } 3.256 + } 3.257 + if ((c.flags_field & ANNOTATION) != 0) { 3.258 + ct.interfaces_field = List.of(syms.annotationType); 3.259 + ct.all_interfaces_field = ct.interfaces_field; 3.260 + } else { 3.261 + ct.interfaces_field = interfaces.toList(); 3.262 + ct.all_interfaces_field = (all_interfaces == null) 3.263 + ? ct.interfaces_field : all_interfaces.toList(); 3.264 + } 3.265 + 3.266 + if (c.fullname == names.java_lang_Object) { 3.267 + if (tree.extending != null) { 3.268 + chk.checkNonCyclic(tree.extending.pos(), 3.269 + supertype); 3.270 + ct.supertype_field = Type.noType; 3.271 + } 3.272 + else if (tree.implementing.nonEmpty()) { 3.273 + chk.checkNonCyclic(tree.implementing.head.pos(), 3.274 + ct.interfaces_field.head); 3.275 + ct.interfaces_field = List.nil(); 3.276 + } 3.277 + } 3.278 + 3.279 + // Annotations. 3.280 + // In general, we cannot fully process annotations yet, but we 3.281 + // can attribute the annotation types and then check to see if the 3.282 + // @Deprecated annotation is present. 3.283 + attr.attribAnnotationTypes(tree.mods.annotations, baseEnv); 3.284 + if (hasDeprecatedAnnotation(tree.mods.annotations)) 3.285 + c.flags_field |= DEPRECATED; 3.286 + annotateLater(tree.mods.annotations, baseEnv, c, tree.pos()); 3.287 + // class type parameters use baseEnv but everything uses env 3.288 + 3.289 + chk.checkNonCyclicDecl(tree); 3.290 + 3.291 + attr.attribTypeVariables(tree.typarams, baseEnv); 3.292 + // Do this here, where we have the symbol. 3.293 + for (JCTypeParameter tp : tree.typarams) 3.294 + typeAnnotate(tp, baseEnv, sym, tree.pos()); 3.295 + 3.296 + // Add default constructor if needed. 3.297 + if ((c.flags() & INTERFACE) == 0 && 3.298 + !TreeInfo.hasConstructors(tree.defs)) { 3.299 + List<Type> argtypes = List.nil(); 3.300 + List<Type> typarams = List.nil(); 3.301 + List<Type> thrown = List.nil(); 3.302 + long ctorFlags = 0; 3.303 + boolean based = false; 3.304 + boolean addConstructor = true; 3.305 + JCNewClass nc = null; 3.306 + if (c.name.isEmpty()) { 3.307 + nc = (JCNewClass)env.next.tree; 3.308 + if (nc.constructor != null) { 3.309 + addConstructor = nc.constructor.kind != ERR; 3.310 + Type superConstrType = types.memberType(c.type, 3.311 + nc.constructor); 3.312 + argtypes = superConstrType.getParameterTypes(); 3.313 + typarams = superConstrType.getTypeArguments(); 3.314 + ctorFlags = nc.constructor.flags() & VARARGS; 3.315 + if (nc.encl != null) { 3.316 + argtypes = argtypes.prepend(nc.encl.type); 3.317 + based = true; 3.318 + } 3.319 + thrown = superConstrType.getThrownTypes(); 3.320 + } 3.321 + } 3.322 + if (addConstructor) { 3.323 + MethodSymbol basedConstructor = nc != null ? 3.324 + (MethodSymbol)nc.constructor : null; 3.325 + JCTree constrDef = DefaultConstructor(make.at(tree.pos), c, 3.326 + basedConstructor, 3.327 + typarams, argtypes, thrown, 3.328 + ctorFlags, based); 3.329 + tree.defs = tree.defs.prepend(constrDef); 3.330 + } 3.331 + } 3.332 + 3.333 + // enter symbols for 'this' into current scope. 3.334 + VarSymbol thisSym = 3.335 + new VarSymbol(FINAL | HASINIT, names._this, c.type, c); 3.336 + thisSym.pos = Position.FIRSTPOS; 3.337 + env.info.scope.enter(thisSym); 3.338 + // if this is a class, enter symbol for 'super' into current scope. 3.339 + if ((c.flags_field & INTERFACE) == 0 && 3.340 + ct.supertype_field.hasTag(CLASS)) { 3.341 + VarSymbol superSym = 3.342 + new VarSymbol(FINAL | HASINIT, names._super, 3.343 + ct.supertype_field, c); 3.344 + superSym.pos = Position.FIRSTPOS; 3.345 + env.info.scope.enter(superSym); 3.346 + } 3.347 + 3.348 + // check that no package exists with same fully qualified name, 3.349 + // but admit classes in the unnamed package which have the same 3.350 + // name as a top-level package. 3.351 + if (checkClash && 3.352 + c.owner.kind == PCK && c.owner != syms.unnamedPackage && 3.353 + reader.packageExists(c.fullname)) { 3.354 + log.error(tree.pos, "clash.with.pkg.of.same.name", Kinds.kindName(sym), c); 3.355 + } 3.356 + if (c.owner.kind == PCK && (c.flags_field & PUBLIC) == 0 && 3.357 + !env.toplevel.sourcefile.isNameCompatible(c.name.toString(),JavaFileObject.Kind.SOURCE)) { 3.358 + c.flags_field |= AUXILIARY; 3.359 + } 3.360 + } catch (CompletionFailure ex) { 3.361 + chk.completionError(tree.pos(), ex); 3.362 + } finally { 3.363 + deferredLintHandler.setPos(prevLintPos); 3.364 + log.useSource(prev); 3.365 } 3.366 3.367 - if (c.owner.kind == TYP) 3.368 - c.owner.complete(); 3.369 - 3.370 - // create an environment for evaluating the base clauses 3.371 - Env<AttrContext> baseEnv = baseEnv(tree, env); 3.372 - 3.373 - if (tree.extending != null) 3.374 - typeAnnotate(tree.extending, baseEnv, sym, tree.pos()); 3.375 - for (JCExpression impl : tree.implementing) 3.376 - typeAnnotate(impl, baseEnv, sym, tree.pos()); 3.377 - annotate.flush(); 3.378 - 3.379 - // Determine supertype. 3.380 - Type supertype = 3.381 - (tree.extending != null) 3.382 - ? attr.attribBase(tree.extending, baseEnv, true, false, true) 3.383 - : ((tree.mods.flags & Flags.ENUM) != 0) 3.384 - ? attr.attribBase(enumBase(tree.pos, c), baseEnv, 3.385 - true, false, false) 3.386 - : (c.fullname == names.java_lang_Object) 3.387 - ? Type.noType 3.388 - : syms.objectType; 3.389 - ct.supertype_field = modelMissingTypes(supertype, tree.extending, false); 3.390 - 3.391 - // Determine interfaces. 3.392 - ListBuffer<Type> interfaces = new ListBuffer<Type>(); 3.393 - ListBuffer<Type> all_interfaces = null; // lazy init 3.394 - Set<Type> interfaceSet = new HashSet<Type>(); 3.395 - List<JCExpression> interfaceTrees = tree.implementing; 3.396 - for (JCExpression iface : interfaceTrees) { 3.397 - Type i = attr.attribBase(iface, baseEnv, false, true, true); 3.398 - if (i.hasTag(CLASS)) { 3.399 - interfaces.append(i); 3.400 - if (all_interfaces != null) all_interfaces.append(i); 3.401 - chk.checkNotRepeated(iface.pos(), types.erasure(i), interfaceSet); 3.402 - } else { 3.403 - if (all_interfaces == null) 3.404 - all_interfaces = new ListBuffer<Type>().appendList(interfaces); 3.405 - all_interfaces.append(modelMissingTypes(i, iface, true)); 3.406 + // Enter all member fields and methods of a set of half completed 3.407 + // classes in a second phase. 3.408 + if (wasFirst) { 3.409 + try { 3.410 + while (halfcompleted.nonEmpty()) { 3.411 + Env<AttrContext> toFinish = halfcompleted.next(); 3.412 + finish(toFinish); 3.413 + if (allowTypeAnnos) { 3.414 + typeAnnotations.organizeTypeAnnotationsSignatures(toFinish, (JCClassDecl)toFinish.tree); 3.415 + typeAnnotations.validateTypeAnnotationsSignatures(toFinish, (JCClassDecl)toFinish.tree); 3.416 + } 3.417 + } 3.418 + } finally { 3.419 + isFirst = true; 3.420 } 3.421 } 3.422 - if ((c.flags_field & ANNOTATION) != 0) { 3.423 - ct.interfaces_field = List.of(syms.annotationType); 3.424 - ct.all_interfaces_field = ct.interfaces_field; 3.425 - } else { 3.426 - ct.interfaces_field = interfaces.toList(); 3.427 - ct.all_interfaces_field = (all_interfaces == null) 3.428 - ? ct.interfaces_field : all_interfaces.toList(); 3.429 - } 3.430 - 3.431 - if (c.fullname == names.java_lang_Object) { 3.432 - if (tree.extending != null) { 3.433 - chk.checkNonCyclic(tree.extending.pos(), 3.434 - supertype); 3.435 - ct.supertype_field = Type.noType; 3.436 - } 3.437 - else if (tree.implementing.nonEmpty()) { 3.438 - chk.checkNonCyclic(tree.implementing.head.pos(), 3.439 - ct.interfaces_field.head); 3.440 - ct.interfaces_field = List.nil(); 3.441 - } 3.442 - } 3.443 - 3.444 - // Annotations. 3.445 - // In general, we cannot fully process annotations yet, but we 3.446 - // can attribute the annotation types and then check to see if the 3.447 - // @Deprecated annotation is present. 3.448 - attr.attribAnnotationTypes(tree.mods.annotations, baseEnv); 3.449 - if (hasDeprecatedAnnotation(tree.mods.annotations)) 3.450 - c.flags_field |= DEPRECATED; 3.451 - annotateLater(tree.mods.annotations, baseEnv, c, tree.pos()); 3.452 - // class type parameters use baseEnv but everything uses env 3.453 - 3.454 - chk.checkNonCyclicDecl(tree); 3.455 - 3.456 - attr.attribTypeVariables(tree.typarams, baseEnv); 3.457 - // Do this here, where we have the symbol. 3.458 - for (JCTypeParameter tp : tree.typarams) 3.459 - typeAnnotate(tp, baseEnv, sym, tree.pos()); 3.460 - 3.461 - // Add default constructor if needed. 3.462 - if ((c.flags() & INTERFACE) == 0 && 3.463 - !TreeInfo.hasConstructors(tree.defs)) { 3.464 - List<Type> argtypes = List.nil(); 3.465 - List<Type> typarams = List.nil(); 3.466 - List<Type> thrown = List.nil(); 3.467 - long ctorFlags = 0; 3.468 - boolean based = false; 3.469 - boolean addConstructor = true; 3.470 - JCNewClass nc = null; 3.471 - if (c.name.isEmpty()) { 3.472 - nc = (JCNewClass)env.next.tree; 3.473 - if (nc.constructor != null) { 3.474 - addConstructor = nc.constructor.kind != ERR; 3.475 - Type superConstrType = types.memberType(c.type, 3.476 - nc.constructor); 3.477 - argtypes = superConstrType.getParameterTypes(); 3.478 - typarams = superConstrType.getTypeArguments(); 3.479 - ctorFlags = nc.constructor.flags() & VARARGS; 3.480 - if (nc.encl != null) { 3.481 - argtypes = argtypes.prepend(nc.encl.type); 3.482 - based = true; 3.483 - } 3.484 - thrown = superConstrType.getThrownTypes(); 3.485 - } 3.486 - } 3.487 - if (addConstructor) { 3.488 - MethodSymbol basedConstructor = nc != null ? 3.489 - (MethodSymbol)nc.constructor : null; 3.490 - JCTree constrDef = DefaultConstructor(make.at(tree.pos), c, 3.491 - basedConstructor, 3.492 - typarams, argtypes, thrown, 3.493 - ctorFlags, based); 3.494 - tree.defs = tree.defs.prepend(constrDef); 3.495 - } 3.496 - } 3.497 - 3.498 - // enter symbols for 'this' into current scope. 3.499 - VarSymbol thisSym = 3.500 - new VarSymbol(FINAL | HASINIT, names._this, c.type, c); 3.501 - thisSym.pos = Position.FIRSTPOS; 3.502 - env.info.scope.enter(thisSym); 3.503 - // if this is a class, enter symbol for 'super' into current scope. 3.504 - if ((c.flags_field & INTERFACE) == 0 && 3.505 - ct.supertype_field.hasTag(CLASS)) { 3.506 - VarSymbol superSym = 3.507 - new VarSymbol(FINAL | HASINIT, names._super, 3.508 - ct.supertype_field, c); 3.509 - superSym.pos = Position.FIRSTPOS; 3.510 - env.info.scope.enter(superSym); 3.511 - } 3.512 - 3.513 - // check that no package exists with same fully qualified name, 3.514 - // but admit classes in the unnamed package which have the same 3.515 - // name as a top-level package. 3.516 - if (checkClash && 3.517 - c.owner.kind == PCK && c.owner != syms.unnamedPackage && 3.518 - reader.packageExists(c.fullname)) { 3.519 - log.error(tree.pos, "clash.with.pkg.of.same.name", Kinds.kindName(sym), c); 3.520 - } 3.521 - if (c.owner.kind == PCK && (c.flags_field & PUBLIC) == 0 && 3.522 - !env.toplevel.sourcefile.isNameCompatible(c.name.toString(),JavaFileObject.Kind.SOURCE)) { 3.523 - c.flags_field |= AUXILIARY; 3.524 - } 3.525 - } catch (CompletionFailure ex) { 3.526 - chk.completionError(tree.pos(), ex); 3.527 } finally { 3.528 - deferredLintHandler.setPos(prevLintPos); 3.529 - log.useSource(prev); 3.530 - } 3.531 - 3.532 - // Enter all member fields and methods of a set of half completed 3.533 - // classes in a second phase. 3.534 - if (wasFirst) { 3.535 - try { 3.536 - while (halfcompleted.nonEmpty()) { 3.537 - Env<AttrContext> toFinish = halfcompleted.next(); 3.538 - finish(toFinish); 3.539 - if (allowTypeAnnos) { 3.540 - typeAnnotations.organizeTypeAnnotationsSignatures(toFinish, (JCClassDecl)toFinish.tree); 3.541 - typeAnnotations.validateTypeAnnotationsSignatures(toFinish, (JCClassDecl)toFinish.tree); 3.542 - } 3.543 - } 3.544 - } finally { 3.545 - isFirst = true; 3.546 - } 3.547 + annotate.enterDone(); 3.548 } 3.549 } 3.550
4.1 --- a/src/share/classes/com/sun/tools/javac/jvm/Code.java Wed Oct 29 10:50:43 2014 -0700 4.2 +++ b/src/share/classes/com/sun/tools/javac/jvm/Code.java Fri Oct 31 20:19:04 2014 -0700 4.3 @@ -2017,13 +2017,12 @@ 4.4 List<VarSymbol> locals = lvtRanges.getVars(meth, tree); 4.5 for (LocalVar localVar: lvar) { 4.6 for (VarSymbol aliveLocal : locals) { 4.7 - if (localVar == null) { 4.8 - return; 4.9 - } 4.10 - if (localVar.sym == aliveLocal && localVar.lastRange() != null) { 4.11 - char length = (char)(closingCP - localVar.lastRange().start_pc); 4.12 - if (length < Character.MAX_VALUE) { 4.13 - localVar.closeRange(length); 4.14 + if (localVar != null) { 4.15 + if (localVar.sym == aliveLocal && localVar.lastRange() != null) { 4.16 + char length = (char)(closingCP - localVar.lastRange().start_pc); 4.17 + if (length < Character.MAX_VALUE) { 4.18 + localVar.closeRange(length); 4.19 + } 4.20 } 4.21 } 4.22 }
5.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 5.2 +++ b/test/tools/javac/annotations/FinalStringInNested.java Fri Oct 31 20:19:04 2014 -0700 5.3 @@ -0,0 +1,46 @@ 5.4 +/* 5.5 + * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved. 5.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 5.7 + * 5.8 + * This code is free software; you can redistribute it and/or modify it 5.9 + * under the terms of the GNU General Public License version 2 only, as 5.10 + * published by the Free Software Foundation. 5.11 + * 5.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 5.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 5.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 5.15 + * version 2 for more details (a copy is included in the LICENSE file that 5.16 + * accompanied this code). 5.17 + * 5.18 + * You should have received a copy of the GNU General Public License version 5.19 + * 2 along with this work; if not, write to the Free Software Foundation, 5.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 5.21 + * 5.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 5.23 + * or visit www.oracle.com if you need additional information or have any 5.24 + * questions. 5.25 + */ 5.26 + 5.27 +/* 5.28 + * @test 5.29 + * @bug 8054448 5.30 + * @summary Verify that constant strings in nested classes in anonymous classes 5.31 + * can be used in annotations. 5.32 + * @compile FinalStringInNested.java 5.33 + */ 5.34 + 5.35 +public class FinalStringInNested { 5.36 + 5.37 + public void f() { 5.38 + Object o = new Object() { 5.39 + @FinalStringInNested.Annotation(Nested.ID) 5.40 + class Nested { 5.41 + static final String ID = "B"; 5.42 + } 5.43 + }; 5.44 + } 5.45 + 5.46 + @interface Annotation { 5.47 + String value(); 5.48 + } 5.49 +}
6.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 6.2 +++ b/test/tools/javac/generics/inference/8058511/T8058511a.java Fri Oct 31 20:19:04 2014 -0700 6.3 @@ -0,0 +1,38 @@ 6.4 +/* 6.5 + * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved. 6.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 6.7 + * 6.8 + * This code is free software; you can redistribute it and/or modify it 6.9 + * under the terms of the GNU General Public License version 2 only, as 6.10 + * published by the Free Software Foundation. Oracle designates this 6.11 + * particular file as subject to the "Classpath" exception as provided 6.12 + * by Oracle in the LICENSE file that accompanied this code. 6.13 + * 6.14 + * This code is distributed in the hope that it will be useful, but WITHOUT 6.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 6.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 6.17 + * version 2 for more details (a copy is included in the LICENSE file that 6.18 + * accompanied this code). 6.19 + * 6.20 + * You should have received a copy of the GNU General Public License version 6.21 + * 2 along with this work; if not, write to the Free Software Foundation, 6.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 6.23 + * 6.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 6.25 + * or visit www.oracle.com if you need additional information or have any 6.26 + * questions. 6.27 + */ 6.28 + 6.29 +/** 6.30 + * @test 6.31 + * @bug 8058511 6.32 + * @summary StackOverflowError at com.sun.tools.javac.code.Types.lub 6.33 + * @compile T8058511a.java 6.34 + */ 6.35 +class T8058511a { 6.36 + <Z> void choose(Z z1, Z z2) { } 6.37 + 6.38 + void test(Class<Double> cd, Class<? extends double[]> cdarr) { 6.39 + choose(cd, cdarr); 6.40 + } 6.41 +}
7.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 7.2 +++ b/test/tools/javac/generics/inference/8058511/T8058511b.java Fri Oct 31 20:19:04 2014 -0700 7.3 @@ -0,0 +1,36 @@ 7.4 +/* 7.5 + * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved. 7.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 7.7 + * 7.8 + * This code is free software; you can redistribute it and/or modify it 7.9 + * under the terms of the GNU General Public License version 2 only, as 7.10 + * published by the Free Software Foundation. Oracle designates this 7.11 + * particular file as subject to the "Classpath" exception as provided 7.12 + * by Oracle in the LICENSE file that accompanied this code. 7.13 + * 7.14 + * This code is distributed in the hope that it will be useful, but WITHOUT 7.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 7.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 7.17 + * version 2 for more details (a copy is included in the LICENSE file that 7.18 + * accompanied this code). 7.19 + * 7.20 + * You should have received a copy of the GNU General Public License version 7.21 + * 2 along with this work; if not, write to the Free Software Foundation, 7.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 7.23 + * 7.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 7.25 + * or visit www.oracle.com if you need additional information or have any 7.26 + * questions. 7.27 + */ 7.28 + 7.29 +/** 7.30 + * @test 7.31 + * @bug 8058511 7.32 + * @summary StackOverflowError at com.sun.tools.javac.code.Types.lub 7.33 + * @compile T8058511b.java 7.34 + */ 7.35 +class T8058511b { 7.36 + void test(Class<Double> cd, Class<? extends double[]> cdarr) { 7.37 + ((false) ? cd : cdarr).toString(); 7.38 + } 7.39 +}
8.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 8.2 +++ b/test/tools/javac/generics/inference/8058511/T8058511c.java Fri Oct 31 20:19:04 2014 -0700 8.3 @@ -0,0 +1,38 @@ 8.4 +/* 8.5 + * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved. 8.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 8.7 + * 8.8 + * This code is free software; you can redistribute it and/or modify it 8.9 + * under the terms of the GNU General Public License version 2 only, as 8.10 + * published by the Free Software Foundation. Oracle designates this 8.11 + * particular file as subject to the "Classpath" exception as provided 8.12 + * by Oracle in the LICENSE file that accompanied this code. 8.13 + * 8.14 + * This code is distributed in the hope that it will be useful, but WITHOUT 8.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 8.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 8.17 + * version 2 for more details (a copy is included in the LICENSE file that 8.18 + * accompanied this code). 8.19 + * 8.20 + * You should have received a copy of the GNU General Public License version 8.21 + * 2 along with this work; if not, write to the Free Software Foundation, 8.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 8.23 + * 8.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 8.25 + * or visit www.oracle.com if you need additional information or have any 8.26 + * questions. 8.27 + */ 8.28 + 8.29 +/** 8.30 + * @test 8.31 + * @bug 8058511 8.32 + * @summary StackOverflowError at com.sun.tools.javac.code.Types.lub 8.33 + * @compile T8058511c.java 8.34 + */ 8.35 +import java.util.List; 8.36 + 8.37 +class T8058511c { 8.38 + void test(List<? extends double[]> l) { 8.39 + (true ? l.get(0) : l.get(0)).toString(); 8.40 + } 8.41 +}