+ * if (injectBranchProbability(0.9, a > b)) {
+ * // ...
+ * }
+ *
+ *
+ * There are predefined constants for commonly used probabilities (see
+ * {@link #LIKELY_PROBABILITY} , {@link #UNLIKELY_PROBABILITY}, {@link #SLOWPATH_PROBABILITY},
+ * {@link #FASTPATH_PROBABILITY} ).
+ *
+ * @param probability the probability value between 0.0 and 1.0 that should be injected
+ */
+ public static boolean injectBranchProbability(double probability, boolean condition) {
+ assert probability >= 0.0 && probability <= 1.0;
+ return condition;
+ }
+
+ /**
+ * Injects an average iteration count of a loop into the probability information of a loop exit
+ * condition. The iteration count specifies how often the condition is checked, i.e. in for and
+ * while loops it is one more than the body iteration count, and in do-while loops it is equal
+ * to the body iteration count. The iteration count must be >= 1.0.
+ *
+ * Example usage (it specifies that the expected iteration count of the loop condition is 500,
+ * so the iteration count of the loop body is 499):
+ *
+ *
+ * for (int i = 0; injectIterationCount(500, i < array.length); i++) {
+ * // ...
+ * }
+ *
+ *
+ * @param iterations the expected number of iterations that should be injected
+ */
+ public static boolean injectIterationCount(double iterations, boolean condition) {
+ return injectBranchProbability(1. - 1. / iterations, condition);
+ }
+
+ /**
+ * Consume a value, making sure the compiler doesn't optimize away the computation of this
+ * value, even if it is otherwise unused.
+ */
+ @SuppressWarnings("unused")
+ public static void blackhole(boolean value) {
+ }
+
+ /**
+ * Consume a value, making sure the compiler doesn't optimize away the computation of this
+ * value, even if it is otherwise unused.
+ */
+ @SuppressWarnings("unused")
+ public static void blackhole(byte value) {
+ }
+
+ /**
+ * Consume a value, making sure the compiler doesn't optimize away the computation of this
+ * value, even if it is otherwise unused.
+ */
+ @SuppressWarnings("unused")
+ public static void blackhole(short value) {
+ }
+
+ /**
+ * Consume a value, making sure the compiler doesn't optimize away the computation of this
+ * value, even if it is otherwise unused.
+ */
+ @SuppressWarnings("unused")
+ public static void blackhole(char value) {
+ }
+
+ /**
+ * Consume a value, making sure the compiler doesn't optimize away the computation of this
+ * value, even if it is otherwise unused.
+ */
+ @SuppressWarnings("unused")
+ public static void blackhole(int value) {
+ }
+
+ /**
+ * Consume a value, making sure the compiler doesn't optimize away the computation of this
+ * value, even if it is otherwise unused.
+ */
+ @SuppressWarnings("unused")
+ public static void blackhole(long value) {
+ }
+
+ /**
+ * Consume a value, making sure the compiler doesn't optimize away the computation of this
+ * value, even if it is otherwise unused.
+ */
+ @SuppressWarnings("unused")
+ public static void blackhole(float value) {
+ }
+
+ /**
+ * Consume a value, making sure the compiler doesn't optimize away the computation of this
+ * value, even if it is otherwise unused.
+ */
+ @SuppressWarnings("unused")
+ public static void blackhole(double value) {
+ }
+
+ /**
+ * Consume a value, making sure the compiler doesn't optimize away the computation of this
+ * value, even if it is otherwise unused.
+ */
+ @SuppressWarnings("unused")
+ public static void blackhole(Object value) {
+ }
+
+ /**
+ * Forces a value to be kept in a register.
+ */
+ @SuppressWarnings("unused")
+ public static void bindToRegister(boolean value) {
+ }
+
+ /**
+ * Forces a value to be kept in a register.
+ */
+ @SuppressWarnings("unused")
+ public static void bindToRegister(byte value) {
+ }
+
+ /**
+ * Forces a value to be kept in a register.
+ */
+ @SuppressWarnings("unused")
+ public static void bindToRegister(short value) {
+ }
+
+ /**
+ * Forces a value to be kept in a register.
+ */
+ @SuppressWarnings("unused")
+ public static void bindToRegister(char value) {
+ }
+
+ /**
+ * Forces a value to be kept in a register.
+ */
+ @SuppressWarnings("unused")
+ public static void bindToRegister(int value) {
+ }
+
+ /**
+ * Forces a value to be kept in a register.
+ */
+ @SuppressWarnings("unused")
+ public static void bindToRegister(long value) {
+ }
+
+ /**
+ * Forces a value to be kept in a register.
+ */
+ @SuppressWarnings("unused")
+ public static void bindToRegister(float value) {
+ }
+
+ /**
+ * Forces a value to be kept in a register.
+ */
+ @SuppressWarnings("unused")
+ public static void bindToRegister(double value) {
+ }
+
+ /**
+ * Forces a value to be kept in a register.
+ */
+ @SuppressWarnings("unused")
+ public static void bindToRegister(Object value) {
+ }
+
+ /**
+ * Spills all caller saved registers.
+ */
+ public static void spillRegisters() {
+ }
+
+ /**
+ * Do nothing, but also make sure the compiler doesn't do any optimizations across this call.
+ *
+ * For example, the compiler will constant fold the expression 5 * 3, but the expression 5 *
+ * opaque(3) will result in a real multiplication, because the compiler will not see that
+ * opaque(3) is a constant.
+ */
+ public static boolean opaque(boolean value) {
+ return value;
+ }
+
+ /**
+ * Do nothing, but also make sure the compiler doesn't do any optimizations across this call.
+ *
+ * For example, the compiler will constant fold the expression 5 * 3, but the expression 5 *
+ * opaque(3) will result in a real multiplication, because the compiler will not see that
+ * opaque(3) is a constant.
+ */
+ public static byte opaque(byte value) {
+ return value;
+ }
+
+ /**
+ * Do nothing, but also make sure the compiler doesn't do any optimizations across this call.
+ *
+ * For example, the compiler will constant fold the expression 5 * 3, but the expression 5 *
+ * opaque(3) will result in a real multiplication, because the compiler will not see that
+ * opaque(3) is a constant.
+ */
+ public static short opaque(short value) {
+ return value;
+ }
+
+ /**
+ * Do nothing, but also make sure the compiler doesn't do any optimizations across this call.
+ *
+ * For example, the compiler will constant fold the expression 5 * 3, but the expression 5 *
+ * opaque(3) will result in a real multiplication, because the compiler will not see that
+ * opaque(3) is a constant.
+ */
+ public static char opaque(char value) {
+ return value;
+ }
+
+ /**
+ * Do nothing, but also make sure the compiler doesn't do any optimizations across this call.
+ *
+ * For example, the compiler will constant fold the expression 5 * 3, but the expression 5 *
+ * opaque(3) will result in a real multiplication, because the compiler will not see that
+ * opaque(3) is a constant.
+ */
+ public static int opaque(int value) {
+ return value;
+ }
+
+ /**
+ * Do nothing, but also make sure the compiler doesn't do any optimizations across this call.
+ *
+ * For example, the compiler will constant fold the expression 5 * 3, but the expression 5 *
+ * opaque(3) will result in a real multiplication, because the compiler will not see that
+ * opaque(3) is a constant.
+ */
+ public static long opaque(long value) {
+ return value;
+ }
+
+ /**
+ * Do nothing, but also make sure the compiler doesn't do any optimizations across this call.
+ *
+ * For example, the compiler will constant fold the expression 5 * 3, but the expression 5 *
+ * opaque(3) will result in a real multiplication, because the compiler will not see that
+ * opaque(3) is a constant.
+ */
+ public static float opaque(float value) {
+ return value;
+ }
+
+ /**
+ * Do nothing, but also make sure the compiler doesn't do any optimizations across this call.
+ *
+ * For example, the compiler will constant fold the expression 5 * 3, but the expression 5 *
+ * opaque(3) will result in a real multiplication, because the compiler will not see that
+ * opaque(3) is a constant.
+ */
+ public static double opaque(double value) {
+ return value;
+ }
+
+ /**
+ * Do nothing, but also make sure the compiler doesn't do any optimizations across this call.
+ *
+ * For example, the compiler will constant fold the expression 5 * 3, but the expression 5 *
+ * opaque(3) will result in a real multiplication, because the compiler will not see that
+ * opaque(3) is a constant.
+ */
+ public static + * + *+ * + * @see #instrumentationBegin() + */ + public static void instrumentationBeginForPredecessor() { + } + + /** + * Marks the end of the instrumentation boundary. + * + * @see #instrumentationBegin() + */ + public static void instrumentationEnd() { + } + + /** + * @return true if the enclosing method is inlined. + */ + public static boolean isMethodInlined() { + return false; + } + + private static final Charset UTF8 = Charset.forName("UTF-8"); + + /** + * @return the name of the root method for the current compilation task. If the enclosing method + * is inlined, it returns the name of the method into which it is inlined. + */ + public static String rootName() { + return new String(rawRootName(), UTF8); + } + + public static byte[] rawRootName() { + return new byte[0]; + } + +}+ * 0 new java.lang.Object + * 3 invokestatic org.graalvm.compiler.api.directives.GraalDirectives.instrumentationBeginForPredecessor() : void + * 6 invokestatic AllocationProfiler.countActualAllocation() : void + * 9 invokestatic org.graalvm.compiler.api.directives.GraalDirectives.instrumentationEnd() : void + * 12 invokespecial java.lang.Object() + *+ * + *