Mercurial > hg > truffle
comparison graal/com.oracle.truffle.api/src/com/oracle/truffle/api/CompilerDirectives.java @ 9319:1188b7c42196
Changed the behavior of CompilerDirectives.injectBranchProbability and added javadoc to document the new behavior. Introduced probability constants. Removed CompilerDirectives.slowpath().
author | Thomas Wuerthinger <thomas.wuerthinger@oracle.com> |
---|---|
date | Thu, 25 Apr 2013 22:44:28 +0200 |
parents | 6369d37b37d1 |
children | 0fccad3ce40d |
comparison
equal
deleted
inserted
replaced
9318:dc04c7e8f714 | 9319:1188b7c42196 |
---|---|
29 * Directives that influence the optimizations of the Truffle compiler. All of the operations have | 29 * Directives that influence the optimizations of the Truffle compiler. All of the operations have |
30 * no effect when executed in the Truffle interpreter. | 30 * no effect when executed in the Truffle interpreter. |
31 */ | 31 */ |
32 public class CompilerDirectives { | 32 public class CompilerDirectives { |
33 | 33 |
34 private static final double SLOWPATH_PROBABILITY = 0.0001; | 34 public static final double LIKELY_PROBABILITY = 0.75; |
35 public static final double UNLIKELY_PROBABILITY = 1.0 - LIKELY_PROBABILITY; | |
36 | |
37 public static final double SLOWPATH_PROBABILITY = 0.0001; | |
38 public static final double FASTPATH_PROBABILITY = 1.0 - SLOWPATH_PROBABILITY; | |
35 | 39 |
36 /** | 40 /** |
37 * Directive for the compiler to discontinue compilation at this code position and instead | 41 * Directive for the compiler to discontinue compilation at this code position and instead |
38 * insert a transfer to the interpreter. | 42 * insert a transfer to the interpreter. |
39 */ | 43 */ |
61 public static <T> T interpreterOnly(Callable<T> callable) throws Exception { | 65 public static <T> T interpreterOnly(Callable<T> callable) throws Exception { |
62 return callable.call(); | 66 return callable.call(); |
63 } | 67 } |
64 | 68 |
65 /** | 69 /** |
66 * Directive for the compiler that the current path has a very low probability to be executed. | 70 * Injects a probability for the given condition into the probability information of the |
67 */ | 71 * immediately succeeding branch instruction for the condition. The probability must be a value |
68 public static void slowpath() { | 72 * between 0.0 and 1.0 (inclusive). The condition should not be a combined condition. |
69 injectBranchProbability(SLOWPATH_PROBABILITY); | 73 * |
70 } | 74 * Example usage immediately before an if statement (it specifies that the likelihood for a to |
71 | 75 * be greater than b is 90%): |
72 /** | 76 * |
73 * Injects a probability for the current path into the probability information of the | 77 * <code> |
74 * immediately preceeding branch instruction. | 78 * if (injectBranchProbability(0.9, a > b)) { |
79 * // ... | |
80 * } | |
81 * </code> | |
82 * | |
83 * Example usage for a combined condition (it specifies that the likelihood for a to be greater | |
84 * than b is 90% and under the assumption that this is true, the likelihood for a being 0 is | |
85 * 10%): | |
86 * | |
87 * <code> | |
88 * if (injectBranchProbability(0.9, a > b) && injectBranchProbability(0.1, a == 0)) { | |
89 * // ... | |
90 * } | |
91 * </code> | |
92 * | |
93 * There are predefined constants for commonly used probabilities (see | |
94 * {@link #LIKELY_PROBABILITY} , {@link #UNLIKELY_PROBABILITY}, {@link #SLOWPATH_PROBABILITY}, | |
95 * {@link #FASTPATH_PROBABILITY} ). | |
75 * | 96 * |
76 * @param probability the probability value between 0.0 and 1.0 that should be injected | 97 * @param probability the probability value between 0.0 and 1.0 that should be injected |
77 */ | 98 */ |
78 public static void injectBranchProbability(double probability) { | 99 public static boolean injectBranchProbability(double probability, boolean condition) { |
79 assert probability >= 0.0 && probability <= 1.0; | 100 assert probability >= 0.0 && probability <= 1.0; |
101 return condition; | |
80 } | 102 } |
81 | 103 |
82 /** | 104 /** |
83 * Bails out of a compilation (e.g., for guest language features that should never be compiled). | 105 * Bails out of a compilation (e.g., for guest language features that should never be compiled). |
84 * | 106 * |