changeset 12478:b4b7d39cdf73

Truffle: Update for the CompilationPolicy
author Christian Wirth <christian.wirth@oracle.com>
date Fri, 18 Oct 2013 13:49:41 +0200
parents a5d83166dca6
children 36a438ebab50
files graal/com.oracle.graal.truffle/src/com/oracle/graal/truffle/CompilationPolicy.java graal/com.oracle.graal.truffle/src/com/oracle/graal/truffle/OptimizedCallTarget.java graal/com.oracle.graal.truffle/src/com/oracle/graal/truffle/TruffleCompilerOptions.java
diffstat 3 files changed, 23 insertions(+), 10 deletions(-) [+]
line wrap: on
line diff
--- a/graal/com.oracle.graal.truffle/src/com/oracle/graal/truffle/CompilationPolicy.java	Thu Oct 17 19:59:25 2013 -0700
+++ b/graal/com.oracle.graal.truffle/src/com/oracle/graal/truffle/CompilationPolicy.java	Fri Oct 18 13:49:41 2013 +0200
@@ -31,17 +31,21 @@
     private int loopAndInvokeCounter;
     private long prevTimestamp;
 
-    private final int initialInvokeCounter;
     private final int compilationThreshold;
+    private final String name;
 
-    public CompilationPolicy(final int compilationThreshold, final int initialInvokeCounter) {
+    public CompilationPolicy(final int compilationThreshold, final int initialInvokeCounter, final String name) {
         this.invokeCounter = initialInvokeCounter;
         this.loopAndInvokeCounter = compilationThreshold;
         this.originalInvokeCounter = compilationThreshold;
-        this.prevTimestamp = System.currentTimeMillis();
+        this.prevTimestamp = System.nanoTime();
 
         this.compilationThreshold = compilationThreshold;
-        this.initialInvokeCounter = initialInvokeCounter;
+        this.name = name;
+    }
+
+    public String getName() {
+        return this.name;
     }
 
     public int getInvokeCounter() {
@@ -91,19 +95,23 @@
     public boolean compileOrInline() {
         if (invokeCounter <= 0 && loopAndInvokeCounter <= 0) {
             if (TruffleUseTimeForCompilationDecision.getValue()) {
-                long timestamp = System.currentTimeMillis();
-                if ((timestamp - prevTimestamp) < TruffleCompilationDecisionTime.getValue()) {
+                long timestamp = System.nanoTime();
+                long timespan = (timestamp - prevTimestamp);
+                if (timespan < (TruffleCompilationDecisionTime.getValue())) {
                     return true;
                 }
-                this.invokeCounter = initialInvokeCounter;
                 this.loopAndInvokeCounter = compilationThreshold;
                 this.originalInvokeCounter = compilationThreshold;
                 this.prevTimestamp = timestamp;
+                if (TruffleCompilationDecisionTimePrintFail.getValue()) {
+                    // Checkstyle: stop
+                    System.out.println(name + ": timespan  " + (timespan / 1000000) + " ms  larger than threshold");
+                    // Checkstyle: resume
+                }
             } else {
                 return true;
             }
         }
         return false;
     }
-
 }
--- a/graal/com.oracle.graal.truffle/src/com/oracle/graal/truffle/OptimizedCallTarget.java	Thu Oct 17 19:59:25 2013 -0700
+++ b/graal/com.oracle.graal.truffle/src/com/oracle/graal/truffle/OptimizedCallTarget.java	Fri Oct 18 13:49:41 2013 +0200
@@ -46,7 +46,7 @@
     protected OptimizedCallTarget(RootNode rootNode, FrameDescriptor descriptor, TruffleCompiler compiler, int invokeCounter, int compilationThreshold) {
         super(rootNode, descriptor);
         this.compiler = compiler;
-        this.compilationPolicy = new CompilationPolicy(compilationThreshold, invokeCounter);
+        this.compilationPolicy = new CompilationPolicy(compilationThreshold, invokeCounter, rootNode.toString());
         this.rootNode.setCallTarget(this);
 
         if (TruffleCallTargetProfiling.getValue()) {
--- a/graal/com.oracle.graal.truffle/src/com/oracle/graal/truffle/TruffleCompilerOptions.java	Thu Oct 17 19:59:25 2013 -0700
+++ b/graal/com.oracle.graal.truffle/src/com/oracle/graal/truffle/TruffleCompilerOptions.java	Fri Oct 18 13:49:41 2013 +0200
@@ -70,7 +70,12 @@
     @Option(help = "")
     public static final OptionValue<Boolean> TruffleUseTimeForCompilationDecision = new OptionValue<>(false);
     @Option(help = "")
-    public static final OptionValue<Integer> TruffleCompilationDecisionTime = new OptionValue<>(100);
+    public static final OptionValue<Long> TruffleCompilationDecisionTime = new OptionValue<>(100 * 1000000L);
+    @Option(help = "")
+    public static final OptionValue<Boolean> TruffleCompilationDecisionTimePrintFail = new OptionValue<>(false);
+    @Option(help = "")
+    public static final OptionValue<Boolean> TruffleBackgroundCompilation = new OptionValue<>(true);
+
     // tracing
     @Option(help = "")
     public static final OptionValue<Boolean> TraceTruffleCompilation = new OptionValue<>(true);