diff graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/PiNode.java @ 11752:7e7edb86fb43

Refactor the handling of unsafe casts to distinguish between word-object-conversions, PiNode-like type information, and real unsafe casts.
author Christian Wimmer <christian.wimmer@oracle.com>
date Mon, 23 Sep 2013 14:36:00 -0700
parents 972f2e2c797a
children c2d8e5813925
line wrap: on
line diff
--- a/graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/PiNode.java	Sun Sep 22 02:24:13 2013 +0200
+++ b/graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/PiNode.java	Mon Sep 23 14:36:00 2013 -0700
@@ -49,13 +49,21 @@
         this.object = object;
     }
 
-    public PiNode(ValueNode object, Stamp stamp, GuardingNode anchor) {
-        super(stamp, anchor);
+    public PiNode(ValueNode object, Stamp stamp, ValueNode anchor) {
+        super(stamp, (GuardingNode) anchor);
         this.object = object;
     }
 
+    public PiNode(ValueNode object, ResolvedJavaType toType, boolean exactType, boolean nonNull) {
+        this(object, StampFactory.object(toType, exactType, nonNull || ObjectStamp.isObjectNonNull(object.stamp())));
+    }
+
     @Override
     public void generate(LIRGeneratorTool generator) {
+        assert kind() == Kind.Object && object.kind() == Kind.Object;
+        assert ObjectStamp.typeOrNull(object) == null || ObjectStamp.typeOrNull(this).isInterface() || ObjectStamp.typeOrNull(object).isInterface() ||
+                        ObjectStamp.typeOrNull(object).isAssignableFrom(ObjectStamp.typeOrNull(this));
+
         if (object.kind() != Kind.Void && object.kind() != Kind.Illegal) {
             generator.setResult(this, generator.operand(object));
         }
@@ -63,6 +71,9 @@
 
     @Override
     public boolean inferStamp() {
+        if (stamp() == StampFactory.forNodeIntrinsic()) {
+            return false;
+        }
         return updateStamp(stamp().join(object().stamp()));
     }
 
@@ -70,14 +81,7 @@
     public void virtualize(VirtualizerTool tool) {
         State state = tool.getObjectState(object);
         if (state != null && state.getState() == EscapeState.Virtual) {
-            ResolvedJavaType virtualObjectType = state.getVirtualObject().type();
-            if (this.kind() == Kind.Object) {
-                ObjectStamp myStamp = ((ObjectStamp) this.stamp());
-                ResolvedJavaType myType = myStamp.type();
-                if (!myType.isAssignableFrom(virtualObjectType)) {
-                    return;
-                }
-            }
+            assert ObjectStamp.typeOrNull(this).isAssignableFrom(state.getVirtualObject().type());
             tool.replaceWithVirtual(state.getVirtualObject());
         }
     }
@@ -95,4 +99,16 @@
     public ValueNode getOriginalValue() {
         return object;
     }
+
+    @NodeIntrinsic
+    public static native <T> T piCast(Object object, @ConstantNodeParameter Stamp stamp);
+
+    @NodeIntrinsic
+    public static native <T> T piCast(Object object, @ConstantNodeParameter Stamp stamp, GuardingNode anchor);
+
+    @SuppressWarnings("unused")
+    @NodeIntrinsic
+    public static <T> T piCast(Object object, @ConstantNodeParameter Class<T> toType, @ConstantNodeParameter boolean exactType, @ConstantNodeParameter boolean nonNull) {
+        return toType.cast(object);
+    }
 }