8005167: execution time of combo tests in javac should be improved
Reviewed-by: jjg, jjh
--- a/langtools/test/tools/javac/Diagnostics/6769027/T6769027.java Tue Jan 08 10:17:29 2013 +0100
+++ b/langtools/test/tools/javac/Diagnostics/6769027/T6769027.java Tue Jan 08 13:47:57 2013 +0000
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2009, 2011, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2009, 2013, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@@ -26,14 +26,19 @@
* @bug 6769027
* @summary Source line should be displayed immediately after the first diagnostic line
* @author Maurizio Cimadamore
+ * @library ../../lib
+ * @build JavacTestingAbstractThreadedTest
* @run main/othervm T6769027
*/
+
import java.net.URI;
import java.util.regex.Matcher;
import javax.tools.*;
import com.sun.tools.javac.util.*;
-public class T6769027 {
+public class T6769027
+ extends JavacTestingAbstractThreadedTest
+ implements Runnable {
enum OutputKind {
RAW("rawDiagnostics","rawDiagnostics"),
@@ -314,7 +319,7 @@
@Override
protected java.io.PrintWriter getWriterForDiagnosticType(JCDiagnostic.DiagnosticType dt) {
- return new java.io.PrintWriter(System.out);
+ return outWriter;
}
@Override
@@ -323,13 +328,42 @@
}
}
- int nerrors = 0;
+ OutputKind outputKind;
+ ErrorKind errorKind;
+ MultilineKind multiKind;
+ MultilinePolicy multiPolicy;
+ PositionKind posKind;
+ XDiagsSource xdiagsSource;
+ XDiagsCompact xdiagsCompact;
+ CaretKind caretKind;
+ SourceLineKind sourceLineKind;
+ IndentKind summaryIndent;
+ IndentKind detailsIndent;
+ IndentKind sourceIndent;
+ IndentKind subdiagsIndent;
- void exec(OutputKind outputKind, ErrorKind errorKind, MultilineKind multiKind,
+ T6769027(OutputKind outputKind, ErrorKind errorKind, MultilineKind multiKind,
MultilinePolicy multiPolicy, PositionKind posKind, XDiagsSource xdiagsSource,
XDiagsCompact xdiagsCompact, CaretKind caretKind, SourceLineKind sourceLineKind,
IndentKind summaryIndent, IndentKind detailsIndent, IndentKind sourceIndent,
IndentKind subdiagsIndent) {
+ this.outputKind = outputKind;
+ this.errorKind = errorKind;
+ this.multiKind = multiKind;
+ this.multiPolicy = multiPolicy;
+ this.posKind = posKind;
+ this.xdiagsSource = xdiagsSource;
+ this.xdiagsCompact = xdiagsCompact;
+ this.caretKind = caretKind;
+ this.sourceLineKind = sourceLineKind;
+ this.summaryIndent = summaryIndent;
+ this.detailsIndent = detailsIndent;
+ this.sourceIndent = sourceIndent;
+ this.subdiagsIndent = subdiagsIndent;
+ }
+
+ @Override
+ public void run() {
Context ctx = new Context();
Options options = Options.instance(ctx);
outputKind.init(options);
@@ -362,23 +396,10 @@
d = new JCDiagnostic.MultilineDiagnostic(d, subdiags);
}
String diag = log.getDiagnosticFormatter().format(d, messages.getCurrentLocale());
- checkOutput(diag,
- outputKind,
- errorKind,
- multiKind,
- multiPolicy,
- posKind,
- xdiagsSource,
- xdiagsCompact,
- caretKind,
- sourceLineKind,
- summaryIndent,
- detailsIndent,
- sourceIndent,
- subdiagsIndent);
+ checkOutput(diag);
}
- void test() {
+ public static void main(String[] args) throws Exception {
for (OutputKind outputKind : OutputKind.values()) {
for (ErrorKind errKind : ErrorKind.values()) {
for (MultilineKind multiKind : MultilineKind.values()) {
@@ -392,7 +413,7 @@
for (IndentKind detailsIndent : IndentKind.values()) {
for (IndentKind sourceIndent : IndentKind.values()) {
for (IndentKind subdiagsIndent : IndentKind.values()) {
- exec(outputKind,
+ pool.execute(new T6769027(outputKind,
errKind,
multiKind,
multiPolicy,
@@ -404,7 +425,7 @@
summaryIndent,
detailsIndent,
sourceIndent,
- subdiagsIndent);
+ subdiagsIndent));
}
}
}
@@ -418,15 +439,11 @@
}
}
}
- if (nerrors != 0)
- throw new AssertionError(nerrors + " errors found");
+
+ checkAfterExec(false);
}
- void printInfo(String msg, OutputKind outputKind, ErrorKind errorKind, MultilineKind multiKind,
- MultilinePolicy multiPolicy, PositionKind posKind, XDiagsSource xdiagsSource,
- XDiagsCompact xdiagsCompact, CaretKind caretKind, SourceLineKind sourceLineKind,
- IndentKind summaryIndent, IndentKind detailsIndent, IndentKind sourceIndent,
- IndentKind subdiagsIndent, String errorLine) {
+ void printInfo(String msg, String errorLine) {
String sep = "*********************************************************";
String desc = "raw=" + outputKind + " pos=" + posKind + " key=" + errorKind.key() +
" multiline=" + multiKind +" multiPolicy=" + multiPolicy.value +
@@ -434,18 +451,14 @@
" caret=" + caretKind + " sourcePosition=" + sourceLineKind +
" summaryIndent=" + summaryIndent + " detailsIndent=" + detailsIndent +
" sourceIndent=" + sourceIndent + " subdiagsIndent=" + subdiagsIndent;
- System.out.println(sep);
- System.out.println(desc);
- System.out.println(sep);
- System.out.println(msg);
- System.out.println("Diagnostic formatting problem - expected diagnostic...\n" + errorLine);
+ errWriter.println(sep);
+ errWriter.println(desc);
+ errWriter.println(sep);
+ errWriter.println(msg);
+ errWriter.println("Diagnostic formatting problem - expected diagnostic...\n" + errorLine);
}
- void checkOutput(String msg, OutputKind outputKind, ErrorKind errorKind, MultilineKind multiKind,
- MultilinePolicy multiPolicy, PositionKind posKind, XDiagsSource xdiagsSource,
- XDiagsCompact xdiagsCompact, CaretKind caretKind, SourceLineKind sourceLineKind,
- IndentKind summaryIndent, IndentKind detailsIndent, IndentKind sourceIndent,
- IndentKind subdiagsIndent) {
+ void checkOutput(String msg) {
boolean shouldPrintSource = posKind == PositionKind.POS &&
xdiagsSource != XDiagsSource.NO_SOURCE &&
(xdiagsSource == XDiagsSource.SOURCE ||
@@ -453,7 +466,8 @@
String errorLine = posKind.getOutput(outputKind) +
errorKind.getOutput(outputKind, summaryIndent, detailsIndent);
if (xdiagsCompact != XDiagsCompact.COMPACT)
- errorLine += multiKind.getOutput(outputKind, errorKind, multiPolicy, summaryIndent, detailsIndent, subdiagsIndent);
+ errorLine += multiKind.getOutput(outputKind, errorKind, multiPolicy,
+ summaryIndent, detailsIndent, subdiagsIndent);
String[] lines = errorLine.split("\n");
if (xdiagsCompact == XDiagsCompact.COMPACT) {
errorLine = lines[0];
@@ -474,26 +488,9 @@
}
if (!msg.equals(errorLine)) {
- printInfo(msg,
- outputKind,
- errorKind,
- multiKind,
- multiPolicy,
- posKind,
- xdiagsSource,
- xdiagsCompact,
- caretKind,
- sourceLineKind,
- summaryIndent,
- detailsIndent,
- sourceIndent,
- subdiagsIndent,
- errorLine);
- nerrors++;
+ printInfo(msg, errorLine);
+ errCount.incrementAndGet();
}
}
- public static void main(String... args) throws Exception {
- new T6769027().test();
- }
}
--- a/langtools/test/tools/javac/T7093325.java Tue Jan 08 10:17:29 2013 +0100
+++ b/langtools/test/tools/javac/T7093325.java Tue Jan 08 13:47:57 2013 +0000
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2011, 2013, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@@ -25,35 +25,29 @@
* @test
* @bug 7093325
* @summary Redundant entry in bytecode exception table
+ * @library lib
+ * @build JavacTestingAbstractThreadedTest
+ * @run main T7093325
*/
+import java.io.File;
+import java.net.URI;
+import java.util.Arrays;
+import javax.tools.JavaCompiler;
+import javax.tools.JavaFileObject;
+import javax.tools.SimpleJavaFileObject;
+import javax.tools.ToolProvider;
+
import com.sun.source.util.JavacTask;
import com.sun.tools.classfile.Attribute;
import com.sun.tools.classfile.ClassFile;
import com.sun.tools.classfile.Code_attribute;
import com.sun.tools.classfile.ConstantPool.*;
import com.sun.tools.classfile.Method;
-import com.sun.tools.javac.api.JavacTool;
-import java.io.File;
-import java.net.URI;
-import java.util.Arrays;
-import javax.tools.JavaCompiler;
-import javax.tools.JavaFileObject;
-import javax.tools.SimpleJavaFileObject;
-import javax.tools.StandardJavaFileManager;
-import javax.tools.ToolProvider;
-
-
-public class T7093325 {
-
- /** global decls ***/
-
- // Create a single file manager and reuse it for each compile to save time.
- static StandardJavaFileManager fm = JavacTool.create().getStandardFileManager(null, null, null);
-
- //statistics
- static int checkCount = 0;
+public class T7093325
+ extends JavacTestingAbstractThreadedTest
+ implements Runnable {
enum StatementKind {
THROW("throw new RuntimeException();", false, false),
@@ -89,7 +83,8 @@
if (this.ordinal() == 0) {
return catchStr;
} else {
- return CatchArity.values()[this.ordinal() - 1].catchers() + catchStr;
+ return CatchArity.values()[this.ordinal() - 1].catchers() +
+ catchStr;
}
}
}
@@ -98,31 +93,36 @@
for (CatchArity ca : CatchArity.values()) {
for (StatementKind stmt0 : StatementKind.values()) {
if (ca.ordinal() == 0) {
- new T7093325(ca, stmt0).compileAndCheck();
+ pool.execute(new T7093325(ca, stmt0));
continue;
}
for (StatementKind stmt1 : StatementKind.values()) {
if (ca.ordinal() == 1) {
- new T7093325(ca, stmt0, stmt1).compileAndCheck();
+ pool.execute(new T7093325(ca, stmt0, stmt1));
continue;
}
for (StatementKind stmt2 : StatementKind.values()) {
if (ca.ordinal() == 2) {
- new T7093325(ca, stmt0, stmt1, stmt2).compileAndCheck();
+ pool.execute(new T7093325(ca, stmt0, stmt1, stmt2));
continue;
}
for (StatementKind stmt3 : StatementKind.values()) {
if (ca.ordinal() == 3) {
- new T7093325(ca, stmt0, stmt1, stmt2, stmt3).compileAndCheck();
+ pool.execute(
+ new T7093325(ca, stmt0, stmt1, stmt2, stmt3));
continue;
}
for (StatementKind stmt4 : StatementKind.values()) {
if (ca.ordinal() == 4) {
- new T7093325(ca, stmt0, stmt1, stmt2, stmt3, stmt4).compileAndCheck();
+ pool.execute(
+ new T7093325(ca, stmt0, stmt1,
+ stmt2, stmt3, stmt4));
continue;
}
for (StatementKind stmt5 : StatementKind.values()) {
- new T7093325(ca, stmt0, stmt1, stmt2, stmt3, stmt4, stmt5).compileAndCheck();
+ pool.execute(
+ new T7093325(ca, stmt0, stmt1, stmt2,
+ stmt3, stmt4, stmt5));
}
}
}
@@ -131,7 +131,7 @@
}
}
- System.out.println("Total checks made: " + checkCount);
+ checkAfterExec();
}
/** instance decls **/
@@ -144,17 +144,18 @@
this.stmts = stmts;
}
- void compileAndCheck() throws Exception {
+ @Override
+ public void run() {
+ int id = checkCount.incrementAndGet();
final JavaCompiler tool = ToolProvider.getSystemJavaCompiler();
- JavaSource source = new JavaSource();
- JavacTask ct = (JavacTask)tool.getTask(null, fm, null,
+ JavaSource source = new JavaSource(id);
+ JavacTask ct = (JavacTask)tool.getTask(null, fm.get(), null,
null, null, Arrays.asList(source));
ct.call();
- verifyBytecode(source);
+ verifyBytecode(source, id);
}
- void verifyBytecode(JavaSource source) {
- checkCount++;
+ void verifyBytecode(JavaSource source, int id) {
boolean lastInlined = false;
boolean hasCode = false;
int gapsCount = 0;
@@ -172,11 +173,12 @@
//System.out.printf("gaps %d \n %s \n", gapsCount, source.toString());
- File compiledTest = new File("Test.class");
+ File compiledTest = new File(String.format("Test%s.class", id));
try {
ClassFile cf = ClassFile.read(compiledTest);
if (cf == null) {
- throw new Error("Classfile not found: " + compiledTest.getName());
+ throw new Error("Classfile not found: " +
+ compiledTest.getName());
}
Method test_method = null;
@@ -232,7 +234,7 @@
"class C extends RuntimeException {} \n" +
"class D extends RuntimeException {} \n" +
"class E extends RuntimeException {} \n" +
- "class Test {\n" +
+ "class Test#ID {\n" +
" void test() {\n" +
" try { #S0 } #C finally { System.out.println(); }\n" +
" }\n" +
@@ -240,10 +242,12 @@
String source;
- public JavaSource() {
- super(URI.create("myfo:/Test.java"), JavaFileObject.Kind.SOURCE);
+ public JavaSource(int id) {
+ super(URI.create(String.format("myfo:/Test%s.java", id)),
+ JavaFileObject.Kind.SOURCE);
source = source_template.replace("#C", ca.catchers());
source = source.replace("#S0", stmts[0].stmt);
+ source = source.replace("#ID", String.valueOf(id));
for (int i = 1; i < ca.ordinal() + 1; i++) {
source = source.replace("#S" + i, stmts[i].stmt);
}
@@ -259,4 +263,5 @@
return source;
}
}
+
}
--- a/langtools/test/tools/javac/cast/intersection/IntersectionTypeCastTest.java Tue Jan 08 10:17:29 2013 +0100
+++ b/langtools/test/tools/javac/cast/intersection/IntersectionTypeCastTest.java Tue Jan 08 13:47:57 2013 +0000
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@@ -25,23 +25,26 @@
* @test
* @bug 8002099
* @summary Add support for intersection types in cast expression
+ * @library ../../lib
+ * @build JavacTestingAbstractThreadedTest
+ * @run main/timeout=360 IntersectionTypeCastTest
*/
-import com.sun.source.util.JavacTask;
-import com.sun.tools.javac.util.List;
-import com.sun.tools.javac.util.ListBuffer;
import java.net.URI;
import java.util.Arrays;
import javax.tools.Diagnostic;
import javax.tools.JavaCompiler;
import javax.tools.JavaFileObject;
import javax.tools.SimpleJavaFileObject;
-import javax.tools.StandardJavaFileManager;
import javax.tools.ToolProvider;
-public class IntersectionTypeCastTest {
+import com.sun.source.util.JavacTask;
+import com.sun.tools.javac.util.List;
+import com.sun.tools.javac.util.ListBuffer;
- static int checkCount = 0;
+public class IntersectionTypeCastTest
+ extends JavacTestingAbstractThreadedTest
+ implements Runnable {
interface Type {
boolean subtypeOf(Type that);
@@ -59,7 +62,8 @@
String typeStr;
InterfaceKind superInterface;
- InterfaceKind(String declStr, String typeStr, InterfaceKind superInterface) {
+ InterfaceKind(String declStr, String typeStr,
+ InterfaceKind superInterface) {
this.declStr = declStr;
this.typeStr = typeStr;
this.superInterface = superInterface;
@@ -67,7 +71,8 @@
@Override
public boolean subtypeOf(Type that) {
- return this == that || superInterface == that || that == ClassKind.OBJECT;
+ return this == that || superInterface == that ||
+ that == ClassKind.OBJECT;
}
@Override
@@ -88,19 +93,27 @@
enum ClassKind implements Type {
OBJECT(null, "Object"),
- CA("#M class CA implements A { }\n", "CA", InterfaceKind.A),
- CB("#M class CB implements B { }\n", "CB", InterfaceKind.B),
- CAB("#M class CAB implements A, B { }\n", "CAB", InterfaceKind.A, InterfaceKind.B),
- CC("#M class CC implements C { }\n", "CC", InterfaceKind.C, InterfaceKind.A),
- CCA("#M class CCA implements C, A { }\n", "CCA", InterfaceKind.C, InterfaceKind.A),
- CCB("#M class CCB implements C, B { }\n", "CCB", InterfaceKind.C, InterfaceKind.A, InterfaceKind.B),
- CCAB("#M class CCAB implements C, A, B { }\n", "CCAB", InterfaceKind.C, InterfaceKind.A, InterfaceKind.B);
+ CA("#M class CA implements A { }\n", "CA",
+ InterfaceKind.A),
+ CB("#M class CB implements B { }\n", "CB",
+ InterfaceKind.B),
+ CAB("#M class CAB implements A, B { }\n", "CAB",
+ InterfaceKind.A, InterfaceKind.B),
+ CC("#M class CC implements C { }\n", "CC",
+ InterfaceKind.C, InterfaceKind.A),
+ CCA("#M class CCA implements C, A { }\n", "CCA",
+ InterfaceKind.C, InterfaceKind.A),
+ CCB("#M class CCB implements C, B { }\n", "CCB",
+ InterfaceKind.C, InterfaceKind.A, InterfaceKind.B),
+ CCAB("#M class CCAB implements C, A, B { }\n", "CCAB",
+ InterfaceKind.C, InterfaceKind.A, InterfaceKind.B);
String declTemplate;
String typeStr;
List<InterfaceKind> superInterfaces;
- ClassKind(String declTemplate, String typeStr, InterfaceKind... superInterfaces) {
+ ClassKind(String declTemplate, String typeStr,
+ InterfaceKind... superInterfaces) {
this.declTemplate = declTemplate;
this.typeStr = typeStr;
this.superInterfaces = List.from(superInterfaces);
@@ -114,7 +127,8 @@
@Override
public boolean subtypeOf(Type that) {
- return this == that || superInterfaces.contains(that) || that == OBJECT;
+ return this == that || superInterfaces.contains(that) ||
+ that == OBJECT;
}
@Override
@@ -170,9 +184,11 @@
}
String getCast() {
- String temp = kind.castTemplate.replaceAll("#C", types[0].asString());
+ String temp = kind.castTemplate.replaceAll("#C",
+ types[0].asString());
for (int i = 0; i < kind.interfaceBounds ; i++) {
- temp = temp.replace(String.format("#I%d", i), types[i + 1].asString());
+ temp = temp.replace(String.format("#I%d", i),
+ types[i + 1].asString());
}
return temp;
}
@@ -195,7 +211,8 @@
t1.subtypeOf(t2) ||
t2.subtypeOf(t1) ||
(t1.isInterface() && t2.isInterface()) || //side-cast (1)
- (mod == ModifierKind.NONE && (t1.isInterface() != t2.isInterface())); //side-cast (2)
+ (mod == ModifierKind.NONE &&
+ (t1.isInterface() != t2.isInterface())); //side-cast (2)
if (!compat) return false;
}
}
@@ -204,18 +221,15 @@
}
public static void main(String... args) throws Exception {
- //create default shared JavaCompiler - reused across multiple compilations
- JavaCompiler comp = ToolProvider.getSystemJavaCompiler();
- StandardJavaFileManager fm = comp.getStandardFileManager(null, null, null);
-
for (ModifierKind mod : ModifierKind.values()) {
for (CastInfo cast1 : allCastInfo()) {
for (CastInfo cast2 : allCastInfo()) {
- new IntersectionTypeCastTest(mod, cast1, cast2).run(comp, fm);
+ pool.execute(
+ new IntersectionTypeCastTest(mod, cast1, cast2));
}
}
}
- System.out.println("Total check executed: " + checkCount);
+ checkAfterExec();
}
static List<CastInfo> allCastInfo() {
@@ -235,11 +249,14 @@
} else {
for (InterfaceKind intf2 : InterfaceKind.values()) {
if (kind.interfaceBounds == 2) {
- buf.append(new CastInfo(kind, clazz, intf1, intf2));
+ buf.append(
+ new CastInfo(kind, clazz, intf1, intf2));
continue;
} else {
for (InterfaceKind intf3 : InterfaceKind.values()) {
- buf.append(new CastInfo(kind, clazz, intf1, intf2, intf3));
+ buf.append(
+ new CastInfo(kind, clazz, intf1,
+ intf2, intf3));
continue;
}
}
@@ -265,6 +282,22 @@
this.diagChecker = new DiagnosticChecker();
}
+ @Override
+ public void run() {
+ final JavaCompiler tool = ToolProvider.getSystemJavaCompiler();
+
+ JavacTask ct = (JavacTask)tool.getTask(null, fm.get(), diagChecker,
+ Arrays.asList("-XDallowIntersectionTypes"),
+ null, Arrays.asList(source));
+ try {
+ ct.analyze();
+ } catch (Throwable ex) {
+ throw new AssertionError("Error thrown when compiling the following code:\n" +
+ source.getCharContent(true));
+ }
+ check();
+ }
+
class JavaSource extends SimpleJavaFileObject {
String bodyTemplate = "class Test {\n" +
@@ -282,7 +315,8 @@
for (InterfaceKind ik : InterfaceKind.values()) {
source += ik.declStr;
}
- source += bodyTemplate.replaceAll("#C1", cast1.getCast()).replaceAll("#C2", cast2.getCast());
+ source += bodyTemplate.replaceAll("#C1", cast1.getCast()).
+ replaceAll("#C2", cast2.getCast());
}
@Override
@@ -291,21 +325,11 @@
}
}
- void run(JavaCompiler tool, StandardJavaFileManager fm) throws Exception {
- JavacTask ct = (JavacTask)tool.getTask(null, fm, diagChecker,
- Arrays.asList("-XDallowIntersectionTypes"), null, Arrays.asList(source));
- try {
- ct.analyze();
- } catch (Throwable ex) {
- throw new AssertionError("Error thrown when compiling the following code:\n" + source.getCharContent(true));
- }
- check();
- }
+ void check() {
+ checkCount.incrementAndGet();
- void check() {
- checkCount++;
-
- boolean errorExpected = cast1.hasDuplicateTypes() || cast2.hasDuplicateTypes();
+ boolean errorExpected = cast1.hasDuplicateTypes() ||
+ cast2.hasDuplicateTypes();
errorExpected |= !cast2.compatibleWith(mod, cast1);
@@ -317,7 +341,8 @@
}
}
- static class DiagnosticChecker implements javax.tools.DiagnosticListener<JavaFileObject> {
+ static class DiagnosticChecker
+ implements javax.tools.DiagnosticListener<JavaFileObject> {
boolean errorFound;
@@ -327,4 +352,5 @@
}
}
}
+
}
--- a/langtools/test/tools/javac/defaultMethods/super/TestDefaultSuperCall.java Tue Jan 08 10:17:29 2013 +0100
+++ b/langtools/test/tools/javac/defaultMethods/super/TestDefaultSuperCall.java Tue Jan 08 13:47:57 2013 +0000
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@@ -24,25 +24,25 @@
/*
* @test
* @summary Automatic test for checking correctness of default super/this resolution
+ * @library ../../lib
+ * @build JavacTestingAbstractThreadedTest
+ * @run main TestDefaultSuperCall
*/
-import com.sun.source.util.JavacTask;
import java.net.URI;
import java.util.Arrays;
import java.util.ArrayList;
import java.util.List;
import java.util.Locale;
-import java.util.Map;
import javax.tools.Diagnostic;
-import javax.tools.JavaCompiler;
import javax.tools.JavaFileObject;
import javax.tools.SimpleJavaFileObject;
-import javax.tools.StandardJavaFileManager;
-import javax.tools.ToolProvider;
+
+import com.sun.source.util.JavacTask;
-public class TestDefaultSuperCall {
-
- static int checkCount = 0;
+public class TestDefaultSuperCall
+ extends JavacTestingAbstractThreadedTest
+ implements Runnable {
enum InterfaceKind {
DEFAULT("interface A extends B { default void m() { } }"),
@@ -212,7 +212,7 @@
List<String> elementsWithMethod;
Shape(ElementKind... elements) {
- System.err.println("elements = " + Arrays.toString(elements));
+ errWriter.println("elements = " + Arrays.toString(elements));
enclosingElements = new ArrayList<>();
enclosingNames = new ArrayList<>();
elementsWithMethod = new ArrayList<>();
@@ -231,28 +231,26 @@
elementsWithMethod.add(prevName);
}
String element = ek.templateDecl.replaceAll("#N", name);
- shapeStr = shapeStr == null ? element : shapeStr.replaceAll("#B", element);
+ shapeStr = shapeStr ==
+ null ? element : shapeStr.replaceAll("#B", element);
prevName = name;
}
}
String getShape(QualifierKind qk, ExprKind ek) {
String methName = ek == ExprKind.THIS ? "test" : "m";
- String call = qk.getQualifier(this) + "." + ek.exprStr + "." + methName + "();";
+ String call = qk.getQualifier(this) + "." +
+ ek.exprStr + "." + methName + "();";
return shapeStr.replaceAll("#B", call);
}
String enclosingAt(int index) {
- return index < enclosingNames.size() ? enclosingNames.get(index) : "BAD";
+ return index < enclosingNames.size() ?
+ enclosingNames.get(index) : "BAD";
}
}
public static void main(String... args) throws Exception {
-
- //create default shared JavaCompiler - reused across multiple compilations
- JavaCompiler comp = ToolProvider.getSystemJavaCompiler();
- StandardJavaFileManager fm = comp.getStandardFileManager(null, null, null);
-
for (InterfaceKind ik : InterfaceKind.values()) {
for (PruneKind pk : PruneKind.values()) {
for (ElementKind ek1 : ElementKind.values()) {
@@ -264,10 +262,14 @@
for (ElementKind ek4 : ElementKind.values()) {
if (!ek4.isAllowedEnclosing(ek3, false)) continue;
for (ElementKind ek5 : ElementKind.values()) {
- if (!ek5.isAllowedEnclosing(ek4, false) || ek5.isClassDecl()) continue;
+ if (!ek5.isAllowedEnclosing(ek4, false) ||
+ ek5.isClassDecl()) continue;
for (QualifierKind qk : QualifierKind.values()) {
for (ExprKind ek : ExprKind.values()) {
- new TestDefaultSuperCall(ik, pk, new Shape(ek1, ek2, ek3, ek4, ek5), qk, ek).run(comp, fm);
+ pool.execute(
+ new TestDefaultSuperCall(ik, pk,
+ new Shape(ek1, ek2, ek3,
+ ek4, ek5), qk, ek));
}
}
}
@@ -277,7 +279,8 @@
}
}
}
- System.out.println("Total check executed: " + checkCount);
+
+ checkAfterExec();
}
InterfaceKind ik;
@@ -288,7 +291,8 @@
JavaSource source;
DiagnosticChecker diagChecker;
- TestDefaultSuperCall(InterfaceKind ik, PruneKind pk, Shape sh, QualifierKind qk, ExprKind ek) {
+ TestDefaultSuperCall(InterfaceKind ik, PruneKind pk, Shape sh,
+ QualifierKind qk, ExprKind ek) {
this.ik = ik;
this.pk = pk;
this.sh = sh;
@@ -321,13 +325,14 @@
}
}
- void run(JavaCompiler tool, StandardJavaFileManager fm) throws Exception {
- JavacTask ct = (JavacTask)tool.getTask(null, fm, diagChecker,
+ public void run() {
+ JavacTask ct = (JavacTask)comp.getTask(null, fm.get(), diagChecker,
null, null, Arrays.asList(source));
try {
ct.analyze();
} catch (Throwable ex) {
- throw new AssertionError("Error thrown when analyzing the following source:\n" + source.getCharContent(true));
+ processException(ex);
+ return;
}
check();
}
@@ -370,7 +375,8 @@
int lastIdx = sh.enclosingElements.size() - 1;
boolean found = lastIdx == -1 ? false :
- sh.enclosingElements.get(lastIdx).hasSuper() && qk.allowSuperCall(ik, pk);
+ sh.enclosingElements.get(lastIdx).hasSuper() &&
+ qk.allowSuperCall(ik, pk);
errorExpected |= !found;
if (!found) {
@@ -378,9 +384,10 @@
}
}
- checkCount++;
+ checkCount.incrementAndGet();
if (diagChecker.errorFound != errorExpected) {
- throw new AssertionError("Problem when compiling source:\n" + source.getCharContent(true) +
+ throw new AssertionError("Problem when compiling source:\n" +
+ source.getCharContent(true) +
"\nenclosingElems: " + sh.enclosingElements +
"\nenclosingNames: " + sh.enclosingNames +
"\nelementsWithMethod: " + sh.elementsWithMethod +
@@ -392,15 +399,17 @@
}
}
- static class DiagnosticChecker implements javax.tools.DiagnosticListener<JavaFileObject> {
+ static class DiagnosticChecker
+ implements javax.tools.DiagnosticListener<JavaFileObject> {
boolean errorFound;
public void report(Diagnostic<? extends JavaFileObject> diagnostic) {
if (diagnostic.getKind() == Diagnostic.Kind.ERROR) {
- System.err.println(diagnostic.getMessage(Locale.getDefault()));
+ errWriter.println(diagnostic.getMessage(Locale.getDefault()));
errorFound = true;
}
}
}
+
}
--- a/langtools/test/tools/javac/failover/CheckAttributedTree.java Tue Jan 08 10:17:29 2013 +0100
+++ b/langtools/test/tools/javac/failover/CheckAttributedTree.java Tue Jan 08 13:47:57 2013 +0000
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2010, 2012, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@@ -21,7 +21,15 @@
* questions.
*/
-import com.sun.source.util.TaskEvent;
+/*
+ * @test
+ * @bug 6970584
+ * @summary assorted position errors in compiler syntax trees
+ * @library ../lib
+ * @build JavacTestingAbstractThreadedTest
+ * @run main CheckAttributedTree -q -r -et ERRONEOUS .
+ */
+
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Dimension;
@@ -34,6 +42,20 @@
import java.awt.event.ActionListener;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
+import java.io.File;
+import java.io.IOException;
+import java.io.PrintStream;
+import java.io.PrintWriter;
+import java.io.StringWriter;
+import java.lang.reflect.Field;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.concurrent.atomic.AtomicInteger;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
+
+import javax.lang.model.element.Element;
import javax.swing.DefaultComboBoxModel;
import javax.swing.JComboBox;
import javax.swing.JComponent;
@@ -49,23 +71,14 @@
import javax.swing.text.BadLocationException;
import javax.swing.text.DefaultHighlighter;
import javax.swing.text.Highlighter;
-import java.io.File;
-import java.io.IOException;
-import java.io.PrintStream;
-import java.io.PrintWriter;
-import java.io.StringWriter;
-import java.lang.reflect.Field;
-import java.util.ArrayList;
-import java.util.List;
import javax.tools.Diagnostic;
import javax.tools.DiagnosticListener;
import javax.tools.JavaFileObject;
-import javax.tools.StandardJavaFileManager;
import com.sun.source.tree.CompilationUnitTree;
+import com.sun.source.util.TaskEvent;
import com.sun.source.util.JavacTask;
import com.sun.source.util.TaskListener;
-import com.sun.tools.javac.api.JavacTool;
import com.sun.tools.javac.code.Symbol;
import com.sun.tools.javac.code.Type;
import com.sun.tools.javac.tree.EndPosTable;
@@ -76,11 +89,6 @@
import com.sun.tools.javac.tree.TreeScanner;
import com.sun.tools.javac.util.Pair;
-import java.util.Arrays;
-import java.util.HashSet;
-import java.util.Set;
-import javax.lang.model.element.Element;
-
import static com.sun.tools.javac.tree.JCTree.Tag.*;
/**
@@ -95,13 +103,7 @@
* covering any new language features that may be tested in this test suite.
*/
-/*
- * @test
- * @bug 6970584
- * @summary assorted position errors in compiler syntax trees
- * @run main CheckAttributedTree -q -r -et ERRONEOUS .
- */
-public class CheckAttributedTree {
+public class CheckAttributedTree extends JavacTestingAbstractThreadedTest {
/**
* Main entry point.
* If test.src is set, program runs in jtreg mode, and will throw an Error
@@ -110,9 +112,10 @@
* args is the value of ${test.src}. In jtreg mode, the -r option can be
* given to change the default base directory to the root test directory.
*/
- public static void main(String... args) {
+ public static void main(String... args) throws Exception {
String testSrc = System.getProperty("test.src");
File baseDir = (testSrc == null) ? null : new File(testSrc);
+ throwAssertionOnError = false;
boolean ok = new CheckAttributedTree().run(baseDir, args);
if (!ok) {
if (testSrc != null) // jtreg mode
@@ -130,7 +133,7 @@
* @param args command line args
* @return true if successful or in gui mode
*/
- boolean run(File baseDir, String... args) {
+ boolean run(File baseDir, String... args) throws Exception {
if (args.length == 0) {
usage(System.out);
return true;
@@ -145,8 +148,10 @@
gui = true;
else if (arg.equals("-q"))
quiet = true;
- else if (arg.equals("-v"))
+ else if (arg.equals("-v")) {
verbose = true;
+ printAll = true;
+ }
else if (arg.equals("-t") && i + 1 < args.length)
tags.add(args[++i]);
else if (arg.equals("-ef") && i + 1 < args.length)
@@ -179,12 +184,11 @@
error("File not found: " + file);
}
- if (fileCount != 1)
- System.err.println(fileCount + " files read");
- if (errors > 0)
- System.err.println(errors + " errors");
+ if (fileCount.get() != 1)
+ errWriter.println(fileCount + " files read");
+ checkAfterExec(false);
- return (gui || errors == 0);
+ return (gui || errCount.get() == 0);
}
/**
@@ -215,7 +219,7 @@
* for java files.
* @param file the file or directory to test
*/
- void test(File file) {
+ void test(final File file) {
if (excludeFiles.contains(file)) {
if (!quiet)
error("File " + file + " excluded");
@@ -230,20 +234,24 @@
}
if (file.isFile() && file.getName().endsWith(".java")) {
- try {
- if (verbose)
- System.err.println(file);
- fileCount++;
- NPETester p = new NPETester();
- p.test(read(file));
- } catch (AttributionException e) {
- if (!quiet) {
- error("Error attributing " + file + "\n" + e.getMessage());
+ pool.execute(new Runnable() {
+ @Override
+ public void run() {
+ try {
+ if (verbose)
+ errWriter.println(file);
+ fileCount.incrementAndGet();
+ NPETester p = new NPETester();
+ p.test(read(file));
+ } catch (AttributionException e) {
+ if (!quiet) {
+ error("Error attributing " + file + "\n" + e.getMessage());
+ }
+ } catch (IOException e) {
+ error("Error reading " + file + ": " + e);
+ }
}
- } catch (IOException e) {
- error("Error reading " + file + ": " + e);
- }
- return;
+ });
}
if (!quiet)
@@ -254,8 +262,6 @@
StringWriter sw = new StringWriter();
PrintWriter pw = new PrintWriter(sw);
Reporter r = new Reporter(pw);
- JavacTool tool = JavacTool.create();
- StandardJavaFileManager fm = tool.getStandardFileManager(r, null, null);
/**
* Read a file.
@@ -265,11 +271,10 @@
* @throws TreePosTest.ParseException if any errors occur while parsing the file
*/
List<Pair<JCCompilationUnit, JCTree>> read(File file) throws IOException, AttributionException {
- JavacTool tool = JavacTool.create();
r.errors = 0;
- Iterable<? extends JavaFileObject> files = fm.getJavaFileObjects(file);
+ Iterable<? extends JavaFileObject> files = fm.get().getJavaFileObjects(file);
String[] opts = { "-XDshouldStopPolicy=ATTR", "-XDverboseCompilePolicy" };
- JavacTask task = tool.getTask(pw, fm, r, Arrays.asList(opts), null, files);
+ JavacTask task = (JavacTask)comp.getTask(pw, fm.get(), r, Arrays.asList(opts), null, files);
final List<Element> analyzedElems = new ArrayList<>();
task.setTaskListener(new TaskListener() {
public void started(TaskEvent e) {
@@ -308,13 +313,9 @@
*/
void error(String msg) {
System.err.println(msg);
- errors++;
+ errCount.incrementAndGet();
}
- /** Number of files that have been analyzed. */
- int fileCount;
- /** Number of errors reported. */
- int errors;
/** Flag: don't report irrelevant files. */
boolean quiet;
/** Flag: show errors in GUI viewer. */
@@ -385,7 +386,8 @@
viewer = new Viewer();
viewer.addEntry(sourcefile, label, encl, self);
}
- error(label + self.toString() + " encl: " + encl.toString() + " in file: " + sourcefile + " " + self.tree);
+ error(label + self.toString() + " encl: " + encl.toString() +
+ " in file: " + sourcefile + " " + self.tree);
}
}
@@ -754,4 +756,8 @@
final Info self;
}
}
+
+ /** Number of files that have been analyzed. */
+ static AtomicInteger fileCount = new AtomicInteger();
+
}
--- a/langtools/test/tools/javac/generics/diamond/7046778/DiamondAndInnerClassTest.java Tue Jan 08 10:17:29 2013 +0100
+++ b/langtools/test/tools/javac/generics/diamond/7046778/DiamondAndInnerClassTest.java Tue Jan 08 13:47:57 2013 +0000
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2011, 2013, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@@ -25,21 +25,21 @@
* @test
* @bug 7046778
* @summary Project Coin: problem with diamond and member inner classes
+ * @library ../../../lib
+ * @build JavacTestingAbstractThreadedTest
+ * @run main DiamondAndInnerClassTest
*/
import com.sun.source.util.JavacTask;
import java.net.URI;
import java.util.Arrays;
import javax.tools.Diagnostic;
-import javax.tools.JavaCompiler;
import javax.tools.JavaFileObject;
import javax.tools.SimpleJavaFileObject;
-import javax.tools.StandardJavaFileManager;
-import javax.tools.ToolProvider;
-public class DiamondAndInnerClassTest {
-
- static int checkCount = 0;
+public class DiamondAndInnerClassTest
+ extends JavacTestingAbstractThreadedTest
+ implements Runnable {
enum TypeArgumentKind {
NONE(""),
@@ -151,11 +151,6 @@
}
public static void main(String... args) throws Exception {
-
- //create default shared JavaCompiler - reused across multiple compilations
- JavaCompiler comp = ToolProvider.getSystemJavaCompiler();
- StandardJavaFileManager fm = comp.getStandardFileManager(null, null, null);
-
for (InnerClassDeclArity innerClassDeclArity : InnerClassDeclArity.values()) {
for (TypeQualifierArity declType : TypeQualifierArity.values()) {
if (!declType.matches(innerClassDeclArity)) continue;
@@ -168,53 +163,79 @@
//no diamond on decl site
if (taDecl1 == TypeArgumentKind.DIAMOND) continue;
for (TypeArgumentKind taSite1 : TypeArgumentKind.values()) {
- boolean isSiteRaw = taSite1 == TypeArgumentKind.NONE;
+ boolean isSiteRaw =
+ taSite1 == TypeArgumentKind.NONE;
//diamond only allowed on the last type qualifier
if (taSite1 == TypeArgumentKind.DIAMOND &&
- innerClassDeclArity != InnerClassDeclArity.ONE) continue;
+ innerClassDeclArity !=
+ InnerClassDeclArity.ONE)
+ continue;
for (ArgumentKind arg1 : ArgumentKind.values()) {
if (innerClassDeclArity == innerClassDeclArity.ONE) {
- new DiamondAndInnerClassTest(innerClassDeclArity, declType, newClassType,
- argList, new TypeArgumentKind[] {taDecl1},
- new TypeArgumentKind[] {taSite1}, new ArgumentKind[] {arg1}).run(comp, fm);
+ pool.execute(
+ new DiamondAndInnerClassTest(
+ innerClassDeclArity, declType,
+ newClassType, argList,
+ new TypeArgumentKind[] {taDecl1},
+ new TypeArgumentKind[] {taSite1},
+ new ArgumentKind[] {arg1}));
continue;
}
for (TypeArgumentKind taDecl2 : TypeArgumentKind.values()) {
//no rare types
- if (isDeclRaw != (taDecl2 == TypeArgumentKind.NONE)) continue;
+ if (isDeclRaw != (taDecl2 == TypeArgumentKind.NONE))
+ continue;
//no diamond on decl site
- if (taDecl2 == TypeArgumentKind.DIAMOND) continue;
+ if (taDecl2 == TypeArgumentKind.DIAMOND)
+ continue;
for (TypeArgumentKind taSite2 : TypeArgumentKind.values()) {
//no rare types
- if (isSiteRaw != (taSite2 == TypeArgumentKind.NONE)) continue;
+ if (isSiteRaw != (taSite2 == TypeArgumentKind.NONE))
+ continue;
//diamond only allowed on the last type qualifier
if (taSite2 == TypeArgumentKind.DIAMOND &&
- innerClassDeclArity != InnerClassDeclArity.TWO) continue;
+ innerClassDeclArity != InnerClassDeclArity.TWO)
+ continue;
for (ArgumentKind arg2 : ArgumentKind.values()) {
if (innerClassDeclArity == innerClassDeclArity.TWO) {
- new DiamondAndInnerClassTest(innerClassDeclArity, declType, newClassType,
- argList, new TypeArgumentKind[] {taDecl1, taDecl2},
+ pool.execute(
+ new DiamondAndInnerClassTest(
+ innerClassDeclArity,
+ declType,
+ newClassType,
+ argList,
+ new TypeArgumentKind[] {taDecl1, taDecl2},
new TypeArgumentKind[] {taSite1, taSite2},
- new ArgumentKind[] {arg1, arg2}).run(comp, fm);
+ new ArgumentKind[] {arg1, arg2}));
continue;
}
for (TypeArgumentKind taDecl3 : TypeArgumentKind.values()) {
//no rare types
- if (isDeclRaw != (taDecl3 == TypeArgumentKind.NONE)) continue;
+ if (isDeclRaw != (taDecl3 == TypeArgumentKind.NONE))
+ continue;
//no diamond on decl site
- if (taDecl3 == TypeArgumentKind.DIAMOND) continue;
+ if (taDecl3 == TypeArgumentKind.DIAMOND)
+ continue;
for (TypeArgumentKind taSite3 : TypeArgumentKind.values()) {
//no rare types
- if (isSiteRaw != (taSite3 == TypeArgumentKind.NONE)) continue;
+ if (isSiteRaw != (taSite3 == TypeArgumentKind.NONE))
+ continue;
//diamond only allowed on the last type qualifier
if (taSite3 == TypeArgumentKind.DIAMOND &&
- innerClassDeclArity != InnerClassDeclArity.THREE) continue;
+ innerClassDeclArity != InnerClassDeclArity.THREE)
+ continue;
for (ArgumentKind arg3 : ArgumentKind.values()) {
- if (innerClassDeclArity == innerClassDeclArity.THREE) {
- new DiamondAndInnerClassTest(innerClassDeclArity, declType, newClassType,
- argList, new TypeArgumentKind[] {taDecl1, taDecl2, taDecl3},
+ if (innerClassDeclArity ==
+ innerClassDeclArity.THREE) {
+ pool.execute(
+ new DiamondAndInnerClassTest(
+ innerClassDeclArity,
+ declType,
+ newClassType,
+ argList,
+ new TypeArgumentKind[] {taDecl1, taDecl2, taDecl3},
new TypeArgumentKind[] {taSite1, taSite2, taSite3},
- new ArgumentKind[] {arg1, arg2, arg3}).run(comp, fm);
+ new ArgumentKind[] {arg1, arg2, arg3}));
continue;
}
}
@@ -230,7 +251,8 @@
}
}
}
- System.out.println("Total check executed: " + checkCount);
+
+ checkAfterExec();
}
InnerClassDeclArity innerClassDeclArity;
@@ -244,9 +266,9 @@
DiagnosticChecker diagChecker;
DiamondAndInnerClassTest(InnerClassDeclArity innerClassDeclArity,
- TypeQualifierArity declType, TypeQualifierArity siteType, ArgumentListArity argList,
- TypeArgumentKind[] declTypeArgumentKinds, TypeArgumentKind[] siteTypeArgumentKinds,
- ArgumentKind[] argumentKinds) {
+ TypeQualifierArity declType, TypeQualifierArity siteType,
+ ArgumentListArity argList, TypeArgumentKind[] declTypeArgumentKinds,
+ TypeArgumentKind[] siteTypeArgumentKinds, ArgumentKind[] argumentKinds) {
this.innerClassDeclArity = innerClassDeclArity;
this.declType = declType;
this.siteType = siteType;
@@ -267,9 +289,9 @@
public JavaSource() {
super(URI.create("myfo:/Test.java"), JavaFileObject.Kind.SOURCE);
source = innerClassDeclArity.classDeclStr.replace("#B", bodyTemplate)
- .replace("#D", declType.getType(declTypeArgumentKinds))
- .replace("#S", siteType.getType(siteTypeArgumentKinds))
- .replace("#AL", argList.getArgs(argumentKinds));
+ .replace("#D", declType.getType(declTypeArgumentKinds))
+ .replace("#S", siteType.getType(siteTypeArgumentKinds))
+ .replace("#AL", argList.getArgs(argumentKinds));
}
@Override
@@ -278,36 +300,39 @@
}
}
- void run(JavaCompiler tool, StandardJavaFileManager fm) throws Exception {
- JavacTask ct = (JavacTask)tool.getTask(null, fm, diagChecker,
+ @Override
+ public void run() {
+ JavacTask ct = (JavacTask)comp.getTask(null, fm.get(), diagChecker,
null, null, Arrays.asList(source));
try {
ct.analyze();
} catch (Throwable ex) {
- throw new AssertionError("Error thrown when compiling the following code:\n" + source.getCharContent(true));
+ throw new AssertionError("Error thrown when compiling the following code:\n" +
+ source.getCharContent(true));
}
check();
}
void check() {
- checkCount++;
+ checkCount.incrementAndGet();
boolean errorExpected = false;
- TypeArgumentKind[] expectedArgKinds = new TypeArgumentKind[innerClassDeclArity.n];
+ TypeArgumentKind[] expectedArgKinds =
+ new TypeArgumentKind[innerClassDeclArity.n];
for (int i = 0 ; i < innerClassDeclArity.n ; i++) {
if (!declTypeArgumentKinds[i].compatible(siteTypeArgumentKinds[i])) {
errorExpected = true;
break;
}
- expectedArgKinds[i] = siteTypeArgumentKinds[i] == TypeArgumentKind.DIAMOND ?
+ expectedArgKinds[i] = siteTypeArgumentKinds[i] ==
+ TypeArgumentKind.DIAMOND ?
declTypeArgumentKinds[i] : siteTypeArgumentKinds[i];
}
if (!errorExpected) {
for (int i = 0 ; i < innerClassDeclArity.n ; i++) {
- //System.out.println("check " + expectedArgKinds[i] + " against " + argumentKinds[i]);
if (!expectedArgKinds[i].compatible(argumentKinds[i])) {
errorExpected = true;
break;
@@ -323,7 +348,8 @@
}
}
- static class DiagnosticChecker implements javax.tools.DiagnosticListener<JavaFileObject> {
+ static class DiagnosticChecker
+ implements javax.tools.DiagnosticListener<JavaFileObject> {
boolean errorFound;
@@ -333,4 +359,5 @@
}
}
}
+
}
--- a/langtools/test/tools/javac/generics/rawOverride/7062745/GenericOverrideTest.java Tue Jan 08 10:17:29 2013 +0100
+++ b/langtools/test/tools/javac/generics/rawOverride/7062745/GenericOverrideTest.java Tue Jan 08 13:47:57 2013 +0000
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2011, 2013, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@@ -24,22 +24,23 @@
/*
* @test
* @bug 7062745
- * @summary Regression: difference in overload resolution when two methods are maximally specific
+ * @summary Regression: difference in overload resolution when two methods
+ * are maximally specific
+ * @library ../../../lib
+ * @build JavacTestingAbstractThreadedTest
+ * @run main GenericOverrideTest
*/
-import com.sun.source.util.JavacTask;
import java.net.URI;
import java.util.Arrays;
import javax.tools.Diagnostic;
-import javax.tools.JavaCompiler;
import javax.tools.JavaFileObject;
import javax.tools.SimpleJavaFileObject;
-import javax.tools.StandardJavaFileManager;
-import javax.tools.ToolProvider;
+import com.sun.source.util.JavacTask;
-public class GenericOverrideTest {
-
- static int checkCount = 0;
+public class GenericOverrideTest
+ extends JavacTestingAbstractThreadedTest
+ implements Runnable {
enum SignatureKind {
NON_GENERIC(""),
@@ -126,11 +127,6 @@
}
public static void main(String... args) throws Exception {
-
- //create default shared JavaCompiler - reused across multiple compilations
- JavaCompiler comp = ToolProvider.getSystemJavaCompiler();
- StandardJavaFileManager fm = comp.getStandardFileManager(null, null, null);
-
for (SignatureKind sig1 : SignatureKind.values()) {
for (ReturnTypeKind rt1 : ReturnTypeKind.values()) {
for (TypeArgumentKind ta1 : TypeArgumentKind.values()) {
@@ -141,8 +137,12 @@
if (!ta2.compatibleWith(sig2)) continue;
for (ReturnTypeKind rt3 : ReturnTypeKind.values()) {
for (TypeArgumentKind ta3 : TypeArgumentKind.values()) {
- if (!ta3.compatibleWith(SignatureKind.NON_GENERIC)) continue;
- new GenericOverrideTest(sig1, rt1, ta1, sig2, rt2, ta2, rt3, ta3).run(comp, fm);
+ if (!ta3.compatibleWith(SignatureKind.NON_GENERIC))
+ continue;
+ pool.execute(
+ new GenericOverrideTest(sig1,
+ rt1, ta1, sig2, rt2,
+ ta2, rt3, ta3));
}
}
}
@@ -151,7 +151,8 @@
}
}
}
- System.out.println("Total check executed: " + checkCount);
+
+ checkAfterExec();
}
SignatureKind sig1, sig2;
@@ -161,7 +162,8 @@
DiagnosticChecker diagChecker;
GenericOverrideTest(SignatureKind sig1, ReturnTypeKind rt1, TypeArgumentKind ta1,
- SignatureKind sig2, ReturnTypeKind rt2, TypeArgumentKind ta2, ReturnTypeKind rt3, TypeArgumentKind ta3) {
+ SignatureKind sig2, ReturnTypeKind rt2, TypeArgumentKind ta2,
+ ReturnTypeKind rt3, TypeArgumentKind ta3) {
this.sig1 = sig1;
this.sig2 = sig2;
this.rt1 = rt1;
@@ -204,19 +206,21 @@
}
}
- void run(JavaCompiler tool, StandardJavaFileManager fm) throws Exception {
- JavacTask ct = (JavacTask)tool.getTask(null, fm, diagChecker,
+ @Override
+ public void run() {
+ JavacTask ct = (JavacTask)comp.getTask(null, fm.get(), diagChecker,
null, null, Arrays.asList(source));
try {
ct.analyze();
} catch (Throwable ex) {
- throw new AssertionError("Error thrown when compiling the following code:\n" + source.getCharContent(true));
+ throw new AssertionError("Error thrown when compiling the following code:\n" +
+ source.getCharContent(true));
}
check();
}
void check() {
- checkCount++;
+ checkCount.incrementAndGet();
boolean errorExpected = false;
int mostSpecific = 0;
@@ -234,14 +238,17 @@
//check that either TA1 <= TA2 or TA2 <= TA1 (unless most specific return found above is raw)
if (!errorExpected) {
if (ta1 != ta2) {
- boolean useStrictCheck = ta1.moreSpecificThan(ta2, true) || ta2.moreSpecificThan(ta1, true);
+ boolean useStrictCheck = ta1.moreSpecificThan(ta2, true) ||
+ ta2.moreSpecificThan(ta1, true);
if (!ta1.moreSpecificThan(ta2, useStrictCheck) &&
!ta2.moreSpecificThan(ta1, useStrictCheck)) {
errorExpected = true;
} else {
int mostSpecific2 = ta1.moreSpecificThan(ta2, useStrictCheck) ? 1 : 2;
if (mostSpecific != 0 && mostSpecific2 != mostSpecific) {
- errorExpected = mostSpecific == 1 ? ta1 != TypeArgumentKind.NONE : ta2 != TypeArgumentKind.NONE;
+ errorExpected = mostSpecific == 1 ?
+ ta1 != TypeArgumentKind.NONE :
+ ta2 != TypeArgumentKind.NONE;
} else {
mostSpecific = mostSpecific2;
}
@@ -273,7 +280,8 @@
}
}
- static class DiagnosticChecker implements javax.tools.DiagnosticListener<JavaFileObject> {
+ static class DiagnosticChecker
+ implements javax.tools.DiagnosticListener<JavaFileObject> {
boolean errorFound;
@@ -283,4 +291,5 @@
}
}
}
+
}
--- a/langtools/test/tools/javac/lambda/FunctionalInterfaceConversionTest.java Tue Jan 08 10:17:29 2013 +0100
+++ b/langtools/test/tools/javac/lambda/FunctionalInterfaceConversionTest.java Tue Jan 08 13:47:57 2013 +0000
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@@ -27,20 +27,24 @@
* @summary Add lambda tests
* perform several automated checks in lambda conversion, esp. around accessibility
* @author Maurizio Cimadamore
+ * @library ../lib
+ * @build JavacTestingAbstractThreadedTest
* @run main FunctionalInterfaceConversionTest
*/
-import com.sun.source.util.JavacTask;
+import java.io.IOException;
import java.net.URI;
import java.util.Arrays;
import javax.tools.Diagnostic;
import javax.tools.JavaCompiler;
import javax.tools.JavaFileObject;
import javax.tools.SimpleJavaFileObject;
-import javax.tools.StandardJavaFileManager;
import javax.tools.ToolProvider;
+import com.sun.source.util.JavacTask;
-public class FunctionalInterfaceConversionTest {
+public class FunctionalInterfaceConversionTest
+ extends JavacTestingAbstractThreadedTest
+ implements Runnable {
enum PackageKind {
NO_PKG(""),
@@ -139,8 +143,6 @@
}
public static void main(String[] args) throws Exception {
- final JavaCompiler comp = ToolProvider.getSystemJavaCompiler();
- StandardJavaFileManager fm = comp.getStandardFileManager(null, null, null);
for (PackageKind samPkg : PackageKind.values()) {
for (ModifierKind modKind : ModifierKind.values()) {
for (SamKind samKind : SamKind.values()) {
@@ -150,8 +152,11 @@
for (TypeKind argType : TypeKind.values()) {
for (TypeKind thrownType : TypeKind.values()) {
for (ExprKind exprKind : ExprKind.values()) {
- new FunctionalInterfaceConversionTest(samPkg, modKind, samKind,
- samMeth, clientMeth, retType, argType, thrownType, exprKind).test(comp, fm);
+ pool.execute(
+ new FunctionalInterfaceConversionTest(
+ samPkg, modKind, samKind,
+ samMeth, clientMeth, retType,
+ argType, thrownType, exprKind));
}
}
}
@@ -161,6 +166,8 @@
}
}
}
+
+ checkAfterExec(false);
}
PackageKind samPkg;
@@ -175,24 +182,30 @@
DiagnosticChecker dc;
SourceFile samSourceFile = new SourceFile("Sam.java", "#P \n #C") {
+ @Override
public String toString() {
return template.replaceAll("#P", samPkg.getPkgDecl()).
- replaceAll("#C", samKind.getSam(samMeth.getMethod(retType, argType, thrownType)));
+ replaceAll("#C", samKind.getSam(
+ samMeth.getMethod(retType, argType, thrownType)));
}
};
- SourceFile pkgClassSourceFile = new SourceFile("PackageClass.java",
- "#P\n #M class PackageClass extends Exception { }") {
+ SourceFile pkgClassSourceFile =
+ new SourceFile("PackageClass.java",
+ "#P\n #M class PackageClass extends Exception { }") {
+ @Override
public String toString() {
return template.replaceAll("#P", samPkg.getPkgDecl()).
replaceAll("#M", modKind.modifier_str);
}
};
- SourceFile clientSourceFile = new SourceFile("Client.java",
- "#I\n abstract class Client { \n" +
- " Sam s = #E;\n" +
- " #M \n }") {
+ SourceFile clientSourceFile =
+ new SourceFile("Client.java",
+ "#I\n abstract class Client { \n" +
+ " Sam s = #E;\n" +
+ " #M \n }") {
+ @Override
public String toString() {
return template.replaceAll("#I", samPkg.getImportStat())
.replaceAll("#E", exprKind.exprStr)
@@ -200,9 +213,10 @@
}
};
- FunctionalInterfaceConversionTest(PackageKind samPkg, ModifierKind modKind, SamKind samKind,
- MethodKind samMeth, MethodKind clientMeth, TypeKind retType, TypeKind argType,
- TypeKind thrownType, ExprKind exprKind) {
+ FunctionalInterfaceConversionTest(PackageKind samPkg, ModifierKind modKind,
+ SamKind samKind, MethodKind samMeth, MethodKind clientMeth,
+ TypeKind retType, TypeKind argType, TypeKind thrownType,
+ ExprKind exprKind) {
this.samPkg = samPkg;
this.modKind = modKind;
this.samKind = samKind;
@@ -215,12 +229,20 @@
this.dc = new DiagnosticChecker();
}
- void test(JavaCompiler comp, StandardJavaFileManager fm) throws Exception {
- JavacTask ct = (JavacTask)comp.getTask(null, fm, dc,
- null, null, Arrays.asList(samSourceFile, pkgClassSourceFile, clientSourceFile));
- ct.analyze();
+ @Override
+ public void run() {
+ final JavaCompiler tool = ToolProvider.getSystemJavaCompiler();
+
+ JavacTask ct = (JavacTask)tool.getTask(null, fm.get(), dc, null, null,
+ Arrays.asList(samSourceFile, pkgClassSourceFile, clientSourceFile));
+ try {
+ ct.analyze();
+ } catch (IOException ex) {
+ throw new AssertionError("Test failing with cause", ex.getCause());
+ }
if (dc.errorFound == checkSamConversion()) {
- throw new AssertionError(samSourceFile + "\n\n" + pkgClassSourceFile + "\n\n" + clientSourceFile);
+ throw new AssertionError(samSourceFile + "\n\n" +
+ pkgClassSourceFile + "\n\n" + clientSourceFile);
}
}
@@ -264,13 +286,16 @@
return toString();
}
+ @Override
public abstract String toString();
}
- static class DiagnosticChecker implements javax.tools.DiagnosticListener<JavaFileObject> {
+ static class DiagnosticChecker
+ implements javax.tools.DiagnosticListener<JavaFileObject> {
boolean errorFound = false;
+ @Override
public void report(Diagnostic<? extends JavaFileObject> diagnostic) {
if (diagnostic.getKind() == Diagnostic.Kind.ERROR) {
errorFound = true;
--- a/langtools/test/tools/javac/lambda/LambdaParserTest.java Tue Jan 08 10:17:29 2013 +0100
+++ b/langtools/test/tools/javac/lambda/LambdaParserTest.java Tue Jan 08 13:47:57 2013 +0000
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2011, 2013, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@@ -27,21 +27,21 @@
* @bug 8003280
* @summary Add lambda tests
* Add parser support for lambda expressions
+ * @library ../lib
+ * @build JavacTestingAbstractThreadedTest
+ * @run main LambdaParserTest
*/
-import com.sun.source.util.JavacTask;
import java.net.URI;
import java.util.Arrays;
import javax.tools.Diagnostic;
-import javax.tools.JavaCompiler;
import javax.tools.JavaFileObject;
import javax.tools.SimpleJavaFileObject;
-import javax.tools.StandardJavaFileManager;
-import javax.tools.ToolProvider;
+import com.sun.source.util.JavacTask;
-public class LambdaParserTest {
-
- static int checkCount = 0;
+public class LambdaParserTest
+ extends JavacTestingAbstractThreadedTest
+ implements Runnable {
enum LambdaKind {
NILARY_EXPR("()->x"),
@@ -173,25 +173,26 @@
}
public static void main(String... args) throws Exception {
-
- //create default shared JavaCompiler - reused across multiple compilations
- JavaCompiler comp = ToolProvider.getSystemJavaCompiler();
- StandardJavaFileManager fm = comp.getStandardFileManager(null, null, null);
-
for (LambdaKind lk : LambdaKind.values()) {
for (LambdaParameterKind pk1 : LambdaParameterKind.values()) {
- if (lk.arity() < 1 && pk1 != LambdaParameterKind.IMPLICIT) continue;
+ if (lk.arity() < 1 && pk1 != LambdaParameterKind.IMPLICIT)
+ continue;
for (LambdaParameterKind pk2 : LambdaParameterKind.values()) {
- if (lk.arity() < 2 && pk2 != LambdaParameterKind.IMPLICIT) continue;
+ if (lk.arity() < 2 && pk2 != LambdaParameterKind.IMPLICIT)
+ continue;
for (ModifierKind mk1 : ModifierKind.values()) {
- if (mk1 != ModifierKind.NONE && lk.isShort()) continue;
- if (lk.arity() < 1 && mk1 != ModifierKind.NONE) continue;
+ if (mk1 != ModifierKind.NONE && lk.isShort())
+ continue;
+ if (lk.arity() < 1 && mk1 != ModifierKind.NONE)
+ continue;
for (ModifierKind mk2 : ModifierKind.values()) {
- if (lk.arity() < 2 && mk2 != ModifierKind.NONE) continue;
+ if (lk.arity() < 2 && mk2 != ModifierKind.NONE)
+ continue;
for (SubExprKind sk : SubExprKind.values()) {
for (ExprKind ek : ExprKind.values()) {
- new LambdaParserTest(pk1, pk2, mk1, mk2, lk, sk, ek)
- .run(comp, fm);
+ pool.execute(
+ new LambdaParserTest(pk1, pk2, mk1,
+ mk2, lk, sk, ek));
}
}
}
@@ -199,7 +200,8 @@
}
}
}
- System.out.println("Total check executed: " + checkCount);
+
+ checkAfterExec();
}
LambdaParameterKind pk1;
@@ -212,8 +214,9 @@
JavaSource source;
DiagnosticChecker diagChecker;
- LambdaParserTest(LambdaParameterKind pk1, LambdaParameterKind pk2, ModifierKind mk1,
- ModifierKind mk2, LambdaKind lk, SubExprKind sk, ExprKind ek) {
+ LambdaParserTest(LambdaParameterKind pk1, LambdaParameterKind pk2,
+ ModifierKind mk1, ModifierKind mk2, LambdaKind lk,
+ SubExprKind sk, ExprKind ek) {
this.pk1 = pk1;
this.pk2 = pk2;
this.mk1 = mk1;
@@ -235,7 +238,8 @@
public JavaSource() {
super(URI.create("myfo:/Test.java"), JavaFileObject.Kind.SOURCE);
- source = template.replaceAll("#E", ek.expressionString(pk1, pk2, mk1, mk2, lk, sk));
+ source = template.replaceAll("#E",
+ ek.expressionString(pk1, pk2, mk1, mk2, lk, sk));
}
@Override
@@ -244,19 +248,20 @@
}
}
- void run(JavaCompiler tool, StandardJavaFileManager fm) throws Exception {
- JavacTask ct = (JavacTask)tool.getTask(null, fm, diagChecker,
+ public void run() {
+ JavacTask ct = (JavacTask)comp.getTask(null, fm.get(), diagChecker,
null, null, Arrays.asList(source));
try {
ct.parse();
} catch (Throwable ex) {
- throw new AssertionError("Error thrown when parsing the following source:\n" + source.getCharContent(true));
+ processException(ex);
+ return;
}
check();
}
void check() {
- checkCount++;
+ checkCount.incrementAndGet();
boolean errorExpected = (lk.arity() > 0 && !mk1.compatibleWith(pk1)) ||
(lk.arity() > 1 && !mk2.compatibleWith(pk2));
@@ -275,7 +280,8 @@
}
}
- static class DiagnosticChecker implements javax.tools.DiagnosticListener<JavaFileObject> {
+ static class DiagnosticChecker
+ implements javax.tools.DiagnosticListener<JavaFileObject> {
boolean errorFound;
@@ -285,4 +291,5 @@
}
}
}
+
}
--- a/langtools/test/tools/javac/lambda/MethodReferenceParserTest.java Tue Jan 08 10:17:29 2013 +0100
+++ b/langtools/test/tools/javac/lambda/MethodReferenceParserTest.java Tue Jan 08 13:47:57 2013 +0000
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2011, 2012, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2011, 2013, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@@ -27,21 +27,21 @@
* @bug 8003280
* @summary Add lambda tests
* Add parser support for method references
+ * @library ../lib
+ * @build JavacTestingAbstractThreadedTest
+ * @run main MethodReferenceParserTest
*/
-import com.sun.source.util.JavacTask;
import java.net.URI;
import java.util.Arrays;
import javax.tools.Diagnostic;
-import javax.tools.JavaCompiler;
import javax.tools.JavaFileObject;
import javax.tools.SimpleJavaFileObject;
-import javax.tools.StandardJavaFileManager;
-import javax.tools.ToolProvider;
+import com.sun.source.util.JavacTask;
-public class MethodReferenceParserTest {
-
- static int checkCount = 0;
+public class MethodReferenceParserTest
+ extends JavacTestingAbstractThreadedTest
+ implements Runnable {
enum ReferenceKind {
METHOD_REF("#Q::#Gm"),
@@ -88,7 +88,8 @@
this.contextTemplate = contextTemplate;
}
- String contextString(ExprKind ek, ReferenceKind rk, QualifierKind qk, GenericKind gk, SubExprKind sk) {
+ String contextString(ExprKind ek, ReferenceKind rk, QualifierKind qk,
+ GenericKind gk, SubExprKind sk) {
return contextTemplate.replaceAll("#E", ek.expressionString(rk, qk, gk, sk));
}
}
@@ -165,25 +166,21 @@
}
public static void main(String... args) throws Exception {
-
- //create default shared JavaCompiler - reused across multiple compilations
- JavaCompiler comp = ToolProvider.getSystemJavaCompiler();
- StandardJavaFileManager fm = comp.getStandardFileManager(null, null, null);
-
for (ReferenceKind rk : ReferenceKind.values()) {
for (QualifierKind qk : QualifierKind.values()) {
for (GenericKind gk : GenericKind.values()) {
for (SubExprKind sk : SubExprKind.values()) {
for (ExprKind ek : ExprKind.values()) {
for (ContextKind ck : ContextKind.values()) {
- new MethodReferenceParserTest(rk, qk, gk, sk, ek, ck).run(comp, fm);
+ pool.execute(new MethodReferenceParserTest(rk, qk, gk, sk, ek, ck));
}
}
}
}
}
}
- System.out.println("Total check executed: " + checkCount);
+
+ checkAfterExec();
}
ReferenceKind rk;
@@ -227,19 +224,21 @@
}
}
- void run(JavaCompiler tool, StandardJavaFileManager fm) throws Exception {
- JavacTask ct = (JavacTask)tool.getTask(null, fm, diagChecker,
+ @Override
+ public void run() {
+ JavacTask ct = (JavacTask)comp.getTask(null, fm.get(), diagChecker,
null, null, Arrays.asList(source));
try {
ct.parse();
} catch (Throwable ex) {
- throw new AssertionError("Error thrown when parsing the following source:\n" + source.getCharContent(true));
+ processException(ex);
+ return;
}
check();
}
void check() {
- checkCount++;
+ checkCount.incrementAndGet();
if (diagChecker.errorFound != rk.erroneous()) {
throw new Error("invalid diagnostics for source:\n" +
@@ -259,4 +258,5 @@
}
}
}
+
}
--- a/langtools/test/tools/javac/lambda/TestInvokeDynamic.java Tue Jan 08 10:17:29 2013 +0100
+++ b/langtools/test/tools/javac/lambda/TestInvokeDynamic.java Tue Jan 08 13:47:57 2013 +0000
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@@ -28,7 +28,9 @@
* @bug 8003280
* @summary Add lambda tests
* Add back-end support for invokedynamic
- *
+ * @library ../lib
+ * @build JavacTestingAbstractThreadedTest
+ * @run main TestInvokeDynamic
*/
import com.sun.source.tree.MethodInvocationTree;
@@ -66,7 +68,6 @@
import javax.tools.Diagnostic;
import javax.tools.JavaCompiler;
-import javax.tools.JavaFileManager;
import javax.tools.JavaFileObject;
import javax.tools.SimpleJavaFileObject;
import javax.tools.StandardJavaFileManager;
@@ -74,69 +75,80 @@
import static com.sun.tools.javac.jvm.ClassFile.*;
-public class TestInvokeDynamic {
-
- static int checkCount = 0;
+public class TestInvokeDynamic
+ extends JavacTestingAbstractThreadedTest
+ implements Runnable {
enum StaticArgumentKind {
STRING("Hello!", "String", "Ljava/lang/String;") {
@Override
boolean check(CPInfo cpInfo) throws Exception {
return (cpInfo instanceof CONSTANT_String_info) &&
- ((CONSTANT_String_info)cpInfo).getString().equals(value);
+ ((CONSTANT_String_info)cpInfo).getString()
+ .equals(value);
}
},
CLASS(null, "Class<?>", "Ljava/lang/Class;") {
@Override
boolean check(CPInfo cpInfo) throws Exception {
return (cpInfo instanceof CONSTANT_Class_info) &&
- ((CONSTANT_Class_info)cpInfo).getName().equals("java/lang/String");
+ ((CONSTANT_Class_info)cpInfo).getName()
+ .equals("java/lang/String");
}
},
INTEGER(1, "int", "I") {
@Override
boolean check(CPInfo cpInfo) throws Exception {
return (cpInfo instanceof CONSTANT_Integer_info) &&
- ((CONSTANT_Integer_info)cpInfo).value == ((Integer)value).intValue();
+ ((CONSTANT_Integer_info)cpInfo).value ==
+ ((Integer)value).intValue();
}
},
LONG(1L, "long", "J") {
@Override
boolean check(CPInfo cpInfo) throws Exception {
return (cpInfo instanceof CONSTANT_Long_info) &&
- ((CONSTANT_Long_info)cpInfo).value == ((Long)value).longValue();
+ ((CONSTANT_Long_info)cpInfo).value ==
+ ((Long)value).longValue();
}
},
FLOAT(1.0f, "float", "F") {
@Override
boolean check(CPInfo cpInfo) throws Exception {
return (cpInfo instanceof CONSTANT_Float_info) &&
- ((CONSTANT_Float_info)cpInfo).value == ((Float)value).floatValue();
+ ((CONSTANT_Float_info)cpInfo).value ==
+ ((Float)value).floatValue();
}
},
DOUBLE(1.0, "double","D") {
@Override
boolean check(CPInfo cpInfo) throws Exception {
return (cpInfo instanceof CONSTANT_Double_info) &&
- ((CONSTANT_Double_info)cpInfo).value == ((Double)value).doubleValue();
+ ((CONSTANT_Double_info)cpInfo).value ==
+ ((Double)value).doubleValue();
}
},
METHOD_HANDLE(null, "MethodHandle", "Ljava/lang/invoke/MethodHandle;") {
@Override
boolean check(CPInfo cpInfo) throws Exception {
- if (!(cpInfo instanceof CONSTANT_MethodHandle_info)) return false;
- CONSTANT_MethodHandle_info handleInfo = (CONSTANT_MethodHandle_info)cpInfo;
+ if (!(cpInfo instanceof CONSTANT_MethodHandle_info))
+ return false;
+ CONSTANT_MethodHandle_info handleInfo =
+ (CONSTANT_MethodHandle_info)cpInfo;
return handleInfo.getCPRefInfo().getClassName().equals("Array") &&
handleInfo.reference_kind == RefKind.REF_invokeVirtual &&
- handleInfo.getCPRefInfo().getNameAndTypeInfo().getName().equals("clone") &&
- handleInfo.getCPRefInfo().getNameAndTypeInfo().getType().equals("()Ljava/lang/Object;");
+ handleInfo.getCPRefInfo()
+ .getNameAndTypeInfo().getName().equals("clone") &&
+ handleInfo.getCPRefInfo()
+ .getNameAndTypeInfo().getType().equals("()Ljava/lang/Object;");
}
},
METHOD_TYPE(null, "MethodType", "Ljava/lang/invoke/MethodType;") {
@Override
boolean check(CPInfo cpInfo) throws Exception {
return (cpInfo instanceof CONSTANT_MethodType_info) &&
- ((CONSTANT_MethodType_info)cpInfo).getType().equals("()Ljava/lang/Object;");
+ ((CONSTANT_MethodType_info)cpInfo).getType()
+ .equals("()Ljava/lang/Object;");
}
};
@@ -144,7 +156,8 @@
String sourceTypeStr;
String bytecodeTypeStr;
- StaticArgumentKind(Object value, String sourceTypeStr, String bytecodeTypeStr) {
+ StaticArgumentKind(Object value, String sourceTypeStr,
+ String bytecodeTypeStr) {
this.value = value;
this.sourceTypeStr = sourceTypeStr;
this.bytecodeTypeStr = bytecodeTypeStr;
@@ -163,7 +176,8 @@
case CLASS:
return syms.stringType.tsym;
case METHOD_HANDLE:
- return new Pool.MethodHandle(REF_invokeVirtual, syms.arrayCloneMethod, types);
+ return new Pool.MethodHandle(REF_invokeVirtual,
+ syms.arrayCloneMethod, types);
case METHOD_TYPE:
return syms.arrayCloneMethod.type;
default:
@@ -186,23 +200,21 @@
}
public static void main(String... args) throws Exception {
- // Create a single file manager and compiler and reuse it for each compile to save time.
- StandardJavaFileManager fm = JavacTool.create().getStandardFileManager(null, null, null);
- final JavaCompiler tool = ToolProvider.getSystemJavaCompiler();
for (StaticArgumentsArity arity : StaticArgumentsArity.values()) {
if (arity.arity == 0) {
- new TestInvokeDynamic(arity).compileAndCheck(fm, tool);
+ pool.execute(new TestInvokeDynamic(arity));
} else {
for (StaticArgumentKind sak1 : StaticArgumentKind.values()) {
if (arity.arity == 1) {
- new TestInvokeDynamic(arity, sak1).compileAndCheck(fm, tool);
+ pool.execute(new TestInvokeDynamic(arity, sak1));
} else {
for (StaticArgumentKind sak2 : StaticArgumentKind.values()) {
if (arity.arity == 2) {
- new TestInvokeDynamic(arity, sak1, sak2).compileAndCheck(fm, tool);
+ pool.execute(new TestInvokeDynamic(arity, sak1, sak2));
} else {
for (StaticArgumentKind sak3 : StaticArgumentKind.values()) {
- new TestInvokeDynamic(arity, sak1, sak2, sak3).compileAndCheck(fm, tool);
+ pool.execute(
+ new TestInvokeDynamic(arity, sak1, sak2, sak3));
}
}
}
@@ -211,23 +223,23 @@
}
}
- System.out.println("Total checks made: " + checkCount);
+ checkAfterExec();
}
StaticArgumentsArity arity;
StaticArgumentKind[] saks;
- JavaSource source;
DiagChecker dc;
TestInvokeDynamic(StaticArgumentsArity arity, StaticArgumentKind... saks) {
this.arity = arity;
this.saks = saks;
- source = new JavaSource();
dc = new DiagChecker();
}
- void compileAndCheck(JavaFileManager fm, JavaCompiler tool) throws Exception {
- JavacTaskImpl ct = (JavacTaskImpl)tool.getTask(null, fm, dc,
+ public void run() {
+ int id = checkCount.incrementAndGet();
+ JavaSource source = new JavaSource(id);
+ JavacTaskImpl ct = (JavacTaskImpl)comp.getTask(null, fm.get(), dc,
null, null, Arrays.asList(source));
Context context = ct.getContext();
Symtab syms = Symtab.instance(context);
@@ -238,16 +250,20 @@
ct.generate();
} catch (Throwable t) {
t.printStackTrace();
- throw new AssertionError(String.format("Error thrown when compiling following code\n%s", source.source));
+ throw new AssertionError(
+ String.format("Error thrown when compiling following code\n%s",
+ source.source));
}
if (dc.diagFound) {
- throw new AssertionError(String.format("Diags found when compiling following code\n%s\n\n%s", source.source, dc.printDiags()));
+ throw new AssertionError(
+ String.format("Diags found when compiling following code\n%s\n\n%s",
+ source.source, dc.printDiags()));
}
- verifyBytecode();
+ verifyBytecode(id);
}
- void verifyBytecode() {
- File compiledTest = new File("Test.class");
+ void verifyBytecode(int id) {
+ File compiledTest = new File(String.format("Test%d.class", id));
try {
ClassFile cf = ClassFile.read(compiledTest);
Method testMethod = null;
@@ -260,7 +276,8 @@
if (testMethod == null) {
throw new Error("Test method not found");
}
- Code_attribute ea = (Code_attribute)testMethod.attributes.get(Attribute.Code);
+ Code_attribute ea =
+ (Code_attribute)testMethod.attributes.get(Attribute.Code);
if (testMethod == null) {
throw new Error("Code attribute for test() method not found");
}
@@ -270,10 +287,12 @@
for (Instruction i : ea.getInstructions()) {
if (i.getMnemonic().equals("invokedynamic")) {
CONSTANT_InvokeDynamic_info indyInfo =
- (CONSTANT_InvokeDynamic_info)cf.constant_pool.get(i.getShort(1));
+ (CONSTANT_InvokeDynamic_info)cf
+ .constant_pool.get(i.getShort(1));
bsmIdx = indyInfo.bootstrap_method_attr_index;
if (!indyInfo.getNameAndTypeInfo().getType().equals("()V")) {
- throw new AssertionError("type mismatch for CONSTANT_InvokeDynamic_info");
+ throw new
+ AssertionError("type mismatch for CONSTANT_InvokeDynamic_info");
}
}
}
@@ -281,34 +300,41 @@
throw new Error("Missing invokedynamic in generated code");
}
- BootstrapMethods_attribute bsm_attr = (BootstrapMethods_attribute)cf.getAttribute(Attribute.BootstrapMethods);
+ BootstrapMethods_attribute bsm_attr =
+ (BootstrapMethods_attribute)cf
+ .getAttribute(Attribute.BootstrapMethods);
if (bsm_attr.bootstrap_method_specifiers.length != 1) {
- throw new Error("Bad number of method specifiers in BootstrapMethods attribute");
+ throw new Error("Bad number of method specifiers " +
+ "in BootstrapMethods attribute");
}
BootstrapMethods_attribute.BootstrapMethodSpecifier bsm_spec =
bsm_attr.bootstrap_method_specifiers[0];
if (bsm_spec.bootstrap_arguments.length != arity.arity) {
- throw new Error("Bad number of static invokedynamic args in BootstrapMethod attribute");
+ throw new Error("Bad number of static invokedynamic args " +
+ "in BootstrapMethod attribute");
}
int count = 0;
for (StaticArgumentKind sak : saks) {
- if (!sak.check(cf.constant_pool.get(bsm_spec.bootstrap_arguments[count]))) {
+ if (!sak.check(cf.constant_pool
+ .get(bsm_spec.bootstrap_arguments[count]))) {
throw new Error("Bad static argument value " + sak);
}
count++;
}
CONSTANT_MethodHandle_info bsm_handle =
- (CONSTANT_MethodHandle_info)cf.constant_pool.get(bsm_spec.bootstrap_method_ref);
+ (CONSTANT_MethodHandle_info)cf.constant_pool
+ .get(bsm_spec.bootstrap_method_ref);
if (bsm_handle.reference_kind != RefKind.REF_invokeStatic) {
throw new Error("Bad kind on boostrap method handle");
}
CONSTANT_Methodref_info bsm_ref =
- (CONSTANT_Methodref_info)cf.constant_pool.get(bsm_handle.reference_index);
+ (CONSTANT_Methodref_info)cf.constant_pool
+ .get(bsm_handle.reference_index);
if (!bsm_ref.getClassInfo().getName().equals("Bootstrap")) {
throw new Error("Bad owner of boostrap method");
@@ -318,8 +344,11 @@
throw new Error("Bad boostrap method name");
}
- if (!bsm_ref.getNameAndTypeInfo().getType().equals(asBSMSignatureString())) {
- throw new Error("Bad boostrap method type" + bsm_ref.getNameAndTypeInfo().getType() + " " + asBSMSignatureString());
+ if (!bsm_ref.getNameAndTypeInfo()
+ .getType().equals(asBSMSignatureString())) {
+ throw new Error("Bad boostrap method type" +
+ bsm_ref.getNameAndTypeInfo().getType() + " " +
+ asBSMSignatureString());
}
} catch (Exception e) {
e.printStackTrace();
@@ -341,20 +370,22 @@
static final String source_template = "import java.lang.invoke.*;\n" +
"class Bootstrap {\n" +
- " public static CallSite bsm(MethodHandles.Lookup lookup, String name, MethodType methodType #SARGS) {\n" +
+ " public static CallSite bsm(MethodHandles.Lookup lookup, " +
+ "String name, MethodType methodType #SARGS) {\n" +
" return null;\n" +
" }\n" +
"}\n" +
- "class Test {\n" +
+ "class Test#ID {\n" +
" void m() { }\n" +
" void test() { m(); }\n" +
"}";
String source;
- JavaSource() {
+ JavaSource(int id) {
super(URI.create("myfo:/Test.java"), JavaFileObject.Kind.SOURCE);
- source = source_template.replace("#SARGS", asSignatureString());
+ source = source_template.replace("#SARGS", asSignatureString())
+ .replace("#ID", String.valueOf(id));
}
@Override
@@ -411,7 +442,8 @@
for (int i = 0; i < arity.arity ; i++) {
staticArgs[i] = saks[i].getValue(syms, names, types);
}
- ident.sym = new Symbol.DynamicMethodSymbol(oldSym.name, oldSym.owner, REF_invokeStatic, bsm, oldSym.type, staticArgs);
+ ident.sym = new Symbol.DynamicMethodSymbol(oldSym.name,
+ oldSym.owner, REF_invokeStatic, bsm, oldSym.type, staticArgs);
}
return null;
}
@@ -426,7 +458,8 @@
}
}
- static class DiagChecker implements javax.tools.DiagnosticListener<JavaFileObject> {
+ static class DiagChecker
+ implements javax.tools.DiagnosticListener<JavaFileObject> {
boolean diagFound;
ArrayList<String> diags = new ArrayList<>();
@@ -445,4 +478,5 @@
return buf.toString();
}
}
+
}
--- a/langtools/test/tools/javac/lambda/mostSpecific/StructuralMostSpecificTest.java Tue Jan 08 10:17:29 2013 +0100
+++ b/langtools/test/tools/javac/lambda/mostSpecific/StructuralMostSpecificTest.java Tue Jan 08 13:47:57 2013 +0000
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@@ -26,24 +26,23 @@
* @bug 8003280
* @summary Add lambda tests
* Automatic test for checking correctness of structural most specific test routine
- * @run main/timeout=360 StructuralMostSpecificTest
+ * @library ../../lib
+ * @build JavacTestingAbstractThreadedTest
+ * @run main/timeout=600 StructuralMostSpecificTest
*/
-import com.sun.source.util.JavacTask;
-import com.sun.tools.javac.api.ClientCodeWrapper;
-import com.sun.tools.javac.util.JCDiagnostic;
import java.net.URI;
import java.util.Arrays;
import javax.tools.Diagnostic;
-import javax.tools.JavaCompiler;
import javax.tools.JavaFileObject;
import javax.tools.SimpleJavaFileObject;
-import javax.tools.StandardJavaFileManager;
-import javax.tools.ToolProvider;
+import com.sun.source.util.JavacTask;
+import com.sun.tools.javac.api.ClientCodeWrapper;
+import com.sun.tools.javac.util.JCDiagnostic;
-public class StructuralMostSpecificTest {
-
- static int checkCount = 0;
+public class StructuralMostSpecificTest
+ extends JavacTestingAbstractThreadedTest
+ implements Runnable {
enum RetTypeKind {
SHORT("short"),
@@ -105,7 +104,7 @@
VOID("return;"),
SHORT("return (short)0;"),
INT("return 0;"),
- INTEGER("return (Integer)null"),
+ INTEGER("return (Integer)null;"),
NULL("return null;");
String retStr;
@@ -142,11 +141,6 @@
}
public static void main(String... args) throws Exception {
-
- //create default shared JavaCompiler - reused across multiple compilations
- JavaCompiler comp = ToolProvider.getSystemJavaCompiler();
- StandardJavaFileManager fm = comp.getStandardFileManager(null, null, null);
-
for (LambdaReturnKind lrk : LambdaReturnKind.values()) {
for (RetTypeKind rk1 : RetTypeKind.values()) {
for (RetTypeKind rk2 : RetTypeKind.values()) {
@@ -154,7 +148,9 @@
for (ExceptionKind ek2 : ExceptionKind.values()) {
for (ArgTypeKind ak11 : ArgTypeKind.values()) {
for (ArgTypeKind ak12 : ArgTypeKind.values()) {
- new StructuralMostSpecificTest(lrk, rk1, rk2, ek1, ek2, ak11, ak12).run(comp, fm);
+ pool.execute(
+ new StructuralMostSpecificTest(lrk, rk1,
+ rk2, ek1, ek2, ak11, ak12));
}
}
}
@@ -162,7 +158,8 @@
}
}
}
- System.out.println("Total check executed: " + checkCount);
+
+ checkAfterExec();
}
LambdaReturnKind lrk;
@@ -218,20 +215,22 @@
}
}
- void run(JavaCompiler tool, StandardJavaFileManager fm) throws Exception {
- JavacTask ct = (JavacTask)tool.getTask(null, fm, diagChecker,
+ public void run() {
+ JavacTask ct = (JavacTask)comp.getTask(null, fm.get(), diagChecker,
Arrays.asList("-XDverboseResolution=all,-predef,-internal,-object-init"),
null, Arrays.asList(source));
try {
ct.analyze();
} catch (Throwable ex) {
- throw new AssertionError("Error thron when analyzing the following source:\n" + source.getCharContent(true));
+ throw new
+ AssertionError("Error thron when analyzing the following source:\n" +
+ source.getCharContent(true));
}
check();
}
void check() {
- checkCount++;
+ checkCount.incrementAndGet();
if (!lrk.compatibleWith(rt1) || !lrk.compatibleWith(rt2))
return;
@@ -265,8 +264,8 @@
}
}
- boolean moreSpecific(RetTypeKind rk1, RetTypeKind rk2, ExceptionKind ek1, ExceptionKind ek2,
- ArgTypeKind ak1, ArgTypeKind ak2) {
+ boolean moreSpecific(RetTypeKind rk1, RetTypeKind rk2, ExceptionKind ek1,
+ ExceptionKind ek2, ArgTypeKind ak1, ArgTypeKind ak2) {
if (!rk1.moreSpecificThan(rk2))
return false;
@@ -276,7 +275,8 @@
return true;
}
- static class DiagnosticChecker implements javax.tools.DiagnosticListener<JavaFileObject> {
+ static class DiagnosticChecker
+ implements javax.tools.DiagnosticListener<JavaFileObject> {
boolean ambiguityFound;
String mostSpecificSig;
@@ -287,12 +287,16 @@
diagnostic.getCode().equals("compiler.err.ref.ambiguous")) {
ambiguityFound = true;
} else if (diagnostic.getKind() == Diagnostic.Kind.NOTE &&
- diagnostic.getCode().equals("compiler.note.verbose.resolve.multi")) {
+ diagnostic.getCode()
+ .equals("compiler.note.verbose.resolve.multi")) {
ClientCodeWrapper.DiagnosticSourceUnwrapper dsu =
- (ClientCodeWrapper.DiagnosticSourceUnwrapper)diagnostic;
- JCDiagnostic.MultilineDiagnostic mdiag = (JCDiagnostic.MultilineDiagnostic)dsu.d;
+ (ClientCodeWrapper.DiagnosticSourceUnwrapper)diagnostic;
+ JCDiagnostic.MultilineDiagnostic mdiag =
+ (JCDiagnostic.MultilineDiagnostic)dsu.d;
int mostSpecificIndex = (Integer)mdiag.getArgs()[2];
- mostSpecificSig = ((JCDiagnostic)mdiag.getSubdiagnostics().get(mostSpecificIndex)).getArgs()[1].toString();
+ mostSpecificSig =
+ ((JCDiagnostic)mdiag.getSubdiagnostics()
+ .get(mostSpecificIndex)).getArgs()[1].toString();
}
} catch (RuntimeException t) {
t.printStackTrace();
@@ -300,4 +304,5 @@
}
}
}
+
}
--- a/langtools/test/tools/javac/lambda/typeInference/combo/TypeInferenceComboTest.java Tue Jan 08 10:17:29 2013 +0100
+++ b/langtools/test/tools/javac/lambda/typeInference/combo/TypeInferenceComboTest.java Tue Jan 08 13:47:57 2013 +0000
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2011, 2013, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@@ -25,22 +25,24 @@
* @test
* @bug 8003280
* @summary Add lambda tests
- * perform automated checks in type inference in lambda expressions in different contexts
+ * perform automated checks in type inference in lambda expressions
+ * in different contexts
+ * @library ../../../lib
+ * @build JavacTestingAbstractThreadedTest
* @compile TypeInferenceComboTest.java
* @run main/timeout=360 TypeInferenceComboTest
*/
-import com.sun.source.util.JavacTask;
import java.net.URI;
import java.util.Arrays;
import javax.tools.Diagnostic;
-import javax.tools.JavaCompiler;
import javax.tools.JavaFileObject;
import javax.tools.SimpleJavaFileObject;
-import javax.tools.ToolProvider;
-import javax.tools.StandardJavaFileManager;
+import com.sun.source.util.JavacTask;
-public class TypeInferenceComboTest {
+public class TypeInferenceComboTest
+ extends JavacTestingAbstractThreadedTest
+ implements Runnable {
enum Context {
ASSIGNMENT("SAM#Type s = #LBody;"),
METHOD_CALL("#GenericDeclKind void method1(SAM#Type s) { }\n" +
@@ -59,27 +61,35 @@
this.context = context;
}
- String getContext(SamKind sk, TypeKind samTargetT, Keyword kw, TypeKind parameterT, TypeKind returnT, LambdaKind lk, ParameterKind pk, GenericDeclKind gdk, LambdaBody lb) {
+ String getContext(SamKind sk, TypeKind samTargetT, Keyword kw,
+ TypeKind parameterT, TypeKind returnT, LambdaKind lk,
+ ParameterKind pk, GenericDeclKind gdk, LambdaBody lb) {
String result = context;
if (sk == SamKind.GENERIC) {
if(this == Context.METHOD_CALL) {
- result = result.replaceAll("#GenericDeclKind", gdk.getGenericDeclKind(samTargetT));
+ result = result.replaceAll("#GenericDeclKind",
+ gdk.getGenericDeclKind(samTargetT));
if(gdk == GenericDeclKind.NON_GENERIC)
- result = result.replaceAll("#Type", "<" + samTargetT.typeStr + ">");
+ result = result.replaceAll("#Type", "<" +
+ samTargetT.typeStr + ">");
else //#GenericDeclKind is <T> or <T extends xxx>
result = result.replaceAll("#Type", "<T>");
}
else {
if(kw == Keyword.VOID)
- result = result.replaceAll("#Type", "<" + samTargetT.typeStr + ">");
+ result = result.replaceAll("#Type", "<" +
+ samTargetT.typeStr + ">");
else
- result = result.replaceAll("#Type", "<? " + kw.keyStr + " " + samTargetT.typeStr + ">");
+ result = result.replaceAll("#Type", "<? " + kw.keyStr +
+ " " + samTargetT.typeStr + ">");
}
}
else
- result = result.replaceAll("#Type", "").replaceAll("#GenericDeclKind", "");
+ result = result.replaceAll("#Type", "").
+ replaceAll("#GenericDeclKind", "");
- return result.replaceAll("#LBody", lb.getLambdaBody(samTargetT, parameterT, returnT, lk, pk));
+ return result.replaceAll("#LBody",
+ lb.getLambdaBody(samTargetT, parameterT, returnT, lk, pk));
}
}
@@ -94,8 +104,10 @@
}
String getSam(TypeKind parameterT, TypeKind returnT) {
- return sam_str.replaceAll("#ARG", parameterT == TypeKind.VOID ? "" : parameterT.typeStr + " arg")
- .replaceAll("#R", returnT.typeStr);
+ return sam_str.replaceAll("#ARG",
+ parameterT == TypeKind.VOID ?
+ "" : parameterT.typeStr + " arg")
+ .replaceAll("#R", returnT.typeStr);
}
}
@@ -104,7 +116,8 @@
STRING("String", "\"hello\""),
INTEGER("Integer", "1"),
INT("int", "0"),
- COMPARATOR("java.util.Comparator<String>", "(java.util.Comparator<String>)(a, b) -> a.length()-b.length()"),
+ COMPARATOR("java.util.Comparator<String>",
+ "(java.util.Comparator<String>)(a, b) -> a.length()-b.length()"),
SAM("SAM2", "null"),
GENERIC("T", null);
@@ -152,8 +165,10 @@
}
enum LambdaBody {
- RETURN_VOID("() -> #RET"),//no parameters, return type is one of the TypeKind
- RETURN_ARG("(#PK arg) -> #RET");//has parameters, return type is one of the TypeKind
+ //no parameters, return type is one of the TypeKind
+ RETURN_VOID("() -> #RET"),
+ //has parameters, return type is one of the TypeKind
+ RETURN_ARG("(#PK arg) -> #RET");
String bodyStr;
@@ -161,12 +176,14 @@
this.bodyStr = bodyStr;
}
- String getLambdaBody(TypeKind samTargetT, TypeKind parameterT, TypeKind returnT, LambdaKind lk, ParameterKind pk) {
+ String getLambdaBody(TypeKind samTargetT, TypeKind parameterT,
+ TypeKind returnT, LambdaKind lk, ParameterKind pk) {
String result = bodyStr.replaceAll("#PK", pk.paramTemplate);
if(result.contains("#TYPE")) {
if (parameterT == TypeKind.GENERIC && this != RETURN_VOID)
- result = result.replaceAll("#TYPE", samTargetT == null? "": samTargetT.typeStr);
+ result = result.replaceAll("#TYPE",
+ samTargetT == null? "": samTargetT.typeStr);
else
result = result.replaceAll("#TYPE", parameterT.typeStr);
}
@@ -174,9 +191,12 @@
return result.replaceAll("#RET", lk.stmt.replaceAll("#VAL", "arg"));
else {
if(returnT != TypeKind.GENERIC)
- return result.replaceAll("#RET", lk.stmt.replaceAll("#VAL", (returnT==TypeKind.VOID && lk==LambdaKind.EXPRESSION)? "{}" : returnT.valStr));
+ return result.replaceAll("#RET", lk.stmt.replaceAll("#VAL",
+ (returnT==TypeKind.VOID &&
+ lk==LambdaKind.EXPRESSION) ? "{}" : returnT.valStr));
else
- return result.replaceAll("#RET", lk.stmt.replaceAll("#VAL", samTargetT.valStr));
+ return result.replaceAll("#RET",
+ lk.stmt.replaceAll("#VAL", samTargetT.valStr));
}
}
}
@@ -203,8 +223,10 @@
}
else if (lambdaBodyType != LambdaBody.RETURN_ARG)
return false;
- if ( genericDeclKind == GenericDeclKind.GENERIC_NOBOUND || genericDeclKind == GenericDeclKind.GENERIC_BOUND ) {
- if ( parameterType == TypeKind.GENERIC && parameterKind == ParameterKind.IMPLICIT) //cyclic inference
+ if ( genericDeclKind == GenericDeclKind.GENERIC_NOBOUND ||
+ genericDeclKind == GenericDeclKind.GENERIC_BOUND ) {
+ if ( parameterType == TypeKind.GENERIC &&
+ parameterKind == ParameterKind.IMPLICIT) //cyclic inference
return false;
}
return true;
@@ -216,7 +238,8 @@
"}\n";
SourceFile samSourceFile = new SourceFile("Sam.java", templateStr) {
public String toString() {
- return template.replaceAll("#C", samKind.getSam(parameterType, returnType));
+ return template.replaceAll("#C",
+ samKind.getSam(parameterType, returnType));
}
};
@@ -225,22 +248,35 @@
" #Context\n" +
"}") {
public String toString() {
- return template.replaceAll("#Context", context.getContext(samKind, samTargetType, keyword, parameterType, returnType, lambdaKind, parameterKind, genericDeclKind, lambdaBodyType));
+ return template.replaceAll("#Context",
+ context.getContext(samKind, samTargetType, keyword,
+ parameterType, returnType, lambdaKind, parameterKind,
+ genericDeclKind, lambdaBodyType));
}
};
- void test() throws Exception {
- System.out.println("kk:");
+ public void run() {
+ outWriter.println("kk:");
StringBuilder sb = new StringBuilder("SamKind:");
- sb.append(samKind).append(" SamTargetType:").append(samTargetType).append(" ParameterType:").append(parameterType)
- .append(" ReturnType:").append(returnType).append(" Context:").append(context).append(" LambdaKind:").append(lambdaKind)
- .append(" LambdaBodyType:").append(lambdaBodyType).append(" ParameterKind:").append(parameterKind).append(" Keyword:").append(keyword);
- System.out.println(sb);
+ sb.append(samKind).append(" SamTargetType:")
+ .append(samTargetType).append(" ParameterType:").append(parameterType)
+ .append(" ReturnType:").append(returnType).append(" Context:")
+ .append(context).append(" LambdaKind:").append(lambdaKind)
+ .append(" LambdaBodyType:").append(lambdaBodyType)
+ .append(" ParameterKind:").append(parameterKind).append(" Keyword:")
+ .append(keyword);
+ outWriter.println(sb);
DiagnosticChecker dc = new DiagnosticChecker();
- JavacTask ct = (JavacTask)comp.getTask(null, fm, dc, null, null, Arrays.asList(samSourceFile, clientSourceFile));
- ct.analyze();
+ JavacTask ct = (JavacTask)comp.getTask(null, fm.get(), dc,
+ null, null, Arrays.asList(samSourceFile, clientSourceFile));
+ try {
+ ct.analyze();
+ } catch (Throwable t) {
+ processException(t);
+ }
if (dc.errorFound == checkTypeInference()) {
- throw new AssertionError(samSourceFile + "\n\n" + clientSourceFile + "\n" + parameterType + " " + returnType);
+ throw new AssertionError(samSourceFile + "\n\n" +
+ clientSourceFile + "\n" + parameterType + " " + returnType);
}
}
@@ -261,7 +297,8 @@
public abstract String toString();
}
- static class DiagnosticChecker implements javax.tools.DiagnosticListener<JavaFileObject> {
+ static class DiagnosticChecker
+ implements javax.tools.DiagnosticListener<JavaFileObject> {
boolean errorFound = false;
@@ -283,10 +320,9 @@
Keyword keyword;
GenericDeclKind genericDeclKind;
- static JavaCompiler comp = ToolProvider.getSystemJavaCompiler();
- static StandardJavaFileManager fm = comp.getStandardFileManager(null, null, null);
-
- TypeInferenceComboTest(SamKind sk, TypeKind samTargetT, TypeKind parameterT, TypeKind returnT, LambdaBody lb, Context c, LambdaKind lk, ParameterKind pk, Keyword kw, GenericDeclKind gdk) {
+ TypeInferenceComboTest(SamKind sk, TypeKind samTargetT, TypeKind parameterT,
+ TypeKind returnT, LambdaBody lb, Context c, LambdaKind lk,
+ ParameterKind pk, Keyword kw, GenericDeclKind gdk) {
samKind = sk;
samTargetType = samTargetT;
parameterType = parameterT;
@@ -308,24 +344,14 @@
for(LambdaKind lambdaK : LambdaKind.values()) {
for (SamKind sk : SamKind.values()) {
if (sk == SamKind.NON_GENERIC) {
- if(parameterT != TypeKind.GENERIC && returnT != TypeKind.GENERIC )
- new TypeInferenceComboTest(sk, null, parameterT, returnT, lb, ct, lambdaK, parameterK, null, null).test();
+ generateNonGenericSAM(ct, returnT,
+ parameterT, lb, parameterK,
+ lambdaK, sk);
}
else if (sk == SamKind.GENERIC) {
- for (Keyword kw : Keyword.values()) {
- for (TypeKind samTargetT : TypeKind.values()) {
- if(samTargetT != TypeKind.VOID && samTargetT != TypeKind.INT && samTargetT != TypeKind.GENERIC
- && (parameterT == TypeKind.GENERIC || returnT == TypeKind.GENERIC)) {
- if(ct != Context.METHOD_CALL) {
- new TypeInferenceComboTest(sk, samTargetT, parameterT, returnT, lb, ct, lambdaK, parameterK, kw, null).test();
- }
- else {//Context.METHOD_CALL
- for (GenericDeclKind gdk : GenericDeclKind.values())
- new TypeInferenceComboTest(sk, samTargetT, parameterT, returnT, lb, ct, lambdaK, parameterK, kw, gdk).test();
- }
- }
- }
- }
+ generateGenericSAM(ct, returnT,
+ parameterT, lb, parameterK,
+ lambdaK, sk);
}
}
}
@@ -334,5 +360,44 @@
}
}
}
+
+ checkAfterExec(false);
}
+
+ static void generateNonGenericSAM(Context ct, TypeKind returnT,
+ TypeKind parameterT, LambdaBody lb, ParameterKind parameterK,
+ LambdaKind lambdaK, SamKind sk) {
+ if(parameterT != TypeKind.GENERIC && returnT != TypeKind.GENERIC ) {
+ pool.execute(new TypeInferenceComboTest(sk, null, parameterT,
+ returnT, lb, ct, lambdaK, parameterK, null, null));
+ }
+ }
+
+ static void generateGenericSAM(Context ct, TypeKind returnT,
+ TypeKind parameterT, LambdaBody lb, ParameterKind parameterK,
+ LambdaKind lambdaK, SamKind sk) {
+ for (Keyword kw : Keyword.values()) {
+ for (TypeKind samTargetT : TypeKind.values()) {
+ if(samTargetT != TypeKind.VOID &&
+ samTargetT != TypeKind.INT &&
+ samTargetT != TypeKind.GENERIC &&
+ (parameterT == TypeKind.GENERIC ||
+ returnT == TypeKind.GENERIC)) {
+ if(ct != Context.METHOD_CALL) {
+ pool.execute(
+ new TypeInferenceComboTest(sk, samTargetT, parameterT,
+ returnT, lb, ct, lambdaK, parameterK, kw, null));
+ } else {//Context.METHOD_CALL
+ for (GenericDeclKind gdk :
+ GenericDeclKind.values())
+ pool.execute(
+ new TypeInferenceComboTest(sk, samTargetT,
+ parameterT, returnT, lb, ct, lambdaK,
+ parameterK, kw, gdk));
+ }
+ }
+ }
+ }
+ }
+
}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/langtools/test/tools/javac/lib/JavacTestingAbstractThreadedTest.java Tue Jan 08 13:47:57 2013 +0000
@@ -0,0 +1,142 @@
+/*
+ * Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+import java.io.PrintWriter;
+import java.io.StringWriter;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+import java.util.concurrent.ThreadFactory;
+import java.util.concurrent.atomic.AtomicInteger;
+import javax.tools.JavaCompiler;
+import javax.tools.StandardJavaFileManager;
+import javax.tools.ToolProvider;
+
+/**
+ * An abstract superclass for threaded tests.
+ *
+ * This class will try to read a property named test.concurrency.
+ * The property can be provided by passing this option to jtreg:
+ * -javaoption:-Dtest.concurrency=#
+ *
+ * If the property is not set the class will use a heuristic to determine the
+ * maximum number of threads that can be fired to execute a given test.
+ */
+public abstract class JavacTestingAbstractThreadedTest {
+
+ protected static int getThreadPoolSize() {
+ Integer testConc = Integer.getInteger("test.concurrency");
+ if (testConc != null) return testConc;
+ int cores = Runtime.getRuntime().availableProcessors();
+ return Math.max(2, Math.min(8, cores / 2));
+ }
+
+ protected static void checkAfterExec() throws InterruptedException {
+ checkAfterExec(true);
+ };
+
+ protected static boolean throwAssertionOnError = true;
+
+ protected static boolean printAll = false;
+
+ protected static StringWriter errSWriter = new StringWriter();
+ protected static PrintWriter errWriter = new PrintWriter(errSWriter);
+
+ protected static StringWriter outSWriter = new StringWriter();
+ protected static PrintWriter outWriter = new PrintWriter(outSWriter);
+
+ protected static void checkAfterExec(boolean printCheckCount)
+ throws InterruptedException {
+ pool.shutdown();
+ while (!pool.isTerminated()) {
+ Thread.sleep(10);
+ }
+ if (errCount.get() > 0) {
+ if (throwAssertionOnError) {
+ closePrinters();
+ System.err.println(errSWriter.toString());
+ throw new AssertionError(
+ String.format("%d errors found", errCount.get()));
+ } else {
+ System.err.println(
+ String.format("%d errors found", errCount.get()));
+ }
+ } else if (printCheckCount) {
+ outWriter.println("Total check executed: " + checkCount.get());
+ }
+ closePrinters();
+ if (printAll) {
+ System.out.println(errSWriter.toString());
+ System.out.println(outSWriter.toString());
+ }
+ }
+
+ protected static void closePrinters() {
+ errWriter.close();
+ outWriter.close();
+ }
+
+ protected static void processException(Throwable t) {
+ errCount.incrementAndGet();
+ t.printStackTrace(errWriter);
+ pool.shutdown();
+ }
+
+ //number of checks executed
+ protected static AtomicInteger checkCount = new AtomicInteger();
+
+ //number of errors found while running combo tests
+ protected static AtomicInteger errCount = new AtomicInteger();
+
+ //create default shared JavaCompiler - reused across multiple compilations
+ protected static JavaCompiler comp = ToolProvider.getSystemJavaCompiler();
+
+ protected static ExecutorService pool = Executors.newFixedThreadPool(
+ getThreadPoolSize(), new ThreadFactory() {
+ @Override
+ public Thread newThread(Runnable r) {
+ Thread t = new Thread(r);
+ t.setUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() {
+ @Override
+ public void uncaughtException(Thread t, Throwable e) {
+ pool.shutdown();
+ errCount.incrementAndGet();
+ e.printStackTrace(System.err);
+ }
+ });
+ return t;
+ }
+ });
+
+ /*
+ * File manager is not thread-safe so it cannot be re-used across multiple
+ * threads. However we cache per-thread FileManager to avoid excessive
+ * object creation
+ */
+ protected static final ThreadLocal<StandardJavaFileManager> fm =
+ new ThreadLocal<StandardJavaFileManager>() {
+ @Override protected StandardJavaFileManager initialValue() {
+ return comp.getStandardFileManager(null, null, null);
+ }
+ };
+
+}
--- a/langtools/test/tools/javac/multicatch/7030606/DisjunctiveTypeWellFormednessTest.java Tue Jan 08 10:17:29 2013 +0100
+++ b/langtools/test/tools/javac/multicatch/7030606/DisjunctiveTypeWellFormednessTest.java Tue Jan 08 13:47:57 2013 +0000
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2011, 2013, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@@ -25,19 +25,21 @@
* @test
* @bug 7030606
* @summary Project-coin: multi-catch types should be pairwise disjoint
+ * @library ../../lib
+ * @build JavacTestingAbstractThreadedTest
+ * @run main DisjunctiveTypeWellFormednessTest
*/
-import com.sun.source.util.JavacTask;
import java.net.URI;
import java.util.Arrays;
import javax.tools.Diagnostic;
-import javax.tools.JavaCompiler;
import javax.tools.JavaFileObject;
import javax.tools.SimpleJavaFileObject;
-import javax.tools.StandardJavaFileManager;
-import javax.tools.ToolProvider;
+import com.sun.source.util.JavacTask;
-public class DisjunctiveTypeWellFormednessTest {
+public class DisjunctiveTypeWellFormednessTest
+ extends JavacTestingAbstractThreadedTest
+ implements Runnable {
enum Alternative {
EXCEPTION("Exception"),
@@ -92,40 +94,37 @@
}
public static void main(String... args) throws Exception {
-
- //create default shared JavaCompiler - reused across multiple compilations
- JavaCompiler comp = ToolProvider.getSystemJavaCompiler();
- StandardJavaFileManager fm = comp.getStandardFileManager(null, null, null);
-
for (Arity arity : Arity.values()) {
for (Alternative a1 : Alternative.values()) {
if (arity == Arity.ONE) {
- new DisjunctiveTypeWellFormednessTest(a1).run(comp, fm);
+ pool.execute(new DisjunctiveTypeWellFormednessTest(a1));
continue;
}
for (Alternative a2 : Alternative.values()) {
if (arity == Arity.TWO) {
- new DisjunctiveTypeWellFormednessTest(a1, a2).run(comp, fm);
+ pool.execute(new DisjunctiveTypeWellFormednessTest(a1, a2));
continue;
}
for (Alternative a3 : Alternative.values()) {
if (arity == Arity.THREE) {
- new DisjunctiveTypeWellFormednessTest(a1, a2, a3).run(comp, fm);
+ pool.execute(new DisjunctiveTypeWellFormednessTest(a1, a2, a3));
continue;
}
for (Alternative a4 : Alternative.values()) {
if (arity == Arity.FOUR) {
- new DisjunctiveTypeWellFormednessTest(a1, a2, a3, a4).run(comp, fm);
+ pool.execute(new DisjunctiveTypeWellFormednessTest(a1, a2, a3, a4));
continue;
}
for (Alternative a5 : Alternative.values()) {
- new DisjunctiveTypeWellFormednessTest(a1, a2, a3, a4, a5).run(comp, fm);
+ pool.execute(new DisjunctiveTypeWellFormednessTest(a1, a2, a3, a4, a5));
}
}
}
}
}
}
+
+ checkAfterExec(false);
}
Alternative[] alternatives;
@@ -159,10 +158,16 @@
}
}
- void run(JavaCompiler tool, StandardJavaFileManager fm) throws Exception {
- JavacTask ct = (JavacTask)tool.getTask(null, fm, diagChecker,
+ @Override
+ public void run() {
+ JavacTask ct = (JavacTask)comp.getTask(null, fm.get(), diagChecker,
null, null, Arrays.asList(source));
- ct.analyze();
+ try {
+ ct.analyze();
+ } catch (Throwable t) {
+ processException(t);
+ return;
+ }
check();
}
@@ -202,4 +207,5 @@
}
}
}
+
}
--- a/langtools/test/tools/javac/varargs/7042566/T7042566.java Tue Jan 08 10:17:29 2013 +0100
+++ b/langtools/test/tools/javac/varargs/7042566/T7042566.java Tue Jan 08 13:47:57 2013 +0000
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2011, 2013, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@@ -25,8 +25,22 @@
* @test
* @bug 7042566
* @summary Unambiguous varargs method calls flagged as ambiguous
+ * @library ../../lib
+ * @build JavacTestingAbstractThreadedTest
+ * @run main T7042566
*/
+import java.io.File;
+import java.net.URI;
+import java.util.Arrays;
+import java.util.Locale;
+import java.util.concurrent.atomic.AtomicInteger;
+import javax.tools.Diagnostic;
+import javax.tools.JavaCompiler;
+import javax.tools.JavaFileObject;
+import javax.tools.SimpleJavaFileObject;
+import javax.tools.ToolProvider;
+
import com.sun.source.util.JavacTask;
import com.sun.tools.classfile.Instruction;
import com.sun.tools.classfile.Attribute;
@@ -34,44 +48,36 @@
import com.sun.tools.classfile.Code_attribute;
import com.sun.tools.classfile.ConstantPool.*;
import com.sun.tools.classfile.Method;
-import com.sun.tools.javac.api.JavacTool;
import com.sun.tools.javac.util.List;
-import java.io.File;
-import java.net.URI;
-import java.util.Arrays;
-import java.util.Locale;
-import javax.tools.Diagnostic;
-import javax.tools.JavaCompiler;
-import javax.tools.JavaFileObject;
-import javax.tools.SimpleJavaFileObject;
-import javax.tools.StandardJavaFileManager;
-import javax.tools.ToolProvider;
-
-public class T7042566 {
+public class T7042566
+ extends JavacTestingAbstractThreadedTest
+ implements Runnable {
VarargsMethod m1;
VarargsMethod m2;
TypeConfiguration actuals;
- T7042566(TypeConfiguration m1_conf, TypeConfiguration m2_conf, TypeConfiguration actuals) {
+ T7042566(TypeConfiguration m1_conf, TypeConfiguration m2_conf,
+ TypeConfiguration actuals) {
this.m1 = new VarargsMethod(m1_conf);
this.m2 = new VarargsMethod(m2_conf);
this.actuals = actuals;
}
- void compileAndCheck() throws Exception {
+ @Override
+ public void run() {
+ int id = checkCount.incrementAndGet();
final JavaCompiler tool = ToolProvider.getSystemJavaCompiler();
- JavaSource source = new JavaSource();
+ JavaSource source = new JavaSource(id);
ErrorChecker ec = new ErrorChecker();
- JavacTask ct = (JavacTask)tool.getTask(null, fm, ec,
+ JavacTask ct = (JavacTask)tool.getTask(null, fm.get(), ec,
null, null, Arrays.asList(source));
ct.call();
- check(source, ec);
+ check(source, ec, id);
}
- void check(JavaSource source, ErrorChecker ec) {
- checkCount++;
+ void check(JavaSource source, ErrorChecker ec, int id) {
boolean resolutionError = false;
VarargsMethod selectedMethod = null;
@@ -99,13 +105,13 @@
"\nFound error: " + ec.errorFound +
"\nCompiler diagnostics:\n" + ec.printDiags());
} else if (!resolutionError) {
- verifyBytecode(selectedMethod, source);
+ verifyBytecode(selectedMethod, source, id);
}
}
- void verifyBytecode(VarargsMethod selected, JavaSource source) {
- bytecodeCheckCount++;
- File compiledTest = new File("Test.class");
+ void verifyBytecode(VarargsMethod selected, JavaSource source, int id) {
+ bytecodeCheckCount.incrementAndGet();
+ File compiledTest = new File(String.format("Test%d.class", id));
try {
ClassFile cf = ClassFile.read(compiledTest);
Method testMethod = null;
@@ -118,7 +124,8 @@
if (testMethod == null) {
throw new Error("Test method not found");
}
- Code_attribute ea = (Code_attribute)testMethod.attributes.get(Attribute.Code);
+ Code_attribute ea =
+ (Code_attribute)testMethod.attributes.get(Attribute.Code);
if (testMethod == null) {
throw new Error("Code attribute for test() method not found");
}
@@ -127,11 +134,12 @@
if (i.getMnemonic().equals("invokevirtual")) {
int cp_entry = i.getUnsignedShort(1);
CONSTANT_Methodref_info methRef =
- (CONSTANT_Methodref_info)cf.constant_pool.get(cp_entry);
+ (CONSTANT_Methodref_info)cf.constant_pool.get(cp_entry);
String type = methRef.getNameAndTypeInfo().getType();
String sig = selected.parameterTypes.bytecodeSigStr;
if (!type.contains(sig)) {
- throw new Error("Unexpected type method call: " + type + "" +
+ throw new Error("Unexpected type method call: " +
+ type + "" +
"\nfound: " + sig +
"\n" + source.getCharContent(true));
}
@@ -146,7 +154,7 @@
class JavaSource extends SimpleJavaFileObject {
- static final String source_template = "class Test {\n" +
+ static final String source_template = "class Test#ID {\n" +
" #V1\n" +
" #V2\n" +
" void test() { m(#E); }\n" +
@@ -154,11 +162,13 @@
String source;
- public JavaSource() {
- super(URI.create("myfo:/Test.java"), JavaFileObject.Kind.SOURCE);
- source = source_template.replaceAll("#V1", m1.toString()).
- replaceAll("#V2", m2.toString()).
- replaceAll("#E", actuals.expressionListStr);
+ public JavaSource(int id) {
+ super(URI.create(String.format("myfo:/Test%d.java", id)),
+ JavaFileObject.Kind.SOURCE);
+ source = source_template.replaceAll("#V1", m1.toString())
+ .replaceAll("#V2", m2.toString())
+ .replaceAll("#E", actuals.expressionListStr)
+ .replaceAll("#ID", String.valueOf(id));
}
@Override
@@ -167,26 +177,17 @@
}
}
- /** global decls ***/
-
- // Create a single file manager and reuse it for each compile to save time.
- static StandardJavaFileManager fm = JavacTool.create().getStandardFileManager(null, null, null);
-
- //statistics
- static int checkCount = 0;
- static int bytecodeCheckCount = 0;
-
public static void main(String... args) throws Exception {
for (TypeConfiguration tconf1 : TypeConfiguration.values()) {
for (TypeConfiguration tconf2 : TypeConfiguration.values()) {
for (TypeConfiguration tconf3 : TypeConfiguration.values()) {
- new T7042566(tconf1, tconf2, tconf3).compileAndCheck();
+ pool.execute(new T7042566(tconf1, tconf2, tconf3));
}
}
}
- System.out.println("Total checks made: " + checkCount);
- System.out.println("Bytecode checks made: " + bytecodeCheckCount);
+ outWriter.println("Bytecode checks made: " + bytecodeCheckCount.get());
+ checkAfterExec();
}
enum TypeKind {
@@ -326,14 +327,16 @@
}
}
- static class ErrorChecker implements javax.tools.DiagnosticListener<JavaFileObject> {
+ static class ErrorChecker
+ implements javax.tools.DiagnosticListener<JavaFileObject> {
boolean errorFound;
List<String> errDiags = List.nil();
public void report(Diagnostic<? extends JavaFileObject> diagnostic) {
if (diagnostic.getKind() == Diagnostic.Kind.ERROR) {
- errDiags = errDiags.append(diagnostic.getMessage(Locale.getDefault()));
+ errDiags = errDiags
+ .append(diagnostic.getMessage(Locale.getDefault()));
errorFound = true;
}
}
@@ -347,4 +350,8 @@
return buf.toString();
}
}
+
+ //number of bytecode checks made while running combo tests
+ static AtomicInteger bytecodeCheckCount = new AtomicInteger();
+
}
--- a/langtools/test/tools/javac/varargs/warning/Warn4.java Tue Jan 08 10:17:29 2013 +0100
+++ b/langtools/test/tools/javac/varargs/warning/Warn4.java Tue Jan 08 13:47:57 2013 +0000
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2010, 2011, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@@ -26,10 +26,11 @@
* @bug 6945418 6993978
* @summary Project Coin: Simplified Varargs Method Invocation
* @author mcimadamore
+ * @library ../../lib
+ * @build JavacTestingAbstractThreadedTest
* @run main Warn4
*/
-import com.sun.source.util.JavacTask;
-import com.sun.tools.javac.api.JavacTool;
+
import java.net.URI;
import java.util.Arrays;
import java.util.Set;
@@ -38,16 +39,19 @@
import javax.tools.JavaCompiler;
import javax.tools.JavaFileObject;
import javax.tools.SimpleJavaFileObject;
-import javax.tools.StandardJavaFileManager;
import javax.tools.ToolProvider;
+import com.sun.source.util.JavacTask;
-public class Warn4 {
+public class Warn4
+ extends JavacTestingAbstractThreadedTest
+ implements Runnable {
final static Warning[] error = null;
final static Warning[] none = new Warning[] {};
final static Warning[] vararg = new Warning[] { Warning.VARARGS };
final static Warning[] unchecked = new Warning[] { Warning.UNCHECKED };
- final static Warning[] both = new Warning[] { Warning.VARARGS, Warning.UNCHECKED };
+ final static Warning[] both =
+ new Warning[] { Warning.VARARGS, Warning.UNCHECKED };
enum Warning {
UNCHECKED("generic.array.creation"),
@@ -59,8 +63,10 @@
this.key = key;
}
- boolean isSuppressed(TrustMe trustMe, SourceLevel source, SuppressLevel suppressLevelClient,
- SuppressLevel suppressLevelDecl, ModifierKind modKind) {
+ boolean isSuppressed(TrustMe trustMe, SourceLevel source,
+ SuppressLevel suppressLevelClient,
+ SuppressLevel suppressLevelDecl,
+ ModifierKind modKind) {
switch(this) {
case VARARGS:
return source == SourceLevel.JDK_6 ||
@@ -68,7 +74,8 @@
trustMe == TrustMe.TRUST;
case UNCHECKED:
return suppressLevelClient == SuppressLevel.UNCHECKED ||
- (trustMe == TrustMe.TRUST && modKind != ModifierKind.NONE && source == SourceLevel.JDK_7);
+ (trustMe == TrustMe.TRUST && modKind !=
+ ModifierKind.NONE && source == SourceLevel.JDK_7);
}
SuppressLevel supLev = this == VARARGS ?
@@ -172,13 +179,13 @@
for (Signature vararg_meth : Signature.values()) {
for (Signature client_meth : Signature.values()) {
if (vararg_meth.isApplicableTo(client_meth)) {
- test(sourceLevel,
+ pool.execute(new Warn4(sourceLevel,
trustMe,
suppressLevelClient,
suppressLevelDecl,
modKind,
vararg_meth,
- client_meth);
+ client_meth));
}
}
}
@@ -187,63 +194,82 @@
}
}
}
+
+ checkAfterExec();
}
- // Create a single file manager and reuse it for each compile to save time.
- static StandardJavaFileManager fm = JavacTool.create().getStandardFileManager(null, null, null);
+ SourceLevel sourceLevel;
+ TrustMe trustMe;
+ SuppressLevel suppressLevelClient;
+ SuppressLevel suppressLevelDecl;
+ ModifierKind modKind;
+ Signature vararg_meth;
+ Signature client_meth;
+ DiagnosticChecker diagChecker;
- static void test(SourceLevel sourceLevel, TrustMe trustMe, SuppressLevel suppressLevelClient,
- SuppressLevel suppressLevelDecl, ModifierKind modKind, Signature vararg_meth, Signature client_meth) throws Exception {
+ public Warn4(SourceLevel sourceLevel, TrustMe trustMe,
+ SuppressLevel suppressLevelClient, SuppressLevel suppressLevelDecl,
+ ModifierKind modKind, Signature vararg_meth, Signature client_meth) {
+ this.sourceLevel = sourceLevel;
+ this.trustMe = trustMe;
+ this.suppressLevelClient = suppressLevelClient;
+ this.suppressLevelDecl = suppressLevelDecl;
+ this.modKind = modKind;
+ this.vararg_meth = vararg_meth;
+ this.client_meth = client_meth;
+ this.diagChecker = new DiagnosticChecker();
+ }
+
+ @Override
+ public void run() {
+ int id = checkCount.incrementAndGet();
final JavaCompiler tool = ToolProvider.getSystemJavaCompiler();
- JavaSource source = new JavaSource(trustMe, suppressLevelClient, suppressLevelDecl, modKind, vararg_meth, client_meth);
- DiagnosticChecker dc = new DiagnosticChecker();
- JavacTask ct = (JavacTask)tool.getTask(null, fm, dc,
+ JavaSource source = new JavaSource(id);
+ JavacTask ct = (JavacTask)tool.getTask(null, fm.get(), diagChecker,
Arrays.asList("-Xlint:unchecked", "-source", sourceLevel.sourceKey),
null, Arrays.asList(source));
- ct.generate(); //to get mandatory notes
- check(dc.warnings, sourceLevel,
- new boolean[] {vararg_meth.giveUnchecked(client_meth),
- vararg_meth.giveVarargs(client_meth)},
- source, trustMe, suppressLevelClient, suppressLevelDecl, modKind);
+ ct.call(); //to get mandatory notes
+ check(source, new boolean[] {vararg_meth.giveUnchecked(client_meth),
+ vararg_meth.giveVarargs(client_meth)});
}
- static void check(Set<Warning> warnings, SourceLevel sourceLevel, boolean[] warnArr, JavaSource source,
- TrustMe trustMe, SuppressLevel suppressLevelClient, SuppressLevel suppressLevelDecl, ModifierKind modKind) {
+ void check(JavaSource source, boolean[] warnArr) {
boolean badOutput = false;
for (Warning wkind : Warning.values()) {
boolean isSuppressed = wkind.isSuppressed(trustMe, sourceLevel,
suppressLevelClient, suppressLevelDecl, modKind);
System.out.println("SUPPRESSED = " + isSuppressed);
- badOutput |= (warnArr[wkind.ordinal()] && !isSuppressed) != warnings.contains(wkind);
+ badOutput |= (warnArr[wkind.ordinal()] && !isSuppressed) !=
+ diagChecker.warnings.contains(wkind);
}
if (badOutput) {
throw new Error("invalid diagnostics for source:\n" +
source.getCharContent(true) +
"\nExpected unchecked warning: " + warnArr[0] +
"\nExpected unsafe vararg warning: " + warnArr[1] +
- "\nWarnings: " + warnings +
+ "\nWarnings: " + diagChecker.warnings +
"\nSource level: " + sourceLevel);
}
}
- static class JavaSource extends SimpleJavaFileObject {
+ class JavaSource extends SimpleJavaFileObject {
String source;
- public JavaSource(TrustMe trustMe, SuppressLevel suppressLevelClient, SuppressLevel suppressLevelDecl,
- ModifierKind modKind, Signature vararg_meth, Signature client_meth) {
- super(URI.create("myfo:/Test.java"), JavaFileObject.Kind.SOURCE);
+ public JavaSource(int id) {
+ super(URI.create(String.format("myfo:/Test%d.java", id)),
+ JavaFileObject.Kind.SOURCE);
String meth1 = vararg_meth.template.replace("#arity", "...");
meth1 = meth1.replace("#name", "m");
meth1 = meth1.replace("#body", "");
- meth1 = trustMe.anno + "\n" + suppressLevelDecl.getSuppressAnno() + modKind.mod + meth1;
+ meth1 = trustMe.anno + "\n" + suppressLevelDecl.getSuppressAnno() +
+ modKind.mod + meth1;
String meth2 = client_meth.template.replace("#arity", "");
meth2 = meth2.replace("#name", "test");
meth2 = meth2.replace("#body", "m(arg);");
meth2 = suppressLevelClient.getSuppressAnno() + meth2;
- source = "import java.util.List;\n" +
- "class Test {\n" + meth1 +
- "\n" + meth2 + "\n}\n";
+ source = String.format("import java.util.List;\n" +
+ "class Test%s {\n %s \n %s \n } \n", id, meth1, meth2);
}
@Override
@@ -252,7 +278,8 @@
}
}
- static class DiagnosticChecker implements javax.tools.DiagnosticListener<JavaFileObject> {
+ static class DiagnosticChecker
+ implements javax.tools.DiagnosticListener<JavaFileObject> {
Set<Warning> warnings = new HashSet<>();
@@ -267,4 +294,5 @@
}
}
}
+
}
--- a/langtools/test/tools/javac/varargs/warning/Warn5.java Tue Jan 08 10:17:29 2013 +0100
+++ b/langtools/test/tools/javac/varargs/warning/Warn5.java Tue Jan 08 13:47:57 2013 +0000
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2010, 2011, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@@ -26,10 +26,10 @@
* @bug 6993978 7097436
* @summary Project Coin: Annotation to reduce varargs warnings
* @author mcimadamore
+ * @library ../../lib
+ * @build JavacTestingAbstractThreadedTest
* @run main Warn5
*/
-import com.sun.source.util.JavacTask;
-import com.sun.tools.javac.api.JavacTool;
import java.net.URI;
import java.util.Arrays;
import java.util.EnumSet;
@@ -37,10 +37,12 @@
import javax.tools.JavaCompiler;
import javax.tools.JavaFileObject;
import javax.tools.SimpleJavaFileObject;
-import javax.tools.StandardJavaFileManager;
import javax.tools.ToolProvider;
+import com.sun.source.util.JavacTask;
-public class Warn5 {
+public class Warn5
+ extends JavacTestingAbstractThreadedTest
+ implements Runnable {
enum XlintOption {
NONE("none"),
@@ -161,9 +163,6 @@
REDUNDANT_SAFEVARARGS;
}
- // Create a single file manager and reuse it for each compile to save time.
- static StandardJavaFileManager fm = JavacTool.create().getStandardFileManager(null, null, null);
-
public static void main(String... args) throws Exception {
for (SourceLevel sourceLevel : SourceLevel.values()) {
for (XlintOption xlint : XlintOption.values()) {
@@ -173,14 +172,9 @@
for (MethodKind methKind : MethodKind.values()) {
for (SignatureKind sig : SignatureKind.values()) {
for (BodyKind body : BodyKind.values()) {
- new Warn5(sourceLevel,
- xlint,
- trustMe,
- suppressLevel,
- modKind,
- methKind,
- sig,
- body).test();
+ pool.execute(new Warn5(sourceLevel,
+ xlint, trustMe, suppressLevel,
+ modKind, methKind, sig, body));
}
}
}
@@ -189,6 +183,8 @@
}
}
}
+
+ checkAfterExec(false);
}
final SourceLevel sourceLevel;
@@ -202,7 +198,9 @@
final JavaSource source;
final DiagnosticChecker dc;
- public Warn5(SourceLevel sourceLevel, XlintOption xlint, TrustMe trustMe, SuppressLevel suppressLevel, ModifierKind modKind, MethodKind methKind, SignatureKind sig, BodyKind body) {
+ public Warn5(SourceLevel sourceLevel, XlintOption xlint, TrustMe trustMe,
+ SuppressLevel suppressLevel, ModifierKind modKind,
+ MethodKind methKind, SignatureKind sig, BodyKind body) {
this.sourceLevel = sourceLevel;
this.xlint = xlint;
this.trustMe = trustMe;
@@ -215,24 +213,36 @@
this.dc = new DiagnosticChecker();
}
- void test() throws Exception {
+ @Override
+ public void run() {
final JavaCompiler tool = ToolProvider.getSystemJavaCompiler();
- JavacTask ct = (JavacTask)tool.getTask(null, fm, dc,
- Arrays.asList(xlint.getXlintOption(), "-source", sourceLevel.sourceKey), null, Arrays.asList(source));
- ct.analyze();
+ JavacTask ct = (JavacTask)tool.getTask(null, fm.get(), dc,
+ Arrays.asList(xlint.getXlintOption(),
+ "-source", sourceLevel.sourceKey),
+ null, Arrays.asList(source));
+ try {
+ ct.analyze();
+ } catch (Throwable t) {
+ processException(t);
+ }
check();
}
void check() {
- EnumSet<WarningKind> expectedWarnings = EnumSet.noneOf(WarningKind.class);
+ EnumSet<WarningKind> expectedWarnings =
+ EnumSet.noneOf(WarningKind.class);
if (sourceLevel == SourceLevel.JDK_7 &&
trustMe == TrustMe.TRUST &&
suppressLevel != SuppressLevel.VARARGS &&
xlint != XlintOption.NONE &&
- sig.isVarargs && !sig.isReifiableArg && body.hasAliasing &&
- (methKind == MethodKind.CONSTRUCTOR || (methKind == MethodKind.METHOD && modKind != ModifierKind.NONE))) {
+ sig.isVarargs &&
+ !sig.isReifiableArg &&
+ body.hasAliasing &&
+ (methKind == MethodKind.CONSTRUCTOR ||
+ (methKind == MethodKind.METHOD &&
+ modKind != ModifierKind.NONE))) {
expectedWarnings.add(WarningKind.UNSAFE_BODY);
}
@@ -247,7 +257,8 @@
if (sourceLevel == SourceLevel.JDK_7 &&
trustMe == TrustMe.TRUST &&
(!sig.isVarargs ||
- (modKind == ModifierKind.NONE && methKind == MethodKind.METHOD))) {
+ (modKind == ModifierKind.NONE &&
+ methKind == MethodKind.METHOD))) {
expectedWarnings.add(WarningKind.MALFORMED_SAFEVARARGS);
}
@@ -255,7 +266,8 @@
trustMe == TrustMe.TRUST &&
xlint != XlintOption.NONE &&
suppressLevel != SuppressLevel.VARARGS &&
- (modKind != ModifierKind.NONE || methKind == MethodKind.CONSTRUCTOR) &&
+ (modKind != ModifierKind.NONE ||
+ methKind == MethodKind.CONSTRUCTOR) &&
sig.isVarargs &&
sig.isReifiableArg) {
expectedWarnings.add(WarningKind.REDUNDANT_SAFEVARARGS);
@@ -297,19 +309,23 @@
}
}
- class DiagnosticChecker implements javax.tools.DiagnosticListener<JavaFileObject> {
+ class DiagnosticChecker
+ implements javax.tools.DiagnosticListener<JavaFileObject> {
EnumSet<WarningKind> warnings = EnumSet.noneOf(WarningKind.class);
public void report(Diagnostic<? extends JavaFileObject> diagnostic) {
if (diagnostic.getKind() == Diagnostic.Kind.WARNING) {
- if (diagnostic.getCode().contains("unsafe.use.varargs.param")) {
+ if (diagnostic.getCode().
+ contains("unsafe.use.varargs.param")) {
setWarning(WarningKind.UNSAFE_BODY);
- } else if (diagnostic.getCode().contains("redundant.trustme")) {
+ } else if (diagnostic.getCode().
+ contains("redundant.trustme")) {
setWarning(WarningKind.REDUNDANT_SAFEVARARGS);
}
} else if (diagnostic.getKind() == Diagnostic.Kind.MANDATORY_WARNING &&
- diagnostic.getCode().contains("varargs.non.reifiable.type")) {
+ diagnostic.getCode().
+ contains("varargs.non.reifiable.type")) {
setWarning(WarningKind.UNSAFE_DECL);
} else if (diagnostic.getKind() == Diagnostic.Kind.ERROR &&
diagnostic.getCode().contains("invalid.trustme")) {
@@ -319,7 +335,8 @@
void setWarning(WarningKind wk) {
if (!warnings.add(wk)) {
- throw new AssertionError("Duplicate warning of kind " + wk + " in source:\n" + source);
+ throw new AssertionError("Duplicate warning of kind " +
+ wk + " in source:\n" + source);
}
}
@@ -327,4 +344,5 @@
return warnings.contains(wk);
}
}
+
}