test/tools/javac/T7093325.java

changeset 1482
954541f13717
parent 1109
3cdfa97e1be9
child 1520
5c956be64b9e
equal deleted inserted replaced
1481:d07340b61e6a 1482:954541f13717
1 /* 1 /*
2 * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved. 2 * Copyright (c) 2011, 2013, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 * 4 *
5 * This code is free software; you can redistribute it and/or modify it 5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as 6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. 7 * published by the Free Software Foundation.
23 23
24 /* 24 /*
25 * @test 25 * @test
26 * @bug 7093325 26 * @bug 7093325
27 * @summary Redundant entry in bytecode exception table 27 * @summary Redundant entry in bytecode exception table
28 * @library lib
29 * @build JavacTestingAbstractThreadedTest
30 * @run main T7093325
28 */ 31 */
32
33 import java.io.File;
34 import java.net.URI;
35 import java.util.Arrays;
36 import javax.tools.JavaCompiler;
37 import javax.tools.JavaFileObject;
38 import javax.tools.SimpleJavaFileObject;
39 import javax.tools.ToolProvider;
29 40
30 import com.sun.source.util.JavacTask; 41 import com.sun.source.util.JavacTask;
31 import com.sun.tools.classfile.Attribute; 42 import com.sun.tools.classfile.Attribute;
32 import com.sun.tools.classfile.ClassFile; 43 import com.sun.tools.classfile.ClassFile;
33 import com.sun.tools.classfile.Code_attribute; 44 import com.sun.tools.classfile.Code_attribute;
34 import com.sun.tools.classfile.ConstantPool.*; 45 import com.sun.tools.classfile.ConstantPool.*;
35 import com.sun.tools.classfile.Method; 46 import com.sun.tools.classfile.Method;
36 import com.sun.tools.javac.api.JavacTool; 47
37 48 public class T7093325
38 import java.io.File; 49 extends JavacTestingAbstractThreadedTest
39 import java.net.URI; 50 implements Runnable {
40 import java.util.Arrays;
41 import javax.tools.JavaCompiler;
42 import javax.tools.JavaFileObject;
43 import javax.tools.SimpleJavaFileObject;
44 import javax.tools.StandardJavaFileManager;
45 import javax.tools.ToolProvider;
46
47
48 public class T7093325 {
49
50 /** global decls ***/
51
52 // Create a single file manager and reuse it for each compile to save time.
53 static StandardJavaFileManager fm = JavacTool.create().getStandardFileManager(null, null, null);
54
55 //statistics
56 static int checkCount = 0;
57 51
58 enum StatementKind { 52 enum StatementKind {
59 THROW("throw new RuntimeException();", false, false), 53 THROW("throw new RuntimeException();", false, false),
60 RETURN_NONEMPTY("System.out.println(); return;", true, false), 54 RETURN_NONEMPTY("System.out.println(); return;", true, false),
61 RETURN_EMPTY("return;", true, true), 55 RETURN_EMPTY("return;", true, true),
87 81
88 String catchers() { 82 String catchers() {
89 if (this.ordinal() == 0) { 83 if (this.ordinal() == 0) {
90 return catchStr; 84 return catchStr;
91 } else { 85 } else {
92 return CatchArity.values()[this.ordinal() - 1].catchers() + catchStr; 86 return CatchArity.values()[this.ordinal() - 1].catchers() +
87 catchStr;
93 } 88 }
94 } 89 }
95 } 90 }
96 91
97 public static void main(String... args) throws Exception { 92 public static void main(String... args) throws Exception {
98 for (CatchArity ca : CatchArity.values()) { 93 for (CatchArity ca : CatchArity.values()) {
99 for (StatementKind stmt0 : StatementKind.values()) { 94 for (StatementKind stmt0 : StatementKind.values()) {
100 if (ca.ordinal() == 0) { 95 if (ca.ordinal() == 0) {
101 new T7093325(ca, stmt0).compileAndCheck(); 96 pool.execute(new T7093325(ca, stmt0));
102 continue; 97 continue;
103 } 98 }
104 for (StatementKind stmt1 : StatementKind.values()) { 99 for (StatementKind stmt1 : StatementKind.values()) {
105 if (ca.ordinal() == 1) { 100 if (ca.ordinal() == 1) {
106 new T7093325(ca, stmt0, stmt1).compileAndCheck(); 101 pool.execute(new T7093325(ca, stmt0, stmt1));
107 continue; 102 continue;
108 } 103 }
109 for (StatementKind stmt2 : StatementKind.values()) { 104 for (StatementKind stmt2 : StatementKind.values()) {
110 if (ca.ordinal() == 2) { 105 if (ca.ordinal() == 2) {
111 new T7093325(ca, stmt0, stmt1, stmt2).compileAndCheck(); 106 pool.execute(new T7093325(ca, stmt0, stmt1, stmt2));
112 continue; 107 continue;
113 } 108 }
114 for (StatementKind stmt3 : StatementKind.values()) { 109 for (StatementKind stmt3 : StatementKind.values()) {
115 if (ca.ordinal() == 3) { 110 if (ca.ordinal() == 3) {
116 new T7093325(ca, stmt0, stmt1, stmt2, stmt3).compileAndCheck(); 111 pool.execute(
112 new T7093325(ca, stmt0, stmt1, stmt2, stmt3));
117 continue; 113 continue;
118 } 114 }
119 for (StatementKind stmt4 : StatementKind.values()) { 115 for (StatementKind stmt4 : StatementKind.values()) {
120 if (ca.ordinal() == 4) { 116 if (ca.ordinal() == 4) {
121 new T7093325(ca, stmt0, stmt1, stmt2, stmt3, stmt4).compileAndCheck(); 117 pool.execute(
118 new T7093325(ca, stmt0, stmt1,
119 stmt2, stmt3, stmt4));
122 continue; 120 continue;
123 } 121 }
124 for (StatementKind stmt5 : StatementKind.values()) { 122 for (StatementKind stmt5 : StatementKind.values()) {
125 new T7093325(ca, stmt0, stmt1, stmt2, stmt3, stmt4, stmt5).compileAndCheck(); 123 pool.execute(
124 new T7093325(ca, stmt0, stmt1, stmt2,
125 stmt3, stmt4, stmt5));
126 } 126 }
127 } 127 }
128 } 128 }
129 } 129 }
130 } 130 }
131 } 131 }
132 } 132 }
133 133
134 System.out.println("Total checks made: " + checkCount); 134 checkAfterExec();
135 } 135 }
136 136
137 /** instance decls **/ 137 /** instance decls **/
138 138
139 CatchArity ca; 139 CatchArity ca;
142 public T7093325(CatchArity ca, StatementKind... stmts) { 142 public T7093325(CatchArity ca, StatementKind... stmts) {
143 this.ca = ca; 143 this.ca = ca;
144 this.stmts = stmts; 144 this.stmts = stmts;
145 } 145 }
146 146
147 void compileAndCheck() throws Exception { 147 @Override
148 public void run() {
149 int id = checkCount.incrementAndGet();
148 final JavaCompiler tool = ToolProvider.getSystemJavaCompiler(); 150 final JavaCompiler tool = ToolProvider.getSystemJavaCompiler();
149 JavaSource source = new JavaSource(); 151 JavaSource source = new JavaSource(id);
150 JavacTask ct = (JavacTask)tool.getTask(null, fm, null, 152 JavacTask ct = (JavacTask)tool.getTask(null, fm.get(), null,
151 null, null, Arrays.asList(source)); 153 null, null, Arrays.asList(source));
152 ct.call(); 154 ct.call();
153 verifyBytecode(source); 155 verifyBytecode(source, id);
154 } 156 }
155 157
156 void verifyBytecode(JavaSource source) { 158 void verifyBytecode(JavaSource source, int id) {
157 checkCount++;
158 boolean lastInlined = false; 159 boolean lastInlined = false;
159 boolean hasCode = false; 160 boolean hasCode = false;
160 int gapsCount = 0; 161 int gapsCount = 0;
161 for (int i = 0; i < stmts.length ; i++) { 162 for (int i = 0; i < stmts.length ; i++) {
162 lastInlined = stmts[i].canInline; 163 lastInlined = stmts[i].canInline;
170 gapsCount++; 171 gapsCount++;
171 } 172 }
172 173
173 //System.out.printf("gaps %d \n %s \n", gapsCount, source.toString()); 174 //System.out.printf("gaps %d \n %s \n", gapsCount, source.toString());
174 175
175 File compiledTest = new File("Test.class"); 176 File compiledTest = new File(String.format("Test%s.class", id));
176 try { 177 try {
177 ClassFile cf = ClassFile.read(compiledTest); 178 ClassFile cf = ClassFile.read(compiledTest);
178 if (cf == null) { 179 if (cf == null) {
179 throw new Error("Classfile not found: " + compiledTest.getName()); 180 throw new Error("Classfile not found: " +
181 compiledTest.getName());
180 } 182 }
181 183
182 Method test_method = null; 184 Method test_method = null;
183 for (Method m : cf.methods) { 185 for (Method m : cf.methods) {
184 if (m.getName(cf.constant_pool).equals("test")) { 186 if (m.getName(cf.constant_pool).equals("test")) {
230 "class A extends RuntimeException {} \n" + 232 "class A extends RuntimeException {} \n" +
231 "class B extends RuntimeException {} \n" + 233 "class B extends RuntimeException {} \n" +
232 "class C extends RuntimeException {} \n" + 234 "class C extends RuntimeException {} \n" +
233 "class D extends RuntimeException {} \n" + 235 "class D extends RuntimeException {} \n" +
234 "class E extends RuntimeException {} \n" + 236 "class E extends RuntimeException {} \n" +
235 "class Test {\n" + 237 "class Test#ID {\n" +
236 " void test() {\n" + 238 " void test() {\n" +
237 " try { #S0 } #C finally { System.out.println(); }\n" + 239 " try { #S0 } #C finally { System.out.println(); }\n" +
238 " }\n" + 240 " }\n" +
239 "}"; 241 "}";
240 242
241 String source; 243 String source;
242 244
243 public JavaSource() { 245 public JavaSource(int id) {
244 super(URI.create("myfo:/Test.java"), JavaFileObject.Kind.SOURCE); 246 super(URI.create(String.format("myfo:/Test%s.java", id)),
247 JavaFileObject.Kind.SOURCE);
245 source = source_template.replace("#C", ca.catchers()); 248 source = source_template.replace("#C", ca.catchers());
246 source = source.replace("#S0", stmts[0].stmt); 249 source = source.replace("#S0", stmts[0].stmt);
250 source = source.replace("#ID", String.valueOf(id));
247 for (int i = 1; i < ca.ordinal() + 1; i++) { 251 for (int i = 1; i < ca.ordinal() + 1; i++) {
248 source = source.replace("#S" + i, stmts[i].stmt); 252 source = source.replace("#S" + i, stmts[i].stmt);
249 } 253 }
250 } 254 }
251 255
257 @Override 261 @Override
258 public CharSequence getCharContent(boolean ignoreEncodingErrors) { 262 public CharSequence getCharContent(boolean ignoreEncodingErrors) {
259 return source; 263 return source;
260 } 264 }
261 } 265 }
266
262 } 267 }

mercurial