changeset 15163:e5265dc8762f

Truffle: Clean ups around optimized call target.
author Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
date Tue, 15 Apr 2014 15:31:01 +0200
parents dbb1fe8348e6
children 62e218478931
files graal/com.oracle.graal.truffle.hotspot/src/com/oracle/graal/truffle/hotspot/HotSpotOptimizedCallTarget.java graal/com.oracle.graal.truffle.hotspot/src/com/oracle/graal/truffle/hotspot/HotSpotTruffleRuntime.java graal/com.oracle.graal.truffle.hotspot/src/com/oracle/graal/truffle/hotspot/substitutions/HotSpotOptimizedCallTargetSubstitutions.java graal/com.oracle.graal.truffle/src/com/oracle/graal/truffle/PartialEvaluator.java graal/com.oracle.graal.truffle/src/com/oracle/graal/truffle/TruffleCacheImpl.java graal/com.oracle.graal.truffle/src/com/oracle/graal/truffle/TruffleCallBoundary.java graal/com.oracle.graal.truffle/src/com/oracle/graal/truffle/TruffleCompilerOptions.java
diffstat 7 files changed, 88 insertions(+), 37 deletions(-) [+]
line wrap: on
line diff
--- a/graal/com.oracle.graal.truffle.hotspot/src/com/oracle/graal/truffle/hotspot/HotSpotOptimizedCallTarget.java	Tue Apr 15 15:22:37 2014 +0200
+++ b/graal/com.oracle.graal.truffle.hotspot/src/com/oracle/graal/truffle/hotspot/HotSpotOptimizedCallTarget.java	Tue Apr 15 15:31:01 2014 +0200
@@ -56,18 +56,27 @@
         return installedCode != null || installedCodeTask != null;
     }
 
-    @CompilerDirectives.SlowPath
     @Override
     public Object call(Object... args) {
-        return CompilerDirectives.inInterpreter() ? callHelper(args) : executeHelper(args);
+        return callBoundary(args);
     }
 
