# HG changeset patch # User Doug Simon # Date 1358977042 -3600 # Node ID be0d995ef51ef5417deee3d25dc5b5ff8a873b1d # Parent a0298e142ea83831000cf23d07669bf208010742 factored out code common to SystemSubstitutions.identityHashCode() and ObjectSubstitutions.hashCode() diff -r a0298e142ea8 -r be0d995ef51e 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 Wed Jan 23 22:27:45 2013 +0100 +++ b/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/snippets/HotSpotSnippetUtils.java Wed Jan 23 22:37:22 2013 +0100 @@ -22,6 +22,8 @@ */ package com.oracle.graal.hotspot.snippets; +import static com.oracle.graal.snippets.nodes.BranchProbabilityNode.*; + import com.oracle.graal.api.code.*; import com.oracle.graal.api.meta.*; import com.oracle.graal.graph.Node.ConstantNodeParameter; @@ -36,7 +38,7 @@ //JaCoCo Exclude /** - * A collection of methods used in HotSpot snippets. + * A collection of methods used in HotSpot snippets and substitutions. */ public class HotSpotSnippetUtils { @@ -454,4 +456,21 @@ assert arrayIndexScale(Kind.Float) == 4; assert arrayIndexScale(Kind.Double) == 8; } + + static int computeHashCode(Object x) { + Word mark = loadWordFromObject(x, markOffset()); + + // 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())) { + probability(0.99); + int hash = (int) mark.unsignedShiftRight(identityHashCodeShift()).rawValue(); + if (hash != uninitializedIdentityHashCodeValue()) { + probability(0.99); + return hash; + } + } + + return IdentityHashCodeStubCall.call(x); + } } diff -r a0298e142ea8 -r be0d995ef51e graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/snippets/ObjectSubstitutions.java --- a/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/snippets/ObjectSubstitutions.java Wed Jan 23 22:27:45 2013 +0100 +++ b/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/snippets/ObjectSubstitutions.java Wed Jan 23 22:37:22 2013 +0100 @@ -24,9 +24,7 @@ import static com.oracle.graal.hotspot.snippets.HotSpotSnippetUtils.*; import static com.oracle.graal.nodes.extended.UnsafeCastNode.*; -import static com.oracle.graal.snippets.nodes.BranchProbabilityNode.*; -import com.oracle.graal.hotspot.nodes.*; import com.oracle.graal.snippets.*; import com.oracle.graal.snippets.ClassSubstitution.MethodSubstitution; import com.oracle.graal.word.*; @@ -45,19 +43,6 @@ @MethodSubstitution(isStatic = false) public static int hashCode(final Object thisObj) { - Word mark = loadWordFromObject(thisObj, markOffset()); - - // 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())) { - probability(0.99); - int hash = (int) mark.unsignedShiftRight(identityHashCodeShift()).rawValue(); - if (hash != uninitializedIdentityHashCodeValue()) { - probability(0.99); - return hash; - } - } - - return IdentityHashCodeStubCall.call(thisObj); + return computeHashCode(thisObj); } } diff -r a0298e142ea8 -r be0d995ef51e graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/snippets/SystemSubstitutions.java --- a/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/snippets/SystemSubstitutions.java Wed Jan 23 22:27:45 2013 +0100 +++ b/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/snippets/SystemSubstitutions.java Wed Jan 23 22:37:22 2013 +0100 @@ -28,12 +28,10 @@ import com.oracle.graal.api.code.RuntimeCallTarget.Descriptor; import com.oracle.graal.graph.Node.ConstantNodeParameter; import com.oracle.graal.graph.Node.NodeIntrinsic; -import com.oracle.graal.hotspot.nodes.*; import com.oracle.graal.nodes.extended.*; import com.oracle.graal.snippets.*; import com.oracle.graal.snippets.ClassSubstitution.MacroSubstitution; import com.oracle.graal.snippets.ClassSubstitution.MethodSubstitution; -import com.oracle.graal.word.*; /** * Substitutions for {@link java.lang.System} methods. @@ -64,20 +62,7 @@ return 0; } - Word mark = loadWordFromObject(x, markOffset()); - - // 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())) { - probability(0.99); - int hash = (int) mark.unsignedShiftRight(identityHashCodeShift()).rawValue(); - if (hash != uninitializedIdentityHashCodeValue()) { - probability(0.99); - return hash; - } - } - - return IdentityHashCodeStubCall.call(x); + return computeHashCode(x); } @NodeIntrinsic(value = RuntimeCallNode.class, setStampFromReturnType = true)