mcimadamore@1109: /* vromero@1482: * Copyright (c) 2011, 2013, Oracle and/or its affiliates. All rights reserved. mcimadamore@1109: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. mcimadamore@1109: * mcimadamore@1109: * This code is free software; you can redistribute it and/or modify it mcimadamore@1109: * under the terms of the GNU General Public License version 2 only, as mcimadamore@1109: * published by the Free Software Foundation. mcimadamore@1109: * mcimadamore@1109: * This code is distributed in the hope that it will be useful, but WITHOUT mcimadamore@1109: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or mcimadamore@1109: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License mcimadamore@1109: * version 2 for more details (a copy is included in the LICENSE file that mcimadamore@1109: * accompanied this code). mcimadamore@1109: * mcimadamore@1109: * You should have received a copy of the GNU General Public License version mcimadamore@1109: * 2 along with this work; if not, write to the Free Software Foundation, mcimadamore@1109: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. mcimadamore@1109: * mcimadamore@1109: * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA mcimadamore@1109: * or visit www.oracle.com if you need additional information or have any mcimadamore@1109: * questions. mcimadamore@1109: */ mcimadamore@1109: mcimadamore@1109: /* mcimadamore@1109: * @test vromero@1520: * @bug 7093325 8006694 mcimadamore@1109: * @summary Redundant entry in bytecode exception table vromero@1520: * temporarily workaround combo tests are causing time out in several platforms vromero@1482: * @library lib vromero@1482: * @build JavacTestingAbstractThreadedTest vromero@1520: * @run main/othervm T7093325 mcimadamore@1109: */ mcimadamore@1109: vromero@1520: // use /othervm to avoid jtreg timeout issues (CODETOOLS-7900047) vromero@1520: // see JDK-8006746 vromero@1520: vromero@1482: import java.io.File; vromero@1482: import java.net.URI; vromero@1482: import java.util.Arrays; vromero@1482: import javax.tools.JavaCompiler; vromero@1482: import javax.tools.JavaFileObject; vromero@1482: import javax.tools.SimpleJavaFileObject; vromero@1482: import javax.tools.ToolProvider; vromero@1482: mcimadamore@1109: import com.sun.source.util.JavacTask; mcimadamore@1109: import com.sun.tools.classfile.Attribute; mcimadamore@1109: import com.sun.tools.classfile.ClassFile; mcimadamore@1109: import com.sun.tools.classfile.Code_attribute; mcimadamore@1109: import com.sun.tools.classfile.ConstantPool.*; mcimadamore@1109: import com.sun.tools.classfile.Method; mcimadamore@1109: vromero@1482: public class T7093325 vromero@1482: extends JavacTestingAbstractThreadedTest vromero@1482: implements Runnable { mcimadamore@1109: mcimadamore@1109: enum StatementKind { mcimadamore@1109: THROW("throw new RuntimeException();", false, false), mcimadamore@1109: RETURN_NONEMPTY("System.out.println(); return;", true, false), mcimadamore@1109: RETURN_EMPTY("return;", true, true), mcimadamore@1109: APPLY("System.out.println();", true, false); mcimadamore@1109: mcimadamore@1109: String stmt; mcimadamore@1109: boolean canInline; mcimadamore@1109: boolean empty; mcimadamore@1109: mcimadamore@1109: private StatementKind(String stmt, boolean canInline, boolean empty) { mcimadamore@1109: this.stmt = stmt; mcimadamore@1109: this.canInline = canInline; mcimadamore@1109: this.empty = empty; mcimadamore@1109: } mcimadamore@1109: } mcimadamore@1109: mcimadamore@1109: enum CatchArity { mcimadamore@1109: NONE(""), mcimadamore@1109: ONE("catch (A a) { #S1 }"), mcimadamore@1109: TWO("catch (B b) { #S2 }"), mcimadamore@1109: THREE("catch (C c) { #S3 }"), mcimadamore@1109: FOUR("catch (D d) { #S4 }"); mcimadamore@1109: mcimadamore@1109: String catchStr; mcimadamore@1109: mcimadamore@1109: private CatchArity(String catchStr) { mcimadamore@1109: this.catchStr = catchStr; mcimadamore@1109: } mcimadamore@1109: mcimadamore@1109: String catchers() { mcimadamore@1109: if (this.ordinal() == 0) { mcimadamore@1109: return catchStr; mcimadamore@1109: } else { vromero@1482: return CatchArity.values()[this.ordinal() - 1].catchers() + vromero@1482: catchStr; mcimadamore@1109: } mcimadamore@1109: } mcimadamore@1109: } mcimadamore@1109: mcimadamore@1109: public static void main(String... args) throws Exception { mcimadamore@1109: for (CatchArity ca : CatchArity.values()) { mcimadamore@1109: for (StatementKind stmt0 : StatementKind.values()) { mcimadamore@1109: if (ca.ordinal() == 0) { vromero@1482: pool.execute(new T7093325(ca, stmt0)); mcimadamore@1109: continue; mcimadamore@1109: } mcimadamore@1109: for (StatementKind stmt1 : StatementKind.values()) { mcimadamore@1109: if (ca.ordinal() == 1) { vromero@1482: pool.execute(new T7093325(ca, stmt0, stmt1)); mcimadamore@1109: continue; mcimadamore@1109: } mcimadamore@1109: for (StatementKind stmt2 : StatementKind.values()) { mcimadamore@1109: if (ca.ordinal() == 2) { vromero@1482: pool.execute(new T7093325(ca, stmt0, stmt1, stmt2)); mcimadamore@1109: continue; mcimadamore@1109: } mcimadamore@1109: for (StatementKind stmt3 : StatementKind.values()) { mcimadamore@1109: if (ca.ordinal() == 3) { vromero@1482: pool.execute( vromero@1482: new T7093325(ca, stmt0, stmt1, stmt2, stmt3)); mcimadamore@1109: continue; mcimadamore@1109: } mcimadamore@1109: for (StatementKind stmt4 : StatementKind.values()) { mcimadamore@1109: if (ca.ordinal() == 4) { vromero@1482: pool.execute( vromero@1482: new T7093325(ca, stmt0, stmt1, vromero@1482: stmt2, stmt3, stmt4)); mcimadamore@1109: continue; mcimadamore@1109: } mcimadamore@1109: for (StatementKind stmt5 : StatementKind.values()) { vromero@1482: pool.execute( vromero@1482: new T7093325(ca, stmt0, stmt1, stmt2, vromero@1482: stmt3, stmt4, stmt5)); mcimadamore@1109: } mcimadamore@1109: } mcimadamore@1109: } mcimadamore@1109: } mcimadamore@1109: } mcimadamore@1109: } mcimadamore@1109: } mcimadamore@1109: vromero@1482: checkAfterExec(); mcimadamore@1109: } mcimadamore@1109: mcimadamore@1109: /** instance decls **/ mcimadamore@1109: mcimadamore@1109: CatchArity ca; mcimadamore@1109: StatementKind[] stmts; mcimadamore@1109: mcimadamore@1109: public T7093325(CatchArity ca, StatementKind... stmts) { mcimadamore@1109: this.ca = ca; mcimadamore@1109: this.stmts = stmts; mcimadamore@1109: } mcimadamore@1109: vromero@1482: @Override vromero@1482: public void run() { vromero@1482: int id = checkCount.incrementAndGet(); mcimadamore@1109: final JavaCompiler tool = ToolProvider.getSystemJavaCompiler(); vromero@1482: JavaSource source = new JavaSource(id); vromero@1482: JavacTask ct = (JavacTask)tool.getTask(null, fm.get(), null, mcimadamore@1109: null, null, Arrays.asList(source)); mcimadamore@1109: ct.call(); vromero@1482: verifyBytecode(source, id); mcimadamore@1109: } mcimadamore@1109: vromero@1482: void verifyBytecode(JavaSource source, int id) { mcimadamore@1109: boolean lastInlined = false; mcimadamore@1109: boolean hasCode = false; mcimadamore@1109: int gapsCount = 0; mcimadamore@1109: for (int i = 0; i < stmts.length ; i++) { mcimadamore@1109: lastInlined = stmts[i].canInline; mcimadamore@1109: hasCode = hasCode || !stmts[i].empty; mcimadamore@1109: if (lastInlined && hasCode) { mcimadamore@1109: hasCode = false; mcimadamore@1109: gapsCount++; mcimadamore@1109: } mcimadamore@1109: } mcimadamore@1109: if (!lastInlined) { mcimadamore@1109: gapsCount++; mcimadamore@1109: } mcimadamore@1109: vromero@1482: File compiledTest = new File(String.format("Test%s.class", id)); mcimadamore@1109: try { mcimadamore@1109: ClassFile cf = ClassFile.read(compiledTest); mcimadamore@1109: if (cf == null) { vromero@1482: throw new Error("Classfile not found: " + vromero@1482: compiledTest.getName()); mcimadamore@1109: } mcimadamore@1109: mcimadamore@1109: Method test_method = null; mcimadamore@1109: for (Method m : cf.methods) { mcimadamore@1109: if (m.getName(cf.constant_pool).equals("test")) { mcimadamore@1109: test_method = m; mcimadamore@1109: break; mcimadamore@1109: } mcimadamore@1109: } mcimadamore@1109: mcimadamore@1109: if (test_method == null) { mcimadamore@1109: throw new Error("Method test() not found in class Test"); mcimadamore@1109: } mcimadamore@1109: mcimadamore@1109: Code_attribute code = null; mcimadamore@1109: for (Attribute a : test_method.attributes) { mcimadamore@1109: if (a.getName(cf.constant_pool).equals(Attribute.Code)) { mcimadamore@1109: code = (Code_attribute)a; mcimadamore@1109: break; mcimadamore@1109: } mcimadamore@1109: } mcimadamore@1109: mcimadamore@1109: if (code == null) { mcimadamore@1109: throw new Error("Code attribute not found in method test()"); mcimadamore@1109: } mcimadamore@1109: mcimadamore@1109: int actualGapsCount = 0; mcimadamore@1109: for (int i = 0; i < code.exception_table_langth ; i++) { mcimadamore@1109: int catchType = code.exception_table[i].catch_type; mcimadamore@1109: if (catchType == 0) { //any mcimadamore@1109: actualGapsCount++; mcimadamore@1109: } mcimadamore@1109: } mcimadamore@1109: mcimadamore@1109: if (actualGapsCount != gapsCount) { mcimadamore@1109: throw new Error("Bad exception table for test()\n" + mcimadamore@1109: "expected gaps: " + gapsCount + "\n" + mcimadamore@1109: "found gaps: " + actualGapsCount + "\n" + mcimadamore@1109: source); mcimadamore@1109: } mcimadamore@1109: } catch (Exception e) { mcimadamore@1109: e.printStackTrace(); mcimadamore@1109: throw new Error("error reading " + compiledTest +": " + e); mcimadamore@1109: } mcimadamore@1109: mcimadamore@1109: } mcimadamore@1109: mcimadamore@1109: class JavaSource extends SimpleJavaFileObject { mcimadamore@1109: mcimadamore@1109: static final String source_template = mcimadamore@1109: "class A extends RuntimeException {} \n" + mcimadamore@1109: "class B extends RuntimeException {} \n" + mcimadamore@1109: "class C extends RuntimeException {} \n" + mcimadamore@1109: "class D extends RuntimeException {} \n" + mcimadamore@1109: "class E extends RuntimeException {} \n" + vromero@1482: "class Test#ID {\n" + mcimadamore@1109: " void test() {\n" + mcimadamore@1109: " try { #S0 } #C finally { System.out.println(); }\n" + mcimadamore@1109: " }\n" + mcimadamore@1109: "}"; mcimadamore@1109: mcimadamore@1109: String source; mcimadamore@1109: vromero@1482: public JavaSource(int id) { vromero@1482: super(URI.create(String.format("myfo:/Test%s.java", id)), vromero@1482: JavaFileObject.Kind.SOURCE); mcimadamore@1109: source = source_template.replace("#C", ca.catchers()); mcimadamore@1109: source = source.replace("#S0", stmts[0].stmt); vromero@1482: source = source.replace("#ID", String.valueOf(id)); mcimadamore@1109: for (int i = 1; i < ca.ordinal() + 1; i++) { mcimadamore@1109: source = source.replace("#S" + i, stmts[i].stmt); mcimadamore@1109: } mcimadamore@1109: } mcimadamore@1109: mcimadamore@1109: @Override mcimadamore@1109: public String toString() { mcimadamore@1109: return source; mcimadamore@1109: } mcimadamore@1109: mcimadamore@1109: @Override mcimadamore@1109: public CharSequence getCharContent(boolean ignoreEncodingErrors) { mcimadamore@1109: return source; mcimadamore@1109: } mcimadamore@1109: } vromero@1482: mcimadamore@1109: }