Mercurial > hg > truffle
changeset 10649:ac8b195fd3aa
New unsafe cast CompilerDirectives method in Truffle API.
author | Thomas Wuerthinger <thomas.wuerthinger@oracle.com> |
---|---|
date | Sun, 07 Jul 2013 23:51:52 +0200 |
parents | 8660a090c3e2 |
children | b6e46324233f |
files | graal/com.oracle.graal.truffle/src/com/oracle/graal/truffle/nodes/UnsafeCastMacroNode.java graal/com.oracle.graal.truffle/src/com/oracle/graal/truffle/substitutions/CompilerDirectivesSubstitutions.java graal/com.oracle.truffle.api/src/com/oracle/truffle/api/CompilerDirectives.java |
diffstat | 3 files changed, 19 insertions(+), 1 deletions(-) [+] |
line wrap: on
line diff
--- 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; }
--- 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); }
--- 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; + } }