# HG changeset patch # User Christian Wimmer # Date 1359999104 28800 # Node ID 47467b2c3fc5c7d40a3fb8b650b4143999767b3c # Parent 627c284671b76804c6d4b7f162ef93c1c931d402 Use equal() and notEqual() instead of == and != to compare words diff -r 627c284671b7 -r 47467b2c3fc5 graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/snippets/CheckCastSnippets.java --- a/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/snippets/CheckCastSnippets.java Mon Feb 04 07:36:35 2013 -0800 +++ b/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/snippets/CheckCastSnippets.java Mon Feb 04 09:31:44 2013 -0800 @@ -79,7 +79,7 @@ isNull.inc(); } else { Word objectHub = loadHub(object); - if (objectHub != exactHub) { + if (objectHub.notEqual(exactHub)) { probability(DEOPT_PATH_PROBABILITY); exactMiss.inc(); //bkpt(object, exactHub, objectHub); @@ -108,7 +108,7 @@ isNull.inc(); } else { Word objectHub = loadHub(object); - if (objectHub.readWord(superCheckOffset) != hub) { + if (objectHub.readWord(superCheckOffset).notEqual(hub)) { probability(DEOPT_PATH_PROBABILITY); displayMiss.inc(); DeoptimizeNode.deopt(InvalidateReprofile, ClassCastException); @@ -136,7 +136,7 @@ ExplodeLoopNode.explodeLoop(); for (int i = 0; i < hints.length; i++) { Word hintHub = hints[i]; - if (hintHub == objectHub) { + if (hintHub.equal(objectHub)) { hintsHit.inc(); return unsafeCast(verifyOop(object), StampFactory.forNodeIntrinsic()); } diff -r 627c284671b7 -r 47467b2c3fc5 graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/snippets/ClassSubstitutions.java --- a/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/snippets/ClassSubstitutions.java Mon Feb 04 07:36:35 2013 -0800 +++ b/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/snippets/ClassSubstitutions.java Mon Feb 04 09:31:44 2013 -0800 @@ -41,7 +41,7 @@ @MethodSubstitution(isStatic = false) public static int getModifiers(final Class thisObj) { Word klass = loadWordFromObject(thisObj, klassOffset()); - if (klass == Word.zero()) { + if (klass.equal(0)) { // Class for primitive type return Modifier.ABSTRACT | Modifier.FINAL | Modifier.PUBLIC; } else { @@ -52,7 +52,7 @@ @MethodSubstitution(isStatic = false) public static boolean isInterface(final Class thisObj) { Word klass = loadWordFromObject(thisObj, klassOffset()); - if (klass == Word.zero()) { + if (klass.equal(0)) { return false; } else { int accessFlags = klass.readInt(klassAccessFlagsOffset()); @@ -63,7 +63,7 @@ @MethodSubstitution(isStatic = false) public static boolean isArray(final Class thisObj) { Word klass = loadWordFromObject(thisObj, klassOffset()); - if (klass == Word.zero()) { + if (klass.equal(0)) { return false; } else { int layoutHelper = klass.readInt(klassLayoutHelperOffset()); @@ -74,13 +74,13 @@ @MethodSubstitution(isStatic = false) public static boolean isPrimitive(final Class thisObj) { Word klass = loadWordFromObject(thisObj, klassOffset()); - return klass == Word.zero(); + return klass.equal(0); } @MethodSubstitution(isStatic = false) public static Class getSuperclass(final Class thisObj) { Word klass = loadWordFromObject(thisObj, klassOffset()); - if (klass != Word.zero()) { + if (klass.notEqual(0)) { int accessFlags = klass.readInt(klassAccessFlagsOffset()); if ((accessFlags & Modifier.INTERFACE) == 0) { int layoutHelper = klass.readInt(klassLayoutHelperOffset()); @@ -88,7 +88,7 @@ return Object.class; } else { Word superKlass = klass.readWord(klassSuperKlassOffset()); - if (superKlass == Word.zero()) { + if (superKlass.equal(0)) { return null; } else { return unsafeCast(superKlass.readObject(classMirrorOffset()), Class.class, true, true); @@ -102,7 +102,7 @@ @MethodSubstitution(isStatic = false) public static Class getComponentType(final Class thisObj) { Word klass = loadWordFromObject(thisObj, klassOffset()); - if (klass != Word.zero()) { + if (klass.notEqual(0)) { int layoutHelper = klass.readInt(klassLayoutHelperOffset()); if ((layoutHelper & arrayKlassLayoutHelperIdentifier()) != 0) { return unsafeCast(klass.readObject(arrayKlassComponentMirrorOffset()), Class.class, true, true); diff -r 627c284671b7 -r 47467b2c3fc5 graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/snippets/HotSpotSnippetUtils.java --- a/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/snippets/HotSpotSnippetUtils.java Mon Feb 04 07:36:35 2013 -0800 +++ b/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/snippets/HotSpotSnippetUtils.java Mon Feb 04 09:31:44 2013 -0800 @@ -458,7 +458,7 @@ // this code is independent from biased locking (although it does not look that way) final Word biasedLock = mark.and(biasedLockMaskInPlace()); - if (biasedLock == Word.unsigned(unlockedMask())) { + if (biasedLock.equal(Word.unsigned(unlockedMask()))) { probability(FAST_PATH_PROBABILITY); int hash = (int) mark.unsignedShiftRight(identityHashCodeShift()).rawValue(); if (hash != uninitializedIdentityHashCodeValue()) { diff -r 627c284671b7 -r 47467b2c3fc5 graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/snippets/InstanceOfSnippets.java --- a/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/snippets/InstanceOfSnippets.java Mon Feb 04 07:36:35 2013 -0800 +++ b/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/snippets/InstanceOfSnippets.java Mon Feb 04 09:31:44 2013 -0800 @@ -73,7 +73,7 @@ return falseValue; } Word objectHub = loadHub(object); - if (objectHub != exactHub) { + if (objectHub.notEqual(exactHub)) { probability(LIKELY_PROBABILITY); exactMiss.inc(); return falseValue; @@ -99,7 +99,7 @@ return falseValue; } Word objectHub = loadHub(object); - if (objectHub.readWord(superCheckOffset) != hub) { + if (objectHub.readWord(superCheckOffset).notEqual(hub)) { probability(NOT_LIKELY_PROBABILITY); displayMiss.inc(); return falseValue; @@ -129,7 +129,7 @@ ExplodeLoopNode.explodeLoop(); for (int i = 0; i < hints.length; i++) { Word hintHub = hints[i]; - if (hintHub == objectHub) { + if (hintHub.equal(objectHub)) { probability(NOT_FREQUENT_PROBABILITY); hintsHit.inc(); return trueValue; diff -r 627c284671b7 -r 47467b2c3fc5 graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/snippets/MonitorSnippets.java --- a/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/snippets/MonitorSnippets.java Mon Feb 04 07:36:35 2013 -0800 +++ b/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/snippets/MonitorSnippets.java Mon Feb 04 09:31:44 2013 -0800 @@ -76,10 +76,7 @@ public static final boolean CHECK_BALANCED_MONITORS = Boolean.getBoolean("graal.monitors.checkBalanced"); @Snippet - public static void monitorenter(@Parameter("object") - Object object, @ConstantParameter("checkNull") - boolean checkNull, @ConstantParameter("trace") - boolean trace) { + public static void monitorenter(@Parameter("object") Object object, @ConstantParameter("checkNull") boolean checkNull, @ConstantParameter("trace") boolean trace) { verifyOop(object); if (checkNull && object == null) { @@ -105,7 +102,7 @@ final Word biasableLockBits = mark.and(biasedLockMaskInPlace()); // First check to see whether biasing is enabled for this object - if (biasableLockBits != Word.unsigned(biasedLockPattern())) { + if (biasableLockBits.notEqual(Word.unsigned(biasedLockPattern()))) { // Biasing not enabled -> fall through to lightweight locking } else { probability(FREQUENT_PROBABILITY); @@ -118,7 +115,7 @@ trace(trace, "prototypeMarkWord: 0x%016lx\n", prototypeMarkWord); trace(trace, " thread: 0x%016lx\n", thread); trace(trace, " tmp: 0x%016lx\n", tmp); - if (tmp == Word.zero()) { + if (tmp.equal(0)) { // Object is already biased to current thread -> done probability(FREQUENT_PROBABILITY); traceObject(trace, "+lock{bias:existing}", object); @@ -134,7 +131,7 @@ // If the low three bits in the xor result aren't clear, that means // the prototype header is no longer biasable and we have to revoke // the bias on this object. - if (tmp.and(biasedLockMaskInPlace()) == Word.zero()) { + if (tmp.and(biasedLockMaskInPlace()).equal(0)) { probability(FREQUENT_PROBABILITY); // Biasing is still enabled for object's type. See whether the // epoch of the current bias is still valid, meaning that the epoch @@ -145,7 +142,7 @@ // that the current epoch is invalid in order to do this because // otherwise the manipulations it performs on the mark word are // illegal. - if (tmp.and(epochMaskInPlace()) == Word.zero()) { + if (tmp.and(epochMaskInPlace()).equal(0)) { probability(FREQUENT_PROBABILITY); // The epoch of the current bias is still valid but we know nothing // about the owner; it might be set or it might be clear. Try to @@ -157,7 +154,7 @@ Word biasedMark = unbiasedMark.or(thread); trace(trace, " unbiasedMark: 0x%016lx\n", unbiasedMark); trace(trace, " biasedMark: 0x%016lx\n", biasedMark); - if (compareAndSwap(object, markOffset(), unbiasedMark, biasedMark) == unbiasedMark) { + if (compareAndSwap(object, markOffset(), unbiasedMark, biasedMark).equal(unbiasedMark)) { // Object is now biased to current thread -> done traceObject(trace, "+lock{bias:acquired}", object); return; @@ -178,7 +175,7 @@ // the bias from one thread to another directly in this situation. Word biasedMark = prototypeMarkWord.or(thread); trace(trace, " biasedMark: 0x%016lx\n", biasedMark); - if (compareAndSwap(object, markOffset(), mark, biasedMark) == mark) { + if (compareAndSwap(object, markOffset(), mark, biasedMark).equal(mark)) { // Object is now biased to current thread -> done traceObject(trace, "+lock{bias:transfer}", object); return; @@ -223,7 +220,7 @@ // Test if the object's mark word is unlocked, and if so, store the // (address of) the lock slot into the object's mark word. Word currentMark = compareAndSwap(object, markOffset(), unlockedMark, lock); - if (currentMark != unlockedMark) { + if (currentMark.notEqual(unlockedMark)) { trace(trace, " currentMark: 0x%016lx\n", currentMark); // The mark word in the object header was not the same. // Either the object is locked by another thread or is already locked @@ -242,7 +239,7 @@ // significant 2 bits cleared and page_size is a power of 2 final Word alignedMask = Word.unsigned(wordSize() - 1); final Word stackPointer = stackPointer(); - if (currentMark.subtract(stackPointer).and(alignedMask.subtract(pageSize())) != Word.zero()) { + if (currentMark.subtract(stackPointer).and(alignedMask.subtract(pageSize())).notEqual(0)) { // Most likely not a recursive lock, go into a slow runtime call probability(DEOPT_PATH_PROBABILITY); traceObject(trace, "+lock{stub:failed-cas}", object); @@ -268,10 +265,7 @@ * Calls straight out to the monitorenter stub. */ @Snippet - public static void monitorenterStub(@Parameter("object") - Object object, @ConstantParameter("checkNull") - boolean checkNull, @ConstantParameter("trace") - boolean trace) { + public static void monitorenterStub(@Parameter("object") Object object, @ConstantParameter("checkNull") boolean checkNull, @ConstantParameter("trace") boolean trace) { verifyOop(object); incCounter(); if (checkNull && object == null) { @@ -285,9 +279,7 @@ } @Snippet - public static void monitorexit(@Parameter("object") - Object object, @ConstantParameter("trace") - boolean trace) { + public static void monitorexit(@Parameter("object") Object object, @ConstantParameter("trace") boolean trace) { trace(trace, " object: 0x%016lx\n", Word.fromObject(object)); if (useBiasedLocking()) { // Check for biased locking unlock case, which is a no-op @@ -298,7 +290,7 @@ // the bias bit would be clear. final Word mark = loadWordFromObject(object, markOffset()); trace(trace, " mark: 0x%016lx\n", mark); - if (mark.and(biasedLockMaskInPlace()) == Word.unsigned(biasedLockPattern())) { + if (mark.and(biasedLockMaskInPlace()).equal(Word.unsigned(biasedLockPattern()))) { probability(FREQUENT_PROBABILITY); endLockScope(); decCounter(); @@ -313,7 +305,7 @@ final Word displacedMark = lock.readWord(lockDisplacedMarkOffset()); trace(trace, " displacedMark: 0x%016lx\n", displacedMark); - if (displacedMark == Word.zero()) { + if (displacedMark.equal(0)) { // Recursive locking => done traceObject(trace, "-lock{recursive}", object); } else { @@ -321,7 +313,7 @@ // Test if object's mark word is pointing to the displaced mark word, and if so, restore // the displaced mark in the object - if the object's mark word is not pointing to // the displaced mark word, do unlocking via runtime call. - if (DirectCompareAndSwapNode.compareAndSwap(object, markOffset(), lock, displacedMark) != lock) { + if (DirectCompareAndSwapNode.compareAndSwap(object, markOffset(), lock, displacedMark).notEqual(lock)) { // The object's mark word was not pointing to the displaced header, // we do unlocking via runtime call. probability(DEOPT_PATH_PROBABILITY); @@ -339,9 +331,7 @@ * Calls straight out to the monitorexit stub. */ @Snippet - public static void monitorexitStub(@Parameter("object") - Object object, @ConstantParameter("trace") - boolean trace) { + public static void monitorexitStub(@Parameter("object") Object object, @ConstantParameter("trace") boolean trace) { verifyOop(object); traceObject(trace, "-lock{stub}", object); MonitorExitStubCall.call(object); @@ -434,8 +424,7 @@ this.useFastLocking = useFastLocking; } - public void lower(MonitorEnterNode monitorenterNode, @SuppressWarnings("unused") - LoweringTool tool) { + public void lower(MonitorEnterNode monitorenterNode, @SuppressWarnings("unused") LoweringTool tool) { StructuredGraph graph = (StructuredGraph) monitorenterNode.graph(); checkBalancedMonitors(graph); @@ -466,8 +455,7 @@ } } - public void lower(MonitorExitNode monitorexitNode, @SuppressWarnings("unused") - LoweringTool tool) { + public void lower(MonitorExitNode monitorexitNode, @SuppressWarnings("unused") LoweringTool tool) { StructuredGraph graph = (StructuredGraph) monitorexitNode.graph(); FrameState stateAfter = monitorexitNode.stateAfter(); boolean eliminated = monitorexitNode.eliminated(); diff -r 627c284671b7 -r 47467b2c3fc5 graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/snippets/NewObjectSnippets.java --- a/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/snippets/NewObjectSnippets.java Mon Feb 04 07:36:35 2013 -0800 +++ b/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/snippets/NewObjectSnippets.java Mon Feb 04 09:31:44 2013 -0800 @@ -84,7 +84,7 @@ @ConstantParameter("locked") boolean locked) { Object result; - if (memory == Word.zero()) { + if (memory.equal(0)) { new_stub.inc(); result = NewInstanceStubCall.call(hub); } else { @@ -118,7 +118,7 @@ private static Object initializeArray(Word memory, Word hub, int length, int allocationSize, Word prototypeMarkWord, int headerSize, boolean fillContents) { Object result; - if (memory == Word.zero()) { + if (memory.equal(0)) { newarray_stub.inc(); result = NewArrayStubCall.call(hub, length); } else { diff -r 627c284671b7 -r 47467b2c3fc5 graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/snippets/TypeCheckSnippetUtils.java --- a/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/snippets/TypeCheckSnippetUtils.java Mon Feb 04 07:36:35 2013 -0800 +++ b/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/snippets/TypeCheckSnippetUtils.java Mon Feb 04 09:31:44 2013 -0800 @@ -41,7 +41,7 @@ static boolean checkSecondarySubType(Word t, Word s) { // if (S.cache == T) return true - if (s.readWord(secondarySuperCacheOffset()) == t) { + if (s.readWord(secondarySuperCacheOffset()).equal(t)) { cacheHit.inc(); return true; } @@ -55,7 +55,7 @@ boolean primary = superCheckOffset != secondarySuperCacheOffset(); // if (T = S[off]) return true - if (s.readWord(superCheckOffset) == t) { + if (s.readWord(superCheckOffset).equal(t)) { if (primary) { cacheHit.inc(); } else { @@ -75,7 +75,7 @@ private static boolean checkSelfAndSupers(Word t, Word s) { // if (T == S) return true - if (s == t) { + if (s.equal(t)) { T_equals_S.inc(); return true; } @@ -84,7 +84,7 @@ Word secondarySupers = s.readWord(secondarySupersOffset()); int length = secondarySupers.readInt(metaspaceArrayLengthOffset()); for (int i = 0; i < length; i++) { - if (t == loadWordElement(secondarySupers, i)) { + if (t.equal(loadWordElement(secondarySupers, i))) { probability(NOT_LIKELY_PROBABILITY); s.writeWord(secondarySuperCacheOffset(), t); secondariesHit.inc(); diff -r 627c284671b7 -r 47467b2c3fc5 graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/stubs/NewArrayStub.java --- a/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/stubs/NewArrayStub.java Mon Feb 04 07:36:35 2013 -0800 +++ b/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/stubs/NewArrayStub.java Mon Feb 04 09:31:44 2013 -0800 @@ -80,7 +80,7 @@ // check that array length is small enough for fast path. if (length <= MAX_ARRAY_FAST_PATH_ALLOCATION_LENGTH) { Word memory = refillAllocate(intArrayHub, sizeInBytes, log); - if (memory != Word.zero()) { + if (memory.notEqual(0)) { log(log, "newArray: allocated new array at %p\n", memory); formatArray(hub, sizeInBytes, length, headerSize, memory, Word.unsigned(arrayPrototypeMarkWord()), true); return verifyOop(memory.toObject()); diff -r 627c284671b7 -r 47467b2c3fc5 graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/stubs/NewInstanceStub.java --- a/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/stubs/NewInstanceStub.java Mon Feb 04 07:36:35 2013 -0800 +++ b/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/stubs/NewInstanceStub.java Mon Feb 04 09:31:44 2013 -0800 @@ -71,7 +71,7 @@ if (!forceSlowPath() && inlineContiguousAllocationSupported()) { if (hub.readInt(klassStateOffset()) == klassStateFullyInitialized()) { Word memory = refillAllocate(intArrayHub, sizeInBytes, log); - if (memory != Word.zero()) { + if (memory.notEqual(0)) { Word prototypeMarkWord = hub.readWord(prototypeMarkWordOffset()); memory.writeWord(markOffset(), prototypeMarkWord); memory.writeWord(hubOffset(), hub); @@ -129,7 +129,7 @@ // if TLAB is currently allocated (top or end != null) then // fill [top, end + alignment_reserve) with array object - if (top != Word.zero()) { + if (top.notEqual(0)) { int headerSize = arrayBaseOffset(Kind.Int); // just like the HotSpot assembler stubs, assumes that tlabFreeSpaceInInts fits in // an int @@ -147,7 +147,7 @@ Word tlabRefillSizeInBytes = tlabRefillSizeInWords.multiply(wordSize()); // allocate new TLAB, address returned in top top = edenAllocate(tlabRefillSizeInBytes, log); - if (top != Word.zero()) { + if (top.notEqual(0)) { thread.writeWord(threadTlabStartOffset(), top); thread.writeWord(threadTlabTopOffset(), top); @@ -195,7 +195,7 @@ return Word.zero(); } - if (compareAndSwap(heapTopAddress, 0, heapTop, newHeapTop) == heapTop) { + if (compareAndSwap(heapTopAddress, 0, heapTop, newHeapTop).equal(heapTop)) { return heapTop; } } diff -r 627c284671b7 -r 47467b2c3fc5 graal/com.oracle.graal.word/src/com/oracle/graal/word/Signed.java --- a/graal/com.oracle.graal.word/src/com/oracle/graal/word/Signed.java Mon Feb 04 07:36:35 2013 -0800 +++ b/graal/com.oracle.graal.word/src/com/oracle/graal/word/Signed.java Mon Feb 04 09:31:44 2013 -0800 @@ -119,6 +119,22 @@ * Compares this Signed with the specified value. * * @param val value to which this Signed is to be compared. + * @return {@code this == val} + */ + boolean equal(Signed val); + + /** + * Compares this Signed with the specified value. + * + * @param val value to which this Signed is to be compared. + * @return {@code this != val} + */ + boolean notEqual(Signed val); + + /** + * Compares this Signed with the specified value. + * + * @param val value to which this Signed is to be compared. * @return {@code this < val} */ boolean lessThan(Signed val); @@ -234,6 +250,22 @@ * Compares this Signed with the specified value. * * @param val value to which this Signed is to be compared. + * @return {@code this == val} + */ + boolean equal(int val); + + /** + * Compares this Signed with the specified value. + * + * @param val value to which this Signed is to be compared. + * @return {@code this != val} + */ + boolean notEqual(int val); + + /** + * Compares this Signed with the specified value. + * + * @param val value to which this Signed is to be compared. * @return {@code this < val} */ boolean lessThan(int val); diff -r 627c284671b7 -r 47467b2c3fc5 graal/com.oracle.graal.word/src/com/oracle/graal/word/Unsigned.java --- a/graal/com.oracle.graal.word/src/com/oracle/graal/word/Unsigned.java Mon Feb 04 07:36:35 2013 -0800 +++ b/graal/com.oracle.graal.word/src/com/oracle/graal/word/Unsigned.java Mon Feb 04 09:31:44 2013 -0800 @@ -115,6 +115,22 @@ * Compares this Unsigned with the specified value. * * @param val value to which this Unsigned is to be compared. + * @return {@code this == val} + */ + boolean equal(Unsigned val); + + /** + * Compares this Unsigned with the specified value. + * + * @param val value to which this Unsigned is to be compared. + * @return {@code this != val} + */ + boolean notEqual(Unsigned val); + + /** + * Compares this Unsigned with the specified value. + * + * @param val value to which this Unsigned is to be compared. * @return {@code this < val} */ boolean belowThan(Unsigned val); @@ -260,6 +276,28 @@ * Therefore, the result is only well-defined for positive right operands. * * @param val value to which this Unsigned is to be compared. + * @return {@code this == val} + */ + boolean equal(int val); + + /** + * Compares this Unsigned with the specified value. + *

