7018753: tools/javac/varargs/warning/Warn5.java times out on slow machines

Use a single file manager for all JavacTasks

Reviewed-by: jjg, mcimadamore
This commit is contained in:
Jim Holmlund 2011-02-24 08:40:49 -08:00
parent b6bfe0166b
commit 6d172a6a63
3 changed files with 18 additions and 3 deletions

View File

@ -37,6 +37,7 @@ import com.sun.tools.classfile.ClassFile;
import com.sun.tools.classfile.Code_attribute; import com.sun.tools.classfile.Code_attribute;
import com.sun.tools.classfile.ConstantPool.*; import com.sun.tools.classfile.ConstantPool.*;
import com.sun.tools.classfile.Method; import com.sun.tools.classfile.Method;
import com.sun.tools.javac.api.JavacTool;
import com.sun.tools.javac.util.List; import com.sun.tools.javac.util.List;
import java.io.File; import java.io.File;
@ -47,6 +48,7 @@ import javax.tools.Diagnostic;
import javax.tools.JavaCompiler; import javax.tools.JavaCompiler;
import javax.tools.JavaFileObject; import javax.tools.JavaFileObject;
import javax.tools.SimpleJavaFileObject; import javax.tools.SimpleJavaFileObject;
import javax.tools.StandardJavaFileManager;
import javax.tools.ToolProvider; import javax.tools.ToolProvider;
public class T6199075 { public class T6199075 {
@ -157,11 +159,14 @@ public class T6199075 {
System.out.println("Bytecode checks made: " + bytecodeCheckCount); System.out.println("Bytecode checks made: " + bytecodeCheckCount);
} }
// Create a single file manager and reuse it for each compile to save time.
StandardJavaFileManager fm = JavacTool.create().getStandardFileManager(null, null, null);
void compileAndCheck(VarargsMethod m1, VarargsMethod m2, TypeKind actual, ArgumentsArity argsArity) throws Exception { void compileAndCheck(VarargsMethod m1, VarargsMethod m2, TypeKind actual, ArgumentsArity argsArity) throws Exception {
final JavaCompiler tool = ToolProvider.getSystemJavaCompiler(); final JavaCompiler tool = ToolProvider.getSystemJavaCompiler();
JavaSource source = new JavaSource(m1, m2, actual, argsArity); JavaSource source = new JavaSource(m1, m2, actual, argsArity);
ErrorChecker ec = new ErrorChecker(); ErrorChecker ec = new ErrorChecker();
JavacTask ct = (JavacTask)tool.getTask(null, null, ec, JavacTask ct = (JavacTask)tool.getTask(null, fm, ec,
null, null, Arrays.asList(source)); null, null, Arrays.asList(source));
ct.generate(); ct.generate();
check(source, ec, m1, m2, actual, argsArity); check(source, ec, m1, m2, actual, argsArity);

View File

@ -29,6 +29,7 @@
* @run main Warn4 * @run main Warn4
*/ */
import com.sun.source.util.JavacTask; import com.sun.source.util.JavacTask;
import com.sun.tools.javac.api.JavacTool;
import java.net.URI; import java.net.URI;
import java.util.Arrays; import java.util.Arrays;
import java.util.Set; import java.util.Set;
@ -37,6 +38,7 @@ import javax.tools.Diagnostic;
import javax.tools.JavaCompiler; import javax.tools.JavaCompiler;
import javax.tools.JavaFileObject; import javax.tools.JavaFileObject;
import javax.tools.SimpleJavaFileObject; import javax.tools.SimpleJavaFileObject;
import javax.tools.StandardJavaFileManager;
import javax.tools.ToolProvider; import javax.tools.ToolProvider;
public class Warn4 { public class Warn4 {
@ -187,12 +189,15 @@ public class Warn4 {
} }
} }
// Create a single file manager and reuse it for each compile to save time.
static StandardJavaFileManager fm = JavacTool.create().getStandardFileManager(null, null, null);
static void test(SourceLevel sourceLevel, TrustMe trustMe, SuppressLevel suppressLevelClient, static void test(SourceLevel sourceLevel, TrustMe trustMe, SuppressLevel suppressLevelClient,
SuppressLevel suppressLevelDecl, ModifierKind modKind, Signature vararg_meth, Signature client_meth) throws Exception { SuppressLevel suppressLevelDecl, ModifierKind modKind, Signature vararg_meth, Signature client_meth) throws Exception {
final JavaCompiler tool = ToolProvider.getSystemJavaCompiler(); final JavaCompiler tool = ToolProvider.getSystemJavaCompiler();
JavaSource source = new JavaSource(trustMe, suppressLevelClient, suppressLevelDecl, modKind, vararg_meth, client_meth); JavaSource source = new JavaSource(trustMe, suppressLevelClient, suppressLevelDecl, modKind, vararg_meth, client_meth);
DiagnosticChecker dc = new DiagnosticChecker(); DiagnosticChecker dc = new DiagnosticChecker();
JavacTask ct = (JavacTask)tool.getTask(null, null, dc, JavacTask ct = (JavacTask)tool.getTask(null, fm, dc,
Arrays.asList("-Xlint:unchecked", "-source", sourceLevel.sourceKey), Arrays.asList("-Xlint:unchecked", "-source", sourceLevel.sourceKey),
null, Arrays.asList(source)); null, Arrays.asList(source));
ct.generate(); //to get mandatory notes ct.generate(); //to get mandatory notes

View File

@ -29,6 +29,7 @@
* @run main Warn5 * @run main Warn5
*/ */
import com.sun.source.util.JavacTask; import com.sun.source.util.JavacTask;
import com.sun.tools.javac.api.JavacTool;
import java.net.URI; import java.net.URI;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
@ -36,6 +37,7 @@ import javax.tools.Diagnostic;
import javax.tools.JavaCompiler; import javax.tools.JavaCompiler;
import javax.tools.JavaFileObject; import javax.tools.JavaFileObject;
import javax.tools.SimpleJavaFileObject; import javax.tools.SimpleJavaFileObject;
import javax.tools.StandardJavaFileManager;
import javax.tools.ToolProvider; import javax.tools.ToolProvider;
public class Warn5 { public class Warn5 {
@ -207,12 +209,15 @@ public class Warn5 {
} }
} }
// Create a single file manager and reuse it for each compile to save time.
static StandardJavaFileManager fm = JavacTool.create().getStandardFileManager(null, null, null);
static void test(SourceLevel sourceLevel, XlintOption xlint, TrustMe trustMe, SuppressLevel suppressLevel, static void test(SourceLevel sourceLevel, XlintOption xlint, TrustMe trustMe, SuppressLevel suppressLevel,
ModifierKind modKind, MethodKind methKind, SignatureKind sig, BodyKind body) throws Exception { ModifierKind modKind, MethodKind methKind, SignatureKind sig, BodyKind body) throws Exception {
final JavaCompiler tool = ToolProvider.getSystemJavaCompiler(); final JavaCompiler tool = ToolProvider.getSystemJavaCompiler();
JavaSource source = new JavaSource(trustMe, suppressLevel, modKind, methKind, sig, body); JavaSource source = new JavaSource(trustMe, suppressLevel, modKind, methKind, sig, body);
DiagnosticChecker dc = new DiagnosticChecker(); DiagnosticChecker dc = new DiagnosticChecker();
JavacTask ct = (JavacTask)tool.getTask(null, null, dc, JavacTask ct = (JavacTask)tool.getTask(null, fm, dc,
Arrays.asList(xlint.getXlintOption(), "-source", sourceLevel.sourceKey), null, Arrays.asList(source)); Arrays.asList(xlint.getXlintOption(), "-source", sourceLevel.sourceKey), null, Arrays.asList(source));
ct.analyze(); ct.analyze();
check(sourceLevel, dc, source, xlint, trustMe, check(sourceLevel, dc, source, xlint, trustMe,