# HG changeset patch # User asaha # Date 1446164472 25200 # Node ID 874f6272fa9f47223c66b6d440df99f08c32ef85 # Parent 25b6cb57f5eb2f4ac6ed2aa323fb451911027adc# Parent c3be0c29c83c4f8687033fe9145ef9a86b1b1899 Merge diff -r 25b6cb57f5eb -r 874f6272fa9f .hgtags --- a/.hgtags Fri Oct 16 12:19:45 2015 -0700 +++ b/.hgtags Thu Oct 29 17:21:12 2015 -0700 @@ -500,4 +500,14 @@ fb2756fb330047dbbff0fa89b79e1d8d96146868 jdk8u71-b01 21306b94f23ef63cc3ac48a509d491187dadb0f6 jdk8u71-b02 43002f1aebfdaa64ad497f86c5f9a2f9b450b464 jdk8u71-b03 +531efb9ef9808eef700a0b4d9c3996090469ad6c jdk8u71-b04 +89deefc7b6bac551bb16fbb8740775cfd5f73998 jdk8u71-b05 +bc15decea6ad7b8b34b217af102f175a9a0d52c3 jdk8u71-b06 +1c93d260bf996e56d1e1f6d187aceadaa9a38d0c jdk8u72-b00 +aec633bcb3af5382013c6c25b435564aba5bc3d4 jdk8u72-b01 +dfb368f2498e5bfaac7cc7730b5e822999736cd7 jdk8u72-b02 +975709317923c28f0dfcf99d8456048f920d087e jdk8u72-b03 +106fb99e28d20623748c2c3a2120be37fcfac78f jdk8u72-b04 +5bb4ad0363a74265a931b24d0bb0f51b23f09060 jdk8u72-b05 +2e722fd7496556350510c5d3fc02c77377fd8bff jdk8u72-b06 90b497af2ba5329448da3a46a185687ae17f7098 jdk8u75-b00 diff -r 25b6cb57f5eb -r 874f6272fa9f src/share/classes/com/sun/tools/javac/code/Type.java --- a/src/share/classes/com/sun/tools/javac/code/Type.java Fri Oct 16 12:19:45 2015 -0700 +++ b/src/share/classes/com/sun/tools/javac/code/Type.java Thu Oct 29 17:21:12 2015 -0700 @@ -421,6 +421,14 @@ && (tsym.flags() & COMPOUND) != 0; } + public boolean isIntersection() { + return false; + } + + public boolean isUnion() { + return false; + } + public boolean isInterface() { return (tsym.flags() & INTERFACE) != 0; } @@ -970,6 +978,11 @@ } @Override + public boolean isUnion() { + return true; + } + + @Override public TypeKind getKind() { return TypeKind.UNION; } @@ -1003,6 +1016,11 @@ return interfaces_field.prepend(supertype_field); } + @Override + public boolean isIntersection() { + return true; + } + public List getExplicitComponents() { return allInterfaces ? interfaces_field : diff -r 25b6cb57f5eb -r 874f6272fa9f src/share/classes/com/sun/tools/javac/code/Types.java --- a/src/share/classes/com/sun/tools/javac/code/Types.java Fri Oct 16 12:19:45 2015 -0700 +++ b/src/share/classes/com/sun/tools/javac/code/Types.java Thu Oct 29 17:21:12 2015 -0700 @@ -1539,8 +1539,8 @@ } } - if (t.isCompound() || s.isCompound()) { - return !t.isCompound() ? + if (t.isIntersection() || s.isIntersection()) { + return !t.isIntersection() ? visitIntersectionType((IntersectionClassType)s.unannotatedType(), t, true) : visitIntersectionType((IntersectionClassType)t.unannotatedType(), s, false); } @@ -2255,19 +2255,28 @@ } // - // + // /** - * Make a compound type from non-empty list of types. The list should be - * ordered according to {@link Symbol#precedes(TypeSymbol,Types)}. + * Make an intersection type from non-empty list of types. The list should be ordered according to + * {@link TypeSymbol#precedes(TypeSymbol, Types)}. Note that this might cause a symbol completion. + * Hence, this version of makeIntersectionType may not be called during a classfile read. * - * @param bounds the types from which the compound type is formed - * @param supertype is objectType if all bounds are interfaces, - * null otherwise. + * @param bounds the types from which the intersection type is formed */ - public Type makeCompoundType(List bounds) { - return makeCompoundType(bounds, bounds.head.tsym.isInterface()); + public IntersectionClassType makeIntersectionType(List bounds) { + return makeIntersectionType(bounds, bounds.head.tsym.isInterface()); } - public Type makeCompoundType(List bounds, boolean allInterfaces) { + + /** + * Make an intersection type from non-empty list of types. The list should be ordered according to + * {@link TypeSymbol#precedes(TypeSymbol, Types)}. This does not cause symbol completion as + * an extra parameter indicates as to whether all bounds are interfaces - in which case the + * supertype is implicitly assumed to be 'Object'. + * + * @param bounds the types from which the intersection type is formed + * @param allInterfaces are all bounds interface types? + */ + public IntersectionClassType makeIntersectionType(List bounds, boolean allInterfaces) { Assert.check(bounds.nonEmpty()); Type firstExplicitBound = bounds.head; if (allInterfaces) { @@ -2280,23 +2289,24 @@ : names.empty, null, syms.noSymbol); - bc.type = new IntersectionClassType(bounds, bc, allInterfaces); + IntersectionClassType intersectionType = new IntersectionClassType(bounds, bc, allInterfaces); + bc.type = intersectionType; bc.erasure_field = (bounds.head.hasTag(TYPEVAR)) ? syms.objectType : // error condition, recover erasure(firstExplicitBound); bc.members_field = new Scope(bc); - return bc.type; + return intersectionType; } /** - * A convenience wrapper for {@link #makeCompoundType(List)}; the + * A convenience wrapper for {@link #makeIntersectionType(List)}; the * arguments are converted to a list and passed to the other * method. Note that this might cause a symbol completion. - * Hence, this version of makeCompoundType may not be called + * Hence, this version of makeIntersectionType may not be called * during a classfile read. */ - public Type makeCompoundType(Type bound1, Type bound2) { - return makeCompoundType(List.of(bound1, bound2)); + public Type makeIntersectionType(Type bound1, Type bound2) { + return makeIntersectionType(List.of(bound1, bound2)); } // @@ -2436,7 +2446,7 @@ private final UnaryVisitor> directSupertypes = new UnaryVisitor>() { public List visitType(final Type type, final Void ignored) { - if (!type.isCompound()) { + if (!type.isIntersection()) { final Type sup = supertype(type); return (sup == Type.noType || sup == type || sup == null) ? interfaces(type) @@ -2490,30 +2500,32 @@ // /** - * Set the bounds field of the given type variable to reflect a - * (possibly multiple) list of bounds. - * @param t a type variable - * @param bounds the bounds, must be nonempty - * @param supertype is objectType if all bounds are interfaces, - * null otherwise. + * Same as {@link Types#setBounds(TypeVar, List, boolean)}, except that third parameter is computed directly, + * as follows: if all all bounds are interface types, the computed supertype is Object,otherwise + * the supertype is simply left null (in this case, the supertype is assumed to be the head of + * the bound list passed as second argument). Note that this check might cause a symbol completion. + * Hence, this version of setBounds may not be called during a classfile read. + * + * @param t a type variable + * @param bounds the bounds, must be nonempty */ public void setBounds(TypeVar t, List bounds) { setBounds(t, bounds, bounds.head.tsym.isInterface()); } /** - * Same as {@link #setBounds(Type.TypeVar,List,Type)}, except that - * third parameter is computed directly, as follows: if all - * all bounds are interface types, the computed supertype is Object, - * otherwise the supertype is simply left null (in this case, the supertype - * is assumed to be the head of the bound list passed as second argument). - * Note that this check might cause a symbol completion. Hence, this version of - * setBounds may not be called during a classfile read. + * Set the bounds field of the given type variable to reflect a (possibly multiple) list of bounds. + * This does not cause symbol completion as an extra parameter indicates as to whether all bounds + * are interfaces - in which case the supertype is implicitly assumed to be 'Object'. + * + * @param t a type variable + * @param bounds the bounds, must be nonempty + * @param allInterfaces are all bounds interface types? */ public void setBounds(TypeVar t, List bounds, boolean allInterfaces) { t.bound = bounds.tail.isEmpty() ? bounds.head : - makeCompoundType(bounds, allInterfaces); + makeIntersectionType(bounds, allInterfaces); t.rank_field = -1; } // @@ -3063,7 +3075,7 @@ if (st == supertype(t) && is == interfaces(t)) return t; else - return makeCompoundType(is.prepend(st)); + return makeIntersectionType(is.prepend(st)); } } @@ -3566,7 +3578,7 @@ else if (compound.tail.isEmpty()) return compound.head; else - return makeCompoundType(compound); + return makeIntersectionType(compound); } /** @@ -3744,8 +3756,8 @@ synchronized (this) { if (arraySuperType == null) { // JLS 10.8: all arrays implement Cloneable and Serializable. - arraySuperType = makeCompoundType(List.of(syms.serializableType, - syms.cloneableType), true); + arraySuperType = makeIntersectionType(List.of(syms.serializableType, + syms.cloneableType), true); } } } @@ -3811,7 +3823,7 @@ return glbFlattened(union(bounds, lowers), errT); } } - return makeCompoundType(bounds); + return makeIntersectionType(bounds); } // diff -r 25b6cb57f5eb -r 874f6272fa9f src/share/classes/com/sun/tools/javac/comp/Attr.java --- a/src/share/classes/com/sun/tools/javac/comp/Attr.java Fri Oct 16 12:19:45 2015 -0700 +++ b/src/share/classes/com/sun/tools/javac/comp/Attr.java Thu Oct 29 17:21:12 2015 -0700 @@ -2434,7 +2434,7 @@ @Override public Type visitClassType(ClassType t, DiagnosticPosition pos) { - return t.isCompound() ? + return t.isIntersection() ? visitIntersectionClassType((IntersectionClassType)t, pos) : t; } @@ -2465,8 +2465,7 @@ } supertypes.append(i.tsym.type); } - IntersectionClassType notionalIntf = - (IntersectionClassType)types.makeCompoundType(supertypes.toList()); + IntersectionClassType notionalIntf = types.makeIntersectionType(supertypes.toList()); notionalIntf.allparams_field = targs.toList(); notionalIntf.tsym.flags_field |= INTERFACE; return notionalIntf.tsym; @@ -4032,7 +4031,7 @@ } else if (bounds.length() == 1) { return bounds.head.type; } else { - Type owntype = types.makeCompoundType(TreeInfo.types(bounds)); + Type owntype = types.makeIntersectionType(TreeInfo.types(bounds)); // ... the variable's bound is a class type flagged COMPOUND // (see comment for TypeVar.bound). // In this case, generate a class tree that represents the diff -r 25b6cb57f5eb -r 874f6272fa9f src/share/classes/com/sun/tools/javac/comp/Check.java --- a/src/share/classes/com/sun/tools/javac/comp/Check.java Fri Oct 16 12:19:45 2015 -0700 +++ b/src/share/classes/com/sun/tools/javac/comp/Check.java Thu Oct 29 17:21:12 2015 -0700 @@ -1813,7 +1813,7 @@ Type t1, Type t2) { return checkCompatibleAbstracts(pos, t1, t2, - types.makeCompoundType(t1, t2)); + types.makeIntersectionType(t1, t2)); } public boolean checkCompatibleAbstracts(DiagnosticPosition pos, diff -r 25b6cb57f5eb -r 874f6272fa9f src/share/classes/com/sun/tools/javac/comp/Infer.java --- a/src/share/classes/com/sun/tools/javac/comp/Infer.java Fri Oct 16 12:19:45 2015 -0700 +++ b/src/share/classes/com/sun/tools/javac/comp/Infer.java Thu Oct 29 17:21:12 2015 -0700 @@ -373,7 +373,7 @@ List upperBounds = uv.getBounds(InferenceBound.UPPER); if (Type.containsAny(upperBounds, vars)) { TypeSymbol fresh_tvar = new TypeVariableSymbol(Flags.SYNTHETIC, uv.qtype.tsym.name, null, uv.qtype.tsym.owner); - fresh_tvar.type = new TypeVar(fresh_tvar, types.makeCompoundType(uv.getBounds(InferenceBound.UPPER)), null); + fresh_tvar.type = new TypeVar(fresh_tvar, types.makeIntersectionType(uv.getBounds(InferenceBound.UPPER)), null); todo.append(uv); uv.inst = fresh_tvar.type; } else if (upperBounds.nonEmpty()) { diff -r 25b6cb57f5eb -r 874f6272fa9f src/share/classes/com/sun/tools/javac/comp/LambdaToMethod.java --- a/src/share/classes/com/sun/tools/javac/comp/LambdaToMethod.java Fri Oct 16 12:19:45 2015 -0700 +++ b/src/share/classes/com/sun/tools/javac/comp/LambdaToMethod.java Thu Oct 29 17:21:12 2015 -0700 @@ -1179,12 +1179,14 @@ @Override public void visitClassDef(JCClassDecl tree) { List prevStack = frameStack; + int prevLambdaCount = lambdaCount; SyntheticMethodNameCounter prevSyntheticMethodNameCounts = syntheticMethodNameCounts; Map prevClinits = clinits; DiagnosticSource prevSource = log.currentSource(); try { log.useSource(tree.sym.sourcefile); + lambdaCount = 0; syntheticMethodNameCounts = new SyntheticMethodNameCounter(); prevClinits = new HashMap(); if (tree.sym.owner.kind == MTH) { @@ -1211,6 +1213,7 @@ finally { log.useSource(prevSource.getFile()); frameStack = prevStack; + lambdaCount = prevLambdaCount; syntheticMethodNameCounts = prevSyntheticMethodNameCounts; clinits = prevClinits; } diff -r 25b6cb57f5eb -r 874f6272fa9f src/share/classes/com/sun/tools/javac/comp/TransTypes.java --- a/src/share/classes/com/sun/tools/javac/comp/TransTypes.java Fri Oct 16 12:19:45 2015 -0700 +++ b/src/share/classes/com/sun/tools/javac/comp/TransTypes.java Thu Oct 29 17:21:12 2015 -0700 @@ -750,7 +750,7 @@ Type originalTarget = tree.type; tree.type = erasure(tree.type); tree.expr = translate(tree.expr, tree.type); - if (originalTarget.isCompound()) { + if (originalTarget.isIntersection()) { Type.IntersectionClassType ict = (Type.IntersectionClassType)originalTarget; for (Type c : ict.getExplicitComponents()) { Type ec = erasure(c); diff -r 25b6cb57f5eb -r 874f6272fa9f src/share/classes/com/sun/tools/javac/resources/javac.properties --- a/src/share/classes/com/sun/tools/javac/resources/javac.properties Fri Oct 16 12:19:45 2015 -0700 +++ b/src/share/classes/com/sun/tools/javac/resources/javac.properties Thu Oct 29 17:21:12 2015 -0700 @@ -232,9 +232,9 @@ javac.msg.bug=\ An exception has occurred in the compiler ({0}). \ -Please file a bug at the Java Bug Database (http://bugreport.java.com/bugreport/) \ -after checking the database for duplicates. \ -Include your program and the following diagnostic in your report. Thank you. +Please file a bug against the Java compiler via the Java bug reporting page (http://bugreport.java.com) \ +after checking the Bug Database (http://bugs.java.com) for duplicates. \ +Include your program and the following diagnostic in your report. Thank you. javac.msg.io=\ \n\nAn input/output error occurred.\n\ diff -r 25b6cb57f5eb -r 874f6272fa9f test/tools/javac/lambda/lambdaNaming/TestNonSerializableLambdaNameStability.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/tools/javac/lambda/lambdaNaming/TestNonSerializableLambdaNameStability.java Thu Oct 29 17:21:12 2015 -0700 @@ -0,0 +1,157 @@ +/* + * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +/* + * @test + * @bug 8067422 + * @summary Check that the lambda names are not unnecessarily unstable + * @run main TestNonSerializableLambdaNameStability + */ + +import com.sun.tools.classfile.ClassFile; +import com.sun.tools.classfile.Method; + +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; +import java.io.IOException; +import java.io.InputStream; +import java.io.OutputStream; +import java.net.URI; +import java.net.URISyntaxException; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import javax.tools.FileObject; +import javax.tools.ForwardingJavaFileManager; +import javax.tools.JavaCompiler; +import javax.tools.JavaFileManager; +import javax.tools.JavaFileObject; +import javax.tools.JavaFileObject.Kind; +import javax.tools.SimpleJavaFileObject; +import javax.tools.ToolProvider; + +public class TestNonSerializableLambdaNameStability { + + public static void main(String... args) throws Exception { + new TestNonSerializableLambdaNameStability().run(); + } + + String lambdaSource = "public class L%d {\n" + + " public static class A {\n" + + " private Runnable r = () -> { };\n" + + " }\n" + + " public static class B {\n" + + " private Runnable r = () -> { };\n" + + " }\n" + + " private Runnable r = () -> { };\n" + + "}\n"; + + String expectedLambdaMethodName = "lambda$new$0"; + + void run() throws Exception { + List sources = new ArrayList<>(); + + for (int i = 0; i < 3; i++) { + sources.add(new SourceJavaFileObject("L" + i, String.format(lambdaSource, i))); + } + + JavaCompiler compiler = ToolProvider.getSystemJavaCompiler(); + + try (MemoryFileManager fm = new MemoryFileManager(compiler.getStandardFileManager(null, null, null))) { + if (!compiler.getTask(null, fm, null, null, null, sources).call()) { + throw new AssertionError("Compilation failed!"); + } + + for (String file : fm.name2Content.keySet()) { + byte[] fileBytes = fm.name2Content.get(file); + try (InputStream in = new ByteArrayInputStream(fileBytes)) { + boolean foundLambdaMethod = false; + ClassFile cf = ClassFile.read(in); + StringBuilder seenMethods = new StringBuilder(); + String sep = ""; + for (Method m : cf.methods) { + String methodName = m.getName(cf.constant_pool); + if (expectedLambdaMethodName.equals(methodName)) { + foundLambdaMethod = true; + break; + } + seenMethods.append(sep); + seenMethods.append(methodName); + sep = ", "; + } + + if (!foundLambdaMethod) { + throw new AbstractMethodError("Did not find the lambda method, " + + "found methods: " + seenMethods.toString()); + } + } + } + } + } + + class MemoryFileManager extends ForwardingJavaFileManager { + + final Map name2Content = new HashMap<>(); + + public MemoryFileManager(JavaFileManager fileManager) { + super(fileManager); + } + + @Override + public JavaFileObject getJavaFileForOutput(Location location, String className, Kind kind, FileObject sibling) throws IOException { + try { + return new SimpleJavaFileObject(new URI("mem://" + className.replace('.', '/') + kind.extension), kind) { + @Override public OutputStream openOutputStream() throws IOException { + return new ByteArrayOutputStream() { + @Override public void close() throws IOException { + super.close(); + name2Content.put(className, toByteArray()); + } + }; + } + }; + } catch (URISyntaxException ex) { + throw new AssertionError(ex); + } + } + + } + + class SourceJavaFileObject extends SimpleJavaFileObject { + + private final String code; + + public SourceJavaFileObject(String name, String code) throws URISyntaxException { + super(new URI("mem:///" + name + ".java"), Kind.SOURCE); + this.code = code; + } + + @Override + public CharSequence getCharContent(boolean ignoreEncodingErrors) throws IOException { + return code; + } + + } +} diff -r 25b6cb57f5eb -r 874f6272fa9f test/tools/javac/multicatch/8071291/T8071291.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/tools/javac/multicatch/8071291/T8071291.java Thu Oct 29 17:21:12 2015 -0700 @@ -0,0 +1,49 @@ +/* + * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +/* + * @test + * @bug 8071291 + * @summary Compiler crashes trying to cast UnionType to IntersectionClassType + * @compile T8071291.java + */ + +class T8071291 { + + interface A { } + class Exception1 extends Exception implements A { } + class Exception2 extends Exception implements A { } + + void test(boolean cond) { + try { + if (cond) { + throw new Exception1(); + } else { + throw new Exception2(); + } + } + catch (Exception1|Exception2 x) { + if (x instanceof Exception1) { } + } + } +}