# HG changeset patch # User Thomas Wuerthinger # Date 1373233912 -7200 # Node ID ac8b195fd3aa449d4f94d462d9fde5d13051d93c # Parent 8660a090c3e2535146d6fdb87e50d793e2ea126e New unsafe cast CompilerDirectives method in Truffle API. diff -r 8660a090c3e2 -r ac8b195fd3aa graal/com.oracle.graal.truffle/src/com/oracle/graal/truffle/nodes/UnsafeCastMacroNode.java --- a/graal/com.oracle.graal.truffle/src/com/oracle/graal/truffle/nodes/UnsafeCastMacroNode.java Sun Jul 07 23:32:05 2013 +0200 +++ b/graal/com.oracle.graal.truffle/src/com/oracle/graal/truffle/nodes/UnsafeCastMacroNode.java Sun Jul 07 23:51:52 2013 +0200 @@ -41,7 +41,10 @@ Class c = (Class) arguments.get(1).asConstant().asObject(); ResolvedJavaType lookupJavaType = tool.runtime().lookupJavaType(c); Stamp s = StampFactory.declaredNonNull(lookupJavaType); - return graph().unique(new UnsafeCastNode(arguments.get(0), s)); + ValueAnchorNode valueAnchorNode = graph().add(new ValueAnchorNode()); + UnsafeCastNode unsafeCast = graph().unique(new UnsafeCastNode(arguments.get(0), s, (GuardingNode) valueAnchorNode)); + this.replaceAtUsages(unsafeCast); + return valueAnchorNode; } return this; } diff -r 8660a090c3e2 -r ac8b195fd3aa graal/com.oracle.graal.truffle/src/com/oracle/graal/truffle/substitutions/CompilerDirectivesSubstitutions.java --- a/graal/com.oracle.graal.truffle/src/com/oracle/graal/truffle/substitutions/CompilerDirectivesSubstitutions.java Sun Jul 07 23:32:05 2013 +0200 +++ b/graal/com.oracle.graal.truffle/src/com/oracle/graal/truffle/substitutions/CompilerDirectivesSubstitutions.java Sun Jul 07 23:51:52 2013 +0200 @@ -57,4 +57,7 @@ @MacroSubstitution(macro = BailoutNode.class, isStatic = true) public static native void bailout(String reason); + + @MacroSubstitution(macro = UnsafeCastMacroNode.class, isStatic = true) + public static native Object unsafeCast(Object value, Class clazz); } diff -r 8660a090c3e2 -r ac8b195fd3aa 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 Sun Jul 07 23:32:05 2013 +0200 +++ b/graal/com.oracle.truffle.api/src/com/oracle/truffle/api/CompilerDirectives.java Sun Jul 07 23:51:52 2013 +0200 @@ -126,4 +126,16 @@ @Target({ElementType.METHOD}) public @interface Unsafe { } + + /** + * Treats the given value as a value of the given class. The class must evaluate to a constant. + * + * @param value the value that is known to have the specified type + * @param clazz the specified type of the value + * @return the value + */ + @Unsafe + public static Object unsafeCast(Object value, Class clazz) { + return value; + } }