# HG changeset patch # User Andreas Woess # Date 1391837609 -3600 # Node ID d6b340b757a242d629f7d88dfb3ab9d17bc3ed75 # Parent a8ff7d969666df696cf3464c36381e19157048b0 Truffle: refactorings diff -r a8ff7d969666 -r d6b340b757a2 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 Fri Feb 07 17:46:38 2014 +0100 +++ b/graal/com.oracle.graal.truffle/src/com/oracle/graal/truffle/GraalTruffleRuntime.java Sat Feb 08 06:33:29 2014 +0100 @@ -73,13 +73,10 @@ } public RootCallTarget createCallTarget(RootNode rootNode) { - if (!acceptForCompilation(rootNode)) { - return new UnoptimizedCallTarget(rootNode); - } if (truffleCompiler == null) { truffleCompiler = new TruffleCompilerImpl(); } - return new OptimizedCallTarget(rootNode, truffleCompiler, TruffleMinInvokeThreshold.getValue(), TruffleCompilationThreshold.getValue()); + return new OptimizedCallTarget(rootNode, truffleCompiler, TruffleMinInvokeThreshold.getValue(), TruffleCompilationThreshold.getValue(), acceptForCompilation(rootNode)); } @Override diff -r a8ff7d969666 -r d6b340b757a2 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 Fri Feb 07 17:46:38 2014 +0100 +++ b/graal/com.oracle.graal.truffle/src/com/oracle/graal/truffle/OptimizedCallTarget.java Sat Feb 08 06:33:29 2014 +0100 @@ -38,7 +38,7 @@ /** * Call target that is optimized by Graal upon surpassing a specific invocation threshold. */ -public final class OptimizedCallTarget extends DefaultCallTarget implements FrameFactory, LoopCountReceiver, ReplaceObserver { +public final class OptimizedCallTarget extends DefaultCallTarget implements LoopCountReceiver, ReplaceObserver { private static final PrintStream OUT = TTY.out().out(); @@ -52,7 +52,7 @@ private int callCount; private SpeculationLog speculationLog = new SpeculationLog(); - protected OptimizedCallTarget(RootNode rootNode, TruffleCompiler compiler, int invokeCounter, int compilationThreshold) { + OptimizedCallTarget(RootNode rootNode, TruffleCompiler compiler, int invokeCounter, int compilationThreshold, boolean compilationEnabled) { super(rootNode); this.compiler = compiler; this.compilationProfile = new CompilationProfile(compilationThreshold, invokeCounter, rootNode.toString()); @@ -62,7 +62,7 @@ } else { compilationPolicy = new DefaultCompilationPolicy(); } - this.compilationEnabled = true; + this.compilationEnabled = compilationEnabled; if (TruffleCallTargetProfiling.getValue()) { registerCallTarget(this); @@ -79,13 +79,7 @@ private Object callHelper(PackedFrame caller, Arguments args) { if (installedCode != null && installedCode.isValid()) { - TruffleRuntime runtime = Truffle.getRuntime(); - if (runtime instanceof GraalTruffleRuntime) { - if (TraceTruffleCompilation.getValue()) { - OUT.println("[truffle] reinstall OptimizedCallTarget.call code with frame prolog shortcut."); - } - GraalTruffleRuntime.installOptimizedCallTargetCallMethod(); - } + reinstallCallMethodShortcut(); } if (TruffleCallTargetProfiling.getValue()) { callCount++; @@ -101,6 +95,13 @@ } } + private static void reinstallCallMethodShortcut() { + if (TraceTruffleCompilation.getValue()) { + OUT.println("[truffle] reinstall OptimizedCallTarget.call code with frame prolog shortcut."); + } + GraalTruffleRuntime.installOptimizedCallTargetCallMethod(); + } + public CompilationProfile getCompilationProfile() { return compilationProfile; } @@ -117,7 +118,7 @@ installedCode = null; compilationProfile.reportInvalidated(); if (TraceTruffleCompilation.getValue()) { - OUT.printf("[truffle] invalidated %-48s |Inv# %d |Replace# %d\n", getRootNode(), compilationProfile.getInvalidationCount(), + OUT.printf("[truffle] invalidated %-48s %08x |InvalidationCount %2d |ReplaceCount %3d\n", getRootNode(), getRootNode().hashCode(), compilationProfile.getInvalidationCount(), compilationProfile.getNodeReplaceCount()); } } @@ -221,11 +222,6 @@ } @Override - public VirtualFrame create(FrameDescriptor descriptor, PackedFrame caller, Arguments args) { - return createFrame(descriptor, caller, args); - } - - @Override public void reportLoopCount(int count) { compilationProfile.reportLoopCount(count); } @@ -236,6 +232,10 @@ invalidate(); } + public SpeculationLog getSpeculationLog() { + return speculationLog; + } + private static void printProfiling() { List sortedCallTargets = new ArrayList<>(OptimizedCallTarget.callTargets.keySet()); Collections.sort(sortedCallTargets, new Comparator() { @@ -306,8 +306,4 @@ }); } } - - public SpeculationLog getSpeculationLog() { - return speculationLog; - } } diff -r a8ff7d969666 -r d6b340b757a2 graal/com.oracle.graal.truffle/src/com/oracle/graal/truffle/TruffleCompilerImpl.java --- a/graal/com.oracle.graal.truffle/src/com/oracle/graal/truffle/TruffleCompilerImpl.java Fri Feb 07 17:46:38 2014 +0100 +++ b/graal/com.oracle.graal.truffle/src/com/oracle/graal/truffle/TruffleCompilerImpl.java Sat Feb 08 06:33:29 2014 +0100 @@ -169,13 +169,18 @@ if (TraceTruffleCompilation.getValue()) { int nodeCountTruffle = NodeUtil.countNodes(compilable.getRootNode(), null, true); byte[] code = compiledMethod.getCode(); - OUT.printf("[truffle] optimized %-50s %x |Nodes %7d |Time %5.0f(%4.0f+%-4.0f)ms |Nodes %5d/%5d |CodeSize %d\n", compilable.getRootNode(), compilable.hashCode(), nodeCountTruffle, + OUT.printf("[truffle] optimized %-50s %08x |Tree %8d |Time %5.0f(%4.0f+%-4.0f)ms |Graph %5d/%5d |CodeSize %6d @ %s\n", compilable.getRootNode(), compilable.hashCode(), nodeCountTruffle, (timeCompilationFinished - timeCompilationStarted) / 1e6, (timePartialEvaluationFinished - timeCompilationStarted) / 1e6, - (timeCompilationFinished - timePartialEvaluationFinished) / 1e6, nodeCountPartialEval, nodeCountLowered, code != null ? code.length : 0); + (timeCompilationFinished - timePartialEvaluationFinished) / 1e6, nodeCountPartialEval, nodeCountLowered, code != null ? code.length : 0, + formatSourceSection(compilable.getRootNode().getSourceSection())); } return compiledMethod; } + private static String formatSourceSection(SourceSection sourceSection) { + return sourceSection != null ? sourceSection.toString() : "n/a"; + } + private void printInlineTree(RootNode rootNode) { OUT.println(); OUT.println("Inlining tree for: " + rootNode); diff -r a8ff7d969666 -r d6b340b757a2 graal/com.oracle.graal.truffle/src/com/oracle/graal/truffle/TruffleInliningImpl.java --- a/graal/com.oracle.graal.truffle/src/com/oracle/graal/truffle/TruffleInliningImpl.java Fri Feb 07 17:46:38 2014 +0100 +++ b/graal/com.oracle.graal.truffle/src/com/oracle/graal/truffle/TruffleInliningImpl.java Sat Feb 08 06:33:29 2014 +0100 @@ -115,7 +115,8 @@ private static void printCallSiteInfo(InliningPolicy policy, InlinableCallSiteInfo callSite, String msg) { String calls = String.format("%4s/%4s", callSite.getCallCount(), policy.callerInvocationCount); String nodes = String.format("%3s/%3s", callSite.getInlineNodeCount(), policy.callerNodeCount); - OUT.printf("[truffle] %-9s %-50s |Nodes %6s |Calls %6s %7.3f |%s\n", msg, callSite.getCallNode(), nodes, calls, policy.metric(callSite), callSite.getCallNode().getCallTarget()); + CallTarget inlined = callSite.getCallNode().getCallTarget(); + OUT.printf("[truffle] %-9s %-50s %08x |Tree %8s |Calls %6s %7.3f @ %s\n", msg, inlined, inlined.hashCode(), nodes, calls, policy.metric(callSite), callSite.getCallNode()); } private static final class InliningPolicy { diff -r a8ff7d969666 -r d6b340b757a2 graal/com.oracle.graal.truffle/src/com/oracle/graal/truffle/TruffleReplacements.java --- a/graal/com.oracle.graal.truffle/src/com/oracle/graal/truffle/TruffleReplacements.java Fri Feb 07 17:46:38 2014 +0100 +++ b/graal/com.oracle.graal.truffle/src/com/oracle/graal/truffle/TruffleReplacements.java Sat Feb 08 06:33:29 2014 +0100 @@ -58,7 +58,6 @@ truffleReplacements.registerSubstitutions(FrameWithoutBoxingSubstitutions.class); truffleReplacements.registerSubstitutions(OptimizedAssumptionSubstitutions.class); truffleReplacements.registerSubstitutions(OptimizedCallTargetSubstitutions.class); - truffleReplacements.registerSubstitutions(DefaultCallTargetSubstitutions.class); return truffleReplacements; } diff -r a8ff7d969666 -r d6b340b757a2 graal/com.oracle.graal.truffle/src/com/oracle/graal/truffle/UnoptimizedCallTarget.java --- a/graal/com.oracle.graal.truffle/src/com/oracle/graal/truffle/UnoptimizedCallTarget.java Fri Feb 07 17:46:38 2014 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,36 +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 com.oracle.truffle.api.impl.*; -import com.oracle.truffle.api.nodes.*; - -/** - * Call target that is not optimized by Graal upon surpassing a specific invocation threshold. - */ -public final class UnoptimizedCallTarget extends DefaultCallTarget { - - protected UnoptimizedCallTarget(RootNode rootNode) { - super(rootNode); - } -} diff -r a8ff7d969666 -r d6b340b757a2 graal/com.oracle.graal.truffle/src/com/oracle/graal/truffle/substitutions/DefaultCallTargetSubstitutions.java --- a/graal/com.oracle.graal.truffle/src/com/oracle/graal/truffle/substitutions/DefaultCallTargetSubstitutions.java Fri Feb 07 17:46:38 2014 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,37 +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.substitutions; - -import com.oracle.graal.api.replacements.*; -import com.oracle.graal.nodes.spi.*; -import com.oracle.graal.truffle.nodes.asserts.*; -import com.oracle.truffle.api.*; -import com.oracle.truffle.api.frame.*; -import com.oracle.truffle.api.impl.*; - -@ClassSubstitution(DefaultCallTarget.class) -public class DefaultCallTargetSubstitutions { - - @MacroSubstitution(macro = NeverInlineMacroNode.class, isStatic = false) - public static native Object call(DefaultCallTarget target, PackedFrame caller, Arguments args); -} diff -r a8ff7d969666 -r d6b340b757a2 graal/com.oracle.graal.truffle/src/com/oracle/graal/truffle/substitutions/OptimizedCallTargetSubstitutions.java --- a/graal/com.oracle.graal.truffle/src/com/oracle/graal/truffle/substitutions/OptimizedCallTargetSubstitutions.java Fri Feb 07 17:46:38 2014 +0100 +++ b/graal/com.oracle.graal.truffle/src/com/oracle/graal/truffle/substitutions/OptimizedCallTargetSubstitutions.java Sat Feb 08 06:33:29 2014 +0100 @@ -46,10 +46,4 @@ private static FrameWithoutBoxing createFrame(FrameDescriptor descriptor, PackedFrame caller, Arguments args) { return NewFrameNode.allocate(descriptor, caller, args); } - - @SuppressWarnings("unused") - @MethodSubstitution(isStatic = false) - private static VirtualFrame create(OptimizedCallTarget target, FrameDescriptor descriptor, PackedFrame caller, Arguments args) { - return createFrame(descriptor, caller, args); - } } diff -r a8ff7d969666 -r d6b340b757a2 graal/com.oracle.truffle.api/src/com/oracle/truffle/api/nodes/FrameFactory.java --- a/graal/com.oracle.truffle.api/src/com/oracle/truffle/api/nodes/FrameFactory.java Fri Feb 07 17:46:38 2014 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,44 +0,0 @@ -/* - * 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. Oracle designates this - * particular file as subject to the "Classpath" exception as provided - * by Oracle in the LICENSE file that accompanied this code. - * - * 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.nodes; - -import com.oracle.truffle.api.*; -import com.oracle.truffle.api.frame.*; - -/** - * Factory for virtual frame creation. - */ -public interface FrameFactory { - - /** - * Creates a new virtual frame from the given frame descriptor and arguments. - * - * @param descriptor describes the frame to be created - * @param caller the packed caller frame or {@code null} - * @param args {@link Arguments} object to be stored in the frame - * @return a new virtual frame - */ - VirtualFrame create(FrameDescriptor descriptor, PackedFrame caller, Arguments args); -} diff -r a8ff7d969666 -r d6b340b757a2 graal/com.oracle.truffle.api/src/com/oracle/truffle/api/nodes/Node.java --- a/graal/com.oracle.truffle.api/src/com/oracle/truffle/api/nodes/Node.java Fri Feb 07 17:46:38 2014 +0100 +++ b/graal/com.oracle.truffle.api/src/com/oracle/truffle/api/nodes/Node.java Sat Feb 08 06:33:29 2014 +0100 @@ -172,7 +172,7 @@ * @return the new node */ public final T replace(T newNode, String reason) { - CompilerDirectives.transferToInterpreter(); + CompilerDirectives.transferToInterpreterAndInvalidate(); if (this.getParent() == null) { throw new IllegalStateException("This node cannot be replaced, because it does not yet have a parent."); }