ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/jsr166/jsr166/src/jsr166e/ConcurrentHashMapV8.java
(Generate patch)

Comparing jsr166/src/jsr166e/ConcurrentHashMapV8.java (file contents):
Revision 1.33 by jsr166, Mon Dec 5 04:50:19 2011 UTC vs.
Revision 1.37 by dl, Sun Mar 4 20:34:27 2012 UTC

# Line 20 | Line 20 | import java.util.Enumeration;
20   import java.util.ConcurrentModificationException;
21   import java.util.NoSuchElementException;
22   import java.util.concurrent.ConcurrentMap;
23 + import java.util.concurrent.ThreadLocalRandom;
24   import java.util.concurrent.locks.LockSupport;
25   import java.io.Serializable;
26  
# Line 351 | Line 352 | public class ConcurrentHashMapV8<K, V>
352       * Encodings for special uses of Node hash fields. See above for
353       * explanation.
354       */
355 <    static final int MOVED     = 0x80000000; // hash field for fowarding nodes
355 >    static final int MOVED     = 0x80000000; // hash field for forwarding nodes
356      static final int LOCKED    = 0x40000000; // set/tested only as a bit
357      static final int WAITING   = 0xc0000000; // both bits set/tested together
358      static final int HASH_BITS = 0x3fffffff; // usable bits of normal node hash
# Line 435 | Line 436 | public class ConcurrentHashMapV8<K, V>
436           */
437          final void tryAwaitLock(Node[] tab, int i) {
438              if (tab != null && i >= 0 && i < tab.length) { // bounds check
439 +                int r = ThreadLocalRandom.current().nextInt(); // randomize spins
440                  int spins = MAX_SPINS, h;
441                  while (tabAt(tab, i) == this && ((h = hash) & LOCKED) != 0) {
442                      if (spins >= 0) {
443 <                        if (--spins == MAX_SPINS >>> 1)
444 <                            Thread.yield();  // heuristically yield mid-way
443 >                        r ^= r << 1; r ^= r >>> 3; r ^= r << 10; // xorshift
444 >                        if (r >= 0 && --spins == 0)
445 >                            Thread.yield();  // yield before block
446                      }
447                      else if (casHash(h, h | WAITING)) {
448                          synchronized (this) {
# Line 1291 | Line 1294 | public class ConcurrentHashMapV8<K, V>
1294       *
1295       * At each step, the iterator snapshots the key ("nextKey") and
1296       * value ("nextVal") of a valid node (i.e., one that, at point of
1297 <     * snapshot, has a nonnull user value). Because val fields can
1297 >     * snapshot, has a non-null user value). Because val fields can
1298       * change (including to null, indicating deletion), field nextVal
1299       * might not be accurate at point of use, but still maintains the
1300       * weak consistency property of holding a value that was once
# Line 2237 | Line 2240 | public class ConcurrentHashMapV8<K, V>
2240      }
2241  
2242      static final class Values<K,V> extends MapView<K,V>
2243 <        implements Collection<V>  {
2243 >        implements Collection<V> {
2244          Values(ConcurrentHashMapV8<K, V> map)   { super(map); }
2245          public final boolean contains(Object o) { return map.containsValue(o); }
2246  

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines