# HG changeset patch # User Jaroslav Tulach # Date 1450356337 -3600 # Node ID d80a5ff56f51482fa5d9af16dfc2cdd296eaf15a # Parent 828c67903db2d8db8b189804bd3d709de9a2aa1a Storing the profiling enabled information in a static field; checking it only once; shielding against missing method in the TruffleRuntime interface diff -r 828c67903db2 -r d80a5ff56f51 truffle/com.oracle.truffle.api.profiles/src/com/oracle/truffle/api/profiles/BranchProfile.java --- 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; /** *

@@ -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; diff -r 828c67903db2 -r d80a5ff56f51 truffle/com.oracle.truffle.api.profiles/src/com/oracle/truffle/api/profiles/ByteValueProfile.java --- 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; /** *

@@ -73,7 +72,7 @@ * @see ByteValueProfile */ public static ByteValueProfile createIdentityProfile() { - if (Truffle.getRuntime().isProfilingEnabled()) { + if (Profile.isProfilingEnabled()) { return Enabled.create(); } else { return Disabled.INSTANCE; diff -r 828c67903db2 -r d80a5ff56f51 truffle/com.oracle.truffle.api.profiles/src/com/oracle/truffle/api/profiles/ConditionProfile.java --- 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; /** *

@@ -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; diff -r 828c67903db2 -r d80a5ff56f51 truffle/com.oracle.truffle.api.profiles/src/com/oracle/truffle/api/profiles/DoubleValueProfile.java --- 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; /** *

@@ -74,7 +73,7 @@ * @see IntValueProfile */ public static DoubleValueProfile createRawIdentityProfile() { - if (Truffle.getRuntime().isProfilingEnabled()) { + if (Profile.isProfilingEnabled()) { return Enabled.create(); } else { return Disabled.INSTANCE; diff -r 828c67903db2 -r d80a5ff56f51 truffle/com.oracle.truffle.api.profiles/src/com/oracle/truffle/api/profiles/FloatValueProfile.java --- 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; /** *

@@ -74,7 +73,7 @@ * @see IntValueProfile */ public static FloatValueProfile createRawIdentityProfile() { - if (Truffle.getRuntime().isProfilingEnabled()) { + if (Profile.isProfilingEnabled()) { return Enabled.create(); } else { return Disabled.INSTANCE; diff -r 828c67903db2 -r d80a5ff56f51 truffle/com.oracle.truffle.api.profiles/src/com/oracle/truffle/api/profiles/IntValueProfile.java --- 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; /** *

@@ -73,7 +72,7 @@ * @see IntValueProfile */ public static IntValueProfile createIdentityProfile() { - if (Truffle.getRuntime().isProfilingEnabled()) { + if (Profile.isProfilingEnabled()) { return Enabled.create(); } else { return Disabled.INSTANCE; diff -r 828c67903db2 -r d80a5ff56f51 truffle/com.oracle.truffle.api.profiles/src/com/oracle/truffle/api/profiles/LongValueProfile.java --- 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; /** *

@@ -72,7 +71,7 @@ * @see LongValueProfile */ public static LongValueProfile createIdentityProfile() { - if (Truffle.getRuntime().isProfilingEnabled()) { + if (Profile.isProfilingEnabled()) { return Enabled.create(); } else { return Disabled.INSTANCE; diff -r 828c67903db2 -r d80a5ff56f51 truffle/com.oracle.truffle.api.profiles/src/com/oracle/truffle/api/profiles/LoopConditionProfile.java --- 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; /** *

@@ -118,7 +117,7 @@ * @see LoopConditionProfile */ public static LoopConditionProfile createCountingProfile() { - if (Truffle.getRuntime().isProfilingEnabled()) { + if (Profile.isProfilingEnabled()) { return Enabled.create(); } else { return Disabled.INSTANCE; diff -r 828c67903db2 -r d80a5ff56f51 truffle/com.oracle.truffle.api.profiles/src/com/oracle/truffle/api/profiles/PrimitiveValueProfile.java --- 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; /** *

@@ -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; diff -r 828c67903db2 -r d80a5ff56f51 truffle/com.oracle.truffle.api.profiles/src/com/oracle/truffle/api/profiles/Profile.java --- 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. */ diff -r 828c67903db2 -r d80a5ff56f51 truffle/com.oracle.truffle.api.profiles/src/com/oracle/truffle/api/profiles/ValueProfile.java --- 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; /** *

@@ -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 @@ *

*/ public static ValueProfile createIdentityProfile() { - if (Truffle.getRuntime().isProfilingEnabled()) { + if (Profile.isProfilingEnabled()) { return Identity.create(); } else { return Disabled.INSTANCE; @@ -135,7 +134,7 @@ *

*/ public static ValueProfile createEqualityProfile() { - if (Truffle.getRuntime().isProfilingEnabled()) { + if (Profile.isProfilingEnabled()) { return Equality.create(); } else { return Disabled.INSTANCE;