diff graal/com.oracle.truffle.api/src/com/oracle/truffle/api/CompilerDirectives.java @ 14880:73546bd550f0

CompilerDirectives: add optional nonNull parameter to unsafeCast
author Andreas Woess <andreas.woess@jku.at>
date Fri, 28 Mar 2014 18:33:05 +0100
parents fca29edf5667
children f3a5036cc13c
line wrap: on
line diff
--- a/graal/com.oracle.truffle.api/src/com/oracle/truffle/api/CompilerDirectives.java	Fri Mar 28 17:55:46 2014 +0100
+++ b/graal/com.oracle.truffle.api/src/com/oracle/truffle/api/CompilerDirectives.java	Fri Mar 28 18:33:05 2014 +0100
@@ -76,7 +76,7 @@
 
     /**
      * Returns a boolean value indicating whether the method is executed in the interpreter.
-     * 
+     *
      * @return {@code true} when executed in the interpreter, {@code false} in compiled code.
      */
     public static boolean inInterpreter() {
@@ -86,7 +86,7 @@
     /**
      * Directive for the compiler that the given runnable should only be executed in the interpreter
      * and ignored in the compiled code.
-     * 
+     *
      * @param runnable the closure that should only be executed in the interpreter
      */
     public static void interpreterOnly(Runnable runnable) {
@@ -96,7 +96,7 @@
     /**
      * Directive for the compiler that the given callable should only be executed in the
      * interpreter.
-     * 
+     *
      * @param callable the closure that should only be executed in the interpreter
      * @return the result of executing the closure in the interpreter and null in the compiled code
      * @throws Exception If the closure throws an exception when executed in the interpreter.
@@ -109,30 +109,30 @@
      * Injects a probability for the given condition into the probability information of the
      * immediately succeeding branch instruction for the condition. The probability must be a value
      * between 0.0 and 1.0 (inclusive). The condition should not be a combined condition.
-     * 
+     *
      * Example usage immediately before an if statement (it specifies that the likelihood for a to
      * be greater than b is 90%):
-     * 
+     *
      * <code>
      * if (injectBranchProbability(0.9, a > b)) {
      *    // ...
      * }
      * </code>
-     * 
+     *
      * Example usage for a combined condition (it specifies that the likelihood for a to be greater
      * than b is 90% and under the assumption that this is true, the likelihood for a being 0 is
      * 10%):
-     * 
+     *
      * <code>
      * if (injectBranchProbability(0.9, a > b) && injectBranchProbability(0.1, a == 0)) {
      *    // ...
      * }
      * </code>
-     * 
+     *
      * 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) {
@@ -142,7 +142,7 @@
 
     /**
      * Bails out of a compilation (e.g., for guest language features that should never be compiled).
-     * 
+     *
      * @param reason the reason for the bailout
      */
     public static void bailout(String reason) {
@@ -161,21 +161,37 @@
      * Casts the given value to the value of the given type without any checks. The class must
      * evaluate to a constant. The condition parameter gives a hint to the compiler under which
      * circumstances this cast can be moved to an earlier location in the program.
-     * 
+     *
      * @param value the value that is known to have the specified type
      * @param type the specified new type of the value
      * @param condition the condition that makes this cast safe also at an earlier location of the
      *            program
      * @return the value to be casted to the new type
      */
+    public static <T> T unsafeCast(Object value, Class<T> type, boolean condition) {
+        return unsafeCast(value, type, condition, false);
+    }
+
+    /**
+     * Casts the given value to the value of the given type without any checks. The class must
+     * evaluate to a constant. The condition parameter gives a hint to the compiler under which
+     * circumstances this cast can be moved to an earlier location in the program.
+     *
+     * @param value the value that is known to have the specified type
+     * @param type the specified new type of the value
+     * @param condition the condition that makes this cast safe also at an earlier location of the
+     *            program
+     * @param nonNull whether value is known to never be null
+     * @return the value to be casted to the new type
+     */
     @SuppressWarnings("unchecked")
-    public static <T> T unsafeCast(Object value, Class<T> type, boolean condition) {
+    public static <T> T unsafeCast(Object value, Class<T> type, boolean condition, boolean nonNull) {
         return (T) value;
     }
 
     /**
      * Asserts that this value is not null and retrieved from a call to Frame.materialize.
-     * 
+     *
      * @param value the value that is known to have been obtained via Frame.materialize
      * @return the value to be casted to the new type
      */
@@ -192,7 +208,7 @@
      * the compiler under which circumstances this access can be moved to an earlier location in the
      * program. The location identity gives a hint to the compiler for improved global value
      * numbering.
-     * 
+     *
      * @param receiver the object that is accessed
      * @param offset the offset at which to access the object in bytes
      * @param condition the condition that makes this access safe also at an earlier location in the
@@ -210,7 +226,7 @@
      * compiler under which circumstances this access can be moved to an earlier location in the
      * program. The location identity gives a hint to the compiler for improved global value
      * numbering.
-     * 
+     *
      * @param receiver the object that is accessed
      * @param offset the offset at which to access the object in bytes
      * @param condition the condition that makes this access safe also at an earlier location in the
@@ -228,7 +244,7 @@
      * compiler under which circumstances this access can be moved to an earlier location in the
      * program. The location identity gives a hint to the compiler for improved global value
      * numbering.
-     * 
+     *
      * @param receiver the object that is accessed
      * @param offset the offset at which to access the object in bytes
      * @param condition the condition that makes this access safe also at an earlier location in the
@@ -246,7 +262,7 @@
      * compiler under which circumstances this access can be moved to an earlier location in the
      * program. The location identity gives a hint to the compiler for improved global value
      * numbering.
-     * 
+     *
      * @param receiver the object that is accessed
      * @param offset the offset at which to access the object in bytes
      * @param condition the condition that makes this access safe also at an earlier location in the
@@ -264,7 +280,7 @@
      * compiler under which circumstances this access can be moved to an earlier location in the
      * program. The location identity gives a hint to the compiler for improved global value
      * numbering.
-     * 
+     *
      * @param receiver the object that is accessed
      * @param offset the offset at which to access the object in bytes
      * @param condition the condition that makes this access safe also at an earlier location in the
@@ -282,7 +298,7 @@
      * compiler under which circumstances this access can be moved to an earlier location in the
      * program. The location identity gives a hint to the compiler for improved global value
      * numbering.
-     * 
+     *
      * @param receiver the object that is accessed
      * @param offset the offset at which to access the object in bytes
      * @param condition the condition that makes this access safe also at an earlier location in the
@@ -300,7 +316,7 @@
      * compiler under which circumstances this access can be moved to an earlier location in the
      * program. The location identity gives a hint to the compiler for improved global value
      * numbering.
-     * 
+     *
      * @param receiver the object that is accessed
      * @param offset the offset at which to access the object in bytes
      * @param condition the condition that makes this access safe also at an earlier location in the
@@ -318,7 +334,7 @@
      * the compiler under which circumstances this access can be moved to an earlier location in the
      * program. The location identity gives a hint to the compiler for improved global value
      * numbering.
-     * 
+     *
      * @param receiver the object that is accessed
      * @param offset the offset at which to access the object in bytes
      * @param condition the condition that makes this access safe also at an earlier location in the
@@ -334,7 +350,7 @@
     /**
      * Write a boolean value within an object. The location identity gives a hint to the compiler
      * for improved global value numbering.
-     * 
+     *
      * @param receiver the object that is written to
      * @param offset the offset at which to write to the object in bytes
      * @param value the value to be written
@@ -348,7 +364,7 @@
     /**
      * Write a byte value within an object. The location identity gives a hint to the compiler for
      * improved global value numbering.
-     * 
+     *
      * @param receiver the object that is written to
      * @param offset the offset at which to write to the object in bytes
      * @param value the value to be written
@@ -362,7 +378,7 @@
     /**
      * Write a short value within an object. The location identity gives a hint to the compiler for
      * improved global value numbering.
-     * 
+     *
      * @param receiver the object that is written to
      * @param offset the offset at which to write to the object in bytes
      * @param value the value to be written
@@ -376,7 +392,7 @@
     /**
      * Write an int value within an object. The location identity gives a hint to the compiler for
      * improved global value numbering.
-     * 
+     *
      * @param receiver the object that is written to
      * @param offset the offset at which to write to the object in bytes
      * @param value the value to be written
@@ -390,7 +406,7 @@
     /**
      * Write a long value within an object. The location identity gives a hint to the compiler for
      * improved global value numbering.
-     * 
+     *
      * @param receiver the object that is written to
      * @param offset the offset at which to write to the object in bytes
      * @param value the value to be written
@@ -404,7 +420,7 @@
     /**
      * Write a float value within an object. The location identity gives a hint to the compiler for
      * improved global value numbering.
-     * 
+     *
      * @param receiver the object that is written to
      * @param offset the offset at which to write to the object in bytes
      * @param value the value to be written
@@ -418,7 +434,7 @@
     /**
      * Write a double value within an object. The location identity gives a hint to the compiler for
      * improved global value numbering.
-     * 
+     *
      * @param receiver the object that is written to
      * @param offset the offset at which to write to the object in bytes
      * @param value the value to be written
@@ -432,7 +448,7 @@
     /**
      * Write an Object value within an object. The location identity gives a hint to the compiler
      * for improved global value numbering.
-     * 
+     *
      * @param receiver the object that is written to
      * @param offset the offset at which to write to the object in bytes
      * @param value the value to be written
@@ -448,7 +464,7 @@
      * to the compiler under which circumstances this access can be moved to an earlier location in
      * the program. The location identity gives a hint to the compiler for improved global value
      * numbering.
-     * 
+     *
      * @param receiver the object that is accessed
      * @param offset the offset at which to access the object in bytes
      * @param condition the condition that makes this access safe also at an earlier location in the
@@ -466,7 +482,7 @@
      * the compiler under which circumstances this access can be moved to an earlier location in the
      * program. The location identity gives a hint to the compiler for improved global value
      * numbering.
-     * 
+     *
      * @param receiver the object that is accessed
      * @param offset the offset at which to access the object in bytes
      * @param condition the condition that makes this access safe also at an earlier location in the
@@ -484,7 +500,7 @@
      * to the compiler under which circumstances this access can be moved to an earlier location in
      * the program. The location identity gives a hint to the compiler for improved global value
      * numbering.
-     * 
+     *
      * @param receiver the object that is accessed
      * @param offset the offset at which to access the object in bytes
      * @param condition the condition that makes this access safe also at an earlier location in the
@@ -502,7 +518,7 @@
      * the compiler under which circumstances this access can be moved to an earlier location in the
      * program. The location identity gives a hint to the compiler for improved global value
      * numbering.
-     * 
+     *
      * @param receiver the object that is accessed
      * @param offset the offset at which to access the object in bytes
      * @param condition the condition that makes this access safe also at an earlier location in the
@@ -520,7 +536,7 @@
      * the compiler under which circumstances this access can be moved to an earlier location in the
      * program. The location identity gives a hint to the compiler for improved global value
      * numbering.
-     * 
+     *
      * @param receiver the object that is accessed
      * @param offset the offset at which to access the object in bytes
      * @param condition the condition that makes this access safe also at an earlier location in the
@@ -538,7 +554,7 @@
      * to the compiler under which circumstances this access can be moved to an earlier location in
      * the program. The location identity gives a hint to the compiler for improved global value
      * numbering.
-     * 
+     *
      * @param receiver the object that is accessed
      * @param offset the offset at which to access the object in bytes
      * @param condition the condition that makes this access safe also at an earlier location in the
@@ -556,7 +572,7 @@
      * to the compiler under which circumstances this access can be moved to an earlier location in
      * the program. The location identity gives a hint to the compiler for improved global value
      * numbering.
-     * 
+     *
      * @param receiver the object that is accessed
      * @param offset the offset at which to access the object in bytes
      * @param condition the condition that makes this access safe also at an earlier location in the
@@ -574,7 +590,7 @@
      * to the compiler under which circumstances this access can be moved to an earlier location in
      * the program. The location identity gives a hint to the compiler for improved global value
      * numbering.
-     * 
+     *
      * @param receiver the object that is accessed
      * @param offset the offset at which to access the object in bytes
      * @param condition the condition that makes this access safe also at an earlier location in the