test/tools/javac/T5053846/MethodRefDupInConstantPoolTest.java

Wed, 13 Aug 2014 14:50:00 -0700

author
katleman
date
Wed, 13 Aug 2014 14:50:00 -0700
changeset 2549
0b6cc4ea670f
parent 1687
a4be2c2fe0a1
child 2525
2eb010b6cb22
permissions
-rw-r--r--

Added tag jdk8u40-b01 for changeset bf89a471779d

vromero@1640 1 /*
vromero@1640 2 * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved.
vromero@1640 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
vromero@1640 4 *
vromero@1640 5 * This code is free software; you can redistribute it and/or modify it
vromero@1640 6 * under the terms of the GNU General Public License version 2 only, as
vromero@1640 7 * published by the Free Software Foundation.
vromero@1640 8 *
vromero@1640 9 * This code is distributed in the hope that it will be useful, but WITHOUT
vromero@1640 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
vromero@1640 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
vromero@1640 12 * version 2 for more details (a copy is included in the LICENSE file that
vromero@1640 13 * accompanied this code).
vromero@1640 14 *
vromero@1640 15 * You should have received a copy of the GNU General Public License version
vromero@1640 16 * 2 along with this work; if not, write to the Free Software Foundation,
vromero@1640 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
vromero@1640 18 *
vromero@1640 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
vromero@1640 20 * or visit www.oracle.com if you need additional information or have any
vromero@1640 21 * questions.
vromero@1640 22 */
vromero@1640 23
vromero@1640 24 /*
vromero@1640 25 * @test
vromero@1687 26 * @bug 5053846 8011432
vromero@1640 27 * @summary javac: MethodRef entries are duplicated in the constant pool
vromero@1687 28 * @summary javac, compiler regression iterable + captured type
vromero@1640 29 */
vromero@1640 30
vromero@1640 31 import java.io.PrintWriter;
vromero@1640 32 import java.io.StringWriter;
vromero@1640 33 import java.nio.file.Paths;
vromero@1640 34 import java.util.*;
vromero@1640 35
vromero@1640 36 public class MethodRefDupInConstantPoolTest {
vromero@1640 37
vromero@1640 38 private static final String methodToLookFor =
vromero@1640 39 "java/util/Vector.iterator:()Ljava/util/Iterator;";
vromero@1640 40
vromero@1640 41 public static void main(String[] args) {
vromero@1640 42 new MethodRefDupInConstantPoolTest().run();
vromero@1640 43 }
vromero@1640 44
vromero@1640 45 void run() {
vromero@1640 46 check("-v", Paths.get(System.getProperty("test.classes"),
vromero@1687 47 this.getClass().getSimpleName() + "$TestHelper1.class").toString());
vromero@1640 48 check("-v", Paths.get(System.getProperty("test.classes"),
vromero@1687 49 this.getClass().getSimpleName() + "$TestHelper2.class").toString());
vromero@1687 50 check("-v", Paths.get(System.getProperty("test.classes"),
vromero@1687 51 this.getClass().getSimpleName() + "$TestHelper3.class").toString());
vromero@1687 52 check("-v", Paths.get(System.getProperty("test.classes"),
vromero@1687 53 this.getClass().getSimpleName() + "$TestHelper4.class").toString());
vromero@1640 54 }
vromero@1640 55
vromero@1640 56 void check(String... params) {
vromero@1640 57 StringWriter s;
vromero@1640 58 String out;
vromero@1640 59 try (PrintWriter pw = new PrintWriter(s = new StringWriter())) {
vromero@1640 60 com.sun.tools.javap.Main.run(params, pw);
vromero@1640 61 out = s.toString();
vromero@1640 62 }
vromero@1640 63 String constantPool = getConstantPool(out);
vromero@1640 64 if (constantPool.indexOf(methodToLookFor) !=
vromero@1640 65 constantPool.lastIndexOf(methodToLookFor)) {
vromero@1640 66 throw new AssertionError("There is more than one entry for the method seek " +
vromero@1640 67 methodToLookFor);
vromero@1640 68 }
vromero@1640 69 }
vromero@1640 70
vromero@1640 71 String getConstantPool(String out) {
vromero@1640 72 int start = out.indexOf("Constant pool:");
vromero@1640 73 int end = out.indexOf("{");
vromero@1640 74 return out.substring(start, end);
vromero@1640 75 }
vromero@1640 76
vromero@1687 77 class TestHelper1 {
vromero@1687 78 void m() {
vromero@1687 79 Vector v = new Vector();
vromero@1687 80 Iterator iter = v.iterator();
vromero@1687 81 while (iter.hasNext()) {
vromero@1687 82 Object o = iter.next();
vromero@1687 83 Object o2 = o;
vromero@1687 84 }
vromero@1687 85 for (Object o: v) {
vromero@1687 86 Object o2 = o;
vromero@1687 87 }
vromero@1640 88 }
vromero@1640 89 }
vromero@1640 90
vromero@1687 91 class TestHelper2<X extends Number & Iterable<String>> {
vromero@1687 92 void test(X x) {
vromero@1687 93 for (String s : x) { }
vromero@1687 94 }
vromero@1687 95 }
vromero@1687 96
vromero@1687 97 interface Data extends Iterable<String> {}
vromero@1687 98
vromero@1687 99 class TestHelper3<X extends Number & Iterable<? extends Data>> {
vromero@1687 100 void test(X x) {
vromero@1687 101 for (Data s : x) { }
vromero@1687 102 }
vromero@1687 103 }
vromero@1687 104
vromero@1687 105 class TestHelper4 {
vromero@1687 106 void test(Iterable<? extends Data> t) {
vromero@1687 107 for(Object a: t.iterator().next());
vromero@1687 108 }
vromero@1640 109 }
vromero@1640 110 }

mercurial