changeset 22504:d80a5ff56f51

Storing the profiling enabled information in a static field; checking it only once; shielding against missing method in the TruffleRuntime interface
author Jaroslav Tulach <jaroslav.tulach@oracle.com>
date Thu, 17 Dec 2015 13:45:37 +0100
parents 828c67903db2
children c81e7280af42
files truffle/com.oracle.truffle.api.profiles/src/com/oracle/truffle/api/profiles/BranchProfile.java truffle/com.oracle.truffle.api.profiles/src/com/oracle/truffle/api/profiles/ByteValueProfile.java truffle/com.oracle.truffle.api.profiles/src/com/oracle/truffle/api/profiles/ConditionProfile.java truffle/com.oracle.truffle.api.profiles/src/com/oracle/truffle/api/profiles/DoubleValueProfile.java truffle/com.oracle.truffle.api.profiles/src/com/oracle/truffle/api/profiles/FloatValueProfile.java truffle/com.oracle.truffle.api.profiles/src/com/oracle/truffle/api/profiles/IntValueProfile.java truffle/com.oracle.truffle.api.profiles/src/com/oracle/truffle/api/profiles/LongValueProfile.java truffle/com.oracle.truffle.api.profiles/src/com/oracle/truffle/api/profiles/LoopConditionProfile.java truffle/com.oracle.truffle.api.profiles/src/com/oracle/truffle/api/profiles/PrimitiveValueProfile.java truffle/com.oracle.truffle.api.profiles/src/com/oracle/truffle/api/profiles/Profile.java truffle/com.oracle.truffle.api.profiles/src/com/oracle/truffle/api/profiles/ValueProfile.java
diffstat 11 files changed, 29 insertions(+), 23 deletions(-) [+]
line wrap: on
line diff
--- a/truffle/com.oracle.truffle.api.profiles/src/com/oracle/truffle/api/profiles/BranchProfile.java	Thu Dec 17 10:01:38 2015 +0100
+++ b/truffle/com.oracle.truffle.api.profiles/src/com/oracle/truffle/api/profiles/BranchProfile.java	Thu Dec 17 13:45:37 2015 +0100
@@ -26,7 +26,6 @@
 
 import com.oracle.truffle.api.CompilerDirectives;
 import com.oracle.truffle.api.CompilerDirectives.CompilationFinal;
