comparison graal/com.oracle.truffle.api/src/com/oracle/truffle/api/utilities/ConditionProfile.java @ 16860:fa5e62620593

Truffle: made constructors of condition profiles package protected to delegate them later to TruffleRuntime.
author Christian Humer <christian.humer@gmail.com>
date Tue, 19 Aug 2014 14:56:19 +0200
parents fc6f12ee71e5
children db090a8d3705
comparison
equal deleted inserted replaced
16855:226552569e34 16860:fa5e62620593
22 * or visit www.oracle.com if you need additional information or have any 22 * or visit www.oracle.com if you need additional information or have any
23 * questions. 23 * questions.
24 */ 24 */
25 package com.oracle.truffle.api.utilities; 25 package com.oracle.truffle.api.utilities;
26 26
27 import com.oracle.truffle.api.*;
28
27 /** 29 /**
28 * Abstract utility class to speculate on conditions. Condition profiles are intended to be used as 30 * Abstract utility class to speculate on conditions. Condition profiles are intended to be used as
29 * part of if conditions. 31 * part of if conditions.
30 * 32 *
31 * Example usage: 33 * Example usage:
32 * 34 *
33 * <pre> 35 * <pre>
34 * private final ConditionProfile zero = ...; 36 * private final ConditionProfile zero = ConditionProfile.createBinaryProfile();
35 * 37 *
36 * int value = ...; 38 * int value = ...;
37 * if (zero.profile(value == 0)) { 39 * if (zero.profile(value == 0)) {
38 * return 0; 40 * return 0;
39 * } else { 41 * } else {
40 * return value; 42 * return value;
41 * } 43 * }
42 * 44 *
43 * </pre> 45 * </pre>
44 * 46 *
45 * @see BinaryConditionProfile 47 * @see #createCountingProfile()
46 * @see CountingConditionProfile 48 * @see #createBinaryProfile()
47 */ 49 */
48 public abstract class ConditionProfile { 50 public abstract class ConditionProfile {
49 51
50 public abstract boolean profile(boolean value); 52 public abstract boolean profile(boolean value);
51 53
54 /**
55 * Returns a {@link ConditionProfile} that speculates on conditions to be never
56 * <code>true</code> or to be never <code>false</code>. Additionally to a binary profile this
57 * method returns a condition profile that also counts the number of times the condition was
58 * true and false. This information is reported to the underlying optimization system using
59 * {@link CompilerDirectives#injectBranchProbability(double, boolean)}. Condition profiles are
60 * intended to be used as part of if conditions.
61 *
62 * @see ConditionProfile
63 * @see #createBinaryProfile()
64 */
65 public static CountingConditionProfile createCountingProfile() {
66 return new CountingConditionProfile();
67 }
68
69 /**
70 * REturns a {@link ConditionProfile} that speculates on conditions to be never true or to be
71 * never false. Condition profiles are intended to be used as part of if conditions.
72 *
73 * @see ConditionProfile
74 * @see ConditionProfile#createBinaryProfile()
75 */
76 public static BinaryConditionProfile createBinaryProfile() {
77 return new BinaryConditionProfile();
78 }
79
52 } 80 }