Mercurial > hg > truffle
changeset 18260:0f23e16288c5
prevent use of identity for ArithmeticOpTable and ArithmeticOpTable.Op
author | Doug Simon <doug.simon@oracle.com> |
---|---|
date | Wed, 05 Nov 2014 17:07:30 +0100 |
parents | e1b2489393f4 |
children | d66c79acfeac |
files | graal/com.oracle.graal.compiler.common/src/com/oracle/graal/compiler/common/type/ArithmeticOpTable.java graal/com.oracle.graal.compiler.common/src/com/oracle/graal/compiler/common/type/ArithmeticStamp.java graal/com.oracle.graal.compiler.test/src/com/oracle/graal/compiler/test/CheckGraalInvariants.java graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/calc/BinaryArithmeticNode.java |
diffstat | 4 files changed, 47 insertions(+), 3 deletions(-) [+] |
line wrap: on
line diff
--- a/graal/com.oracle.graal.compiler.common/src/com/oracle/graal/compiler/common/type/ArithmeticOpTable.java Wed Nov 05 17:04:18 2014 +0100 +++ b/graal/com.oracle.graal.compiler.common/src/com/oracle/graal/compiler/common/type/ArithmeticOpTable.java Wed Nov 05 17:07:30 2014 +0100 @@ -22,6 +22,8 @@ */ package com.oracle.graal.compiler.common.type; +import static com.oracle.graal.api.meta.MetaUtil.*; + import java.util.*; import java.util.function.*; import java.util.stream.*; @@ -240,6 +242,15 @@ return floatConvert[op.ordinal()]; } + public static String toString(Op... ops) { + return Arrays.asList(ops).stream().map(o -> o == null ? "null" : o.operator + "{" + getSimpleName(o.getClass(), false) + "}").collect(Collectors.joining(",")); + } + + @Override + public String toString() { + return getClass().getSimpleName() + "[" + toString(neg, add, sub, mul, div, rem, not, and, or, xor, zeroExtend, signExtend, narrow) + ",floatConvert[" + toString(floatConvert) + "]]"; + } + public abstract static class Op { private final String operator; @@ -252,6 +263,22 @@ public String toString() { return operator; } + + @Override + public boolean equals(Object obj) { + if (obj == this) { + return true; + } + if (obj != null && getClass() == obj.getClass()) { + return obj.toString().equals(toString()); + } + return false; + } + + @Override + public int hashCode() { + return toString().hashCode(); + } } /** @@ -410,6 +437,20 @@ public Constant getZero(Stamp stamp) { return null; } + + @Override + public String toString() { + if (associative) { + if (commutative) { + return super.toString() + "[AC]"; + } else { + return super.toString() + "[A]"; + } + } else if (commutative) { + return super.toString() + "[C]"; + } + return super.toString(); + } } public abstract static class FloatConvertOp extends UnaryOp<FloatConvertOp> {
--- a/graal/com.oracle.graal.compiler.common/src/com/oracle/graal/compiler/common/type/ArithmeticStamp.java Wed Nov 05 17:04:18 2014 +0100 +++ b/graal/com.oracle.graal.compiler.common/src/com/oracle/graal/compiler/common/type/ArithmeticStamp.java Wed Nov 05 17:07:30 2014 +0100 @@ -53,7 +53,7 @@ if (!(obj instanceof ArithmeticStamp)) { return false; } - ArithmeticStamp other = (ArithmeticStamp) obj; - return this.ops == other.ops; + assert this.ops.toString().equals(((ArithmeticStamp) obj).ops.toString()); + return true; } }
--- a/graal/com.oracle.graal.compiler.test/src/com/oracle/graal/compiler/test/CheckGraalInvariants.java Wed Nov 05 17:04:18 2014 +0100 +++ b/graal/com.oracle.graal.compiler.test/src/com/oracle/graal/compiler/test/CheckGraalInvariants.java Wed Nov 05 17:07:30 2014 +0100 @@ -38,6 +38,7 @@ import com.oracle.graal.api.runtime.*; import com.oracle.graal.compiler.*; import com.oracle.graal.compiler.CompilerThreadFactory.DebugConfigAccess; +import com.oracle.graal.compiler.common.type.*; import com.oracle.graal.debug.*; import com.oracle.graal.graph.*; import com.oracle.graal.java.*; @@ -208,6 +209,8 @@ new VerifyUsageWithEquals(JavaField.class).apply(graph, context); new VerifyUsageWithEquals(LocationIdentity.class).apply(graph, context); new VerifyUsageWithEquals(LIRKind.class).apply(graph, context); + new VerifyUsageWithEquals(ArithmeticOpTable.class).apply(graph, context); + new VerifyUsageWithEquals(ArithmeticOpTable.Op.class).apply(graph, context); } new VerifyDebugUsage().apply(graph, context); }
--- a/graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/calc/BinaryArithmeticNode.java Wed Nov 05 17:04:18 2014 +0100 +++ b/graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/calc/BinaryArithmeticNode.java Wed Nov 05 17:07:30 2014 +0100 @@ -47,7 +47,7 @@ protected final BinaryOp<OP> getOp(ValueNode forX, ValueNode forY) { ArithmeticOpTable table = ArithmeticOpTable.forStamp(forX.stamp()); - assert table == ArithmeticOpTable.forStamp(forY.stamp()); + assert table.toString().equals(ArithmeticOpTable.forStamp(forY.stamp()).toString()); return getOp.apply(table); }