vromero@1640: /* vromero@1640: * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved. vromero@1640: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. vromero@1640: * vromero@1640: * This code is free software; you can redistribute it and/or modify it vromero@1640: * under the terms of the GNU General Public License version 2 only, as vromero@1640: * published by the Free Software Foundation. vromero@1640: * vromero@1640: * This code is distributed in the hope that it will be useful, but WITHOUT vromero@1640: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or vromero@1640: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License vromero@1640: * version 2 for more details (a copy is included in the LICENSE file that vromero@1640: * accompanied this code). vromero@1640: * vromero@1640: * You should have received a copy of the GNU General Public License version vromero@1640: * 2 along with this work; if not, write to the Free Software Foundation, vromero@1640: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. vromero@1640: * vromero@1640: * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA vromero@1640: * or visit www.oracle.com if you need additional information or have any vromero@1640: * questions. vromero@1640: */ vromero@1640: vromero@1640: /* vromero@1640: * @test vromero@1687: * @bug 5053846 8011432 vromero@1640: * @summary javac: MethodRef entries are duplicated in the constant pool vromero@1687: * @summary javac, compiler regression iterable + captured type vromero@1640: */ vromero@1640: vromero@1640: import java.io.PrintWriter; vromero@1640: import java.io.StringWriter; vromero@1640: import java.nio.file.Paths; vromero@1640: import java.util.*; vromero@1640: vromero@1640: public class MethodRefDupInConstantPoolTest { vromero@1640: vromero@1640: private static final String methodToLookFor = vromero@1640: "java/util/Vector.iterator:()Ljava/util/Iterator;"; vromero@1640: vromero@1640: public static void main(String[] args) { vromero@1640: new MethodRefDupInConstantPoolTest().run(); vromero@1640: } vromero@1640: vromero@1640: void run() { vromero@1640: check("-v", Paths.get(System.getProperty("test.classes"), vromero@1687: this.getClass().getSimpleName() + "$TestHelper1.class").toString()); vromero@1640: check("-v", Paths.get(System.getProperty("test.classes"), vromero@1687: this.getClass().getSimpleName() + "$TestHelper2.class").toString()); vromero@1687: check("-v", Paths.get(System.getProperty("test.classes"), vromero@1687: this.getClass().getSimpleName() + "$TestHelper3.class").toString()); vromero@1687: check("-v", Paths.get(System.getProperty("test.classes"), vromero@1687: this.getClass().getSimpleName() + "$TestHelper4.class").toString()); vromero@1640: } vromero@1640: vromero@1640: void check(String... params) { vromero@1640: StringWriter s; vromero@1640: String out; vromero@1640: try (PrintWriter pw = new PrintWriter(s = new StringWriter())) { vromero@1640: com.sun.tools.javap.Main.run(params, pw); vromero@1640: out = s.toString(); vromero@1640: } vromero@1640: String constantPool = getConstantPool(out); vromero@1640: if (constantPool.indexOf(methodToLookFor) != vromero@1640: constantPool.lastIndexOf(methodToLookFor)) { vromero@1640: throw new AssertionError("There is more than one entry for the method seek " + vromero@1640: methodToLookFor); vromero@1640: } vromero@1640: } vromero@1640: vromero@1640: String getConstantPool(String out) { vromero@1640: int start = out.indexOf("Constant pool:"); vromero@1640: int end = out.indexOf("{"); vromero@1640: return out.substring(start, end); vromero@1640: } vromero@1640: vromero@1687: class TestHelper1 { vromero@1687: void m() { vromero@1687: Vector v = new Vector(); vromero@1687: Iterator iter = v.iterator(); vromero@1687: while (iter.hasNext()) { vromero@1687: Object o = iter.next(); vromero@1687: Object o2 = o; vromero@1687: } vromero@1687: for (Object o: v) { vromero@1687: Object o2 = o; vromero@1687: } vromero@1640: } vromero@1640: } vromero@1640: vromero@1687: class TestHelper2> { vromero@1687: void test(X x) { vromero@1687: for (String s : x) { } vromero@1687: } vromero@1687: } vromero@1687: vromero@1687: interface Data extends Iterable {} vromero@1687: vromero@1687: class TestHelper3> { vromero@1687: void test(X x) { vromero@1687: for (Data s : x) { } vromero@1687: } vromero@1687: } vromero@1687: vromero@1687: class TestHelper4 { vromero@1687: void test(Iterable t) { vromero@1687: for(Object a: t.iterator().next()); vromero@1687: } vromero@1640: } vromero@1640: }