# HG changeset patch # User Thomas Wuerthinger # Date 1397749220 -7200 # Node ID ea9d5b6044af84964a40cfb5dccf79d3d9834241 # Parent 59f71608aa9a53c677b911c63c2edcac72f98fb7 Remove runtime-specific optimized call target. diff -r 59f71608aa9a -r ea9d5b6044af 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:51:51 2014 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,146 +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.hotspot; - -import static com.oracle.graal.truffle.TruffleCompilerOptions.*; -import static com.oracle.graal.truffle.OptimizedCallTargetLog.*; - -import com.oracle.graal.api.code.*; -import com.oracle.graal.hotspot.meta.*; -import com.oracle.graal.truffle.*; -import com.oracle.truffle.api.*; -import com.oracle.truffle.api.nodes.*; - -/** - * Call target for running truffle on a standard VM (and not in SubstrateVM). - */ -public final class HotSpotOptimizedCallTarget extends OptimizedCallTarget { - - protected final GraalTruffleRuntime runtime; - private SpeculationLog speculationLog = new HotSpotSpeculationLog(); - - HotSpotOptimizedCallTarget(RootNode rootNode, GraalTruffleRuntime runtime, int invokeCounter, int compilationThreshold, CompilationPolicy compilationPolicy) { - super(rootNode, invokeCounter, compilationThreshold, compilationPolicy); - this.runtime = runtime; - } - - @Override - public SpeculationLog getSpeculationLog() { - return speculationLog; - } - - @Override - public Object call(Object... args) { - return callBoundary(args); - } - - @TruffleCallBoundary - private Object callBoundary(Object[] args) { - if (CompilerDirectives.inInterpreter()) { - return compiledCallFallback(args); - } else { - // We come here from compiled code (i.e., we have been inlined). - return executeHelper(args); - } - } - - private Object compiledCallFallback(Object[] args) { - if (isValid()) { - reinstallCallMethodShortcut(); - } - return interpreterCall(args); - } - - private static void reinstallCallMethodShortcut() { - if (TraceTruffleCompilation.getValue()) { - OUT.println("[truffle] reinstall OptimizedCallTarget.call code with frame prolog shortcut."); - } - HotSpotTruffleRuntime.installOptimizedCallTargetCallMethod(); - } - - @Override - public void invalidate() { - this.runtime.invalidateInstalledCode(this); - } - - @Override - protected void invalidate(Node oldNode, Node newNode, CharSequence reason) { - if (isValid()) { - CompilerAsserts.neverPartOfCompilation(); - invalidate(); - compilationProfile.reportInvalidated(); - logOptimizedInvalidated(this, oldNode, newNode, reason); - } - cancelInstalledTask(oldNode, newNode, reason); - } - - private void cancelInstalledTask(Node oldNode, Node newNode, CharSequence reason) { - if (this.runtime.cancelInstalledTask(this)) { - logOptimizingUnqueued(this, oldNode, newNode, reason); - compilationProfile.reportInvalidated(); - } - } - - private Object interpreterCall(Object[] args) { - CompilerAsserts.neverPartOfCompilation(); - compilationProfile.reportInterpreterCall(); - if (TruffleCallTargetProfiling.getValue()) { - callCount++; - } - - if (compilationPolicy.shouldCompile(compilationProfile)) { - compile(); - if (isValid()) { - return call(args); - } - } - return executeHelper(args); - } - - @Override - public void compile() { - if (!runtime.isCompiling(this)) { - performInlining(); - logOptimizingQueued(this); - runtime.compile(this, TruffleBackgroundCompilation.getValue()); - } - } - - @Override - public void compilationFinished(Throwable t) { - if (t == null) { - // Compilation was successful. - } else { - compilationPolicy.recordCompilationFailure(t); - logOptimizingFailed(this, t.getMessage()); - if (t instanceof BailoutException) { - // Bailout => move on. - } else { - if (TruffleCompilationExceptionsAreFatal.getValue()) { - t.printStackTrace(OUT); - System.exit(-1); - } - } - } - } -} diff -r 59f71608aa9a -r ea9d5b6044af graal/com.oracle.graal.truffle.hotspot/src/com/oracle/graal/truffle/hotspot/HotSpotTruffleReplacements.java --- a/graal/com.oracle.graal.truffle.hotspot/src/com/oracle/graal/truffle/hotspot/HotSpotTruffleReplacements.java Thu Apr 17 16:51:51 2014 +0200 +++ b/graal/com.oracle.graal.truffle.hotspot/src/com/oracle/graal/truffle/hotspot/HotSpotTruffleReplacements.java Thu Apr 17 17:40:20 2014 +0200 @@ -28,7 +28,6 @@ import com.oracle.graal.phases.util.*; import com.oracle.graal.runtime.*; import com.oracle.graal.truffle.*; -import com.oracle.graal.truffle.hotspot.substitutions.*; public final class HotSpotTruffleReplacements extends TruffleReplacements { @@ -41,10 +40,4 @@ SnippetReflectionProvider snippetReflection = Graal.getRequiredCapability(SnippetReflectionProvider.class); return new HotSpotTruffleReplacements(providers, snippetReflection); } - - @Override - protected void registerTruffleSubstitutions() { - super.registerTruffleSubstitutions(); - registerSubstitutions(HotSpotOptimizedCallTargetSubstitutions.class); - } } diff -r 59f71608aa9a -r ea9d5b6044af 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:51:51 2014 +0200 +++ b/graal/com.oracle.graal.truffle.hotspot/src/com/oracle/graal/truffle/hotspot/HotSpotTruffleRuntime.java Thu Apr 17 17:40:20 2014 +0200 @@ -39,6 +39,7 @@ import com.oracle.graal.debug.*; import com.oracle.graal.debug.Debug.Scope; import com.oracle.graal.hotspot.*; +import com.oracle.graal.hotspot.meta.*; import com.oracle.graal.java.*; import com.oracle.graal.lir.asm.*; import com.oracle.graal.nodes.*; @@ -110,7 +111,7 @@ } else { compilationPolicy = new InterpreterOnlyCompilationPolicy(); } - return new HotSpotOptimizedCallTarget(rootNode, this, TruffleMinInvokeThreshold.getValue(), TruffleCompilationThreshold.getValue(), compilationPolicy); + return new OptimizedCallTarget(rootNode, this, TruffleMinInvokeThreshold.getValue(), TruffleCompilationThreshold.getValue(), compilationPolicy, new HotSpotSpeculationLog()); } public DirectCallNode createDirectCallNode(CallTarget target) { @@ -199,7 +200,7 @@ public static void installOptimizedCallTargetCallMethod() { Providers providers = getGraalProviders(); MetaAccessProvider metaAccess = providers.getMetaAccess(); - ResolvedJavaType type = metaAccess.lookupJavaType(HotSpotOptimizedCallTarget.class); + ResolvedJavaType type = metaAccess.lookupJavaType(OptimizedCallTarget.class); for (ResolvedJavaMethod method : type.getDeclaredMethods()) { if (method.getAnnotation(TruffleCallBoundary.class) != null) { CompilationResult compResult = compileMethod(method); diff -r 59f71608aa9a -r ea9d5b6044af graal/com.oracle.graal.truffle.hotspot/src/com/oracle/graal/truffle/hotspot/substitutions/HotSpotOptimizedCallTargetSubstitutions.java --- a/graal/com.oracle.graal.truffle.hotspot/src/com/oracle/graal/truffle/hotspot/substitutions/HotSpotOptimizedCallTargetSubstitutions.java Thu Apr 17 16:51:51 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.hotspot.substitutions; - -import com.oracle.graal.api.replacements.*; -import com.oracle.graal.truffle.hotspot.*; - -@ClassSubstitution(HotSpotOptimizedCallTarget.class) -public class HotSpotOptimizedCallTargetSubstitutions { - -} diff -r 59f71608aa9a -r ea9d5b6044af graal/com.oracle.graal.truffle/src/com/oracle/graal/truffle/CompilationProfile.java --- a/graal/com.oracle.graal.truffle/src/com/oracle/graal/truffle/CompilationProfile.java Thu Apr 17 16:51:51 2014 +0200 +++ b/graal/com.oracle.graal.truffle/src/com/oracle/graal/truffle/CompilationProfile.java Thu Apr 17 17:40:20 2014 +0200 @@ -40,8 +40,6 @@ private long previousTimestamp; - private final String name; - private int callCount; private int callAndLoopCount; private int compilationCallThreshold; @@ -50,13 +48,12 @@ private final int originalInvokeCounter; private final int originalCompilationThreshold; - public CompilationProfile(final int compilationThreshold, final int initialInvokeCounter, final String name) { + public CompilationProfile(final int compilationThreshold, final int initialInvokeCounter) { this.previousTimestamp = System.nanoTime(); this.compilationCallThreshold = initialInvokeCounter; this.compilationCallAndLoopThreshold = compilationThreshold; this.originalInvokeCounter = initialInvokeCounter; this.originalCompilationThreshold = compilationThreshold; - this.name = name; } @Override @@ -86,10 +83,6 @@ return previousTimestamp; } - public String getName() { - return this.name; - } - public int getInvalidationCount() { return invalidationCount; } diff -r 59f71608aa9a -r ea9d5b6044af 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:51:51 2014 +0200 +++ b/graal/com.oracle.graal.truffle/src/com/oracle/graal/truffle/OptimizedCallTarget.java Thu Apr 17 17:40:20 2014 +0200 @@ -38,10 +38,12 @@ /** * Call target that is optimized by Graal upon surpassing a specific invocation threshold. */ -public abstract class OptimizedCallTarget extends InstalledCode implements RootCallTarget, LoopCountReceiver, ReplaceObserver { +public class OptimizedCallTarget extends InstalledCode implements RootCallTarget, LoopCountReceiver, ReplaceObserver { protected static final PrintStream OUT = TTY.out().out(); + protected final GraalTruffleRuntime runtime; + private SpeculationLog speculationLog; protected int callCount; protected boolean inliningPerformed; protected final CompilationProfile compilationProfile; @@ -55,17 +57,105 @@ return rootNode; } - public OptimizedCallTarget(RootNode rootNode, int invokeCounter, int compilationThreshold, CompilationPolicy compilationPolicy) { + public OptimizedCallTarget(RootNode rootNode, GraalTruffleRuntime runtime, int invokeCounter, int compilationThreshold, CompilationPolicy compilationPolicy, SpeculationLog speculationLog) { + this.runtime = runtime; + this.speculationLog = speculationLog; this.rootNode = rootNode; this.rootNode.adoptChildren(); this.rootNode.setCallTarget(this); this.compilationPolicy = compilationPolicy; - this.compilationProfile = new CompilationProfile(compilationThreshold, invokeCounter, rootNode.toString()); + this.compilationProfile = new CompilationProfile(compilationThreshold, invokeCounter); if (TruffleCallTargetProfiling.getValue()) { registerCallTarget(this); } } + public SpeculationLog getSpeculationLog() { + return speculationLog; + } + + @Override + public Object call(Object... args) { + return callBoundary(args); + } + + @TruffleCallBoundary + private Object callBoundary(Object[] args) { + if (CompilerDirectives.inInterpreter()) { + return compiledCallFallback(args); + } else { + // We come here from compiled code (i.e., we have been inlined). + return executeHelper(args); + } + } + + private Object compiledCallFallback(Object[] args) { + return interpreterCall(args); + } + + @Override + public void invalidate() { + this.runtime.invalidateInstalledCode(this); + } + + protected void invalidate(Node oldNode, Node newNode, CharSequence reason) { + if (isValid()) { + CompilerAsserts.neverPartOfCompilation(); + invalidate(); + compilationProfile.reportInvalidated(); + logOptimizedInvalidated(this, oldNode, newNode, reason); + } + cancelInstalledTask(oldNode, newNode, reason); + } + + private void cancelInstalledTask(Node oldNode, Node newNode, CharSequence reason) { + if (this.runtime.cancelInstalledTask(this)) { + logOptimizingUnqueued(this, oldNode, newNode, reason); + compilationProfile.reportInvalidated(); + } + } + + private Object interpreterCall(Object[] args) { + CompilerAsserts.neverPartOfCompilation(); + compilationProfile.reportInterpreterCall(); + if (TruffleCallTargetProfiling.getValue()) { + callCount++; + } + + if (compilationPolicy.shouldCompile(compilationProfile)) { + compile(); + if (isValid()) { + return call(args); + } + } + return executeHelper(args); + } + + public void compile() { + if (!runtime.isCompiling(this)) { + performInlining(); + logOptimizingQueued(this); + runtime.compile(this, TruffleBackgroundCompilation.getValue()); + } + } + + public void compilationFinished(Throwable t) { + if (t == null) { + // Compilation was successful. + } else { + compilationPolicy.recordCompilationFailure(t); + logOptimizingFailed(this, t.getMessage()); + if (t instanceof BailoutException) { + // Bailout => move on. + } else { + if (TruffleCompilationExceptionsAreFatal.getValue()) { + t.printStackTrace(OUT); + System.exit(-1); + } + } + } + } + protected final Object callProxy(VirtualFrame frame) { try { return getRootNode().execute(frame); @@ -111,11 +201,6 @@ return compilationProfile; } - @Override - public abstract Object call(Object... args); - - public abstract void compile(); - public final Object callInlined(Object[] arguments) { if (CompilerDirectives.inInterpreter()) { compilationProfile.reportInlinedCall(); @@ -150,8 +235,6 @@ } } - protected abstract void invalidate(Node oldNode, Node newNode, CharSequence reason); - public final Object executeHelper(Object[] args) { VirtualFrame frame = createFrame(getRootNode().getFrameDescriptor(), args); return callProxy(frame); @@ -176,8 +259,6 @@ invalidate(oldNode, newNode, reason); } - public abstract SpeculationLog getSpeculationLog(); - public Map getDebugProperties() { Map properties = new LinkedHashMap<>(); addASTSizeProperty(this, properties); @@ -185,7 +266,4 @@ return properties; } - - public abstract void compilationFinished(Throwable e); - }