1.1 --- a/test/tools/javac/T7093325.java Tue Jan 08 10:17:29 2013 +0100 1.2 +++ b/test/tools/javac/T7093325.java Tue Jan 08 13:47:57 2013 +0000 1.3 @@ -1,5 +1,5 @@ 1.4 /* 1.5 - * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved. 1.6 + * Copyright (c) 2011, 2013, Oracle and/or its affiliates. All rights reserved. 1.7 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 1.8 * 1.9 * This code is free software; you can redistribute it and/or modify it 1.10 @@ -25,35 +25,29 @@ 1.11 * @test 1.12 * @bug 7093325 1.13 * @summary Redundant entry in bytecode exception table 1.14 + * @library lib 1.15 + * @build JavacTestingAbstractThreadedTest 1.16 + * @run main T7093325 1.17 */ 1.18 1.19 +import java.io.File; 1.20 +import java.net.URI; 1.21 +import java.util.Arrays; 1.22 +import javax.tools.JavaCompiler; 1.23 +import javax.tools.JavaFileObject; 1.24 +import javax.tools.SimpleJavaFileObject; 1.25 +import javax.tools.ToolProvider; 1.26 + 1.27 import com.sun.source.util.JavacTask; 1.28 import com.sun.tools.classfile.Attribute; 1.29 import com.sun.tools.classfile.ClassFile; 1.30 import com.sun.tools.classfile.Code_attribute; 1.31 import com.sun.tools.classfile.ConstantPool.*; 1.32 import com.sun.tools.classfile.Method; 1.33 -import com.sun.tools.javac.api.JavacTool; 1.34 1.35 -import java.io.File; 1.36 -import java.net.URI; 1.37 -import java.util.Arrays; 1.38 -import javax.tools.JavaCompiler; 1.39 -import javax.tools.JavaFileObject; 1.40 -import javax.tools.SimpleJavaFileObject; 1.41 -import javax.tools.StandardJavaFileManager; 1.42 -import javax.tools.ToolProvider; 1.43 - 1.44 - 1.45 -public class T7093325 { 1.46 - 1.47 - /** global decls ***/ 1.48 - 1.49 - // Create a single file manager and reuse it for each compile to save time. 1.50 - static StandardJavaFileManager fm = JavacTool.create().getStandardFileManager(null, null, null); 1.51 - 1.52 - //statistics 1.53 - static int checkCount = 0; 1.54 +public class T7093325 1.55 + extends JavacTestingAbstractThreadedTest 1.56 + implements Runnable { 1.57 1.58 enum StatementKind { 1.59 THROW("throw new RuntimeException();", false, false), 1.60 @@ -89,7 +83,8 @@ 1.61 if (this.ordinal() == 0) { 1.62 return catchStr; 1.63 } else { 1.64 - return CatchArity.values()[this.ordinal() - 1].catchers() + catchStr; 1.65 + return CatchArity.values()[this.ordinal() - 1].catchers() + 1.66 + catchStr; 1.67 } 1.68 } 1.69 } 1.70 @@ -98,31 +93,36 @@ 1.71 for (CatchArity ca : CatchArity.values()) { 1.72 for (StatementKind stmt0 : StatementKind.values()) { 1.73 if (ca.ordinal() == 0) { 1.74 - new T7093325(ca, stmt0).compileAndCheck(); 1.75 + pool.execute(new T7093325(ca, stmt0)); 1.76 continue; 1.77 } 1.78 for (StatementKind stmt1 : StatementKind.values()) { 1.79 if (ca.ordinal() == 1) { 1.80 - new T7093325(ca, stmt0, stmt1).compileAndCheck(); 1.81 + pool.execute(new T7093325(ca, stmt0, stmt1)); 1.82 continue; 1.83 } 1.84 for (StatementKind stmt2 : StatementKind.values()) { 1.85 if (ca.ordinal() == 2) { 1.86 - new T7093325(ca, stmt0, stmt1, stmt2).compileAndCheck(); 1.87 + pool.execute(new T7093325(ca, stmt0, stmt1, stmt2)); 1.88 continue; 1.89 } 1.90 for (StatementKind stmt3 : StatementKind.values()) { 1.91 if (ca.ordinal() == 3) { 1.92 - new T7093325(ca, stmt0, stmt1, stmt2, stmt3).compileAndCheck(); 1.93 + pool.execute( 1.94 + new T7093325(ca, stmt0, stmt1, stmt2, stmt3)); 1.95 continue; 1.96 } 1.97 for (StatementKind stmt4 : StatementKind.values()) { 1.98 if (ca.ordinal() == 4) { 1.99 - new T7093325(ca, stmt0, stmt1, stmt2, stmt3, stmt4).compileAndCheck(); 1.100 + pool.execute( 1.101 + new T7093325(ca, stmt0, stmt1, 1.102 + stmt2, stmt3, stmt4)); 1.103 continue; 1.104 } 1.105 for (StatementKind stmt5 : StatementKind.values()) { 1.106 - new T7093325(ca, stmt0, stmt1, stmt2, stmt3, stmt4, stmt5).compileAndCheck(); 1.107 + pool.execute( 1.108 + new T7093325(ca, stmt0, stmt1, stmt2, 1.109 + stmt3, stmt4, stmt5)); 1.110 } 1.111 } 1.112 } 1.113 @@ -131,7 +131,7 @@ 1.114 } 1.115 } 1.116 1.117 - System.out.println("Total checks made: " + checkCount); 1.118 + checkAfterExec(); 1.119 } 1.120 1.121 /** instance decls **/ 1.122 @@ -144,17 +144,18 @@ 1.123 this.stmts = stmts; 1.124 } 1.125 1.126 - void compileAndCheck() throws Exception { 1.127 + @Override 1.128 + public void run() { 1.129 + int id = checkCount.incrementAndGet(); 1.130 final JavaCompiler tool = ToolProvider.getSystemJavaCompiler(); 1.131 - JavaSource source = new JavaSource(); 1.132 - JavacTask ct = (JavacTask)tool.getTask(null, fm, null, 1.133 + JavaSource source = new JavaSource(id); 1.134 + JavacTask ct = (JavacTask)tool.getTask(null, fm.get(), null, 1.135 null, null, Arrays.asList(source)); 1.136 ct.call(); 1.137 - verifyBytecode(source); 1.138 + verifyBytecode(source, id); 1.139 } 1.140 1.141 - void verifyBytecode(JavaSource source) { 1.142 - checkCount++; 1.143 + void verifyBytecode(JavaSource source, int id) { 1.144 boolean lastInlined = false; 1.145 boolean hasCode = false; 1.146 int gapsCount = 0; 1.147 @@ -172,11 +173,12 @@ 1.148 1.149 //System.out.printf("gaps %d \n %s \n", gapsCount, source.toString()); 1.150 1.151 - File compiledTest = new File("Test.class"); 1.152 + File compiledTest = new File(String.format("Test%s.class", id)); 1.153 try { 1.154 ClassFile cf = ClassFile.read(compiledTest); 1.155 if (cf == null) { 1.156 - throw new Error("Classfile not found: " + compiledTest.getName()); 1.157 + throw new Error("Classfile not found: " + 1.158 + compiledTest.getName()); 1.159 } 1.160 1.161 Method test_method = null; 1.162 @@ -232,7 +234,7 @@ 1.163 "class C extends RuntimeException {} \n" + 1.164 "class D extends RuntimeException {} \n" + 1.165 "class E extends RuntimeException {} \n" + 1.166 - "class Test {\n" + 1.167 + "class Test#ID {\n" + 1.168 " void test() {\n" + 1.169 " try { #S0 } #C finally { System.out.println(); }\n" + 1.170 " }\n" + 1.171 @@ -240,10 +242,12 @@ 1.172 1.173 String source; 1.174 1.175 - public JavaSource() { 1.176 - super(URI.create("myfo:/Test.java"), JavaFileObject.Kind.SOURCE); 1.177 + public JavaSource(int id) { 1.178 + super(URI.create(String.format("myfo:/Test%s.java", id)), 1.179 + JavaFileObject.Kind.SOURCE); 1.180 source = source_template.replace("#C", ca.catchers()); 1.181 source = source.replace("#S0", stmts[0].stmt); 1.182 + source = source.replace("#ID", String.valueOf(id)); 1.183 for (int i = 1; i < ca.ordinal() + 1; i++) { 1.184 source = source.replace("#S" + i, stmts[i].stmt); 1.185 } 1.186 @@ -259,4 +263,5 @@ 1.187 return source; 1.188 } 1.189 } 1.190 + 1.191 }