changeset 16852:3c114b3e08c3

Truffle: renamed BooleanConditionProfile to BinaryConditionProfile and IntegerConditionProfile to CountingConditionProfile.
author Christian Humer <christian.humer@gmail.com>
date Mon, 18 Aug 2014 19:00:20 +0200
parents 2db61eddcb97
children bcfb6f72ace6
files CHANGELOG.md graal/com.oracle.truffle.api.test/src/com/oracle/truffle/api/test/utilities/BooleanConditionProfileTest.java graal/com.oracle.truffle.api.test/src/com/oracle/truffle/api/test/utilities/IntegerConditionProfileTest.java graal/com.oracle.truffle.api/src/com/oracle/truffle/api/utilities/BinaryConditionProfile.java graal/com.oracle.truffle.api/src/com/oracle/truffle/api/utilities/BooleanConditionProfile.java graal/com.oracle.truffle.api/src/com/oracle/truffle/api/utilities/ConditionProfile.java graal/com.oracle.truffle.api/src/com/oracle/truffle/api/utilities/CountingConditionProfile.java graal/com.oracle.truffle.api/src/com/oracle/truffle/api/utilities/IntegerConditionProfile.java
diffstat 8 files changed, 186 insertions(+), 186 deletions(-) [+]
line wrap: on
line diff
--- a/CHANGELOG.md	Mon Aug 18 18:41:16 2014 +0200
+++ b/CHANGELOG.md	Mon Aug 18 19:00:20 2014 +0200
@@ -22,7 +22,7 @@
 * New flag -G:TruffleSplittingStartCallCount=3 which sets the number of minimal calls until splitting is performed.
 * New flag -G:-TruffleSplittingAggressive if enabled splits every function call.
 * Added isVisited method for BranchProfile.
-* Added new ConditionProfile, BooleanConditionProfile and IntegerConditionProfile utility classes to profile if conditions.
+* Added new ConditionProfile, BinaryConditionProfile and CountingConditionProfile utility classes to profile if conditions.
 * ...
 
 ## Version 0.3
