changeset 12591:33fe56e68abd

Simplifications of OptimizedCallTarget.
author Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
date Thu, 17 Oct 2013 14:28:37 +0200
parents ce82cdbffe47
children 42c8f76a98bf
files graal/com.oracle.graal.truffle/src/com/oracle/graal/truffle/OptimizedCallTarget.java graal/com.oracle.graal.truffle/src/com/oracle/graal/truffle/TruffleCompilerImpl.java
diffstat 2 files changed, 50 insertions(+), 52 deletions(-) [+]
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);
--- a/graal/com.oracle.graal.truffle/src/com/oracle/graal/truffle/TruffleCompilerImpl.java	Wed Oct 16 21:44:51 2013 +0200
+++ b/graal/com.oracle.graal.truffle/src/com/oracle/graal/truffle/TruffleCompilerImpl.java	Thu Oct 17 14:28:37 2013 +0200
@@ -23,7 +23,9 @@
 package com.oracle.graal.truffle;
 
 import static com.oracle.graal.api.code.CodeUtil.*;
+import static com.oracle.graal.truffle.TruffleCompilerOptions.*;
 
+import java.io.*;
 import java.util.*;
 import java.util.concurrent.*;
 
@@ -54,6 +56,8 @@
  */
 public class TruffleCompilerImpl implements TruffleCompiler {
 
+    private static final PrintStream OUT = TTY.out().out();
+
     private final Providers providers;
     private final Suites suites;
     private final PartialEvaluator partialEvaluator;
@@ -115,24 +119,27 @@
         config.setSkippedExceptionTypes(skippedExceptionTypes);
         runtime.evictDeoptedGraphs();
 
-        compilable.timeCompilationStarted = System.nanoTime();
+        long timeCompilationStarted = System.nanoTime();
         Assumptions assumptions = new Assumptions(true);
         try (TimerCloseable a = PartialEvaluationTime.start()) {
             graph = partialEvaluator.createGraph(compilable, assumptions);
         }
-        compilable.timePartialEvaluationFinished = System.nanoTime();
-        compilable.nodeCountPartialEval = graph.getNodeCount();
-        InstalledCode compiledMethod = compileMethodHelper(graph, config, compilable, assumptions);
-        compilable.timeCompilationFinished = System.nanoTime();
-        compilable.nodeCountLowered = graph.getNodeCount();
+        long timePartialEvaluationFinished = System.nanoTime();
+        int nodeCountPartialEval = graph.getNodeCount();
+        InstalledCode compiledMethod = compileMethodHelper(graph, config, assumptions);
+        long timeCompilationFinished = System.nanoTime();
+        int nodeCountLowered = graph.getNodeCount();
+
+        if (TraceTruffleCompilation.getValue() && compiledMethod != null) {
+            int nodeCountTruffle = NodeUtil.countNodes(compilable.getRootNode());
+            OUT.printf("[truffle] optimized %-50s |Nodes %7d |Time %5.0f(%4.0f+%-4.0f)ms |Nodes %5d/%5d |CodeSize %d\n", compilable.getRootNode(), nodeCountTruffle,
+                            (timeCompilationFinished - timeCompilationStarted) / 1e6, (timePartialEvaluationFinished - timeCompilationStarted) / 1e6,
+                            (timeCompilationFinished - timePartialEvaluationFinished) / 1e6, nodeCountPartialEval, nodeCountLowered, compiledMethod.getCode().length);
+        }
         return compiledMethod;
     }
 
     public InstalledCode compileMethodHelper(final StructuredGraph graph, final GraphBuilderConfiguration config, final Assumptions assumptions) {
-        return compileMethodHelper(graph, config, null, assumptions);
-    }
-
-    public InstalledCode compileMethodHelper(final StructuredGraph graph, final GraphBuilderConfiguration config, final OptimizedCallTarget compilable, final Assumptions assumptions) {
         final PhasePlan plan = createPhasePlan(config);
 
         Debug.scope("TruffleFinal", graph, new Runnable() {
@@ -193,9 +200,6 @@
         if (Debug.isLogEnabled()) {
             Debug.log(providers.getCodeCache().disassemble(result, compiledMethod));
         }
-        if (compilable != null) {
-            compilable.codeSize = result.getTargetCodeSize();
-        }
         return compiledMethod;
     }