changeset 18476:2e2148013010

Move nonNull and alwaysNull flags up to AbstractPointerStamp.
author Roland Schatz <roland.schatz@oracle.com>
date Wed, 19 Nov 2014 16:52:54 +0100
parents 96528e410fab
children 7b5106be0f18
files graal/com.oracle.graal.compiler.common/src/com/oracle/graal/compiler/common/type/AbstractObjectStamp.java graal/com.oracle.graal.compiler.common/src/com/oracle/graal/compiler/common/type/AbstractPointerStamp.java graal/com.oracle.graal.compiler.common/src/com/oracle/graal/compiler/common/type/PointerStamp.java graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/nodes/type/NarrowPointerStamp.java
diffstat 4 files changed, 53 insertions(+), 39 deletions(-) [+]
line wrap: on
line diff
--- a/graal/com.oracle.graal.compiler.common/src/com/oracle/graal/compiler/common/type/AbstractObjectStamp.java	Thu Nov 20 17:25:52 2014 +0100
+++ b/graal/com.oracle.graal.compiler.common/src/com/oracle/graal/compiler/common/type/AbstractObjectStamp.java	Wed Nov 19 16:52:54 2014 +0100
@@ -33,15 +33,11 @@
 
     private final ResolvedJavaType type;
     private final boolean exactType;
-    private final boolean nonNull;
-    private final boolean alwaysNull;
 
     protected AbstractObjectStamp(ResolvedJavaType type, boolean exactType, boolean nonNull, boolean alwaysNull) {
-        super(PointerType.Object);
+        super(PointerType.Object, nonNull, alwaysNull);
         this.type = type;
         this.exactType = exactType;
-        this.nonNull = nonNull;
-        this.alwaysNull = alwaysNull;
     }
 
     protected abstract AbstractObjectStamp copyWith(ResolvedJavaType newType, boolean newExactType, boolean newNonNull, boolean newAlwaysNull);
@@ -81,14 +77,6 @@
         return metaAccess.lookupJavaType(Object.class);
     }
 
-    public boolean nonNull() {
-        return nonNull;
-    }
-
-    public boolean alwaysNull() {
-        return alwaysNull;
-    }
-
     public ResolvedJavaType type() {
         return type;
     }
@@ -98,7 +86,7 @@
     }
 
     protected void appendString(StringBuilder str) {
-        str.append(nonNull ? "!" : "").append(exactType ? "#" : "").append(' ').append(type == null ? "-" : type.getName()).append(alwaysNull ? " NULL" : "");
+        str.append(nonNull() ? "!" : "").append(exactType ? "#" : "").append(' ').append(type == null ? "-" : type.getName()).append(alwaysNull() ? " NULL" : "");
     }
 
     @Override
@@ -119,16 +107,16 @@
         boolean meetExactType;
         boolean meetNonNull;
         boolean meetAlwaysNull;
-        if (other.alwaysNull) {
+        if (other.alwaysNull()) {
             meetType = type();
             meetExactType = exactType;
             meetNonNull = false;
-            meetAlwaysNull = alwaysNull;
-        } else if (alwaysNull) {
+            meetAlwaysNull = alwaysNull();
+        } else if (alwaysNull()) {
             meetType = other.type();
             meetExactType = other.exactType;
             meetNonNull = false;
-            meetAlwaysNull = other.alwaysNull;
+            meetAlwaysNull = other.alwaysNull();
         } else {
             meetType = meetTypes(type(), other.type());
             meetExactType = exactType && other.exactType;
@@ -136,13 +124,13 @@
                 // meeting two valid exact types may result in a non-exact type
                 meetExactType = Objects.equals(meetType, type) && Objects.equals(meetType, other.type);
             }
-            meetNonNull = nonNull && other.nonNull;
+            meetNonNull = nonNull() && other.nonNull();
             meetAlwaysNull = false;
         }
 
