# HG changeset patch # User Christian Humer # Date 1408381220 -7200 # Node ID 3c114b3e08c3e1eed6ff0e82b4ebfaa00153189c # Parent 2db61eddcb97f0d2396fb4718d99708e688b13ff Truffle: renamed BooleanConditionProfile to BinaryConditionProfile and IntegerConditionProfile to CountingConditionProfile. diff -r 2db61eddcb97 -r 3c114b3e08c3 CHANGELOG.md --- 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 diff -r 2db61eddcb97 -r 3c114b3e08c3 graal/com.oracle.truffle.api.test/src/com/oracle/truffle/api/test/utilities/BooleanConditionProfileTest.java --- 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); diff -r 2db61eddcb97 -r 3c114b3e08c3 graal/com.oracle.truffle.api.test/src/com/oracle/truffle/api/test/utilities/IntegerConditionProfileTest.java --- 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); diff -r 2db61eddcb97 -r 3c114b3e08c3 graal/com.oracle.truffle.api/src/com/oracle/truffle/api/utilities/BinaryConditionProfile.java --- /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: + * + *
+ * private final ConditionProfile zero = new BooleanConditionProfile();
+ * 
+ * int value = ...;
+ * if (zero.profile(value == 0)) {
+ *   return 0;
+ * } else {
+ *   return value;
+ * }
+ *
+ * 
+ * + * @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()); + } +} diff -r 2db61eddcb97 -r 3c114b3e08c3 graal/com.oracle.truffle.api/src/com/oracle/truffle/api/utilities/BooleanConditionProfile.java --- 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: - * - *
- * private final ConditionProfile zero = new BooleanConditionProfile();
- * 
- * int value = ...;
- * if (zero.profile(value == 0)) {
- *   return 0;
- * } else {
- *   return value;
- * }
- *
- * 
- * - * @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()); - } -} diff -r 2db61eddcb97 -r 3c114b3e08c3 graal/com.oracle.truffle.api/src/com/oracle/truffle/api/utilities/ConditionProfile.java --- 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 @@ * * * - * @see BooleanConditionProfile - * @see IntegerConditionProfile + * @see BinaryConditionProfile + * @see CountingConditionProfile */ public abstract class ConditionProfile { diff -r 2db61eddcb97 -r 3c114b3e08c3 graal/com.oracle.truffle.api/src/com/oracle/truffle/api/utilities/CountingConditionProfile.java --- /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: + * + *
+ * private final ConditionProfile zero = new IntegerConditionProfile();
+ * 
+ * int value = ...;
+ * if (zero.profile(value == 0)) {
+ *   return 0;
+ * } else {
+ *   return value;
+ * }
+ *
+ * 
+ * + * @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()); + } +} diff -r 2db61eddcb97 -r 3c114b3e08c3 graal/com.oracle.truffle.api/src/com/oracle/truffle/api/utilities/IntegerConditionProfile.java --- 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: - * - *
- * private final ConditionProfile zero = new IntegerConditionProfile();
- *
- * int value = ...;
- * if (zero.profile(value == 0)) {
- *   return 0;
- * } else {
- *   return value;
- * }
- *
- * 
- * - * @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()); - } -}