# HG changeset patch # User Doug Simon # Date 1415784990 -3600 # Node ID d60dd21329f2cd1a89ebf53f7b0206ff5cb52473 # Parent 8169f68e9530e94b95d814acfe0c7b90ecf08266 implemented .equals() for CompilationResult and the objects it encapsulates diff -r 8169f68e9530 -r d60dd21329f2 graal/com.oracle.graal.api.code/src/com/oracle/graal/api/code/Architecture.java --- a/graal/com.oracle.graal.api.code/src/com/oracle/graal/api/code/Architecture.java Tue Nov 11 14:30:55 2014 -0800 +++ b/graal/com.oracle.graal.api.code/src/com/oracle/graal/api/code/Architecture.java Wed Nov 12 10:36:30 2014 +0100 @@ -23,6 +23,7 @@ package com.oracle.graal.api.code; import java.nio.*; +import java.util.*; import com.oracle.graal.api.code.Register.RegisterCategory; import com.oracle.graal.api.meta.*; @@ -218,4 +219,31 @@ * @return the largest kind that can be stored in a register {@code category} */ public abstract PlatformKind getLargestStorableKind(RegisterCategory category); + + @Override + public final boolean equals(Object obj) { + if (obj == this) { + return true; + } + if (obj instanceof Architecture) { + Architecture that = (Architecture) obj; + if (this.name.equals(that.name)) { + assert this.byteOrder.equals(that.byteOrder); + assert this.implicitMemoryBarriers == that.implicitMemoryBarriers; + assert this.machineCodeCallDisplacementOffset == that.machineCodeCallDisplacementOffset; + assert this.registerReferenceMapSize == that.registerReferenceMapSize; + assert Arrays.equals(this.registers, that.registers); + assert this.returnAddressSize == that.returnAddressSize; + assert this.unalignedMemoryAccess == that.unalignedMemoryAccess; + assert this.wordSize == that.wordSize; + return true; + } + } + return false; + } + + @Override + public final int hashCode() { + return name.hashCode(); + } } diff -r 8169f68e9530 -r d60dd21329f2 graal/com.oracle.graal.api.code/src/com/oracle/graal/api/code/Assumptions.java --- a/graal/com.oracle.graal.api.code/src/com/oracle/graal/api/code/Assumptions.java Tue Nov 11 14:30:55 2014 -0800 +++ b/graal/com.oracle.graal.api.code/src/com/oracle/graal/api/code/Assumptions.java Wed Nov 12 10:36:30 2014 +0100 @@ -237,7 +237,7 @@ public boolean equals(Object obj) { if (obj instanceof CallSiteTargetValue) { CallSiteTargetValue other = (CallSiteTargetValue) obj; - return other.callSite == callSite && other.methodHandle == methodHandle; + return callSite.equals(other.callSite) && methodHandle.equals(other.methodHandle); } return false; } @@ -275,6 +275,31 @@ } @Override + public int hashCode() { + throw new UnsupportedOperationException("hashCode"); + } + + @Override + public boolean equals(Object obj) { + if (this == obj) { + return true; + } + if (obj instanceof Assumptions) { + Assumptions that = (Assumptions) obj; + if (useOptimisticAssumptions != that.useOptimisticAssumptions || count != that.count) { + return false; + } + for (int i = 0; i < count; i++) { + if (!list[i].equals(that.list[i])) { + return false; + } + } + return true; + } + return false; + } + + @Override public Iterator iterator() { return new Iterator() { diff -r 8169f68e9530 -r d60dd21329f2 graal/com.oracle.graal.api.code/src/com/oracle/graal/api/code/BytecodeFrame.java --- a/graal/com.oracle.graal.api.code/src/com/oracle/graal/api/code/BytecodeFrame.java Tue Nov 11 14:30:55 2014 -0800 +++ b/graal/com.oracle.graal.api.code/src/com/oracle/graal/api/code/BytecodeFrame.java Wed Nov 12 10:36:30 2014 +0100 @@ -23,6 +23,7 @@ package com.oracle.graal.api.code; import java.io.*; +import java.util.*; import com.oracle.graal.api.meta.*; @@ -216,6 +217,28 @@ } @Override + public boolean equals(Object obj) { + if (this == obj) { + return true; + } + if (obj instanceof BytecodeFrame && super.equals(obj)) { + BytecodeFrame that = (BytecodeFrame) obj; + // @formatter:off + if (this.duringCall == that.duringCall && + this.rethrowException == that.rethrowException && + this.numLocals == that.numLocals && + this.numLocks == that.numLocks && + this.numStack == that.numStack && + Arrays.equals(this.values, that.values)) { + return true; + } + // @formatter:off + return true; + } + return false; + } + + @Override public String toString() { return CodeUtil.append(new StringBuilder(100), this).toString(); } diff -r 8169f68e9530 -r d60dd21329f2 graal/com.oracle.graal.api.code/src/com/oracle/graal/api/code/BytecodePosition.java --- a/graal/com.oracle.graal.api.code/src/com/oracle/graal/api/code/BytecodePosition.java Tue Nov 11 14:30:55 2014 -0800 +++ b/graal/com.oracle.graal.api.code/src/com/oracle/graal/api/code/BytecodePosition.java Wed Nov 12 10:36:30 2014 +0100 @@ -23,6 +23,7 @@ package com.oracle.graal.api.code; import java.io.*; +import java.util.*; import com.oracle.graal.api.meta.*; @@ -72,13 +73,10 @@ if (obj == this) { return true; } - if (obj instanceof BytecodePosition) { - BytecodePosition other = (BytecodePosition) obj; - if (other.getMethod().equals(getMethod()) && other.getBCI() == getBCI()) { - if (getCaller() == null) { - return other.getCaller() == null; - } - return getCaller().equals(other.getCaller()); + if (obj != null && getClass() == obj.getClass()) { + BytecodePosition that = (BytecodePosition) obj; + if (this.bci == that.bci && Objects.equals(this.getMethod(), that.getMethod()) && Objects.equals(this.caller, that.caller)) { + return true; } } return false; diff -r 8169f68e9530 -r d60dd21329f2 graal/com.oracle.graal.api.code/src/com/oracle/graal/api/code/CompilationResult.java --- a/graal/com.oracle.graal.api.code/src/com/oracle/graal/api/code/CompilationResult.java Tue Nov 11 14:30:55 2014 -0800 +++ b/graal/com.oracle.graal.api.code/src/com/oracle/graal/api/code/CompilationResult.java Wed Nov 12 10:36:30 2014 +0100 @@ -52,6 +52,14 @@ public Site(int pos) { this.pcOffset = pos; } + + @Override + public final int hashCode() { + throw new UnsupportedOperationException("hashCode"); + } + + @Override + public abstract boolean equals(Object obj); } /** @@ -88,6 +96,20 @@ } return this.reason.compareTo(o.reason); } + + @Override + public boolean equals(Object obj) { + if (this == obj) { + return true; + } + if (obj != null && obj.getClass() == getClass()) { + Infopoint that = (Infopoint) obj; + if (this.pcOffset == that.pcOffset && Objects.equals(this.debugInfo, that.debugInfo) && Objects.equals(this.reason, that.reason)) { + return true; + } + } + return false; + } } /** @@ -122,6 +144,20 @@ } @Override + public boolean equals(Object obj) { + if (this == obj) { + return true; + } + if (obj instanceof Call && super.equals(obj)) { + Call that = (Call) obj; + if (this.size == that.size && this.direct == that.direct && Objects.equals(this.target, that.target)) { + return true; + } + } + return false; + } + + @Override public String toString() { StringBuilder sb = new StringBuilder(); sb.append(pcOffset); @@ -143,9 +179,17 @@ public abstract static class Reference implements Serializable { private static final long serialVersionUID = 4841246083028477946L; + + @Override + public final int hashCode() { + throw new UnsupportedOperationException("hashCode"); + } + + @Override + public abstract boolean equals(Object obj); } - public static class ConstantReference extends Reference { + public static final class ConstantReference extends Reference { private static final long serialVersionUID = 5841121930949053612L; @@ -165,25 +209,19 @@ } @Override - public int hashCode() { - return getConstant().hashCode(); - } - - @Override public boolean equals(Object obj) { if (this == obj) { return true; } if (obj instanceof ConstantReference) { - ConstantReference other = (ConstantReference) obj; - return getConstant().equals(other.getConstant()); - } else { - return false; + ConstantReference that = (ConstantReference) obj; + return Objects.equals(this.constant, that.constant); } + return false; } } - public static class DataSectionReference extends Reference { + public static final class DataSectionReference extends Reference { private static final long serialVersionUID = 9011681879878139182L; @@ -201,6 +239,18 @@ public void setOffset(int offset) { this.offset = offset; } + + @Override + public boolean equals(Object obj) { + if (this == obj) { + return true; + } + if (obj instanceof DataSectionReference) { + DataSectionReference that = (DataSectionReference) obj; + return this.offset == that.offset; + } + return false; + } } /** @@ -222,6 +272,20 @@ public String toString() { return String.format("%d[]", pcOffset, reference.toString()); } + + @Override + public boolean equals(Object obj) { + if (this == obj) { + return true; + } + if (obj instanceof DataPatch) { + DataPatch that = (DataPatch) obj; + if (this.pcOffset == that.pcOffset && Objects.equals(this.reference, that.reference)) { + return true; + } + } + return false; + } } /** @@ -237,6 +301,14 @@ public CodeAnnotation(int position) { this.position = position; } + + @Override + public final int hashCode() { + throw new UnsupportedOperationException("hashCode"); + } + + @Override + public abstract boolean equals(Object obj); } /** @@ -256,6 +328,20 @@ } @Override + public boolean equals(Object obj) { + if (this == obj) { + return true; + } + if (obj instanceof CodeComment) { + CodeComment that = (CodeComment) obj; + if (this.position == that.position && this.value.equals(that.value)) { + return true; + } + } + return false; + } + + @Override public String toString() { return getClass().getSimpleName() + "@" + position + ": " + value; } @@ -297,6 +383,20 @@ } @Override + public boolean equals(Object obj) { + if (this == obj) { + return true; + } + if (obj instanceof JumpTable) { + JumpTable that = (JumpTable) obj; + if (this.position == that.position && this.entrySize == that.entrySize && this.low == that.low && this.high == that.high) { + return true; + } + } + return false; + } + + @Override public String toString() { return getClass().getSimpleName() + "@" + position + ": [" + low + " .. " + high + "]"; } @@ -320,6 +420,20 @@ public String toString() { return String.format("%d[]", pcOffset, handlerPos); } + + @Override + public boolean equals(Object obj) { + if (this == obj) { + return true; + } + if (obj instanceof ExceptionHandler) { + ExceptionHandler that = (ExceptionHandler) obj; + if (this.pcOffset == that.pcOffset && this.handlerPos == that.handlerPos) { + return true; + } + } + return false; + } } /** @@ -346,6 +460,20 @@ return String.format("%d[]", pcOffset, id.toString()); } } + + @Override + public boolean equals(Object obj) { + if (this == obj) { + return true; + } + if (obj instanceof Mark) { + Mark that = (Mark) obj; + if (this.pcOffset == that.pcOffset && Objects.equals(this.id, that.id)) { + return true; + } + } + return false; + } } private int id = -1; @@ -385,6 +513,41 @@ this.name = name; } + @Override + public int hashCode() { + // CompilationResult instances should not be used as hash map keys + throw new UnsupportedOperationException("hashCode"); + } + + @Override + public boolean equals(Object obj) { + if (this == obj) { + return true; + } + if (obj != null && obj.getClass() == getClass()) { + CompilationResult that = (CompilationResult) obj; + // @formatter:off + if (this.entryBCI == that.entryBCI && + this.id == that.id && + this.customStackAreaOffset == that.customStackAreaOffset && + this.totalFrameSize == that.totalFrameSize && + this.targetCodeSize == that.targetCodeSize && + Objects.equals(this.name, that.name) && + Objects.equals(this.annotations, that.annotations) && + Objects.equals(this.assumptions, that.assumptions) && + Objects.equals(this.dataSection, that.dataSection) && + Objects.equals(this.exceptionHandlers, that.exceptionHandlers) && + Objects.equals(this.dataPatches, that.dataPatches) && + Objects.equals(this.infopoints, that.infopoints) && + Objects.equals(this.marks, that.marks) && + Arrays.equals(targetCode, that.targetCode)) { + return true; + } + // @formatter:on + } + return false; + } + /** * @return the compile id */ diff -r 8169f68e9530 -r d60dd21329f2 graal/com.oracle.graal.api.code/src/com/oracle/graal/api/code/DataSection.java --- a/graal/com.oracle.graal.api.code/src/com/oracle/graal/api/code/DataSection.java Tue Nov 11 14:30:55 2014 -0800 +++ b/graal/com.oracle.graal.api.code/src/com/oracle/graal/api/code/DataSection.java Wed Nov 12 10:36:30 2014 +0100 @@ -32,7 +32,7 @@ import com.oracle.graal.api.code.DataSection.Data; import com.oracle.graal.api.meta.*; -public class DataSection implements Serializable, Iterable { +public final class DataSection implements Serializable, Iterable { private static final long serialVersionUID = -1375715553825731716L; @@ -94,7 +94,7 @@ } } - public static class Data implements Serializable { + public static final class Data implements Serializable { private static final long serialVersionUID = -719932751800916080L; @@ -131,6 +131,27 @@ public DataBuilder getBuilder() { return builder; } + + @Override + public int hashCode() { + // Data instances should not be used as hash map keys + throw new UnsupportedOperationException("hashCode"); + } + + @Override + public boolean equals(Object obj) { + assert ref != null; + if (obj == this) { + return true; + } + if (obj instanceof Data) { + Data that = (Data) obj; + if (this.alignment == that.alignment && this.size == that.size && this.ref.equals(that.ref)) { + return true; + } + } + return false; + } } private final ArrayList dataItems = new ArrayList<>(); @@ -139,6 +160,26 @@ private int sectionAlignment; private int sectionSize; + @Override + public int hashCode() { + // DataSection instances should not be used as hash map keys + throw new UnsupportedOperationException("hashCode"); + } + + @Override + public boolean equals(Object obj) { + if (this == obj) { + return true; + } + if (obj instanceof DataSection) { + DataSection that = (DataSection) obj; + if (this.finalLayout == that.finalLayout && this.sectionAlignment == that.sectionAlignment && this.sectionSize == that.sectionSize && Objects.equals(this.dataItems, that.dataItems)) { + return true; + } + } + return false; + } + /** * Insert a {@link Data} item into the data section. If the item is already in the data section, * the same {@link DataSectionReference} is returned. diff -r 8169f68e9530 -r d60dd21329f2 graal/com.oracle.graal.api.code/src/com/oracle/graal/api/code/DebugInfo.java --- a/graal/com.oracle.graal.api.code/src/com/oracle/graal/api/code/DebugInfo.java Tue Nov 11 14:30:55 2014 -0800 +++ b/graal/com.oracle.graal.api.code/src/com/oracle/graal/api/code/DebugInfo.java Wed Nov 12 10:36:30 2014 +0100 @@ -22,6 +22,8 @@ */ package com.oracle.graal.api.code; +import java.util.*; + /** * Represents the debugging information for a particular point of execution. This information * includes: @@ -34,7 +36,7 @@ * current frame * */ -public class DebugInfo { +public final class DebugInfo { private final BytecodePosition bytecodePosition; private final ReferenceMap referenceMap; @@ -104,4 +106,23 @@ public RegisterSaveLayout getCalleeSaveInfo() { return calleeSaveInfo; } + + @Override + public int hashCode() { + throw new UnsupportedOperationException("hashCode"); + } + + @Override + public boolean equals(Object obj) { + if (this == obj) { + return true; + } + if (obj instanceof DebugInfo) { + DebugInfo that = (DebugInfo) obj; + if (Objects.equals(this.bytecodePosition, that.bytecodePosition) && Objects.equals(this.calleeSaveInfo, that.calleeSaveInfo) && Objects.equals(this.referenceMap, that.referenceMap)) { + return true; + } + } + return false; + } } diff -r 8169f68e9530 -r d60dd21329f2 graal/com.oracle.graal.api.code/src/com/oracle/graal/api/code/RegisterSaveLayout.java --- a/graal/com.oracle.graal.api.code/src/com/oracle/graal/api/code/RegisterSaveLayout.java Tue Nov 11 14:30:55 2014 -0800 +++ b/graal/com.oracle.graal.api.code/src/com/oracle/graal/api/code/RegisterSaveLayout.java Wed Nov 12 10:36:30 2014 +0100 @@ -28,7 +28,7 @@ * A map from registers to frame slots. This can be used to describe where callee saved registers * are saved in a callee's frame. */ -public class RegisterSaveLayout { +public final class RegisterSaveLayout { /** * Keys. @@ -102,6 +102,25 @@ } @Override + public int hashCode() { + throw new UnsupportedOperationException(); + } + + @Override + public boolean equals(Object obj) { + if (this == obj) { + return true; + } + if (obj instanceof RegisterSaveLayout) { + RegisterSaveLayout that = (RegisterSaveLayout) obj; + if (Arrays.equals(registers, that.registers) && Arrays.equals(slots, that.slots)) { + return true; + } + } + return false; + } + + @Override public String toString() { return registersToSlots(true).toString(); } diff -r 8169f68e9530 -r d60dd21329f2 graal/com.oracle.graal.api.code/src/com/oracle/graal/api/code/TargetDescription.java --- a/graal/com.oracle.graal.api.code/src/com/oracle/graal/api/code/TargetDescription.java Tue Nov 11 14:30:55 2014 -0800 +++ b/graal/com.oracle.graal.api.code/src/com/oracle/graal/api/code/TargetDescription.java Wed Nov 12 10:36:30 2014 +0100 @@ -82,6 +82,33 @@ this.inlineObjects = inlineObjects; } + @Override + public final int hashCode() { + throw new UnsupportedOperationException(); + } + + @Override + public final boolean equals(Object obj) { + if (this == obj) { + return true; + } + if (obj instanceof TargetDescription) { + TargetDescription that = (TargetDescription) obj; + // @formatter:off + if (this.implicitNullCheckLimit == that.implicitNullCheckLimit && + this.inlineObjects == that.inlineObjects && + this.isMP == that.isMP && + this.stackAlignment == that.stackAlignment && + this.wordKind.equals(that.wordKind) && + this.wordSize == that.wordSize && + this.arch.equals(that.arch)) { + return true; + } + // @formatter:on + } + return false; + } + public int getSizeInBytes(PlatformKind kind) { return arch.getSizeInBytes(kind); } diff -r 8169f68e9530 -r d60dd21329f2 graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/HotSpotReferenceMap.java --- a/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/HotSpotReferenceMap.java Tue Nov 11 14:30:55 2014 -0800 +++ b/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/HotSpotReferenceMap.java Wed Nov 12 10:36:30 2014 +0100 @@ -30,7 +30,7 @@ import com.oracle.graal.api.meta.*; import com.oracle.graal.compiler.common.*; -public class HotSpotReferenceMap implements ReferenceMap, Serializable { +public final class HotSpotReferenceMap implements ReferenceMap, Serializable { private static final long serialVersionUID = -1052183095979496819L; @@ -154,6 +154,30 @@ } } + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + ((frameRefMap == null) ? 0 : frameRefMap.hashCode()); + result = prime * result + ((registerRefMap == null) ? 0 : registerRefMap.hashCode()); + result = prime * result + ((target == null) ? 0 : target.hashCode()); + return result; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) { + return true; + } + if (obj instanceof HotSpotReferenceMap) { + HotSpotReferenceMap that = (HotSpotReferenceMap) obj; + if (this.frameRefMap.equals(that.frameRefMap) && this.registerRefMap.equals(that.registerRefMap) && this.target.equals(that.target)) { + return true; + } + } + return false; + } + public boolean hasRegisterRefMap() { return registerRefMap != null && registerRefMap.size() > 0; } diff -r 8169f68e9530 -r d60dd21329f2 graal/com.oracle.graal.truffle/src/com/oracle/graal/truffle/nodes/AssumptionValidAssumption.java --- a/graal/com.oracle.graal.truffle/src/com/oracle/graal/truffle/nodes/AssumptionValidAssumption.java Tue Nov 11 14:30:55 2014 -0800 +++ b/graal/com.oracle.graal.truffle/src/com/oracle/graal/truffle/nodes/AssumptionValidAssumption.java Wed Nov 12 10:36:30 2014 +0100 @@ -49,7 +49,7 @@ public boolean equals(Object obj) { if (obj instanceof AssumptionValidAssumption) { AssumptionValidAssumption other = (AssumptionValidAssumption) obj; - return other.assumption == this.assumption; + return this.assumption == other.assumption; } return false; }