changeset 7543:be0d995ef51e

factored out code common to SystemSubstitutions.identityHashCode() and ObjectSubstitutions.hashCode()
author Doug Simon <doug.simon@oracle.com>
date Wed, 23 Jan 2013 22:37:22 +0100
parents a0298e142ea8
children 5d9c23b8dbb8
files graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/snippets/HotSpotSnippetUtils.java graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/snippets/ObjectSubstitutions.java graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/snippets/SystemSubstitutions.java
diffstat 3 files changed, 22 insertions(+), 33 deletions(-) [+]
line wrap: on
line diff
--- 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);
+    }
 }
--- 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);
     }
 }
--- 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)