diff graal/com.oracle.graal.truffle/src/com/oracle/graal/truffle/OptimizedCallTarget.java @ 12591:33fe56e68abd

Simplifications of OptimizedCallTarget.
author Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
date Thu, 17 Oct 2013 14:28:37 +0200
parents 139b84d713bc
children 42c8f76a98bf
line wrap: on
line diff
--- a/graal/com.oracle.graal.truffle/src/com/oracle/graal/truffle/OptimizedCallTarget.java	Wed Oct 16 21:44:51 2013 +0200
+++ b/graal/com.oracle.graal.truffle/src/com/oracle/graal/truffle/OptimizedCallTarget.java	Thu Oct 17 14:28:37 2013 +0200
@@ -29,7 +29,6 @@
 
 import com.oracle.graal.api.code.*;
 import com.oracle.graal.debug.*;
-import com.oracle.graal.hotspot.meta.*;
 import com.oracle.truffle.api.*;
 import com.oracle.truffle.api.frame.*;
 import com.oracle.truffle.api.impl.*;
@@ -54,21 +53,21 @@
         }
     }
 
-    private HotSpotNmethod compiledMethod;
+    private InstalledCode installedCode;
     private final TruffleCompiler compiler;
     private final CompilationPolicy compilationPolicy;
+    private boolean disableCompilation;
+    private int callCount;
 
-    private boolean disableCompilation;
-
-    private int callCount;
+    /**
+     * Number of times an installed code for this tree was invalidated.
+     */
     private int invalidationCount;
-    private int replaceCount;
-    long timeCompilationStarted;
-    long timePartialEvaluationFinished;
-    long timeCompilationFinished;
-    int codeSize;
-    int nodeCountPartialEval;
-    int nodeCountLowered;
+
+    /**
+     * Number of times a node was replaced in this tree.
+     */
+    private int nodeReplaceCount;
 
     @Override
     public Object call(PackedFrame caller, Arguments args) {
@@ -79,9 +78,9 @@
         if (TruffleCallTargetProfiling.getValue()) {
             callCount++;
         }
-        if (CompilerDirectives.injectBranchProbability(CompilerDirectives.FASTPATH_PROBABILITY, compiledMethod != null)) {
+        if (CompilerDirectives.injectBranchProbability(CompilerDirectives.FASTPATH_PROBABILITY, installedCode != null)) {
             try {
-                return compiledMethod.execute(this, caller, args);
+                return installedCode.execute(this, caller, args);
             } catch (InvalidInstalledCodeException ex) {
                 return compiledCodeInvalidated(caller, args);
             }
@@ -91,15 +90,21 @@
     }
 
     private Object compiledCodeInvalidated(PackedFrame caller, Arguments args) {
-        CompilerAsserts.neverPartOfCompilation();
-        compiledMethod = null;
-        invalidationCount++;
-        compilationPolicy.compilationInvalidated();
-        if (TraceTruffleCompilation.getValue()) {
-            OUT.printf("[truffle] invalidated %-48s |Alive %5.0fms |Inv# %d                                     |Replace# %d\n", rootNode, (System.nanoTime() - timeCompilationFinished) / 1e6,
-                            invalidationCount, replaceCount);
+        invalidate();
+        return call(caller, args);
+    }
+
+    private void invalidate() {
+        InstalledCode m = this.installedCode;
+        if (m != null) {
+            CompilerAsserts.neverPartOfCompilation();
+            installedCode = null;
+            invalidationCount++;
+            compilationPolicy.compilationInvalidated();
+            if (TraceTruffleCompilation.getValue()) {
+                OUT.printf("[truffle] invalidated %-48s |Inv# %d                                     |Replace# %d\n", rootNode, invalidationCount, nodeReplaceCount);
+            }
         }
-        return call(caller, args);
     }
 
     private Object interpreterCall(PackedFrame caller, Arguments args) {
@@ -129,16 +134,10 @@
     public void compile() {
         CompilerAsserts.neverPartOfCompilation();
         try {
-            compiledMethod = (HotSpotNmethod) compiler.compile(this);
-            if (compiledMethod == null) {
-                throw new BailoutException(String.format("code installation failed (codeSize=%s)", codeSize));
+            installedCode = compiler.compile(this);
+            if (installedCode == null) {
+                throw new BailoutException(String.format("code installation failed"));
             } else {
-                if (TraceTruffleCompilation.getValue()) {
-                    int nodeCountTruffle = NodeUtil.countNodes(rootNode);
-                    OUT.printf("[truffle] optimized %-50s |Nodes %7d |Time %5.0f(%4.0f+%-4.0f)ms |Nodes %5d/%5d |CodeSize %d\n", rootNode, nodeCountTruffle,
-                                    (timeCompilationFinished - timeCompilationStarted) / 1e6, (timePartialEvaluationFinished - timeCompilationStarted) / 1e6,
-                                    (timeCompilationFinished - timePartialEvaluationFinished) / 1e6, nodeCountPartialEval, nodeCountLowered, codeSize);
-                }
                 if (TruffleCallTargetProfiling.getValue()) {
                     resetProfiling();
                 }
@@ -182,13 +181,8 @@
 
     @Override
     public void nodeReplaced() {
-        replaceCount++;
-        if (compiledMethod != null) {
-            if (compiledMethod.isValid()) {
-                compiledMethod.invalidate();
-            }
-            compiledMethod = null;
-        }
+        nodeReplaceCount++;
+        invalidate();
         compilationPolicy.nodeReplaced();
     }
 
@@ -402,7 +396,7 @@
             int notInlinedCallSiteCount = InliningHelper.getInlinableCallSites(callTarget).size();
             int nodeCount = NodeUtil.countNodes(callTarget.rootNode);
             int inlinedCallSiteCount = NodeUtil.countNodes(callTarget.rootNode, InlinedCallSite.class);
-            String comment = callTarget.compiledMethod == null ? " int" : "";
+            String comment = callTarget.installedCode == null ? " int" : "";
             comment += callTarget.disableCompilation ? " fail" : "";
             OUT.printf("%-50s | %10d | %15d | %15d | %10d | %3d%s\n", callTarget.getRootNode(), callTarget.callCount, inlinedCallSiteCount, notInlinedCallSiteCount, nodeCount,
                             callTarget.invalidationCount, comment);