Merge jdk8u66-b34

Fri, 13 Nov 2015 15:39:33 -0800

author
asaha
date
Fri, 13 Nov 2015 15:39:33 -0800
changeset 3113
0d7fcabf56ed
parent 3110
ef60638ad242
parent 3112
c474809c1579
child 3114
5ceff8f21ebd

Merge

.hgtags file | annotate | diff | comparison | revisions
src/share/classes/com/sun/tools/javac/comp/LambdaToMethod.java file | annotate | diff | comparison | revisions
     1.1 --- a/.hgtags	Tue Nov 03 07:19:08 2015 -0800
     1.2 +++ b/.hgtags	Fri Nov 13 15:39:33 2015 -0800
     1.3 @@ -427,6 +427,7 @@
     1.4  57ea4856a08f0bc87f2fe56d57b3cf1497c0cb51 jdk8u51-b31
     1.5  153378991303acf7906684380a025347a95bc95e jdk8u51-b32
     1.6  e7810a2613c9b9b407125cbd17add7bfeebfdb03 jdk8u51-b33
     1.7 +51997141b15c0903773064cb9c1e57b791ffd66d jdk8u51-b34
     1.8  0c514d1fd006fc79d35b670de10c370c8d559db7 jdk8u60-b00
     1.9  0ba07c272e33c93377a5d7ed98b9de873cc91980 jdk8u60-b01
    1.10  387cf62ce7895dd5e067aaa51faa93d5c078583e jdk8u60-b02
     2.1 --- a/src/share/classes/com/sun/tools/javac/comp/LambdaToMethod.java	Tue Nov 03 07:19:08 2015 -0800
     2.2 +++ b/src/share/classes/com/sun/tools/javac/comp/LambdaToMethod.java	Fri Nov 13 15:39:33 2015 -0800
     2.3 @@ -1179,12 +1179,14 @@
     2.4          @Override
     2.5          public void visitClassDef(JCClassDecl tree) {
     2.6              List<Frame> prevStack = frameStack;
     2.7 +            int prevLambdaCount = lambdaCount;
     2.8              SyntheticMethodNameCounter prevSyntheticMethodNameCounts =
     2.9                      syntheticMethodNameCounts;
    2.10              Map<ClassSymbol, Symbol> prevClinits = clinits;
    2.11              DiagnosticSource prevSource = log.currentSource();
    2.12              try {
    2.13                  log.useSource(tree.sym.sourcefile);
    2.14 +                lambdaCount = 0;
    2.15                  syntheticMethodNameCounts = new SyntheticMethodNameCounter();
    2.16                  prevClinits = new HashMap<ClassSymbol, Symbol>();
    2.17                  if (tree.sym.owner.kind == MTH) {
    2.18 @@ -1211,6 +1213,7 @@
    2.19              finally {
    2.20                  log.useSource(prevSource.getFile());
    2.21                  frameStack = prevStack;
    2.22 +                lambdaCount = prevLambdaCount;
    2.23                  syntheticMethodNameCounts = prevSyntheticMethodNameCounts;
    2.24                  clinits = prevClinits;
    2.25              }
     3.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     3.2 +++ b/test/tools/javac/lambda/lambdaNaming/TestNonSerializableLambdaNameStability.java	Fri Nov 13 15:39:33 2015 -0800
     3.3 @@ -0,0 +1,157 @@
     3.4 +/*
     3.5 + * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
     3.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     3.7 + *
     3.8 + * This code is free software; you can redistribute it and/or modify it
     3.9 + * under the terms of the GNU General Public License version 2 only, as
    3.10 + * published by the Free Software Foundation.
    3.11 + *
    3.12 + * This code is distributed in the hope that it will be useful, but WITHOUT
    3.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    3.14 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
    3.15 + * version 2 for more details (a copy is included in the LICENSE file that
    3.16 + * accompanied this code).
    3.17 + *
    3.18 + * You should have received a copy of the GNU General Public License version
    3.19 + * 2 along with this work; if not, write to the Free Software Foundation,
    3.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
    3.21 + *
    3.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
    3.23 + * or visit www.oracle.com if you need additional information or have any
    3.24 + * questions.
    3.25 + */
    3.26 +
    3.27 +/*
    3.28 + * @test
    3.29 + * @bug 8067422
    3.30 + * @summary Check that the lambda names are not unnecessarily unstable
    3.31 + * @run main TestNonSerializableLambdaNameStability
    3.32 + */
    3.33 +
    3.34 +import com.sun.tools.classfile.ClassFile;
    3.35 +import com.sun.tools.classfile.Method;
    3.36 +
    3.37 +import java.io.ByteArrayInputStream;
    3.38 +import java.io.ByteArrayOutputStream;
    3.39 +import java.io.IOException;
    3.40 +import java.io.InputStream;
    3.41 +import java.io.OutputStream;
    3.42 +import java.net.URI;
    3.43 +import java.net.URISyntaxException;
    3.44 +import java.util.ArrayList;
    3.45 +import java.util.HashMap;
    3.46 +import java.util.List;
    3.47 +import java.util.Map;
    3.48 +
    3.49 +import javax.tools.FileObject;
    3.50 +import javax.tools.ForwardingJavaFileManager;
    3.51 +import javax.tools.JavaCompiler;
    3.52 +import javax.tools.JavaFileManager;
    3.53 +import javax.tools.JavaFileObject;
    3.54 +import javax.tools.JavaFileObject.Kind;
    3.55 +import javax.tools.SimpleJavaFileObject;
    3.56 +import javax.tools.ToolProvider;
    3.57 +
    3.58 +public class TestNonSerializableLambdaNameStability {
    3.59 +
    3.60 +    public static void main(String... args) throws Exception {
    3.61 +        new TestNonSerializableLambdaNameStability().run();
    3.62 +    }
    3.63 +
    3.64 +    String lambdaSource = "public class L%d {\n" +
    3.65 +                          "    public static class A {\n" +
    3.66 +                          "        private Runnable r = () -> { };\n" +
    3.67 +                          "    }\n" +
    3.68 +                          "    public static class B {\n" +
    3.69 +                          "        private Runnable r = () -> { };\n" +
    3.70 +                          "    }\n" +
    3.71 +                          "    private Runnable r = () -> { };\n" +
    3.72 +                          "}\n";
    3.73 +
    3.74 +    String expectedLambdaMethodName = "lambda$new$0";
    3.75 +
    3.76 +    void run() throws Exception {
    3.77 +        List<JavaFileObject> sources = new ArrayList<>();
    3.78 +
    3.79 +        for (int i = 0; i < 3; i++) {
    3.80 +            sources.add(new SourceJavaFileObject("L" + i, String.format(lambdaSource, i)));
    3.81 +        }
    3.82 +
    3.83 +        JavaCompiler compiler = ToolProvider.getSystemJavaCompiler();
    3.84 +
    3.85 +        try (MemoryFileManager fm = new MemoryFileManager(compiler.getStandardFileManager(null, null, null))) {
    3.86 +            if (!compiler.getTask(null, fm, null, null, null, sources).call()) {
    3.87 +                throw new AssertionError("Compilation failed!");
    3.88 +            }
    3.89 +
    3.90 +            for (String file : fm.name2Content.keySet()) {
    3.91 +                byte[] fileBytes = fm.name2Content.get(file);
    3.92 +                try (InputStream in = new ByteArrayInputStream(fileBytes)) {
    3.93 +                    boolean foundLambdaMethod = false;
    3.94 +                    ClassFile cf = ClassFile.read(in);
    3.95 +                    StringBuilder seenMethods = new StringBuilder();
    3.96 +                    String sep = "";
    3.97 +                    for (Method m : cf.methods) {
    3.98 +                        String methodName = m.getName(cf.constant_pool);
    3.99 +                        if (expectedLambdaMethodName.equals(methodName)) {
   3.100 +                            foundLambdaMethod = true;
   3.101 +                            break;
   3.102 +                        }
   3.103 +                        seenMethods.append(sep);
   3.104 +                        seenMethods.append(methodName);
   3.105 +                        sep = ", ";
   3.106 +                    }
   3.107 +
   3.108 +                    if (!foundLambdaMethod) {
   3.109 +                        throw new AbstractMethodError("Did not find the lambda method, " +
   3.110 +                                                      "found methods: " + seenMethods.toString());
   3.111 +                    }
   3.112 +                }
   3.113 +            }
   3.114 +        }
   3.115 +    }
   3.116 +
   3.117 +    class MemoryFileManager extends ForwardingJavaFileManager<JavaFileManager> {
   3.118 +
   3.119 +        final Map<String, byte[]> name2Content = new HashMap<>();
   3.120 +
   3.121 +        public MemoryFileManager(JavaFileManager fileManager) {
   3.122 +            super(fileManager);
   3.123 +        }
   3.124 +
   3.125 +        @Override
   3.126 +        public JavaFileObject getJavaFileForOutput(Location location, String className, Kind kind, FileObject sibling) throws IOException {
   3.127 +            try {
   3.128 +                return new SimpleJavaFileObject(new URI("mem://" + className.replace('.', '/') + kind.extension), kind) {
   3.129 +                    @Override public OutputStream openOutputStream() throws IOException {
   3.130 +                        return new ByteArrayOutputStream() {
   3.131 +                            @Override public void close() throws IOException {
   3.132 +                                super.close();
   3.133 +                                name2Content.put(className, toByteArray());
   3.134 +                            }
   3.135 +                        };
   3.136 +                    }
   3.137 +                };
   3.138 +            } catch (URISyntaxException ex) {
   3.139 +                throw new AssertionError(ex);
   3.140 +            }
   3.141 +        }
   3.142 +
   3.143 +    }
   3.144 +
   3.145 +    class SourceJavaFileObject extends SimpleJavaFileObject {
   3.146 +
   3.147 +        private final String code;
   3.148 +
   3.149 +        public SourceJavaFileObject(String name, String code) throws URISyntaxException {
   3.150 +            super(new URI("mem:///" + name + ".java"), Kind.SOURCE);
   3.151 +            this.code = code;
   3.152 +        }
   3.153 +
   3.154 +        @Override
   3.155 +        public CharSequence getCharContent(boolean ignoreEncodingErrors) throws IOException {
   3.156 +            return code;
   3.157 +        }
   3.158 +
   3.159 +    }
   3.160 +}

mercurial