+ * Note that the right operand is a signed value, while the operation is performed unsigned. + * Therefore, the result is only well-defined for positive right operands. + * + * @param val value to which this Unsigned is to be compared. + * @return {@code this != val} + */ + boolean notEqual(int val); + + /** + * Compares this Unsigned with the specified value. + *

+ * Note that the right operand is a signed value, while the operation is performed unsigned. + * Therefore, the result is only well-defined for positive right operands. + * + * @param val value to which this Unsigned is to be compared. * @return {@code this < val} */ boolean belowThan(int val); diff -r 627c284671b7 -r 47467b2c3fc5 graal/com.oracle.graal.word/src/com/oracle/graal/word/Word.java --- a/graal/com.oracle.graal.word/src/com/oracle/graal/word/Word.java Mon Feb 04 07:36:35 2013 -0800 +++ b/graal/com.oracle.graal.word/src/com/oracle/graal/word/Word.java Mon Feb 04 09:31:44 2013 -0800 @@ -25,9 +25,9 @@ import static com.oracle.graal.graph.UnsafeAccess.*; import java.lang.annotation.*; -import java.util.concurrent.*; import com.oracle.graal.api.code.*; +import com.oracle.graal.graph.*; import com.oracle.graal.nodes.*; import com.oracle.graal.nodes.calc.*; @@ -415,6 +415,52 @@ } @Override + @Operation(opcode = Opcode.COMPARISON, condition = Condition.EQ) + public boolean equal(Signed val) { + return equal((Word) val); + } + + @Override + @Operation(opcode = Opcode.COMPARISON, condition = Condition.EQ) + public boolean equal(Unsigned val) { + return equal((Word) val); + } + + @Override + @Operation(opcode = Opcode.COMPARISON, condition = Condition.EQ) + public boolean equal(int val) { + return equal(intParam(val)); + } + + @Operation(opcode = Opcode.COMPARISON, condition = Condition.EQ) + public boolean equal(Word val) { + return unbox() == val.unbox(); + } + + @Override + @Operation(opcode = Opcode.COMPARISON, condition = Condition.NE) + public boolean notEqual(Signed val) { + return notEqual((Word) val); + } + + @Override + @Operation(opcode = Opcode.COMPARISON, condition = Condition.NE) + public boolean notEqual(Unsigned val) { + return notEqual((Word) val); + } + + @Override + @Operation(opcode = Opcode.COMPARISON, condition = Condition.NE) + public boolean notEqual(int val) { + return notEqual(intParam(val)); + } + + @Operation(opcode = Opcode.COMPARISON, condition = Condition.NE) + public boolean notEqual(Word val) { + return unbox() != val.unbox(); + } + + @Override @Operation(opcode = Opcode.COMPARISON, condition = Condition.LT) public boolean lessThan(Signed val) { return lessThan((Word) val); @@ -815,6 +861,16 @@ public void writeObject(int offset, Object val) { writeObject(signed(offset), val); } + + @Override + public final boolean equals(Object obj) { + throw GraalInternalError.shouldNotReachHere("equals must not be called on words"); + } + + @Override + public final int hashCode() { + throw GraalInternalError.shouldNotReachHere("hashCode must not be called on words"); + } } final class HostedWord extends Word { @@ -823,7 +879,6 @@ private static final int SMALL_TO = 100; private static final HostedWord[] smallCache = new HostedWord[SMALL_TO - SMALL_FROM + 1]; - private static final ConcurrentHashMap cache = new ConcurrentHashMap<>(); static { for (int i = SMALL_FROM; i <= SMALL_TO; i++) { @@ -841,14 +896,7 @@ if (val >= SMALL_FROM && val <= SMALL_TO) { return smallCache[(int) val - SMALL_FROM]; } - Long key = val; - HostedWord result = cache.get(key); - if (result != null) { - return result; - } - HostedWord newValue = new HostedWord(val); - HostedWord oldValue = cache.putIfAbsent(key, newValue); - return oldValue == null ? newValue : oldValue; + return new HostedWord(val); } @Override diff -r 627c284671b7 -r 47467b2c3fc5 graal/com.oracle.graal.word/src/com/oracle/graal/word/phases/WordTypeRewriterPhase.java --- a/graal/com.oracle.graal.word/src/com/oracle/graal/word/phases/WordTypeRewriterPhase.java Mon Feb 04 07:36:35 2013 -0800 +++ b/graal/com.oracle.graal.word/src/com/oracle/graal/word/phases/WordTypeRewriterPhase.java Mon Feb 04 09:31:44 2013 -0800 @@ -95,12 +95,13 @@ if (x.kind() == wordKind || y.kind() == wordKind) { assert x.kind() == wordKind; assert y.kind() == wordKind; - graph.replaceFloating(objectEqualsNode, graph.unique(new IntegerEqualsNode(x, y))); + + // TODO Remove the whole iteration of ObjectEqualsNodes when we are sure that there + // is no more code where this triggers. + throw GraalInternalError.shouldNotReachHere("Comparison of words with == and != is no longer supported"); } } - // Replace ObjectEqualsNodes with IntegerEqualsNodes where the values being compared are - // words for (LoadIndexedNode load : graph.getNodes().filter(LoadIndexedNode.class).snapshot()) { if (isWord(load)) { load.setStamp(StampFactory.forKind(wordKind)); diff -r 627c284671b7 -r 47467b2c3fc5 graal/com.oracle.graal.word/src/com/oracle/graal/word/phases/WordTypeVerificationPhase.java --- a/graal/com.oracle.graal.word/src/com/oracle/graal/word/phases/WordTypeVerificationPhase.java Mon Feb 04 07:36:35 2013 -0800 +++ b/graal/com.oracle.graal.word/src/com/oracle/graal/word/phases/WordTypeVerificationPhase.java Mon Feb 04 09:31:44 2013 -0800 @@ -97,10 +97,8 @@ } } } else if (usage instanceof ObjectEqualsNode) { - ObjectEqualsNode compare = (ObjectEqualsNode) usage; - if (compare.x() == node || compare.y() == node) { - verify(isWord(compare.x()) == isWord(compare.y()), node, compare.usages().first(), "cannot mixed word and non-word type in use of '==' or '!='"); - } + verify(!isWord(node) || ((ObjectEqualsNode) usage).x() != node, node, usage, "cannot use word type in comparison"); + verify(!isWord(node) || ((ObjectEqualsNode) usage).y() != node, node, usage, "cannot use word type in comparison"); } else if (usage instanceof ArrayLengthNode) { verify(!isWord(node) || ((ArrayLengthNode) usage).array() != node, node, usage, "cannot get array length from word value"); } else if (usage instanceof PhiNode) { @@ -148,7 +146,7 @@ return buf.toString(); } else { String loc = GraphUtil.approxSourceLocation(n); - return loc == null ? "" : loc; + return loc == null ? MetaUtil.format("method %h.%n", ((StructuredGraph) n.graph()).method()) : loc; } } }