[jbosscache-commits] JBoss Cache SVN: r6847 - in core/trunk/src/main/java/org/jboss/cache: util/concurrent/locks and 1 other directory.

jbosscache-commits at lists.jboss.org jbosscache-commits at lists.jboss.org
Mon Oct 6 10:53:33 EDT 2008


Author: manik.surtani at jboss.com
Date: 2008-10-06 10:53:33 -0400 (Mon, 06 Oct 2008)
New Revision: 6847

Modified:
   core/trunk/src/main/java/org/jboss/cache/lock/StripedLock.java
   core/trunk/src/main/java/org/jboss/cache/util/concurrent/locks/LockContainer.java
Log:
Better hashcode

Modified: core/trunk/src/main/java/org/jboss/cache/lock/StripedLock.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/lock/StripedLock.java	2008-10-06 14:28:08 UTC (rev 6846)
+++ core/trunk/src/main/java/org/jboss/cache/lock/StripedLock.java	2008-10-06 14:53:33 UTC (rev 6847)
@@ -75,6 +75,9 @@
       lockSegmentShift = 32 - tempLockSegShift;
       lockSegmentMask = numLocks - 1;
 
+      System.out.println("Lock Seg Shift = " + lockSegmentShift);
+      System.out.println("Lock Seg Mask = " + lockSegmentMask);
+
       sharedLocks = new ReentrantReadWriteLock[numLocks];
 
       for (int i = 0; i < numLocks; i++) sharedLocks[i] = new ReentrantReadWriteLock();
@@ -130,17 +133,22 @@
 
    /**
     * Returns a hash code for non-null Object x.
-    * Uses the same hash code spreader as most other java.util hash tables, except that this uses the string representation
-    * of the object passed in.
     *
     * @param x the object serving as a key
     * @return the hash code
     */
    final int hash(Object x)
    {
+      // Spread bits to regularize both segment and index locations,
+      // using variant of single-word Wang/Jenkins hash.
       int h = x.hashCode();
-      h ^= (h >>> 20) ^ (h >>> 12);
-      return h ^ (h >>> 7) ^ (h >>> 4);
+      h += (h << 15) ^ 0xffffcd7d;
+      h ^= (h >>> 10);
+      h += (h << 3);
+      h ^= (h >>> 6);
+      h += (h << 2) + (h << 14);
+      h = h ^ (h >>> 16);
+      return h;
    }
 
    /**

Modified: core/trunk/src/main/java/org/jboss/cache/util/concurrent/locks/LockContainer.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/util/concurrent/locks/LockContainer.java	2008-10-06 14:28:08 UTC (rev 6846)
+++ core/trunk/src/main/java/org/jboss/cache/util/concurrent/locks/LockContainer.java	2008-10-06 14:53:33 UTC (rev 6847)
@@ -67,9 +67,16 @@
     */
    final int hash(E object)
    {
+      // Spread bits to regularize both segment and index locations,
+      // using variant of single-word Wang/Jenkins hash.
       int h = object.hashCode();
-      h ^= (h >>> 20) ^ (h >>> 12);
-      return h ^ (h >>> 7) ^ (h >>> 4);
+      h += (h << 15) ^ 0xffffcd7d;
+      h ^= (h >>> 10);
+      h += (h << 3);
+      h ^= (h >>> 6);
+      h += (h << 2) + (h << 14);
+      h = h ^ (h >>> 16);
+      return h;
    }
 
    protected abstract void initLocks(int numLocks);




More information about the jbosscache-commits mailing list