changeset 15256:7a0e339e0b56

Harmonize the static helpers in ObjectStamp to check for isLegal. Add some Javadoc to these methods
author Gilles Duboscq <duboscq@ssw.jku.at>
date Tue, 22 Apr 2014 09:55:24 +0200
parents cf6aedb39215
children 95219992be88
files graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/replacements/ObjectGetClassNode.java graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/type/ObjectStamp.java
diffstat 2 files changed, 76 insertions(+), 12 deletions(-) [+]
line wrap: on
line diff
--- a/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/replacements/ObjectGetClassNode.java	Tue Apr 22 09:29:57 2014 +0200
+++ b/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/replacements/ObjectGetClassNode.java	Tue Apr 22 09:55:24 2014 +0200
@@ -26,7 +26,6 @@
 
 import com.oracle.graal.api.meta.*;
 import com.oracle.graal.api.meta.ResolvedJavaType.Representation;
-import com.oracle.graal.compiler.common.type.*;
 import com.oracle.graal.graph.*;
 import com.oracle.graal.graph.spi.*;
 import com.oracle.graal.nodes.*;
@@ -68,13 +67,10 @@
         if (usages().isEmpty()) {
             return null;
         } else {
-            Stamp stamp = getObject().stamp();
-            if (stamp instanceof ObjectStamp) {
-                ObjectStamp objectStamp = (ObjectStamp) stamp;
-                if (objectStamp.isLegal() && objectStamp.isExactType()) {
-                    Constant clazz = objectStamp.type().getEncoding(Representation.JavaClass);
-                    return ConstantNode.forConstant(clazz, tool.getMetaAccess(), graph());
-                }
+            if (ObjectStamp.isExactType(getObject())) {
+                ResolvedJavaType type = ObjectStamp.typeOrNull(getObject());
+                Constant clazz = type.getEncoding(Representation.JavaClass);
+                return ConstantNode.forConstant(clazz, tool.getMetaAccess(), graph());
             }
             return this;
         }
--- a/graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/type/ObjectStamp.java	Tue Apr 22 09:29:57 2014 +0200
+++ b/graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/type/ObjectStamp.java	Tue Apr 22 09:55:24 2014 +0200
@@ -297,39 +297,107 @@
         return true;
     }
 
+    /**
+     * Checks whether this {@link ValueNode} represents a {@linkplain Stamp#isLegal() legal} Object
+     * value which is known to be always null.
+     *
+     * @param node the node to check
+     * @return true if this node represents a legal object value which is known to be always null
+     */
     public static boolean isObjectAlwaysNull(ValueNode node) {
         return isObjectAlwaysNull(node.stamp());
     }
 
+    /**
+     * Checks whether this {@link Stamp} represents a {@linkplain Stamp#isLegal() legal} Object
+     * stamp whose values are known to be always null.
+     *
+     * @param stamp the stamp to check
+     * @return true if this stamp represents a legal object stamp whose values are known to be
+     *         always null
+     */
     public static boolean isObjectAlwaysNull(Stamp stamp) {
-        return (stamp instanceof ObjectStamp && ((ObjectStamp) stamp).isLegal() && ((ObjectStamp) stamp).alwaysNull());
+        if (stamp instanceof ObjectStamp && stamp.isLegal()) {
+            return ((ObjectStamp) stamp).alwaysNull();
+        }
+        return false;
     }
 
+    /**
+     * Checks whether this {@link ValueNode} represents a {@linkplain Stamp#isLegal() legal} Object
+     * value which is known to never be null.
+     *
+     * @param node the node to check
+     * @return true if this node represents a legal object value which is known to never be null
+     */
     public static boolean isObjectNonNull(ValueNode node) {
         return isObjectNonNull(node.stamp());
     }
 
+    /**
+     * Checks whether this {@link Stamp} represents a {@linkplain Stamp#isLegal() legal} Object
+     * stamp whose values known to be always null.
+     *
+     * @param stamp the stamp to check
+     * @return true if this stamp represents a legal object stamp whose values are known to be
+     *         always null
+     */
     public static boolean isObjectNonNull(Stamp stamp) {
-        return stamp instanceof ObjectStamp && ((ObjectStamp) stamp).isLegal() && ((ObjectStamp) stamp).nonNull();
+        if (stamp instanceof ObjectStamp && stamp.isLegal()) {
+            return ((ObjectStamp) stamp).nonNull();
+        }
+        return false;
     }
 
+    /**
+     * Returns the {@linkplain ResolvedJavaType java type} this {@linkplain ValueNode} has if it is
+     * a {@linkplain Stamp#isLegal() legal} Object value.
+     *
+     * @param node the node to check
+     * @return the javat type this value has if it is a legal Object type, null otherwise
+     */
     public static ResolvedJavaType typeOrNull(ValueNode node) {
         return typeOrNull(node.stamp());
     }
 
+    /**
+     * Returns the {@linkplain ResolvedJavaType java type} this {@linkplain Stamp} has if it is a
+     * {@linkplain Stamp#isLegal() legal} Object stamp.
+     *
+     * @param stamp the stamp to check
+     * @return the java type this stamp has if it is a legal Object stamp, null otherwise
+     */
     public static ResolvedJavaType typeOrNull(Stamp stamp) {
-        if (stamp instanceof ObjectStamp) {
+        if (stamp instanceof ObjectStamp && stamp.isLegal()) {
             return ((ObjectStamp) stamp).type();
         }
         return null;
     }
 
+    /**
+     * Checks whether this {@link ValueNode} represents a {@linkplain Stamp#isLegal() legal} Object
+     * value whose java type is known exactly. If this method returns true then the
+     * {@linkplain ResolvedJavaType java type} returned by {@link #typeOrNull(ValueNode)} is the
+     * concrete dynamic/runtime java type of this value.
+     *
+     * @param node the node to check
+     * @return true if this node represents a legal object value whose java type is known exactly
+     */
     public static boolean isExactType(ValueNode node) {
         return isExactType(node.stamp());
     }
 
+    /**
+     * Checks whether this {@link Stamp} represents a {@linkplain Stamp#isLegal() legal} Object
+     * stamp whose {@linkplain ResolvedJavaType java type} is known exactly. If this method returns
+     * true then the java type returned by {@link #typeOrNull(Stamp)} is the only concrete
+     * dynamic/runtime java type possible for values of this stamp.
+     *
+     * @param stamp the stamp to check
+     * @return true if this node represents a legal object stamp whose java type is known exactly
+     */
     public static boolean isExactType(Stamp stamp) {
-        if (stamp instanceof ObjectStamp) {
+        if (stamp instanceof ObjectStamp && stamp.isLegal()) {
             return ((ObjectStamp) stamp).isExactType();
         }
         return false;