# HG changeset patch # User Gilles Duboscq # Date 1377173185 -7200 # Node ID 40c7cbe31aa9feb550561bce35ba8c848cb06550 # Parent fb6353944874f891fde22685add1af3e9abc5731 Simplify ObjectStamp.join and make sure there is no type/exact type when going to an allways null stamp diff -r fb6353944874 -r 40c7cbe31aa9 graal/com.oracle.graal.nodes.test/src/com/oracle/graal/nodes/test/ObjectStampJoinTest.java --- a/graal/com.oracle.graal.nodes.test/src/com/oracle/graal/nodes/test/ObjectStampJoinTest.java Thu Aug 22 14:04:03 2013 +0200 +++ b/graal/com.oracle.graal.nodes.test/src/com/oracle/graal/nodes/test/ObjectStampJoinTest.java Thu Aug 22 14:06:25 2013 +0200 @@ -46,6 +46,10 @@ } + private abstract static class E extends A { + + } + private interface I { } @@ -90,7 +94,10 @@ public void testJoin5() { Stamp dExact = StampFactory.exact(getType(D.class)); Stamp c = StampFactory.declared(getType(C.class)); - Assert.assertTrue(ObjectStamp.isObjectAlwaysNull(join(c, dExact))); + Stamp join = join(c, dExact); + Assert.assertTrue(ObjectStamp.isObjectAlwaysNull(join)); + Assert.assertNull(ObjectStamp.typeOrNull(join)); + Assert.assertFalse(ObjectStamp.isExactType(join)); } @Test @@ -103,6 +110,16 @@ } @Test + public void testJoin7() { + Stamp aExact = StampFactory.exact(getType(A.class)); + Stamp e = StampFactory.declared(getType(E.class)); + Stamp join = join(aExact, e); + Assert.assertTrue(ObjectStamp.isObjectAlwaysNull(join)); + Assert.assertNull(ObjectStamp.typeOrNull(join)); + Assert.assertFalse(ObjectStamp.isExactType(join)); + } + + @Test public void testJoinInterface0() { Stamp a = StampFactory.declared(getType(A.class)); Stamp b = StampFactory.declared(getType(I.class)); diff -r fb6353944874 -r 40c7cbe31aa9 graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/type/ObjectStamp.java --- a/graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/type/ObjectStamp.java Thu Aug 22 14:04:03 2013 +0200 +++ b/graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/type/ObjectStamp.java Thu Aug 22 14:06:25 2013 +0200 @@ -37,6 +37,7 @@ public ObjectStamp(ResolvedJavaType type, boolean exactType, boolean nonNull, boolean alwaysNull) { super(Kind.Object); + assert !exactType || (type != null && (!Modifier.isAbstract(type.getModifiers()) || type.isArray())); this.type = type; this.exactType = exactType; this.nonNull = nonNull; @@ -127,12 +128,12 @@ * the {@code to} stamp. While this is very similar to a {@link #join} operation, in the case * where both types are not obviously related, the cast operation will prefer the type of the * {@code to} stamp. This is necessary as long as ObjectStamps are not able to accurately - * represent union types. + * represent intersection types. * * For example when joining the {@link RandomAccess} type with the {@link AbstractList} type, - * without union types, this would result in the most generic type ({@link Object}). For this - * reason, in some cases a {@code castTo} operation is preferable in order to keep at least the - * {@link AbstractList} type. + * without intersection types, this would result in the most generic type ({@link Object} ). For + * this reason, in some cases a {@code castTo} operation is preferable in order to keep at least + * the {@link AbstractList} type. * * @param to the stamp this stamp should be casted to * @return This stamp casted to the {@code to} stamp @@ -155,17 +156,11 @@ ResolvedJavaType joinType; boolean joinAlwaysNull = alwaysNull || other.alwaysNull; boolean joinNonNull = nonNull || other.nonNull; - if (joinAlwaysNull && joinNonNull) { - return StampFactory.illegal(Kind.Object); - } boolean joinExactType = exactType || other.exactType; if (type == other.type) { joinType = type; } else if (type == null && other.type == null) { joinType = null; - if (joinExactType) { - return StampFactory.illegal(Kind.Object); - } } else if (type == null) { joinType = other.type; } else if (other.type == null) { @@ -195,9 +190,14 @@ } } if (joinAlwaysNull) { - if (joinNonNull) { - return StampFactory.illegal(Kind.Object); - } + joinType = null; + joinExactType = false; + } + if (joinExactType && joinType == null) { + return StampFactory.illegal(Kind.Object); + } + if (joinAlwaysNull && joinNonNull) { + return StampFactory.illegal(Kind.Object); } else if (joinExactType && Modifier.isAbstract(joinType.getModifiers()) && !joinType.isArray()) { return StampFactory.illegal(Kind.Object); }