-        if (Objects.equals(meetType, type) && meetExactType == exactType && meetNonNull == nonNull && meetAlwaysNull == alwaysNull) {
+        if (Objects.equals(meetType, type) && meetExactType == exactType && meetNonNull == nonNull() && meetAlwaysNull == alwaysNull()) {
             return this;
-        } else if (Objects.equals(meetType, other.type) && meetExactType == other.exactType && meetNonNull == other.nonNull && meetAlwaysNull == other.alwaysNull) {
+        } else if (Objects.equals(meetType, other.type) && meetExactType == other.exactType && meetNonNull == other.nonNull() && meetAlwaysNull == other.alwaysNull()) {
             return other;
         } else {
             return copyWith(meetType, meetExactType, meetNonNull, meetAlwaysNull);
@@ -188,8 +176,8 @@
         }
 
         ResolvedJavaType joinType;
-        boolean joinAlwaysNull = alwaysNull || other.alwaysNull;
-        boolean joinNonNull = nonNull || other.nonNull;
+        boolean joinAlwaysNull = alwaysNull() || other.alwaysNull();
+        boolean joinNonNull = nonNull() || other.nonNull();
         boolean joinExactType = exactType || other.exactType;
         if (Objects.equals(type, other.type)) {
             joinType = type;
@@ -235,9 +223,9 @@
         } else if (joinExactType && !isConcreteType(joinType)) {
             return StampFactory.illegal(Kind.Object);
         }
-        if (Objects.equals(joinType, type) && joinExactType == exactType && joinNonNull == nonNull && joinAlwaysNull == alwaysNull) {
+        if (Objects.equals(joinType, type) && joinExactType == exactType && joinNonNull == nonNull() && joinAlwaysNull == alwaysNull()) {
             return this;
-        } else if (Objects.equals(joinType, other.type) && joinExactType == other.exactType && joinNonNull == other.nonNull && joinAlwaysNull == other.alwaysNull) {
+        } else if (Objects.equals(joinType, other.type) && joinExactType == other.exactType && joinNonNull == other.nonNull() && joinAlwaysNull == other.alwaysNull()) {
             return other;
         } else {
             return copyWith(joinType, joinExactType, joinNonNull, joinAlwaysNull);
@@ -262,9 +250,8 @@
     public int hashCode() {
         final int prime = 31;
         int result = 1;
+        result = prime * result + super.hashCode();
         result = prime * result + (exactType ? 1231 : 1237);
-        result = prime * result + (nonNull ? 1231 : 1237);
-        result = prime * result + (alwaysNull ? 1231 : 1237);
         result = prime * result + ((type == null) ? 0 : type.hashCode());
         return result;
     }
@@ -278,16 +265,9 @@
             return false;
         }
         AbstractObjectStamp other = (AbstractObjectStamp) obj;
-        if (exactType != other.exactType || nonNull != other.nonNull || alwaysNull != other.alwaysNull) {
+        if (exactType != other.exactType || !Objects.equals(type, other.type)) {
             return false;
         }
-        if (type == null) {
-            if (other.type != null) {
-                return false;
-            }
-        } else if (!type.equals(other.type)) {
-            return false;
-        }
-        return true;
+        return super.equals(other);
     }
 }
--- a/graal/com.oracle.graal.compiler.common/src/com/oracle/graal/compiler/common/type/AbstractPointerStamp.java	Thu Nov 20 17:25:52 2014 +0100
+++ b/graal/com.oracle.graal.compiler.common/src/com/oracle/graal/compiler/common/type/AbstractPointerStamp.java	Wed Nov 19 16:52:54 2014 +0100
@@ -32,15 +32,27 @@
 public abstract class AbstractPointerStamp extends Stamp {
 
     private final PointerType type;
+    private final boolean nonNull;
+    private final boolean alwaysNull;
 
-    protected AbstractPointerStamp(PointerType type) {
+    protected AbstractPointerStamp(PointerType type, boolean nonNull, boolean alwaysNull) {
         this.type = type;
+        this.nonNull = nonNull;
+        this.alwaysNull = alwaysNull;
     }
 
     public PointerType getType() {
         return type;
     }
 
+    public boolean nonNull() {
+        return nonNull;
+    }
+
+    public boolean alwaysNull() {
+        return alwaysNull;
+    }
+
     @Override
     public boolean isCompatible(Stamp otherStamp) {
         if (otherStamp instanceof AbstractPointerStamp) {
@@ -51,6 +63,28 @@
     }
 
     @Override
+    public int hashCode() {
+        final int prime = 31;
+        int result = 1;
+        result = prime * result + (alwaysNull ? 1231 : 1237);
+        result = prime * result + (nonNull ? 1231 : 1237);
+        result = prime * result + ((type == null) ? 0 : type.hashCode());
+        return result;
+    }
+
+    @Override
+    public boolean equals(Object obj) {
+        if (this == obj) {
+            return true;
+        }
+        if (obj == null || getClass() != obj.getClass()) {
+            return false;
+        }
+        AbstractPointerStamp other = (AbstractPointerStamp) obj;
+        return this.type == other.type && this.alwaysNull == other.alwaysNull && this.nonNull == other.nonNull;
+    }
+
+    @Override
     public LIRKind getLIRKind(LIRKindTool tool) {
         return tool.getPointerKind(getType());
     }
--- a/graal/com.oracle.graal.compiler.common/src/com/oracle/graal/compiler/common/type/PointerStamp.java	Thu Nov 20 17:25:52 2014 +0100
+++ b/graal/com.oracle.graal.compiler.common/src/com/oracle/graal/compiler/common/type/PointerStamp.java	Wed Nov 19 16:52:54 2014 +0100
@@ -30,7 +30,7 @@
 public class PointerStamp extends AbstractPointerStamp {
 
     PointerStamp(PointerType type) {
-        super(type);
+        super(type, false, false);
         assert type != PointerType.Object : "object pointers should use ObjectStamp";
     }
 
--- a/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/nodes/type/NarrowPointerStamp.java	Thu Nov 20 17:25:52 2014 +0100
+++ b/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/nodes/type/NarrowPointerStamp.java	Wed Nov 19 16:52:54 2014 +0100
@@ -33,7 +33,7 @@
     private final CompressEncoding encoding;
 
     public NarrowPointerStamp(PointerType type, CompressEncoding encoding) {
-        super(type);
+        super(type, false, false);
         assert type != PointerType.Object : "object pointers should use NarrowOopStamp";
         this.encoding = encoding;
     }