# HG changeset patch # User Gilles Duboscq # Date 1368443742 -7200 # Node ID 309181f26fc70da0dc9b5f5a1cc219fbe8cd17bf # Parent 2adfe940fd55ddc309c7ba3579aa90fa7e4cfdea# Parent 6320d0e541b49da503ceb70b9d2e2ec2ae84ac08 Merge diff -r 2adfe940fd55 -r 309181f26fc7 graal/com.oracle.graal.api.code/src/com/oracle/graal/api/code/Register.java --- a/graal/com.oracle.graal.api.code/src/com/oracle/graal/api/code/Register.java Mon May 13 11:44:49 2013 +0200 +++ b/graal/com.oracle.graal.api.code/src/com/oracle/graal/api/code/Register.java Mon May 13 13:15:42 2013 +0200 @@ -96,29 +96,16 @@ @Override public int hashCode() { - return 31 + ((name == null) ? 0 : name.hashCode()); + return 23 + name.hashCode(); } @Override public boolean equals(Object obj) { - if (this == obj) { - return true; - } - if (obj == null) { - return false; - } - if (getClass() != obj.getClass()) { - return false; + if (obj instanceof RegisterCategory) { + RegisterCategory other = (RegisterCategory) obj; + return name.equals(other.name); } - RegisterCategory other = (RegisterCategory) obj; - if (name == null) { - if (other.name != null) { - return false; - } - } else if (!name.equals(other.name)) { - return false; - } - return true; + return false; } } @@ -219,48 +206,21 @@ @Override public int hashCode() { - final int prime = 31; + final int prime = 17; int result = 1; result = prime * result + encoding; - result = prime * result + ((name == null) ? 0 : name.hashCode()); + result = prime * result + name.hashCode(); result = prime * result + number; - result = prime * result + ((registerCategory == null) ? 0 : registerCategory.hashCode()); + result = prime * result + registerCategory.hashCode(); return result; } @Override public boolean equals(Object obj) { - if (this == obj) { - return true; - } - if (obj == null) { - return false; - } - if (getClass() != obj.getClass()) { - return false; - } - Register other = (Register) obj; - if (encoding != other.encoding) { - return false; + if (obj instanceof Register) { + Register other = (Register) obj; + return encoding == other.encoding && name.equals(other.name) && number == other.number && registerCategory.equals(registerCategory); } - if (name == null) { - if (other.name != null) { - return false; - } - } else if (!name.equals(other.name)) { - return false; - } - if (number != other.number) { - return false; - } - if (registerCategory == null) { - if (other.registerCategory != null) { - return false; - } - } else if (!registerCategory.equals(other.registerCategory)) { - return false; - } - return true; + return false; } - } diff -r 2adfe940fd55 -r 309181f26fc7 graal/com.oracle.graal.api.code/src/com/oracle/graal/api/code/RegisterValue.java --- a/graal/com.oracle.graal.api.code/src/com/oracle/graal/api/code/RegisterValue.java Mon May 13 11:44:49 2013 +0200 +++ b/graal/com.oracle.graal.api.code/src/com/oracle/graal/api/code/RegisterValue.java Mon May 13 13:15:42 2013 +0200 @@ -58,28 +58,15 @@ @Override public int hashCode() { - return 31 * super.hashCode() + ((reg == null) ? 0 : reg.hashCode()); + return 29 * super.hashCode() + reg.hashCode(); } @Override public boolean equals(Object obj) { - if (this == obj) { - return true; - } - if (!super.equals(obj)) { - return false; - } - if (getClass() != obj.getClass()) { - return false; + if (obj instanceof RegisterValue) { + RegisterValue other = (RegisterValue) obj; + return super.equals(obj) && reg.equals(other.reg); } - RegisterValue other = (RegisterValue) obj; - if (reg == null) { - if (other.reg != null) { - return false; - } - } else if (!reg.equals(other.reg)) { - return false; - } - return true; + return false; } } diff -r 2adfe940fd55 -r 309181f26fc7 graal/com.oracle.graal.api.code/src/com/oracle/graal/api/code/StackSlot.java --- a/graal/com.oracle.graal.api.code/src/com/oracle/graal/api/code/StackSlot.java Mon May 13 11:44:49 2013 +0200 +++ b/graal/com.oracle.graal.api.code/src/com/oracle/graal/api/code/StackSlot.java Mon May 13 13:15:42 2013 +0200 @@ -118,7 +118,7 @@ @Override public int hashCode() { - final int prime = 31; + final int prime = 37; int result = super.hashCode(); result = prime * result + (addFrameSize ? 1231 : 1237); result = prime * result + offset; @@ -127,22 +127,10 @@ @Override public boolean equals(Object obj) { - if (this == obj) { - return true; - } - if (!super.equals(obj)) { - return false; - } - if (getClass() != obj.getClass()) { - return false; + if (obj instanceof StackSlot) { + StackSlot other = (StackSlot) obj; + return super.equals(obj) && addFrameSize == other.addFrameSize && offset == other.offset; } - StackSlot other = (StackSlot) obj; - if (addFrameSize != other.addFrameSize) { - return false; - } - if (offset != other.offset) { - return false; - } - return true; + return false; } } diff -r 2adfe940fd55 -r 309181f26fc7 graal/com.oracle.graal.api.meta/src/com/oracle/graal/api/meta/Value.java --- a/graal/com.oracle.graal.api.meta/src/com/oracle/graal/api/meta/Value.java Mon May 13 11:44:49 2013 +0200 +++ b/graal/com.oracle.graal.api.meta/src/com/oracle/graal/api/meta/Value.java Mon May 13 13:15:42 2013 +0200 @@ -81,35 +81,19 @@ @Override public int hashCode() { - final int prime = 31; + final int prime = 41; int result = 1; - result = prime * result + ((kind == null) ? 0 : kind.hashCode()); - result = prime * result + ((platformKind == null) ? 0 : platformKind.hashCode()); + result = prime * result + kind.hashCode(); + result = prime * result + platformKind.hashCode(); return result; } @Override public boolean equals(Object obj) { - if (this == obj) { - return true; - } - if (obj == null) { - return false; - } - if (getClass() != obj.getClass()) { - return false; + if (obj instanceof Value) { + Value other = (Value) obj; + return kind.equals(other.kind) && platformKind.equals(platformKind); } - Value other = (Value) obj; - if (kind != other.kind) { - return false; - } - if (platformKind == null) { - if (other.platformKind != null) { - return false; - } - } else if (!platformKind.equals(other.platformKind)) { - return false; - } - return true; + return false; } } diff -r 2adfe940fd55 -r 309181f26fc7 graal/com.oracle.graal.compiler/src/com/oracle/graal/compiler/GraalCompiler.java --- a/graal/com.oracle.graal.compiler/src/com/oracle/graal/compiler/GraalCompiler.java Mon May 13 11:44:49 2013 +0200 +++ b/graal/com.oracle.graal.compiler/src/com/oracle/graal/compiler/GraalCompiler.java Mon May 13 13:15:42 2013 +0200 @@ -44,6 +44,7 @@ import com.oracle.graal.phases.graph.*; import com.oracle.graal.phases.schedule.*; import com.oracle.graal.phases.tiers.*; +import com.oracle.graal.phases.verify.*; import com.oracle.graal.virtual.phases.ea.*; /** @@ -124,6 +125,7 @@ } else { Debug.dump(graph, "initial state"); } + new VerifyValueUsage(runtime).apply(graph); if (GraalOptions.OptCanonicalizer) { new CanonicalizerPhase.Instance(runtime, assumptions).apply(graph); diff -r 2adfe940fd55 -r 309181f26fc7 graal/com.oracle.graal.compiler/src/com/oracle/graal/compiler/alloc/LinearScanWalker.java --- a/graal/com.oracle.graal.compiler/src/com/oracle/graal/compiler/alloc/LinearScanWalker.java Mon May 13 11:44:49 2013 +0200 +++ b/graal/com.oracle.graal.compiler/src/com/oracle/graal/compiler/alloc/LinearScanWalker.java Mon May 13 13:15:42 2013 +0200 @@ -936,7 +936,7 @@ if (interval.insertMoveWhenActivated()) { assert interval.isSplitChild(); assert interval.currentSplitChild() != null; - assert interval.currentSplitChild().operand != operand : "cannot insert move between same interval"; + assert !interval.currentSplitChild().operand.equals(operand) : "cannot insert move between same interval"; if (GraalOptions.TraceLinearScanLevel >= 4) { TTY.println("Inserting move from interval %d to %d because insertMoveWhenActivated is set", interval.currentSplitChild().operandNumber, interval.operandNumber); } diff -r 2adfe940fd55 -r 309181f26fc7 graal/com.oracle.graal.compiler/src/com/oracle/graal/compiler/alloc/MoveResolver.java --- a/graal/com.oracle.graal.compiler/src/com/oracle/graal/compiler/alloc/MoveResolver.java Mon May 13 11:44:49 2013 +0200 +++ b/graal/com.oracle.graal.compiler/src/com/oracle/graal/compiler/alloc/MoveResolver.java Mon May 13 13:15:42 2013 +0200 @@ -192,7 +192,7 @@ } private void insertMove(Interval fromInterval, Interval toInterval) { - assert fromInterval.operand != toInterval.operand : "from and to interval equal: " + fromInterval; + assert !fromInterval.operand.equals(toInterval.operand) : "from and to interval equal: " + fromInterval; assert fromInterval.kind() == toInterval.kind() : "move between different types"; assert insertIdx != -1 : "must setup insert position first"; @@ -331,7 +331,7 @@ TTY.println("MoveResolver: adding mapping from interval %d (%s) to interval %d (%s)", fromInterval.operandNumber, fromInterval.location(), toInterval.operandNumber, toInterval.location()); } - assert fromInterval.operand != toInterval.operand : "from and to interval equal: " + fromInterval; + assert !fromInterval.operand.equals(toInterval.operand) : "from and to interval equal: " + fromInterval; assert fromInterval.kind() == toInterval.kind(); mappingFrom.add(fromInterval); mappingFromOpr.add(Value.ILLEGAL); diff -r 2adfe940fd55 -r 309181f26fc7 graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/meta/HotSpotMonitorValue.java --- a/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/meta/HotSpotMonitorValue.java Mon May 13 11:44:49 2013 +0200 +++ b/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/meta/HotSpotMonitorValue.java Mon May 13 13:15:42 2013 +0200 @@ -66,43 +66,20 @@ @Override public int hashCode() { - final int prime = 31; + final int prime = 43; int result = super.hashCode(); result = prime * result + (eliminated ? 1231 : 1237); - result = prime * result + ((owner == null) ? 0 : owner.hashCode()); - result = prime * result + ((slot == null) ? 0 : slot.hashCode()); + result = prime * result + owner.hashCode(); + result = prime * result + slot.hashCode(); return result; } @Override public boolean equals(Object obj) { - if (this == obj) { - return true; - } - if (!super.equals(obj)) { - return false; - } - if (getClass() != obj.getClass()) { - return false; - } - HotSpotMonitorValue other = (HotSpotMonitorValue) obj; - if (eliminated != other.eliminated) { - return false; + if (obj instanceof HotSpotMonitorValue) { + HotSpotMonitorValue other = (HotSpotMonitorValue) obj; + return super.equals(obj) && eliminated == other.eliminated && owner.equals(other.owner) && slot.equals(other.slot); } - if (owner == null) { - if (other.owner != null) { - return false; - } - } else if (!owner.equals(other.owner)) { - return false; - } - if (slot == null) { - if (other.slot != null) { - return false; - } - } else if (!slot.equals(other.slot)) { - return false; - } - return true; + return false; } } diff -r 2adfe940fd55 -r 309181f26fc7 graal/com.oracle.graal.lir/src/com/oracle/graal/lir/CompositeValue.java --- a/graal/com.oracle.graal.lir/src/com/oracle/graal/lir/CompositeValue.java Mon May 13 11:44:49 2013 +0200 +++ b/graal/com.oracle.graal.lir/src/com/oracle/graal/lir/CompositeValue.java Mon May 13 13:15:42 2013 +0200 @@ -61,31 +61,15 @@ @Override public int hashCode() { - final int prime = 31; - int result = super.hashCode(); - result = prime * result + ((valueClass == null) ? 0 : valueClass.hashCode()); - return result; + return 53 * super.hashCode() + valueClass.hashCode(); } @Override public boolean equals(Object obj) { - if (this == obj) { - return true; - } - if (!super.equals(obj)) { - return false; - } - if (getClass() != obj.getClass()) { - return false; + if (obj instanceof CompositeValue) { + CompositeValue other = (CompositeValue) obj; + return super.equals(other) && valueClass.equals(other.valueClass); } - CompositeValue other = (CompositeValue) obj; - if (valueClass == null) { - if (other.valueClass != null) { - return false; - } - } else if (!valueClass.equals(other.valueClass)) { - return false; - } - return true; + return false; } } diff -r 2adfe940fd55 -r 309181f26fc7 graal/com.oracle.graal.lir/src/com/oracle/graal/lir/Variable.java --- a/graal/com.oracle.graal.lir/src/com/oracle/graal/lir/Variable.java Mon May 13 11:44:49 2013 +0200 +++ b/graal/com.oracle.graal.lir/src/com/oracle/graal/lir/Variable.java Mon May 13 13:15:42 2013 +0200 @@ -57,24 +57,15 @@ @Override public int hashCode() { - return 31 * super.hashCode() + index; + return 71 * super.hashCode() + index; } @Override public boolean equals(Object obj) { - if (this == obj) { - return true; - } - if (!super.equals(obj)) { - return false; + if (obj instanceof Variable) { + Variable other = (Variable) obj; + return super.equals(other) && index == other.index; } - if (getClass() != obj.getClass()) { - return false; - } - Variable other = (Variable) obj; - if (index != other.index) { - return false; - } - return true; + return false; } } diff -r 2adfe940fd55 -r 309181f26fc7 graal/com.oracle.graal.phases/src/com/oracle/graal/phases/VerifyPhase.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/graal/com.oracle.graal.phases/src/com/oracle/graal/phases/VerifyPhase.java Mon May 13 13:15:42 2013 +0200 @@ -0,0 +1,35 @@ +/* + * Copyright (c) 2013, 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.phases; + +import com.oracle.graal.nodes.*; + +public abstract class VerifyPhase extends Phase { + + @Override + protected final void run(StructuredGraph graph) { + assert verify(graph); + } + + protected abstract boolean verify(StructuredGraph graph); +} diff -r 2adfe940fd55 -r 309181f26fc7 graal/com.oracle.graal.phases/src/com/oracle/graal/phases/verify/VerifyValueUsage.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/graal/com.oracle.graal.phases/src/com/oracle/graal/phases/verify/VerifyValueUsage.java Mon May 13 13:15:42 2013 +0200 @@ -0,0 +1,61 @@ +/* + * Copyright (c) 2013, 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.phases.verify; + +import com.oracle.graal.api.meta.*; +import com.oracle.graal.nodes.*; +import com.oracle.graal.nodes.calc.*; +import com.oracle.graal.nodes.type.*; +import com.oracle.graal.phases.*; + +public class VerifyValueUsage extends VerifyPhase { + + private MetaAccessProvider runtime; + + public VerifyValueUsage(MetaAccessProvider runtime) { + this.runtime = runtime; + } + + private boolean checkType(ValueNode node) { + if (node.stamp() instanceof ObjectStamp) { + ResolvedJavaType valueType = runtime.lookupJavaType(Value.class); + ResolvedJavaType nodeType = node.objectStamp().type(); + + if (valueType.isAssignableFrom(nodeType)) { + return true; + } + } + return false; + } + + @Override + protected boolean verify(StructuredGraph graph) { + for (ObjectEqualsNode cn : graph.getNodes().filter(ObjectEqualsNode.class)) { + String desc = "VerifyValueUsage: " + cn.x() + " or " + cn.y() + " in " + graph.method() + " uses object identity. Should use equals() instead."; + if (!graph.method().toString().endsWith("equals(Object)>")) { + assert !((checkType(cn.x()) && !(cn.y() instanceof ConstantNode)) || (checkType(cn.y()) && !(cn.x() instanceof ConstantNode))) : desc; + } + } + return true; + } +}