-    private Object callHelper(Object[] args) {
-        if (installedCode.isValid()) {
+    @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) {
+        InstalledCode currentInstalledCode = installedCode;
+        if (currentInstalledCode.isValid()) {
             reinstallCallMethodShortcut();
-        }
-        if (TruffleCallTargetProfiling.getValue()) {
-            callCount++;
+        } else {
+            return compiledCodeInvalidated(args);
         }
         return interpreterCall(args);
     }
@@ -109,6 +118,9 @@
     private Object interpreterCall(Object[] args) {
         CompilerAsserts.neverPartOfCompilation();
         compilationProfile.reportInterpreterCall();
+        if (TruffleCallTargetProfiling.getValue()) {
+            callCount++;
+        }
 
         if (compilationEnabled && compilationPolicy.shouldCompile(compilationProfile)) {
             compile();
--- a/graal/com.oracle.graal.truffle.hotspot/src/com/oracle/graal/truffle/hotspot/HotSpotTruffleRuntime.java	Tue Apr 15 15:22:37 2014 +0200
+++ b/graal/com.oracle.graal.truffle.hotspot/src/com/oracle/graal/truffle/hotspot/HotSpotTruffleRuntime.java	Tue Apr 15 15:31:01 2014 +0200
@@ -175,25 +175,43 @@
         }
     }
 
-    public static void installOptimizedCallTargetCallMethod() {
-        Providers providers = getGraalProviders();
-        MetaAccessProvider metaAccess = providers.getMetaAccess();
-        CodeCacheProvider codeCache = providers.getCodeCache();
-        ResolvedJavaMethod resolvedCallMethod = metaAccess.lookupJavaMethod(getCallMethod());
-        CompilationResult compResult = compileMethod(resolvedCallMethod);
-        try (Scope s = Debug.scope("CodeInstall", codeCache, resolvedCallMethod)) {
-            codeCache.setDefaultMethod(resolvedCallMethod, compResult);
+    private static Method[] callBoundaryMethods;
+
+    public static boolean isCallBoundaryMethod(ResolvedJavaMethod method) {
+        for (Method m : getCallBoundaryMethods()) {
+            Providers providers = getGraalProviders();
+            ResolvedJavaMethod current = providers.getMetaAccess().lookupJavaMethod(m);
+            if (current.equals(method)) {
+                return true;
+            }
         }
+        return false;
     }
 
-    private static Method getCallMethod() {
-        Method method;
-        try {
-            method = HotSpotOptimizedCallTarget.class.getDeclaredMethod("call", new Class[]{Object[].class});
-        } catch (NoSuchMethodException | SecurityException e) {
-            throw GraalInternalError.shouldNotReachHere();
+    public static Method[] getCallBoundaryMethods() {
+        if (callBoundaryMethods == null) {
+            try {
+                callBoundaryMethods = new Method[]{HotSpotOptimizedCallTarget.class.getDeclaredMethod("callBoundary", new Class[]{Object[].class})};
+            } catch (NoSuchMethodException | SecurityException e) {
+                throw GraalInternalError.shouldNotReachHere();
+            }
         }
-        return method;
+
+        return callBoundaryMethods;
+    }
+
+    public static void installOptimizedCallTargetCallMethod() {
+        Method[] methods = getCallBoundaryMethods();
+        for (Method method : methods) {
+            Providers providers = getGraalProviders();
+            MetaAccessProvider metaAccess = providers.getMetaAccess();
+            CodeCacheProvider codeCache = providers.getCodeCache();
+            ResolvedJavaMethod resolvedCallMethod = metaAccess.lookupJavaMethod(method);
+            CompilationResult compResult = compileMethod(resolvedCallMethod);
+            try (Scope s = Debug.scope("CodeInstall", codeCache, resolvedCallMethod)) {
+                codeCache.setDefaultMethod(resolvedCallMethod, compResult);
+            }
+        }
     }
 
     private static CompilationResultBuilderFactory getOptimizedCallTargetInstrumentationFactory(String arch, ResolvedJavaMethod method) {
--- a/graal/com.oracle.graal.truffle.hotspot/src/com/oracle/graal/truffle/hotspot/substitutions/HotSpotOptimizedCallTargetSubstitutions.java	Tue Apr 15 15:22:37 2014 +0200
+++ b/graal/com.oracle.graal.truffle.hotspot/src/com/oracle/graal/truffle/hotspot/substitutions/HotSpotOptimizedCallTargetSubstitutions.java	Tue Apr 15 15:31:01 2014 +0200
@@ -23,20 +23,9 @@
 package com.oracle.graal.truffle.hotspot.substitutions;
 
 import com.oracle.graal.api.replacements.*;
-import com.oracle.graal.nodes.spi.*;
-import com.oracle.graal.truffle.*;
 import com.oracle.graal.truffle.hotspot.*;
-import com.oracle.graal.truffle.nodes.asserts.*;
 
 @ClassSubstitution(HotSpotOptimizedCallTarget.class)
 public class HotSpotOptimizedCallTargetSubstitutions {
 
-    @MacroSubstitution(macro = NeverInlineMacroNode.class, isStatic = false)
-    public static native Object callHelper(OptimizedCallTarget target, Object[] args);
-
-    @MacroSubstitution(macro = NeverInlineMacroNode.class, isStatic = false)
-    public static native Object interpreterCall(OptimizedCallTarget target, Object[] args);
-
-    @MacroSubstitution(macro = NeverInlineMacroNode.class, isStatic = false)
-    public static native Object compiledCodeInvalidated(OptimizedCallTarget target, Object[] args);
 }
--- a/graal/com.oracle.graal.truffle/src/com/oracle/graal/truffle/PartialEvaluator.java	Tue Apr 15 15:22:37 2014 +0200
+++ b/graal/com.oracle.graal.truffle/src/com/oracle/graal/truffle/PartialEvaluator.java	Tue Apr 15 15:31:01 2014 +0200
@@ -201,7 +201,7 @@
                         }
 
                         StructuredGraph inlineGraph = replacements.getMethodSubstitution(methodCallTargetNode.targetMethod());
-                        if (inlineGraph == null && !Modifier.isNative(methodCallTargetNode.targetMethod().getModifiers())) {
+                        if (inlineGraph == null && !Modifier.isNative(methodCallTargetNode.targetMethod().getModifiers()) && methodCallTargetNode.targetMethod().canBeInlined()) {
                             inlineGraph = parseGraph(methodCallTargetNode.targetMethod(), methodCallTargetNode.arguments(), assumptions, phaseContext, false);
                         }
 
--- a/graal/com.oracle.graal.truffle/src/com/oracle/graal/truffle/TruffleCacheImpl.java	Tue Apr 15 15:22:37 2014 +0200
+++ b/graal/com.oracle.graal.truffle/src/com/oracle/graal/truffle/TruffleCacheImpl.java	Tue Apr 15 15:31:01 2014 +0200
@@ -264,9 +264,10 @@
     }
 
     private boolean shouldInline(final MethodCallTargetNode methodCallTargetNode) {
-        return (methodCallTargetNode.invokeKind() == InvokeKind.Special || methodCallTargetNode.invokeKind() == InvokeKind.Static) &&
+        boolean result = (methodCallTargetNode.invokeKind() == InvokeKind.Special || methodCallTargetNode.invokeKind() == InvokeKind.Static) && methodCallTargetNode.targetMethod().canBeInlined() &&
                         !Modifier.isNative(methodCallTargetNode.targetMethod().getModifiers()) && methodCallTargetNode.targetMethod().getAnnotation(ExplodeLoop.class) == null &&
                         methodCallTargetNode.targetMethod().getAnnotation(CompilerDirectives.SlowPath.class) == null &&
                         !methodCallTargetNode.targetMethod().getDeclaringClass().equals(stringBuilderClass);
+        return result;
     }
 }
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/graal/com.oracle.graal.truffle/src/com/oracle/graal/truffle/TruffleCallBoundary.java	Tue Apr 15 15:31:01 2014 +0200
@@ -0,0 +1,31 @@
+/*
+ * Copyright (c) 2014, 2014, 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 java.lang.annotation.*;
+
+@Retention(RetentionPolicy.RUNTIME)
+@Target(ElementType.METHOD)
+public @interface TruffleCallBoundary {
+
+}
--- a/graal/com.oracle.graal.truffle/src/com/oracle/graal/truffle/TruffleCompilerOptions.java	Tue Apr 15 15:22:37 2014 +0200
+++ b/graal/com.oracle.graal.truffle/src/com/oracle/graal/truffle/TruffleCompilerOptions.java	Tue Apr 15 15:31:01 2014 +0200
@@ -44,9 +44,9 @@
     @Option(help = "Restrict compilation to comma-separated list of includes (or excludes prefixed with tilde)")
     public static final OptionValue<String> TruffleCompileOnly = new OptionValue<>(null);
     @Option(help = "Compile call target when call count exceeds this threshold")
-    public static final OptionValue<Integer> TruffleCompilationThreshold = new OptionValue<>(3);
+    public static final OptionValue<Integer> TruffleCompilationThreshold = new OptionValue<>(1000);
     @Option(help = "Minimum number of calls before a call target is compiled")
-    public static final OptionValue<Integer> TruffleMinInvokeThreshold = new OptionValue<>(1000);
+    public static final OptionValue<Integer> TruffleMinInvokeThreshold = new OptionValue<>(3);
     @Option(help = "Delay compilation after an invalidation to allow for reprofiling")
     public static final OptionValue<Integer> TruffleInvalidationReprofileCount = new OptionValue<>(3);
     @Option(help = "Delay compilation after a node replacement")