# HG changeset patch # User Lukas Stadler # Date 1401984953 -7200 # Node ID f546f40e1a6d0b79c9fa6bbd8453a14707c86b33 # Parent f0efdd54109401a8b422f14b3207aa3cd9a38c18 use thread pool for CheckGraalInvariants diff -r f0efdd541094 -r f546f40e1a6d graal/com.oracle.graal.compiler.test/src/com/oracle/graal/compiler/test/CheckGraalInvariants.java --- a/graal/com.oracle.graal.compiler.test/src/com/oracle/graal/compiler/test/CheckGraalInvariants.java Thu Jun 05 18:14:14 2014 +0200 +++ b/graal/com.oracle.graal.compiler.test/src/com/oracle/graal/compiler/test/CheckGraalInvariants.java Thu Jun 05 18:15:53 2014 +0200 @@ -27,6 +27,7 @@ import java.io.*; import java.lang.reflect.*; import java.util.*; +import java.util.concurrent.*; import java.util.zip.*; import org.junit.*; @@ -34,6 +35,8 @@ import com.oracle.graal.api.code.*; import com.oracle.graal.api.meta.*; import com.oracle.graal.api.runtime.*; +import com.oracle.graal.compiler.*; +import com.oracle.graal.compiler.CompilerThreadFactory.DebugConfigAccess; import com.oracle.graal.debug.*; import com.oracle.graal.java.*; import com.oracle.graal.nodes.*; @@ -42,6 +45,7 @@ import com.oracle.graal.phases.tiers.*; import com.oracle.graal.phases.util.*; import com.oracle.graal.phases.verify.*; +import com.oracle.graal.printer.*; import com.oracle.graal.runtime.*; import com.oracle.graal.test.*; @@ -97,7 +101,15 @@ String property = System.getProperty(CheckGraalInvariants.class.getName() + ".filters"); String[] filters = property == null ? null : property.split(","); - List errors = new ArrayList<>(); + CompilerThreadFactory factory = new CompilerThreadFactory("CheckInvariantsThread", new DebugConfigAccess() { + public GraalDebugConfig getDebugConfig() { + return DebugEnvironment.initialize(System.out); + } + }); + int availableProcessors = Runtime.getRuntime().availableProcessors(); + ThreadPoolExecutor executor = new ThreadPoolExecutor(availableProcessors, availableProcessors, 0L, TimeUnit.MILLISECONDS, new LinkedBlockingQueue(), factory); + + List errors = Collections.synchronizedList(new ArrayList<>()); for (String className : classNames) { try { Class c = Class.forName(className, false, CheckGraalInvariants.class.getClassLoader()); @@ -107,22 +119,24 @@ } else { String methodName = className + "." + m.getName(); if (matches(filters, methodName)) { - StructuredGraph graph = new StructuredGraph(metaAccess.lookupJavaMethod(m)); - try (DebugConfigScope s = Debug.setConfig(new DelegatingDebugConfig().disable(INTERCEPT))) { - graphBuilderSuite.apply(graph, context); - checkGraph(context, graph); - } catch (VerificationError e) { - errors.add(e.getMessage()); - } catch (LinkageError e) { - // suppress linkages errors resulting from eager resolution - } catch (BailoutException e) { - // Graal bail outs on certain patterns in Java bytecode (e.g., - // unbalanced monitors introduced by jacoco). - } catch (Throwable e) { - StringWriter sw = new StringWriter(); - e.printStackTrace(new PrintWriter(sw)); - errors.add(String.format("Error while checking %s:%n%s", methodName, sw)); - } + executor.execute(() -> { + StructuredGraph graph = new StructuredGraph(metaAccess.lookupJavaMethod(m)); + try (DebugConfigScope s = Debug.setConfig(new DelegatingDebugConfig().disable(INTERCEPT))) { + graphBuilderSuite.apply(graph, context); + checkGraph(context, graph); + } catch (VerificationError e) { + errors.add(e.getMessage()); + } catch (LinkageError e) { + // suppress linkages errors resulting from eager resolution + } catch (BailoutException e) { + // Graal bail outs on certain patterns in Java bytecode (e.g., + // unbalanced monitors introduced by jacoco). + } catch (Throwable e) { + StringWriter sw = new StringWriter(); + e.printStackTrace(new PrintWriter(sw)); + errors.add(String.format("Error while checking %s:%n%s", methodName, sw)); + } + }); } } } @@ -131,6 +145,13 @@ e.printStackTrace(); } } + executor.shutdown(); + try { + executor.awaitTermination(1, TimeUnit.HOURS); + } catch (InterruptedException e1) { + throw new RuntimeException(e1); + } + if (!errors.isEmpty()) { StringBuilder msg = new StringBuilder(); String nl = String.format("%n");