diff graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/snippets/HotSpotSnippetUtils.java @ 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 5e3d1a68664e
children 9472211c812b
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);
+    }
 }