changeset 7035:52c88c405d07

Simplify how stamp is preserved after lowering of allocation nodes
author Christian Wimmer <christian.wimmer@oracle.com>
date Mon, 26 Nov 2012 19:30:54 -0800
parents 89df4e71940a
children 8c4b757c2eb9 742ec0f04559 fdcdbc3dd76c cd2c08049dd5
files graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/nodes/CastFromHub.java graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/snippets/NewObjectSnippets.java graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/extended/UnsafeArrayCastNode.java
diffstat 3 files changed, 77 insertions(+), 83 deletions(-) [+]
line wrap: on
line diff
--- a/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/nodes/CastFromHub.java	Mon Nov 26 18:58:28 2012 -0800
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,67 +0,0 @@
-/*
- * Copyright (c) 2009, 2011, Oracle and/or its affiliates. All rights reserved.
- * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
- *
- * This code is free software; you can redistribute it and/or modify it
- * under the terms of the GNU General Public License version 2 only, as
- * published by the Free Software Foundation.
- *
- * This code is distributed in the hope that it will be useful, but WITHOUT
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
- * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
- * version 2 for more details (a copy is included in the LICENSE file that
- * accompanied this code).
- *
- * You should have received a copy of the GNU General Public License version
- * 2 along with this work; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
- *
- * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
- * or visit www.oracle.com if you need additional information or have any
- * questions.
- */
-package com.oracle.graal.hotspot.nodes;
-
-import com.oracle.graal.api.meta.*;
-import com.oracle.graal.hotspot.meta.*;
-import com.oracle.graal.hotspot.snippets.*;
-import com.oracle.graal.nodes.*;
-import com.oracle.graal.nodes.calc.*;
-import com.oracle.graal.nodes.extended.*;
-import com.oracle.graal.nodes.spi.*;
-import com.oracle.graal.nodes.type.*;
-import com.oracle.graal.snippets.*;
-
-/**
- * This node is used by the {@link NewObjectSnippets} to give a formatted new instance or object its exact type.
- */
-public final class CastFromHub extends FloatingNode implements Canonicalizable {
-
-    @Input private ValueNode object;
-    @Input private ValueNode hub;
-
-    public ValueNode object() {
-        return object;
-    }
-
-    public CastFromHub(ValueNode object, ValueNode hubObject) {
-        // TODO: the non-nullness should really be derived from 'object' but until
-        // control flow sensitive type analysis is implemented, the object coming
-        // from the TLAB fast path is not non-null
-        super(StampFactory.objectNonNull());
-        this.object = object;
-        this.hub = hubObject;
-    }
-
-    @Override
-    public ValueNode canonical(CanonicalizerTool tool) {
-        if (hub.isConstant()) {
-            ResolvedJavaType type = HotSpotResolvedJavaType.fromMetaspaceKlass(hub.asConstant());
-            return graph().unique(new UnsafeCastNode(object, type, true, true));
-        }
-        return this;
-    }
-
-    @NodeIntrinsic
-    public static native <T> T castFromHub(Object object, Word hub);
-}
--- a/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/snippets/NewObjectSnippets.java	Mon Nov 26 18:58:28 2012 -0800
+++ b/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/snippets/NewObjectSnippets.java	Mon Nov 26 19:30:54 2012 -0800
@@ -23,8 +23,9 @@
 package com.oracle.graal.hotspot.snippets;
 
 import static com.oracle.graal.api.code.UnsignedMath.*;
-import static com.oracle.graal.hotspot.nodes.CastFromHub.*;
 import static com.oracle.graal.hotspot.snippets.HotSpotSnippetUtils.*;
+import static com.oracle.graal.nodes.extended.UnsafeArrayCastNode.*;
+import static com.oracle.graal.nodes.extended.UnsafeCastNode.*;
 import static com.oracle.graal.snippets.Snippet.Varargs.*;
 import static com.oracle.graal.snippets.SnippetTemplate.*;
 import static com.oracle.graal.snippets.SnippetTemplate.Arguments.*;
@@ -78,17 +79,19 @@
                     @ConstantParameter("fillContents") boolean fillContents,
                     @ConstantParameter("locked") boolean locked) {
 
+        Object result;
         if (memory == Word.zero()) {
             new_stub.inc();
-            return NewInstanceStubCall.call(hub);
-        }
-        if (locked) {
-            formatObject(hub, size, memory, thread().or(biasedLockPattern()), fillContents);
+            result = NewInstanceStubCall.call(hub);
         } else {
-            formatObject(hub, size, memory, prototypeMarkWord, fillContents);
+            if (locked) {
+                formatObject(hub, size, memory, thread().or(biasedLockPattern()), fillContents);
+            } else {
+                formatObject(hub, size, memory, prototypeMarkWord, fillContents);
+            }
+            result = memory.toObject();
         }
-        Object instance = memory.toObject();
-        return castFromHub(verifyOop(instance), hub);
+        return unsafeCast(verifyOop(result), StampFactory.forNodeIntrinsic());
     }
 
     @Snippet
@@ -126,22 +129,24 @@
     }
 
     private static Object initializeArray(Word memory, Word hub, int length, int size, Word prototypeMarkWord, int headerSize, boolean isObjectArray, boolean fillContents) {
+        Object result;
         if (memory == Word.zero()) {
             if (isObjectArray) {
                 anewarray_stub.inc();
             } else {
                 newarray_stub.inc();
             }
-            return NewArrayStubCall.call(isObjectArray, hub, length);
-        }
-        if (isObjectArray) {
-            anewarray_loopInit.inc();
+            result = NewArrayStubCall.call(isObjectArray, hub, length);
         } else {
-            newarray_loopInit.inc();
+            if (isObjectArray) {
+                anewarray_loopInit.inc();
+            } else {
+                newarray_loopInit.inc();
+            }
+            formatArray(hub, size, length, headerSize, memory, prototypeMarkWord, fillContents);
+            result = memory.toObject();
         }
-        formatArray(hub, size, length, headerSize, memory, prototypeMarkWord, fillContents);
-        Object instance = memory.toObject();
-        return castFromHub(verifyOop(instance), hub);
+        return unsafeArrayCast(verifyOop(result), length, StampFactory.forNodeIntrinsic());
     }
 
     /**
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/extended/UnsafeArrayCastNode.java	Mon Nov 26 19:30:54 2012 -0800
@@ -0,0 +1,56 @@
+/*
+ * Copyright (c) 2012, 2012, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+package com.oracle.graal.nodes.extended;
+
+import com.oracle.graal.nodes.*;
+import com.oracle.graal.nodes.spi.*;
+import com.oracle.graal.nodes.type.*;
+
+/**
+ * The {@code UnsafeCastNode} produces the same value as its input, but with a different type.
+ */
+public final class UnsafeArrayCastNode extends UnsafeCastNode implements ArrayLengthProvider {
+
+    @Input
+    private ValueNode length;
+
+    public ValueNode length() {
+        return length;
+    }
+
+    public UnsafeArrayCastNode(ValueNode object, ValueNode length, Stamp stamp) {
+        super(object, stamp);
+        this.length = length;
+    }
+
+    @Override
+    public ValueNode canonical(CanonicalizerTool tool) {
+        if (!(object() instanceof ArrayLengthProvider) || length() != ((ArrayLengthProvider) object()).length()) {
+            return this;
+        }
+        return super.canonical(tool);
+    }
+
+    @NodeIntrinsic
+    public static native <T> T unsafeArrayCast(Object object, int length, @ConstantNodeParameter Stamp stamp);
+}