changeset 20031:c5c8193325fa

Only report debug values for CTW threads by default
author Tom Rodriguez <tom.rodriguez@oracle.com>
date Wed, 25 Mar 2015 11:48:07 -0700
parents 33b1be0d91fc
children 4d119424b4ce
files graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/CompileTheWorld.java
diffstat 1 files changed, 41 insertions(+), 25 deletions(-) [+]
line wrap: on
line diff
--- 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<Runnable>(), factory);
+        } else {
+            running = true;
         }
+        threadPool = new ThreadPoolExecutor(threadCount, threadCount, 0L, TimeUnit.MILLISECONDS, new LinkedBlockingQueue<Runnable>(), 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();
         }
     }