# HG changeset patch # User Thomas Wuerthinger # Date 1376473935 -7200 # Node ID 28da427847c54a613851ea7c6d6599b88d780a40 # Parent 8bcae501c51b7c4223f9cbc1007aa212f80cdcd8 New Truffle API methods for efficient implementation of a custom type system on top of the JVM. diff -r 8bcae501c51b -r 28da427847c5 graal/com.oracle.truffle.api/src/com/oracle/truffle/api/CompilerDirectives.java --- 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 unsafeCast(Object value, Class 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)