# HG changeset patch # User Thomas Wuerthinger # Date 1397746311 -7200 # Node ID 59f71608aa9a53c677b911c63c2edcac72f98fb7 # Parent 201f6858a4f3377d8d8718cf37deae011f49ea2a Clean up of relationship between compilation policy and optimized call target. diff -r 201f6858a4f3 -r 59f71608aa9a graal/com.oracle.graal.truffle.hotspot/src/com/oracle/graal/truffle/hotspot/HotSpotOptimizedCallTarget.java --- a/graal/com.oracle.graal.truffle.hotspot/src/com/oracle/graal/truffle/hotspot/HotSpotOptimizedCallTarget.java Thu Apr 17 16:25:08 2014 +0200 +++ b/graal/com.oracle.graal.truffle.hotspot/src/com/oracle/graal/truffle/hotspot/HotSpotOptimizedCallTarget.java Thu Apr 17 16:51:51 2014 +0200 @@ -22,7 +22,6 @@ */ package com.oracle.graal.truffle.hotspot; -import static com.oracle.graal.hotspot.HotSpotGraalRuntime.*; import static com.oracle.graal.truffle.TruffleCompilerOptions.*; import static com.oracle.graal.truffle.OptimizedCallTargetLog.*; @@ -40,8 +39,8 @@ protected final GraalTruffleRuntime runtime; private SpeculationLog speculationLog = new HotSpotSpeculationLog(); - HotSpotOptimizedCallTarget(RootNode rootNode, GraalTruffleRuntime runtime, int invokeCounter, int compilationThreshold, boolean compilationEnabled) { - super(rootNode, invokeCounter, compilationThreshold, compilationEnabled, TruffleUseTimeForCompilationDecision.getValue() ? new TimedCompilationPolicy() : new DefaultCompilationPolicy()); + HotSpotOptimizedCallTarget(RootNode rootNode, GraalTruffleRuntime runtime, int invokeCounter, int compilationThreshold, CompilationPolicy compilationPolicy) { + super(rootNode, invokeCounter, compilationThreshold, compilationPolicy); this.runtime = runtime; } @@ -81,12 +80,7 @@ @Override public void invalidate() { - runtime().getCompilerToVM().invalidateInstalledCode(this); - } - - @Override - public Object executeVarargs(Object... args) throws InvalidInstalledCodeException { - return runtime().getCompilerToVM().executeCompiledMethodVarargs(args, this); + this.runtime.invalidateInstalledCode(this); } @Override @@ -114,13 +108,10 @@ callCount++; } - if (compilationEnabled && compilationPolicy.shouldCompile(compilationProfile)) { + if (compilationPolicy.shouldCompile(compilationProfile)) { compile(); if (isValid()) { - try { - return executeVarargs(new Object[]{this, args}); - } catch (InvalidInstalledCodeException ex) { - } + return call(args); } } return executeHelper(args); @@ -140,7 +131,7 @@ if (t == null) { // Compilation was successful. } else { - compilationEnabled = false; + compilationPolicy.recordCompilationFailure(t); logOptimizingFailed(this, t.getMessage()); if (t instanceof BailoutException) { // Bailout => move on. diff -r 201f6858a4f3 -r 59f71608aa9a graal/com.oracle.graal.truffle.hotspot/src/com/oracle/graal/truffle/hotspot/HotSpotTruffleRuntime.java --- a/graal/com.oracle.graal.truffle.hotspot/src/com/oracle/graal/truffle/hotspot/HotSpotTruffleRuntime.java Thu Apr 17 16:25:08 2014 +0200 +++ b/graal/com.oracle.graal.truffle.hotspot/src/com/oracle/graal/truffle/hotspot/HotSpotTruffleRuntime.java Thu Apr 17 16:51:51 2014 +0200 @@ -38,6 +38,7 @@ import com.oracle.graal.compiler.target.*; import com.oracle.graal.debug.*; import com.oracle.graal.debug.Debug.Scope; +import com.oracle.graal.hotspot.*; import com.oracle.graal.java.*; import com.oracle.graal.lir.asm.*; import com.oracle.graal.nodes.*; @@ -103,7 +104,13 @@ } public RootCallTarget createCallTarget(RootNode rootNode) { - return new HotSpotOptimizedCallTarget(rootNode, this, TruffleMinInvokeThreshold.getValue(), TruffleCompilationThreshold.getValue(), acceptForCompilation(rootNode)); + CompilationPolicy compilationPolicy; + if (acceptForCompilation(rootNode)) { + compilationPolicy = new CounterBasedCompilationPolicy(); + } else { + compilationPolicy = new InterpreterOnlyCompilationPolicy(); + } + return new HotSpotOptimizedCallTarget(rootNode, this, TruffleMinInvokeThreshold.getValue(), TruffleCompilationThreshold.getValue(), compilationPolicy); } public DirectCallNode createDirectCallNode(CallTarget target) { @@ -324,4 +331,8 @@ } return false; } + + public void invalidateInstalledCode(OptimizedCallTarget optimizedCallTarget) { + HotSpotGraalRuntime.runtime().getCompilerToVM().invalidateInstalledCode(optimizedCallTarget); + } } diff -r 201f6858a4f3 -r 59f71608aa9a graal/com.oracle.graal.truffle/src/com/oracle/graal/truffle/CompilationPolicy.java --- a/graal/com.oracle.graal.truffle/src/com/oracle/graal/truffle/CompilationPolicy.java Thu Apr 17 16:25:08 2014 +0200 +++ b/graal/com.oracle.graal.truffle/src/com/oracle/graal/truffle/CompilationPolicy.java Thu Apr 17 16:51:51 2014 +0200 @@ -26,4 +26,6 @@ boolean shouldCompile(CompilationProfile profile); + void recordCompilationFailure(Throwable t); + } diff -r 201f6858a4f3 -r 59f71608aa9a graal/com.oracle.graal.truffle/src/com/oracle/graal/truffle/CounterBasedCompilationPolicy.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/graal/com.oracle.graal.truffle/src/com/oracle/graal/truffle/CounterBasedCompilationPolicy.java Thu Apr 17 16:51:51 2014 +0200 @@ -0,0 +1,37 @@ +/* + * Copyright (c) 2013, 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.truffle; + +public class CounterBasedCompilationPolicy implements CompilationPolicy { + + private boolean compilationFailed; + + public boolean shouldCompile(CompilationProfile profile) { + return !compilationFailed && profile.getCallCount() >= profile.getCompilationCallThreshold() && profile.getCallAndLoopCount() >= profile.getCompilationCallAndLoopThreshold(); + } + + public void recordCompilationFailure(Throwable t) { + compilationFailed = true; + } + +} diff -r 201f6858a4f3 -r 59f71608aa9a graal/com.oracle.graal.truffle/src/com/oracle/graal/truffle/DefaultCompilationPolicy.java --- a/graal/com.oracle.graal.truffle/src/com/oracle/graal/truffle/DefaultCompilationPolicy.java Thu Apr 17 16:25:08 2014 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,31 +0,0 @@ -/* - * Copyright (c) 2013, 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.truffle; - -public class DefaultCompilationPolicy implements CompilationPolicy { - - public boolean shouldCompile(CompilationProfile profile) { - return profile.getCallCount() >= profile.getCompilationCallThreshold() && profile.getCallAndLoopCount() >= profile.getCompilationCallAndLoopThreshold(); - } - -} diff -r 201f6858a4f3 -r 59f71608aa9a graal/com.oracle.graal.truffle/src/com/oracle/graal/truffle/GraalTruffleRuntime.java --- a/graal/com.oracle.graal.truffle/src/com/oracle/graal/truffle/GraalTruffleRuntime.java Thu Apr 17 16:25:08 2014 +0200 +++ b/graal/com.oracle.graal.truffle/src/com/oracle/graal/truffle/GraalTruffleRuntime.java Thu Apr 17 16:51:51 2014 +0200 @@ -34,4 +34,6 @@ boolean cancelInstalledTask(OptimizedCallTarget optimizedCallTarget); boolean isCompiling(OptimizedCallTarget optimizedCallTarget); + + void invalidateInstalledCode(OptimizedCallTarget optimizedCallTarget); } diff -r 201f6858a4f3 -r 59f71608aa9a graal/com.oracle.graal.truffle/src/com/oracle/graal/truffle/InterpreterOnlyCompilationPolicy.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/graal/com.oracle.graal.truffle/src/com/oracle/graal/truffle/InterpreterOnlyCompilationPolicy.java Thu Apr 17 16:51:51 2014 +0200 @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2013, 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.truffle; + +public class InterpreterOnlyCompilationPolicy implements CompilationPolicy { + + public boolean shouldCompile(CompilationProfile profile) { + return false; + } + + public void recordCompilationFailure(Throwable t) { + } + +} diff -r 201f6858a4f3 -r 59f71608aa9a graal/com.oracle.graal.truffle/src/com/oracle/graal/truffle/OptimizedCallTarget.java --- a/graal/com.oracle.graal.truffle/src/com/oracle/graal/truffle/OptimizedCallTarget.java Thu Apr 17 16:25:08 2014 +0200 +++ b/graal/com.oracle.graal.truffle/src/com/oracle/graal/truffle/OptimizedCallTarget.java Thu Apr 17 16:51:51 2014 +0200 @@ -42,7 +42,6 @@ protected static final PrintStream OUT = TTY.out().out(); - protected boolean compilationEnabled; protected int callCount; protected boolean inliningPerformed; protected final CompilationProfile compilationProfile; @@ -56,11 +55,10 @@ return rootNode; } - public OptimizedCallTarget(RootNode rootNode, int invokeCounter, int compilationThreshold, boolean compilationEnabled, CompilationPolicy compilationPolicy) { + public OptimizedCallTarget(RootNode rootNode, int invokeCounter, int compilationThreshold, CompilationPolicy compilationPolicy) { this.rootNode = rootNode; this.rootNode.adoptChildren(); this.rootNode.setCallTarget(this); - this.compilationEnabled = compilationEnabled; this.compilationPolicy = compilationPolicy; this.compilationProfile = new CompilationProfile(compilationThreshold, invokeCounter, rootNode.toString()); if (TruffleCallTargetProfiling.getValue()) { diff -r 201f6858a4f3 -r 59f71608aa9a graal/com.oracle.graal.truffle/src/com/oracle/graal/truffle/OptimizedCallTargetLog.java --- a/graal/com.oracle.graal.truffle/src/com/oracle/graal/truffle/OptimizedCallTargetLog.java Thu Apr 17 16:25:08 2014 +0200 +++ b/graal/com.oracle.graal.truffle/src/com/oracle/graal/truffle/OptimizedCallTargetLog.java Thu Apr 17 16:51:51 2014 +0200 @@ -267,7 +267,6 @@ int nodeCount = OptimizedCallUtils.countNonTrivialNodes(callTarget, true); String comment = callTarget.isValid() ? "" : " int"; - comment += callTarget.compilationEnabled ? "" : " fail"; OUT.printf("%-50s | %10d | %15d | %10d | %3d%s\n", callTarget.getRootNode(), callTarget.callCount, nodeCount, nodeCount, callTarget.getCompilationProfile().getInvalidationCount(), comment); totalCallCount += callTarget.callCount; diff -r 201f6858a4f3 -r 59f71608aa9a graal/com.oracle.graal.truffle/src/com/oracle/graal/truffle/TimedCompilationPolicy.java --- a/graal/com.oracle.graal.truffle/src/com/oracle/graal/truffle/TimedCompilationPolicy.java Thu Apr 17 16:25:08 2014 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,51 +0,0 @@ -/* - * Copyright (c) 2013, 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.truffle; - -import static com.oracle.graal.truffle.TruffleCompilerOptions.*; - -import java.io.*; - -public class TimedCompilationPolicy extends DefaultCompilationPolicy { - - @Override - public boolean shouldCompile(CompilationProfile profile) { - if (super.shouldCompile(profile)) { - long timestamp = System.nanoTime(); - long prevTimestamp = profile.getPreviousTimestamp(); - long timespan = (timestamp - prevTimestamp); - if (timespan < (TruffleCompilationDecisionTime.getValue())) { - return true; - } - // TODO shouldCompile should not modify the compilation profile - // maybe introduce another method? - profile.reportTiminingFailed(timestamp); - if (TruffleCompilationDecisionTimePrintFail.getValue()) { - PrintStream out = System.out; - out.println(profile.getName() + ": timespan " + (timespan / 1000000) + " ms larger than threshold"); - } - } - return false; - } - -} diff -r 201f6858a4f3 -r 59f71608aa9a graal/com.oracle.graal.truffle/src/com/oracle/graal/truffle/TruffleCompilerOptions.java --- a/graal/com.oracle.graal.truffle/src/com/oracle/graal/truffle/TruffleCompilerOptions.java Thu Apr 17 16:25:08 2014 +0200 +++ b/graal/com.oracle.graal.truffle/src/com/oracle/graal/truffle/TruffleCompilerOptions.java Thu Apr 17 16:51:51 2014 +0200 @@ -72,8 +72,6 @@ @Option(help = "Enable asynchronous truffle compilation in background thread") public static final OptionValue TruffleBackgroundCompilation = new OptionValue<>(true); @Option(help = "") - public static final OptionValue TruffleUseTimeForCompilationDecision = new OptionValue<>(false); - @Option(help = "") public static final OptionValue TruffleCompilationDecisionTime = new OptionValue<>(100); @Option(help = "") public static final OptionValue TruffleCompilationDecisionTimePrintFail = new OptionValue<>(false);