changeset 11303:28da427847c5

New Truffle API methods for efficient implementation of a custom type system on top of the JVM.
author Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
date Wed, 14 Aug 2013 11:52:15 +0200
parents 8bcae501c51b
children 74ccfb4d39ec
files graal/com.oracle.truffle.api/src/com/oracle/truffle/api/CompilerDirectives.java
diffstat 1 files changed, 46 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/graal/com.oracle.truffle.api/src/com/oracle/truffle/api/CompilerDirectives.java	Tue Aug 13 19:07:41 2013 +0200
+++ b/graal/com.oracle.truffle.api/src/com/oracle/truffle/api/CompilerDirectives.java	Wed Aug 14 11:52:15 2013 +0200
@@ -152,6 +152,52 @@
     }
 
     /**
+     * Associates the given type token with the given value for the case that condition is true.
+     * 
+     * @param condition the custom type check
+     * @param value the value that is of the given custom type after the check
+     * @param customType the custom type that should be associated with the value
+     * @return the type check condition
+     */
+    public static boolean customTypeCheck(boolean condition, Object value, Object customType) {
+        return condition;
+    }
+
+    /**
+     * Treats the given value as a value of the given class. The class must evaluate to a constant.
+     * If the compiler can prove that the given value is of the given custom type, the cast is safe.
+     * 
+     * @param value the value that is known to have the specified type
+     * @param clazz the specified type of the value
+     * @param customType the custom type that if present on a value makes this unsafe cast safe
+     * @return the value
+     */
+    @SuppressWarnings("unchecked")
+    @Unsafe
+    public static <T> T unsafeCast(Object value, Class<T> clazz, Object customType) {
+        return (T) value;
+    }
+
+    /**
+     * Proxies a sun.misc.Unsafe instance into an instance that adds a custom location identity on
+     * its accesses. This means that the accesses on these kind of location identities can only
+     * alias among themselves. It also allows to specify a custom type for the receiver values of
+     * follow-up unsafe accesses. Both the custom type and the location identity must evaluate to a
+     * constant. Furthermore, you should use the new sun.misc.Unsafe instance immediately for one
+     * read or write access via a sun.misc.Unsafe method and not store it anywhere.
+     * 
+     * @param unsafe the instance of sun.misc.Unsafe
+     * @param customType the expected type of the receiver object of follow-up unsafe accesses
+     * @param locationIdentity the location identity token that can be used for improved global
+     *            value numbering or null
+     * @return the accessed value
+     */
+    @Unsafe
+    public static sun.misc.Unsafe unsafeCustomization(sun.misc.Unsafe unsafe, Object customType, Object locationIdentity) {
+        return unsafe;
+    }
+
+    /**
      * Marks methods that are considered slowpath and should therefore not be inlined by default.
      */
     @Retention(RetentionPolicy.RUNTIME)