# HG changeset patch # User Thomas Wuerthinger # Date 1332332027 -3600 # Node ID 8f4f0ebffca2d8ab1196df49ddd517eae5506986 # Parent 4bcd22f088b2b53adcf284b1c8ec391196ea368a Move compilation task logic to separate class. diff -r 4bcd22f088b2 -r 8f4f0ebffca2 graal/com.oracle.graal.compiler/src/com/oracle/graal/compiler/GraalOptions.java --- a/graal/com.oracle.graal.compiler/src/com/oracle/graal/compiler/GraalOptions.java Wed Mar 21 12:12:22 2012 +0100 +++ b/graal/com.oracle.graal.compiler/src/com/oracle/graal/compiler/GraalOptions.java Wed Mar 21 13:13:47 2012 +0100 @@ -105,9 +105,6 @@ public static boolean PrintLIR = ____; public static boolean PrintCFGToFile = ____; - // statistics independent from debug mode - public static boolean PrintCompilationStatistics = ____; - // Debug settings: public static boolean Debug = true; public static boolean PerThreadDebugValues = ____; diff -r 4bcd22f088b2 -r 8f4f0ebffca2 graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/CompilationTask.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/CompilationTask.java Wed Mar 21 13:13:47 2012 +0100 @@ -0,0 +1,94 @@ +/* + * Copyright (c) 2012, 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. + */ +package com.oracle.graal.hotspot; + +import java.util.concurrent.*; + +import com.oracle.graal.compiler.*; +import com.oracle.graal.compiler.phases.*; +import com.oracle.graal.compiler.phases.PhasePlan.*; +import com.oracle.graal.debug.*; +import com.oracle.graal.hotspot.snippets.*; +import com.oracle.graal.java.*; +import com.oracle.max.cri.ci.*; +import com.oracle.max.cri.ri.*; +import com.oracle.max.criutils.*; + + +public final class CompilationTask implements Runnable { + + private final Compiler compiler; + private final PhasePlan plan; + private final RiResolvedMethod method; + + public static CompilationTask create(Compiler compiler, PhasePlan plan, RiResolvedMethod method) { + return new CompilationTask(compiler, plan, method); + } + + private CompilationTask(Compiler compiler, PhasePlan plan, RiResolvedMethod method) { + this.compiler = compiler; + this.plan = plan; + this.method = method; + } + + public void run() { + try { + GraphBuilderPhase graphBuilderPhase = new GraphBuilderPhase(compiler.getRuntime()); + plan.addPhase(PhasePosition.AFTER_PARSING, graphBuilderPhase); + final boolean printCompilation = GraalOptions.PrintCompilation && !TTY.isSuppressed(); + if (printCompilation) { + TTY.println(String.format("Graal %-70s %-45s %-50s ...", method.holder().name(), method.name(), method.signature().asString())); + } + + CiTargetMethod result = null; + TTY.Filter filter = new TTY.Filter(GraalOptions.PrintFilter, method); + try { + result = Debug.scope("Compiling", new Callable() { + + @Override + public CiTargetMethod call() throws Exception { + return compiler.getCompiler().compileMethod(method, -1, plan); + } + }); + } finally { + filter.remove(); + if (printCompilation) { + TTY.println(String.format("Graal %-70s %-45s %-50s | %4dnodes %5dB", "", "", "", 0, (result != null ? result.targetCodeSize() : -1))); + } + } + compiler.getRuntime().installMethod(method, result); + } catch (CiBailout bailout) { + Debug.metric("Bailouts").increment(); + if (GraalOptions.ExitVMOnBailout) { + bailout.printStackTrace(TTY.cachedOut); + System.exit(-1); + } + } catch (Throwable t) { + if (GraalOptions.ExitVMOnException) { + t.printStackTrace(TTY.cachedOut); + System.exit(-1); + } + } + } + +} diff -r 4bcd22f088b2 -r 8f4f0ebffca2 graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/bridge/VMToCompilerImpl.java --- a/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/bridge/VMToCompilerImpl.java Wed Mar 21 12:12:22 2012 +0100 +++ b/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/bridge/VMToCompilerImpl.java Wed Mar 21 13:13:47 2012 +0100 @@ -49,8 +49,6 @@ public class VMToCompilerImpl implements VMToCompiler, Remote { private final Compiler compiler; - private int compiledMethodCount; - private long totalCompilationTime; private IntrinsifyArrayCopyPhase intrinsifyArrayCopy; public final HotSpotTypePrimitive typeBoolean; @@ -206,10 +204,6 @@ } } } - - if (GraalOptions.PrintCompilationStatistics) { - printCompilationStatistics(); - } } private void flattenChildren(DebugValueMap map, DebugValueMap globalMap) { @@ -220,12 +214,6 @@ map.clearChildren(); } - private void printCompilationStatistics() { - TTY.println("Accumulated compilation statistics"); - TTY.println(" Compiled methods : %d", compiledMethodCount); - TTY.println(" Total compilation time : %6.3f s", totalCompilationTime / Math.pow(10, 9)); - } - private static void printSummary(List topLevelMaps, List debugValues) { DebugValueMap result = new DebugValueMap("Summary"); for (int i = debugValues.size() - 1; i >= 0; i--) { @@ -278,75 +266,26 @@ @Override public boolean compileMethod(final HotSpotMethodResolved method, final int entryBCI, boolean blocking) throws Throwable { - try { - if (Thread.currentThread() instanceof CompilerThread) { - if (method.holder().name().contains("java/util/concurrent")) { - // This is required to avoid deadlocking a compiler thread. The issue is that a - // java.util.concurrent.BlockingQueue is used to implement the compilation worker - // queues. If a compiler thread triggers a compilation, then it may be blocked trying - // to add something to its own queue. - return false; - } + if (Thread.currentThread() instanceof CompilerThread) { + if (method.holder().name().contains("java/util/concurrent")) { + // This is required to avoid deadlocking a compiler thread. The issue is that a + // java.util.concurrent.BlockingQueue is used to implement the compilation worker + // queues. If a compiler thread triggers a compilation, then it may be blocked trying + // to add something to its own queue. + return false; } - - Runnable runnable = new Runnable() { - - public void run() { - try { - final PhasePlan plan = getDefaultPhasePlan(); - GraphBuilderPhase graphBuilderPhase = new GraphBuilderPhase(compiler.getRuntime()); - plan.addPhase(PhasePosition.AFTER_PARSING, graphBuilderPhase); - long startTime = System.nanoTime(); - int index = compiledMethodCount++; - final boolean printCompilation = GraalOptions.PrintCompilation && !TTY.isSuppressed(); - if (printCompilation) { - TTY.println(String.format("Graal %4d %-70s %-45s %-50s ...", index, method.holder().name(), method.name(), method.signature().asString())); - } - - CiTargetMethod result = null; - TTY.Filter filter = new TTY.Filter(GraalOptions.PrintFilter, method); - long nanoTime; - try { - result = Debug.scope("Compiling", new Callable() { + } - @Override - public CiTargetMethod call() throws Exception { - return compiler.getCompiler().compileMethod(method, -1, plan); - } - }); - } finally { - filter.remove(); - nanoTime = System.nanoTime() - startTime; - totalCompilationTime += nanoTime; - if (printCompilation) { - TTY.println(String.format("Graal %4d %-70s %-45s %-50s | %3d.%dms %4dnodes %5dB", index, "", "", "", nanoTime / 1000000, nanoTime % 1000000, 0, - (result != null ? result.targetCodeSize() : -1))); - } - } - compiler.getRuntime().installMethod(method, result); - } catch (CiBailout bailout) { - Debug.metric("Bailouts").increment(); - if (GraalOptions.ExitVMOnBailout) { - bailout.printStackTrace(TTY.cachedOut); - System.exit(-1); - } - } catch (Throwable t) { - if (GraalOptions.ExitVMOnException) { - t.printStackTrace(TTY.cachedOut); - System.exit(-1); - } - } - } - }; - - if (blocking) { - runnable.run(); - } else { - compileQueue.execute(runnable); + CompilationTask task = CompilationTask.create(compiler, getDefaultPhasePlan(), method); + if (blocking) { + task.run(); + } else { + try { + compileQueue.execute(task); + } catch (RejectedExecutionException e) { + // The compile queue was already shut down. + return false; } - } catch (RejectedExecutionException e) { - // The compile queue was already shut down. - return false; } return true; }