Mercurial > hg > truffle
changeset 10862:8c570011b86f
Truffle: when a node is replaced, notify optimized call target and delay compilation.
author | Andreas Woess <andreas.woess@jku.at> |
---|---|
date | Tue, 23 Jul 2013 19:05:08 +0200 |
parents | 6872c61c1d3e |
children | 740789178ad8 |
files | graal/com.oracle.graal.truffle/src/com/oracle/graal/truffle/OptimizedCallTarget.java graal/com.oracle.graal.truffle/src/com/oracle/graal/truffle/TruffleCompilerOptions.java graal/com.oracle.truffle.api/src/com/oracle/truffle/api/ReplaceObserver.java graal/com.oracle.truffle.api/src/com/oracle/truffle/api/nodes/Node.java |
diffstat | 4 files changed, 63 insertions(+), 14 deletions(-) [+] |
line wrap: on
line diff
--- a/graal/com.oracle.graal.truffle/src/com/oracle/graal/truffle/OptimizedCallTarget.java Tue Jul 23 18:23:52 2013 +0200 +++ b/graal/com.oracle.graal.truffle/src/com/oracle/graal/truffle/OptimizedCallTarget.java Tue Jul 23 19:05:08 2013 +0200 @@ -37,7 +37,7 @@ /** * Call target that is optimized by Graal upon surpassing a specific invocation threshold. */ -public final class OptimizedCallTarget extends DefaultCallTarget implements LoopCountReceiver, FrameFactory { +public final class OptimizedCallTarget extends DefaultCallTarget implements FrameFactory, LoopCountReceiver, ReplaceObserver { private static final PrintStream OUT = TTY.out().out(); private static final int MIN_INVOKES_AFTER_INLINING = 2; @@ -57,16 +57,15 @@ private InstalledCode compiledMethod; private final TruffleCompiler compiler; + private int invokeCounter; private int originalInvokeCounter; private int loopAndInvokeCounter; private boolean disableCompilation; - // TruffleProfiling private int callCount; private int invalidationCount; - - // TraceTruffleCompilation + private int replaceCount; long timeCompilationStarted; long timePartialEvaluationFinished; long timeCompilationFinished; @@ -100,7 +99,8 @@ originalInvokeCounter += invalidationReprofileCount; } if (TraceTruffleCompilation.getValue()) { - OUT.printf("[truffle] invalidated %-48s |Alive %5.0fms |Inv %d\n", rootNode, (System.nanoTime() - timeCompilationFinished) / 1e6, invalidationCount); + OUT.printf("[truffle] invalidated %-48s |Alive %5.0fms |Inv# %d |Replace# %d\n", rootNode, (System.nanoTime() - timeCompilationFinished) / 1e6, + invalidationCount, replaceCount); } return call(caller, args); } @@ -112,18 +112,22 @@ if (disableCompilation || loopAndInvokeCounter > 0 || invokeCounter > 0) { return executeHelper(caller, args); } else { - if (TruffleFunctionInlining.getValue() && inline()) { - invokeCounter = MIN_INVOKES_AFTER_INLINING; - int inliningReprofileCount = TruffleInliningReprofileCount.getValue(); - loopAndInvokeCounter = inliningReprofileCount; - originalInvokeCounter = inliningReprofileCount; - } else { - compile(); - } + compileOrInline(); return call(caller, args); } } + private void compileOrInline() { + if (TruffleFunctionInlining.getValue() && inline()) { + invokeCounter = MIN_INVOKES_AFTER_INLINING; + int inliningReprofileCount = TruffleInliningReprofileCount.getValue(); + loopAndInvokeCounter = inliningReprofileCount; + originalInvokeCounter = inliningReprofileCount; + } else { + compile(); + } + } + public boolean inline() { CompilerAsserts.neverPartOfCompilation(); return new InliningHelper(this).inline(); @@ -183,6 +187,17 @@ loopAndInvokeCounter -= count; } + @Override + public void nodeReplaced() { + replaceCount++; + + // delay compilation until tree is deemed stable enough + int replaceBackoff = Math.min(TruffleInvalidationReprofileCount.getValue(), TruffleCompilationThreshold.getValue()); + if (invokeCounter < replaceBackoff) { + invokeCounter = replaceBackoff; + } + } + private static class InliningHelper { private final OptimizedCallTarget target;
--- a/graal/com.oracle.graal.truffle/src/com/oracle/graal/truffle/TruffleCompilerOptions.java Tue Jul 23 18:23:52 2013 +0200 +++ b/graal/com.oracle.graal.truffle/src/com/oracle/graal/truffle/TruffleCompilerOptions.java Tue Jul 23 19:05:08 2013 +0200 @@ -46,7 +46,7 @@ @Option(help = "") public static final OptionValue<Integer> TruffleCompilationThreshold = new OptionValue<>(1000); @Option(help = "") - public static final OptionValue<Integer> TruffleInvalidationReprofileCount = new OptionValue<>(3); + public static final OptionValue<Integer> TruffleInvalidationReprofileCount = new OptionValue<>(10); @Option(help = "") public static final OptionValue<Integer> TruffleInliningReprofileCount = new OptionValue<>(100); @Option(help = "")
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/graal/com.oracle.truffle.api/src/com/oracle/truffle/api/ReplaceObserver.java Tue Jul 23 19:05:08 2013 +0200 @@ -0,0 +1,28 @@ +/* + * 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.truffle.api; + +public interface ReplaceObserver { + + void nodeReplaced(); +}
--- a/graal/com.oracle.truffle.api/src/com/oracle/truffle/api/nodes/Node.java Tue Jul 23 18:23:52 2013 +0200 +++ b/graal/com.oracle.truffle.api/src/com/oracle/truffle/api/nodes/Node.java Tue Jul 23 19:05:08 2013 +0200 @@ -211,6 +211,12 @@ * @param reason the reason the replace supplied */ protected void onReplace(Node newNode, String reason) { + RootNode rootNode = NodeUtil.findParent(this, RootNode.class); + if (rootNode != null) { + if (rootNode.getCallTarget() instanceof ReplaceObserver) { + ((ReplaceObserver) rootNode.getCallTarget()).nodeReplaced(); + } + } if (TruffleOptions.TraceRewrites) { Class<? extends Node> from = getClass(); Class<? extends Node> to = newNode.getClass();