--- a/graal/com.oracle.truffle.api.test/src/com/oracle/truffle/api/test/utilities/BooleanConditionProfileTest.java	Mon Aug 18 18:41:16 2014 +0200
+++ b/graal/com.oracle.truffle.api.test/src/com/oracle/truffle/api/test/utilities/BooleanConditionProfileTest.java	Mon Aug 18 19:00:20 2014 +0200
@@ -38,14 +38,14 @@
 
     @Test
     public void testInitial() {
-        BooleanConditionProfile profile = new BooleanConditionProfile();
+        BinaryConditionProfile profile = new BinaryConditionProfile();
         assertThat(profile.wasTrue(), is(false));
         assertThat(profile.wasFalse(), is(false));
     }
 
     @Theory
     public void testProfileOne(boolean value) {
-        BooleanConditionProfile profile = new BooleanConditionProfile();
+        BinaryConditionProfile profile = new BinaryConditionProfile();
         boolean result = profile.profile(value);
 
         assertThat(result, is(value));
@@ -55,7 +55,7 @@
 
     @Theory
     public void testProfileTwo(boolean value0, boolean value1) {
-        BooleanConditionProfile profile = new BooleanConditionProfile();
+        BinaryConditionProfile profile = new BinaryConditionProfile();
         boolean result0 = profile.profile(value0);
         boolean result1 = profile.profile(value1);
 
@@ -67,7 +67,7 @@
 
     @Theory
     public void testProfileThree(boolean value0, boolean value1, boolean value2) {
-        BooleanConditionProfile profile = new BooleanConditionProfile();
+        BinaryConditionProfile profile = new BinaryConditionProfile();
         boolean result0 = profile.profile(value0);
         boolean result1 = profile.profile(value1);
         boolean result2 = profile.profile(value2);
--- a/graal/com.oracle.truffle.api.test/src/com/oracle/truffle/api/test/utilities/IntegerConditionProfileTest.java	Mon Aug 18 18:41:16 2014 +0200
+++ b/graal/com.oracle.truffle.api.test/src/com/oracle/truffle/api/test/utilities/IntegerConditionProfileTest.java	Mon Aug 18 19:00:20 2014 +0200
@@ -38,14 +38,14 @@
 
     @Test
     public void testInitial() {
-        IntegerConditionProfile profile = new IntegerConditionProfile();
+        CountingConditionProfile profile = new CountingConditionProfile();
         assertThat(profile.getTrueCount(), is(0));
         assertThat(profile.getFalseCount(), is(0));
     }
 
     @Theory
     public void testProfileOne(boolean value) {
-        IntegerConditionProfile profile = new IntegerConditionProfile();
+        CountingConditionProfile profile = new CountingConditionProfile();
         boolean result = profile.profile(value);
 
         assertThat(result, is(value));
@@ -55,7 +55,7 @@
 
     @Theory
     public void testProfileTwo(boolean value0, boolean value1) {
-        IntegerConditionProfile profile = new IntegerConditionProfile();
+        CountingConditionProfile profile = new CountingConditionProfile();
         boolean result0 = profile.profile(value0);
         boolean result1 = profile.profile(value1);
 
@@ -67,7 +67,7 @@
 
     @Theory
     public void testProfileThree(boolean value0, boolean value1, boolean value2) {
-        IntegerConditionProfile profile = new IntegerConditionProfile();
+        CountingConditionProfile profile = new CountingConditionProfile();
         boolean result0 = profile.profile(value0);
         boolean result1 = profile.profile(value1);
         boolean result2 = profile.profile(value2);
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/graal/com.oracle.truffle.api/src/com/oracle/truffle/api/utilities/BinaryConditionProfile.java	Mon Aug 18 19:00:20 2014 +0200
@@ -0,0 +1,84 @@
+/*
+ * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+package com.oracle.truffle.api.utilities;
+
+import com.oracle.truffle.api.*;
+import com.oracle.truffle.api.CompilerDirectives.*;
+
+/**
+ * Utility class to speculate on conditions to be never true or to be never false. Condition
+ * profiles are intended to be used as part of if conditions.
+ *
+ * Example usage:
+ *
+ * <pre>
+ * private final ConditionProfile zero = new BooleanConditionProfile();
+ * 
+ * int value = ...;
+ * if (zero.profile(value == 0)) {
+ *   return 0;
+ * } else {
+ *   return value;
+ * }
+ *
+ * </pre>
+ *
+ * @see ConditionProfile
+ * @see CountingConditionProfile
+ */
+public class BinaryConditionProfile extends ConditionProfile {
+
+    @CompilationFinal private boolean wasTrue;
+    @CompilationFinal private boolean wasFalse;
+
+    @Override
+    public boolean profile(boolean value) {
+        if (value) {
+            if (!wasTrue) {
+                CompilerDirectives.transferToInterpreterAndInvalidate();
+                wasTrue = true;
+            }
+        } else {
+            if (!wasFalse) {
+                CompilerDirectives.transferToInterpreterAndInvalidate();
+                wasFalse = true;
+            }
+        }
+        return value;
+    }
+
+    public boolean wasTrue() {
+        return wasTrue;
+    }
+
+    public boolean wasFalse() {
+        return wasFalse;
+    }
+
+    @Override
+    public String toString() {
+        return String.format("%s(wasTrue=%s, wasFalse=%s)@%x", getClass().getSimpleName(), wasTrue, wasFalse, hashCode());
+    }
+}
--- a/graal/com.oracle.truffle.api/src/com/oracle/truffle/api/utilities/BooleanConditionProfile.java	Mon Aug 18 18:41:16 2014 +0200
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,84 +0,0 @@
-/*
- * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved.
- * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
- *
- * This code is free software; you can redistribute it and/or modify it
- * under the terms of the GNU General Public License version 2 only, as
- * published by the Free Software Foundation.  Oracle designates this
- * particular file as subject to the "Classpath" exception as provided
- * by Oracle in the LICENSE file that accompanied this code.
- *
- * This code is distributed in the hope that it will be useful, but WITHOUT
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
- * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
- * version 2 for more details (a copy is included in the LICENSE file that
- * accompanied this code).
- *
- * You should have received a copy of the GNU General Public License version
- * 2 along with this work; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
- *
- * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
- * or visit www.oracle.com if you need additional information or have any
- * questions.
- */
-package com.oracle.truffle.api.utilities;
-
-import com.oracle.truffle.api.*;
-import com.oracle.truffle.api.CompilerDirectives.*;
-
-/**
- * Utility class to speculate on conditions to be never true or to be never false. Condition
- * profiles are intended to be used as part of if conditions.
- *
- * Example usage:
- *
- * <pre>
- * private final ConditionProfile zero = new BooleanConditionProfile();
- * 
- * int value = ...;
- * if (zero.profile(value == 0)) {
- *   return 0;
- * } else {
- *   return value;
- * }
- *
- * </pre>
- *
- * @see ConditionProfile
- * @see IntegerConditionProfile
- */
-public class BooleanConditionProfile extends ConditionProfile {
-
-    @CompilationFinal private boolean wasTrue;
-    @CompilationFinal private boolean wasFalse;
-
-    @Override
-    public boolean profile(boolean value) {
-        if (value) {
-            if (!wasTrue) {
-                CompilerDirectives.transferToInterpreterAndInvalidate();
-                wasTrue = true;
-            }
-        } else {
-            if (!wasFalse) {
-                CompilerDirectives.transferToInterpreterAndInvalidate();
-                wasFalse = true;
-            }
-        }
-        return value;
-    }
-
-    public boolean wasTrue() {
-        return wasTrue;
-    }
-
-    public boolean wasFalse() {
-        return wasFalse;
-    }
-
-    @Override
-    public String toString() {
-        return String.format("%s(wasTrue=%s, wasFalse=%s)@%x", getClass().getSimpleName(), wasTrue, wasFalse, hashCode());
-    }
-}
--- a/graal/com.oracle.truffle.api/src/com/oracle/truffle/api/utilities/ConditionProfile.java	Mon Aug 18 18:41:16 2014 +0200
+++ b/graal/com.oracle.truffle.api/src/com/oracle/truffle/api/utilities/ConditionProfile.java	Mon Aug 18 19:00:20 2014 +0200
@@ -42,8 +42,8 @@
  *
  * </pre>
  *
- * @see BooleanConditionProfile
- * @see IntegerConditionProfile
+ * @see BinaryConditionProfile
+ * @see CountingConditionProfile
  */
 public abstract class ConditionProfile {
 
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/graal/com.oracle.truffle.api/src/com/oracle/truffle/api/utilities/CountingConditionProfile.java	Mon Aug 18 19:00:20 2014 +0200
@@ -0,0 +1,91 @@
+/*
+ * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+package com.oracle.truffle.api.utilities;
+
+import com.oracle.truffle.api.*;
+import com.oracle.truffle.api.CompilerDirectives.*;
+
+/**
+ * Utility class to speculate on conditions to be never true or to be never false. Additionally to
+ * {@link BinaryConditionProfile} this implementation of {@link ConditionProfile} also counts the
+ * number of times the condition was true and false. This information is reported to the underlying
+ * optimization system using {@link CompilerDirectives#injectBranchProbability(double, boolean)}.
+ * Condition profiles are intended to be used as part of if conditions.
+ *
+ * Example usage:
+ *
+ * <pre>
+ * private final ConditionProfile zero = new IntegerConditionProfile();
+ * 
+ * int value = ...;
+ * if (zero.profile(value == 0)) {
+ *   return 0;
+ * } else {
+ *   return value;
+ * }
+ *
+ * </pre>
+ *
+ * @see ConditionProfile
+ * @see CountingConditionProfile
+ */
+public class CountingConditionProfile extends ConditionProfile {
+
+    @CompilationFinal private int trueCount;
+    @CompilationFinal private int falseCount;
+
+    @Override
+    public boolean profile(boolean value) {
+        if (value) {
+            if (trueCount == 0) {
+                CompilerDirectives.transferToInterpreterAndInvalidate();
+            }
+            if (CompilerDirectives.inInterpreter()) {
+                trueCount++;
+            }
+        } else {
+            if (falseCount == 0) {
+                CompilerDirectives.transferToInterpreterAndInvalidate();
+            }
+            if (CompilerDirectives.inInterpreter()) {
+                falseCount++;
+            }
+        }
+        return CompilerDirectives.injectBranchProbability((double) trueCount / (double) (trueCount + falseCount), value);
+    }
+
+    public int getTrueCount() {
+        return trueCount;
+    }
+
+    public int getFalseCount() {
+        return falseCount;
+    }
+
+    @Override
+    public String toString() {
+        return String.format("%s(trueCount=%s, falseCount=%s)@%x", getClass().getSimpleName(), trueCount, falseCount, hashCode());
+    }
+}
--- a/graal/com.oracle.truffle.api/src/com/oracle/truffle/api/utilities/IntegerConditionProfile.java	Mon Aug 18 18:41:16 2014 +0200
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,91 +0,0 @@
-/*
- * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved.
- * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
- *
- * This code is free software; you can redistribute it and/or modify it
- * under the terms of the GNU General Public License version 2 only, as
- * published by the Free Software Foundation.  Oracle designates this
- * particular file as subject to the "Classpath" exception as provided
- * by Oracle in the LICENSE file that accompanied this code.
- *
- * This code is distributed in the hope that it will be useful, but WITHOUT
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
- * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
- * version 2 for more details (a copy is included in the LICENSE file that
- * accompanied this code).
- *
- * You should have received a copy of the GNU General Public License version
- * 2 along with this work; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
- *
- * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
- * or visit www.oracle.com if you need additional information or have any
- * questions.
- */
-package com.oracle.truffle.api.utilities;
-
-import com.oracle.truffle.api.*;
-import com.oracle.truffle.api.CompilerDirectives.*;
-
-/**
- * Utility class to speculate on conditions to be never true or to be never false. Additionally to
- * {@link BooleanConditionProfile} this implementation of {@link ConditionProfile} also counts the
- * number of times the condition was true and false. This information is reported to the underlying
- * optimization system using {@link CompilerDirectives#injectBranchProbability(double, boolean)}.
- * Condition profiles are intended to be used as part of if conditions.
- *
- * Example usage:
- *
- * <pre>
- * private final ConditionProfile zero = new IntegerConditionProfile();
- *
- * int value = ...;
- * if (zero.profile(value == 0)) {
- *   return 0;
- * } else {
- *   return value;
- * }
- *
- * </pre>
- *
- * @see ConditionProfile
- * @see IntegerConditionProfile
- */
-public class IntegerConditionProfile extends ConditionProfile {
-
-    @CompilationFinal private int trueCount;
-    @CompilationFinal private int falseCount;
-
-    @Override
-    public boolean profile(boolean value) {
-        if (value) {
-            if (trueCount == 0) {
-                CompilerDirectives.transferToInterpreterAndInvalidate();
-            }
-            if (CompilerDirectives.inInterpreter()) {
-                trueCount++;
-            }
-        } else {
-            if (falseCount == 0) {
-                CompilerDirectives.transferToInterpreterAndInvalidate();
-            }
-            if (CompilerDirectives.inInterpreter()) {
-                falseCount++;
-            }
-        }
-        return CompilerDirectives.injectBranchProbability((double) trueCount / (double) (trueCount + falseCount), value);
-    }
-
-    public int getTrueCount() {
-        return trueCount;
-    }
-
-    public int getFalseCount() {
-        return falseCount;
-    }
-
-    @Override
-    public String toString() {
-        return String.format("%s(trueCount=%s, falseCount=%s)@%x", getClass().getSimpleName(), trueCount, falseCount, hashCode());
-    }
-}