-import com.oracle.truffle.api.Truffle;
 
 /**
  * <p>
@@ -78,7 +77,7 @@
      * Call to create a new instance of a branch profile.
      */
     public static BranchProfile create() {
-        if (Truffle.getRuntime().isProfilingEnabled()) {
+        if (Profile.isProfilingEnabled()) {
             return Enabled.create0();
         } else {
             return Disabled.INSTANCE;
--- a/truffle/com.oracle.truffle.api.profiles/src/com/oracle/truffle/api/profiles/ByteValueProfile.java	Thu Dec 17 10:01:38 2015 +0100
+++ b/truffle/com.oracle.truffle.api.profiles/src/com/oracle/truffle/api/profiles/ByteValueProfile.java	Thu Dec 17 13:45:37 2015 +0100
@@ -26,7 +26,6 @@
 
 import com.oracle.truffle.api.CompilerDirectives;
 import com.oracle.truffle.api.CompilerDirectives.CompilationFinal;
-import com.oracle.truffle.api.Truffle;
 
 /**
  * <p>
@@ -73,7 +72,7 @@
      * @see ByteValueProfile
      */
     public static ByteValueProfile createIdentityProfile() {
-        if (Truffle.getRuntime().isProfilingEnabled()) {
+        if (Profile.isProfilingEnabled()) {
             return Enabled.create();
         } else {
             return Disabled.INSTANCE;
--- a/truffle/com.oracle.truffle.api.profiles/src/com/oracle/truffle/api/profiles/ConditionProfile.java	Thu Dec 17 10:01:38 2015 +0100
+++ b/truffle/com.oracle.truffle.api.profiles/src/com/oracle/truffle/api/profiles/ConditionProfile.java	Thu Dec 17 13:45:37 2015 +0100
@@ -26,7 +26,6 @@
 
 import com.oracle.truffle.api.CompilerDirectives;
 import com.oracle.truffle.api.CompilerDirectives.CompilationFinal;
-import com.oracle.truffle.api.Truffle;
 
 /**
  * <p>
@@ -76,7 +75,7 @@
      * @see #createBinaryProfile()
      */
     public static ConditionProfile createCountingProfile() {
-        if (Truffle.getRuntime().isProfilingEnabled()) {
+        if (Profile.isProfilingEnabled()) {
             return Counting.create();
         } else {
             return Disabled.INSTANCE;
@@ -92,7 +91,7 @@
      * @see ConditionProfile#createCountingProfile()
      */
     public static ConditionProfile createBinaryProfile() {
-        if (Truffle.getRuntime().isProfilingEnabled()) {
+        if (Profile.isProfilingEnabled()) {
             return Binary.create();
         } else {
             return Disabled.INSTANCE;
--- a/truffle/com.oracle.truffle.api.profiles/src/com/oracle/truffle/api/profiles/DoubleValueProfile.java	Thu Dec 17 10:01:38 2015 +0100
+++ b/truffle/com.oracle.truffle.api.profiles/src/com/oracle/truffle/api/profiles/DoubleValueProfile.java	Thu Dec 17 13:45:37 2015 +0100
@@ -26,7 +26,6 @@
 
 import com.oracle.truffle.api.CompilerDirectives;
 import com.oracle.truffle.api.CompilerDirectives.CompilationFinal;
-import com.oracle.truffle.api.Truffle;
 
 /**
  * <p>
@@ -74,7 +73,7 @@
      * @see IntValueProfile
      */
     public static DoubleValueProfile createRawIdentityProfile() {
-        if (Truffle.getRuntime().isProfilingEnabled()) {
+        if (Profile.isProfilingEnabled()) {
             return Enabled.create();
         } else {
             return Disabled.INSTANCE;
--- a/truffle/com.oracle.truffle.api.profiles/src/com/oracle/truffle/api/profiles/FloatValueProfile.java	Thu Dec 17 10:01:38 2015 +0100
+++ b/truffle/com.oracle.truffle.api.profiles/src/com/oracle/truffle/api/profiles/FloatValueProfile.java	Thu Dec 17 13:45:37 2015 +0100
@@ -26,7 +26,6 @@
 
 import com.oracle.truffle.api.CompilerDirectives;
 import com.oracle.truffle.api.CompilerDirectives.CompilationFinal;
-import com.oracle.truffle.api.Truffle;
 
 /**
  * <p>
@@ -74,7 +73,7 @@
      * @see IntValueProfile
      */
     public static FloatValueProfile createRawIdentityProfile() {
-        if (Truffle.getRuntime().isProfilingEnabled()) {
+        if (Profile.isProfilingEnabled()) {
             return Enabled.create();
         } else {
             return Disabled.INSTANCE;
--- a/truffle/com.oracle.truffle.api.profiles/src/com/oracle/truffle/api/profiles/IntValueProfile.java	Thu Dec 17 10:01:38 2015 +0100
+++ b/truffle/com.oracle.truffle.api.profiles/src/com/oracle/truffle/api/profiles/IntValueProfile.java	Thu Dec 17 13:45:37 2015 +0100
@@ -26,7 +26,6 @@
 
 import com.oracle.truffle.api.CompilerDirectives;
 import com.oracle.truffle.api.CompilerDirectives.CompilationFinal;
-import com.oracle.truffle.api.Truffle;
 
 /**
  * <p>
@@ -73,7 +72,7 @@
      * @see IntValueProfile
      */
     public static IntValueProfile createIdentityProfile() {
-        if (Truffle.getRuntime().isProfilingEnabled()) {
+        if (Profile.isProfilingEnabled()) {
             return Enabled.create();
         } else {
             return Disabled.INSTANCE;
--- a/truffle/com.oracle.truffle.api.profiles/src/com/oracle/truffle/api/profiles/LongValueProfile.java	Thu Dec 17 10:01:38 2015 +0100
+++ b/truffle/com.oracle.truffle.api.profiles/src/com/oracle/truffle/api/profiles/LongValueProfile.java	Thu Dec 17 13:45:37 2015 +0100
@@ -26,7 +26,6 @@
 
 import com.oracle.truffle.api.CompilerDirectives;
 import com.oracle.truffle.api.CompilerDirectives.CompilationFinal;
-import com.oracle.truffle.api.Truffle;
 
 /**
  * <p>
@@ -72,7 +71,7 @@
      * @see LongValueProfile
      */
     public static LongValueProfile createIdentityProfile() {
-        if (Truffle.getRuntime().isProfilingEnabled()) {
+        if (Profile.isProfilingEnabled()) {
             return Enabled.create();
         } else {
             return Disabled.INSTANCE;
--- a/truffle/com.oracle.truffle.api.profiles/src/com/oracle/truffle/api/profiles/LoopConditionProfile.java	Thu Dec 17 10:01:38 2015 +0100
+++ b/truffle/com.oracle.truffle.api.profiles/src/com/oracle/truffle/api/profiles/LoopConditionProfile.java	Thu Dec 17 13:45:37 2015 +0100
@@ -26,7 +26,6 @@
 
 import com.oracle.truffle.api.CompilerDirectives;
 import com.oracle.truffle.api.CompilerDirectives.CompilationFinal;
-import com.oracle.truffle.api.Truffle;
 
 /**
  * <p>
@@ -118,7 +117,7 @@
      * @see LoopConditionProfile
      */
     public static LoopConditionProfile createCountingProfile() {
-        if (Truffle.getRuntime().isProfilingEnabled()) {
+        if (Profile.isProfilingEnabled()) {
             return Enabled.create();
         } else {
             return Disabled.INSTANCE;
--- a/truffle/com.oracle.truffle.api.profiles/src/com/oracle/truffle/api/profiles/PrimitiveValueProfile.java	Thu Dec 17 10:01:38 2015 +0100
+++ b/truffle/com.oracle.truffle.api.profiles/src/com/oracle/truffle/api/profiles/PrimitiveValueProfile.java	Thu Dec 17 13:45:37 2015 +0100
@@ -28,7 +28,6 @@
 
 import com.oracle.truffle.api.CompilerDirectives;
 import com.oracle.truffle.api.CompilerDirectives.CompilationFinal;
-import com.oracle.truffle.api.Truffle;
 
 /**
  * <p>
@@ -70,7 +69,7 @@
      * identity of a value.
      */
     public static PrimitiveValueProfile createEqualityProfile() {
-        if (Truffle.getRuntime().isProfilingEnabled()) {
+        if (Profile.isProfilingEnabled()) {
             return Enabled.create();
         } else {
             return Disabled.INSTANCE;
--- a/truffle/com.oracle.truffle.api.profiles/src/com/oracle/truffle/api/profiles/Profile.java	Thu Dec 17 10:01:38 2015 +0100
+++ b/truffle/com.oracle.truffle.api.profiles/src/com/oracle/truffle/api/profiles/Profile.java	Thu Dec 17 13:45:37 2015 +0100
@@ -27,6 +27,7 @@
 import com.oracle.truffle.api.Assumption;
 import com.oracle.truffle.api.CompilerDirectives;
 import com.oracle.truffle.api.CompilerDirectives.CompilationFinal;
+import com.oracle.truffle.api.Truffle;
 import com.oracle.truffle.api.TruffleRuntime;
 import com.oracle.truffle.api.nodes.Node;
 import com.oracle.truffle.api.nodes.NodeCloneable;
@@ -90,6 +91,21 @@
  * @see Assumption
  */
 public abstract class Profile extends NodeCloneable {
+    private static final boolean ENABLED;
+    static {
+        boolean enabled;
+        try {
+            enabled = Truffle.getRuntime().isProfilingEnabled();
+        } catch (NoSuchMethodError ex) {
+            // running on old version of Graal
+            enabled = true;
+        }
+        ENABLED = enabled;
+    }
+
+    static boolean isProfilingEnabled() {
+        return ENABLED;
+    }
 
     Profile() {
         /* We don't to allow custom profiles. We want to evolve this API further first. Sorry. */
--- a/truffle/com.oracle.truffle.api.profiles/src/com/oracle/truffle/api/profiles/ValueProfile.java	Thu Dec 17 10:01:38 2015 +0100
+++ b/truffle/com.oracle.truffle.api.profiles/src/com/oracle/truffle/api/profiles/ValueProfile.java	Thu Dec 17 13:45:37 2015 +0100
@@ -28,7 +28,6 @@
 
 import com.oracle.truffle.api.CompilerDirectives;
 import com.oracle.truffle.api.CompilerDirectives.CompilationFinal;
-import com.oracle.truffle.api.Truffle;
 
 /**
  * <p>
@@ -92,7 +91,7 @@
      * @see ValueProfile usage example
      */
     public static ValueProfile createClassProfile() {
-        if (Truffle.getRuntime().isProfilingEnabled()) {
+        if (Profile.isProfilingEnabled()) {
             return ExactClass.create();
         } else {
             return Disabled.INSTANCE;
@@ -112,7 +111,7 @@
      * </p>
      */
     public static ValueProfile createIdentityProfile() {
-        if (Truffle.getRuntime().isProfilingEnabled()) {
+        if (Profile.isProfilingEnabled()) {
             return Identity.create();
         } else {
             return Disabled.INSTANCE;
@@ -135,7 +134,7 @@
      * </p>
      */
     public static ValueProfile createEqualityProfile() {
-        if (Truffle.getRuntime().isProfilingEnabled()) {
+        if (Profile.isProfilingEnabled()) {
             return Equality.create();
         } else {
             return Disabled.INSTANCE;