# HG changeset patch # User Tom Rodriguez # Date 1427309287 25200 # Node ID c5c8193325fadc9bba701b8b65a8d285ee966b6f # Parent 33b1be0d91fccdf20f547b9f408ae34315c1de45 Only report debug values for CTW threads by default diff -r 33b1be0d91fc -r c5c8193325fa graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/CompileTheWorld.java --- a/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/CompileTheWorld.java Wed Mar 25 11:48:01 2015 -0700 +++ b/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/CompileTheWorld.java Wed Mar 25 11:48:07 2015 -0700 @@ -42,6 +42,7 @@ import com.oracle.graal.compiler.CompilerThreadFactory.DebugConfigAccess; import com.oracle.graal.compiler.common.*; import com.oracle.graal.debug.*; +import com.oracle.graal.debug.internal.*; import com.oracle.graal.hotspot.meta.*; import com.oracle.graal.options.*; import com.oracle.graal.options.OptionUtils.OptionConsumer; @@ -203,6 +204,11 @@ * files from the boot class path. */ public void compile() throws Throwable { + // By default only report statistics for the CTW threads themselves + if (GraalDebugConfig.DebugValueThreadFilter.hasInitialValue()) { + GraalDebugConfig.DebugValueThreadFilter.setValue("^CompileTheWorld"); + } + if (SUN_BOOT_CLASS_PATH.equals(files)) { final String[] entries = System.getProperty(SUN_BOOT_CLASS_PATH).split(File.pathSeparator); String bcpFiles = ""; @@ -248,18 +254,29 @@ final String[] entries = fileList.split(File.pathSeparator); long start = System.currentTimeMillis(); - if (Options.CompileTheWorldMultiThreaded.getValue()) { - CompilerThreadFactory factory = new CompilerThreadFactory("CompileTheWorld", new DebugConfigAccess() { - public GraalDebugConfig getDebugConfig() { + CompilerThreadFactory factory = new CompilerThreadFactory("CompileTheWorld", new DebugConfigAccess() { + public GraalDebugConfig getDebugConfig() { + if (Debug.isEnabled() && DebugScope.getConfig() == null) { return DebugEnvironment.initialize(System.out); } - }); - int threadCount = Options.CompileTheWorldThreads.getValue(); + return null; + } + }); + + /* + * Always use a thread pool, even for single threaded mode since it simplifies the use of + * DebugValueThreadFilter to filter on the thread names. + */ + int threadCount = 1; + if (Options.CompileTheWorldMultiThreaded.getValue()) { + threadCount = Options.CompileTheWorldThreads.getValue(); if (threadCount == 0) { threadCount = Runtime.getRuntime().availableProcessors(); } - threadPool = new ThreadPoolExecutor(threadCount, threadCount, 0L, TimeUnit.MILLISECONDS, new LinkedBlockingQueue(), factory); + } else { + running = true; } + threadPool = new ThreadPoolExecutor(threadCount, threadCount, 0L, TimeUnit.MILLISECONDS, new LinkedBlockingQueue(), factory); try (OverrideScope s = config.apply()) { for (int i = 0; i < entries.length; i++) { @@ -348,17 +365,17 @@ } } - if (threadPool != null) { + if (!running) { startThreads(); - while (threadPool.getCompletedTaskCount() != threadPool.getTaskCount()) { - TTY.println("CompileTheWorld : Waiting for " + (threadPool.getTaskCount() - threadPool.getCompletedTaskCount()) + " compiles"); - try { - threadPool.awaitTermination(15, TimeUnit.SECONDS); - } catch (InterruptedException e) { - } + } + while (threadPool.getCompletedTaskCount() != threadPool.getTaskCount()) { + TTY.println("CompileTheWorld : Waiting for " + (threadPool.getTaskCount() - threadPool.getCompletedTaskCount()) + " compiles"); + try { + threadPool.awaitTermination(15, TimeUnit.SECONDS); + } catch (InterruptedException e) { } - threadPool = null; } + threadPool = null; long elapsedTime = System.currentTimeMillis() - start; @@ -402,21 +419,20 @@ } } - private void compileMethod(HotSpotResolvedJavaMethod method) { + private void compileMethod(HotSpotResolvedJavaMethod method) throws InterruptedException, ExecutionException { if (methodFilters != null && !MethodFilter.matches(methodFilters, method)) { return; } - if (threadPool != null) { - threadPool.submit(new Runnable() { - public void run() { - waitToRun(); - try (OverrideScope s = config.apply()) { - compileMethod(method, classFileCounter); - } + Future task = threadPool.submit(new Runnable() { + public void run() { + waitToRun(); + try (OverrideScope s = config.apply()) { + compileMethod(method, classFileCounter); } - }); - } else { - compileMethod(method, classFileCounter); + } + }); + if (threadPool.getCorePoolSize() == 1) { + task.get(); } }