ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/jsr166/jsr166/src/main/java/util/concurrent/ConcurrentHashMap.java
(Generate patch)

Comparing jsr166/src/main/java/util/concurrent/ConcurrentHashMap.java (file contents):
Revision 1.301 by jsr166, Sat May 6 06:49:46 2017 UTC vs.
Revision 1.302 by jsr166, Fri Jun 16 01:20:13 2017 UTC

# Line 738 | Line 738 | public class ConcurrentHashMap<K,V> exte
738  
739      static final <K,V> boolean casTabAt(Node<K,V>[] tab, int i,
740                                          Node<K,V> c, Node<K,V> v) {
741 <        return U.compareAndSwapObject(tab, ((long)i << ASHIFT) + ABASE, c, v);
741 >        return U.compareAndSetObject(tab, ((long)i << ASHIFT) + ABASE, c, v);
742      }
743  
744      static final <K,V> void setTabAt(Node<K,V>[] tab, int i, Node<K,V> v) {
# Line 2270 | Line 2270 | public class ConcurrentHashMap<K,V> exte
2270          while ((tab = table) == null || tab.length == 0) {
2271              if ((sc = sizeCtl) < 0)
2272                  Thread.yield(); // lost initialization race; just spin
2273 <            else if (U.compareAndSwapInt(this, SIZECTL, sc, -1)) {
2273 >            else if (U.compareAndSetInt(this, SIZECTL, sc, -1)) {
2274                  try {
2275                      if ((tab = table) == null || tab.length == 0) {
2276                          int n = (sc > 0) ? sc : DEFAULT_CAPACITY;
# Line 2301 | Line 2301 | public class ConcurrentHashMap<K,V> exte
2301      private final void addCount(long x, int check) {
2302          CounterCell[] as; long b, s;
2303          if ((as = counterCells) != null ||
2304 <            !U.compareAndSwapLong(this, BASECOUNT, b = baseCount, s = b + x)) {
2304 >            !U.compareAndSetLong(this, BASECOUNT, b = baseCount, s = b + x)) {
2305              CounterCell a; long v; int m;
2306              boolean uncontended = true;
2307              if (as == null || (m = as.length - 1) < 0 ||
2308                  (a = as[ThreadLocalRandom.getProbe() & m]) == null ||
2309                  !(uncontended =
2310 <                  U.compareAndSwapLong(a, CELLVALUE, v = a.value, v + x))) {
2310 >                  U.compareAndSetLong(a, CELLVALUE, v = a.value, v + x))) {
2311                  fullAddCount(x, uncontended);
2312                  return;
2313              }
# Line 2325 | Line 2325 | public class ConcurrentHashMap<K,V> exte
2325                          sc == rs + MAX_RESIZERS || (nt = nextTable) == null ||
2326                          transferIndex <= 0)
2327                          break;
2328 <                    if (U.compareAndSwapInt(this, SIZECTL, sc, sc + 1))
2328 >                    if (U.compareAndSetInt(this, SIZECTL, sc, sc + 1))
2329                          transfer(tab, nt);
2330                  }
2331 <                else if (U.compareAndSwapInt(this, SIZECTL, sc,
2331 >                else if (U.compareAndSetInt(this, SIZECTL, sc,
2332                                               (rs << RESIZE_STAMP_SHIFT) + 2))
2333                      transfer(tab, null);
2334                  s = sumCount();
# Line 2349 | Line 2349 | public class ConcurrentHashMap<K,V> exte
2349                  if ((sc >>> RESIZE_STAMP_SHIFT) != rs || sc == rs + 1 ||
2350                      sc == rs + MAX_RESIZERS || transferIndex <= 0)
2351                      break;
2352 <                if (U.compareAndSwapInt(this, SIZECTL, sc, sc + 1)) {
2352 >                if (U.compareAndSetInt(this, SIZECTL, sc, sc + 1)) {
2353                      transfer(tab, nextTab);
2354                      break;
2355                  }
# Line 2372 | Line 2372 | public class ConcurrentHashMap<K,V> exte
2372              Node<K,V>[] tab = table; int n;
2373              if (tab == null || (n = tab.length) == 0) {
2374                  n = (sc > c) ? sc : c;
2375 <                if (U.compareAndSwapInt(this, SIZECTL, sc, -1)) {
2375 >                if (U.compareAndSetInt(this, SIZECTL, sc, -1)) {
2376                      try {
2377                          if (table == tab) {
2378                              @SuppressWarnings("unchecked")
# Line 2389 | Line 2389 | public class ConcurrentHashMap<K,V> exte
2389                  break;
2390              else if (tab == table) {
2391                  int rs = resizeStamp(n);
2392 <                if (U.compareAndSwapInt(this, SIZECTL, sc,
2392 >                if (U.compareAndSetInt(this, SIZECTL, sc,
2393                                          (rs << RESIZE_STAMP_SHIFT) + 2))
2394                      transfer(tab, null);
2395              }
# Line 2430 | Line 2430 | public class ConcurrentHashMap<K,V> exte
2430                      i = -1;
2431                      advance = false;
2432                  }
2433 <                else if (U.compareAndSwapInt
2433 >                else if (U.compareAndSetInt
2434                           (this, TRANSFERINDEX, nextIndex,
2435                            nextBound = (nextIndex > stride ?
2436                                         nextIndex - stride : 0))) {
# Line 2447 | Line 2447 | public class ConcurrentHashMap<K,V> exte
2447                      sizeCtl = (n << 1) - (n >>> 1);
2448                      return;
2449                  }
2450 <                if (U.compareAndSwapInt(this, SIZECTL, sc = sizeCtl, sc - 1)) {
2450 >                if (U.compareAndSetInt(this, SIZECTL, sc = sizeCtl, sc - 1)) {
2451                      if ((sc - 2) != resizeStamp(n) << RESIZE_STAMP_SHIFT)
2452                          return;
2453                      finishing = advance = true;
# Line 2572 | Line 2572 | public class ConcurrentHashMap<K,V> exte
2572                      if (cellsBusy == 0) {            // Try to attach new Cell
2573                          CounterCell r = new CounterCell(x); // Optimistic create
2574                          if (cellsBusy == 0 &&
2575 <                            U.compareAndSwapInt(this, CELLSBUSY, 0, 1)) {
2575 >                            U.compareAndSetInt(this, CELLSBUSY, 0, 1)) {
2576                              boolean created = false;
2577                              try {               // Recheck under lock
2578                                  CounterCell[] rs; int m, j;
# Line 2594 | Line 2594 | public class ConcurrentHashMap<K,V> exte
2594                  }
2595                  else if (!wasUncontended)       // CAS already known to fail
2596                      wasUncontended = true;      // Continue after rehash
2597 <                else if (U.compareAndSwapLong(a, CELLVALUE, v = a.value, v + x))
2597 >                else if (U.compareAndSetLong(a, CELLVALUE, v = a.value, v + x))
2598                      break;
2599                  else if (counterCells != as || n >= NCPU)
2600                      collide = false;            // At max size or stale
2601                  else if (!collide)
2602                      collide = true;
2603                  else if (cellsBusy == 0 &&
2604 <                         U.compareAndSwapInt(this, CELLSBUSY, 0, 1)) {
2604 >                         U.compareAndSetInt(this, CELLSBUSY, 0, 1)) {
2605                      try {
2606                          if (counterCells == as) {// Expand table unless stale
2607                              CounterCell[] rs = new CounterCell[n << 1];
# Line 2618 | Line 2618 | public class ConcurrentHashMap<K,V> exte
2618                  h = ThreadLocalRandom.advanceProbe(h);
2619              }
2620              else if (cellsBusy == 0 && counterCells == as &&
2621 <                     U.compareAndSwapInt(this, CELLSBUSY, 0, 1)) {
2621 >                     U.compareAndSetInt(this, CELLSBUSY, 0, 1)) {
2622                  boolean init = false;
2623                  try {                           // Initialize table
2624                      if (counterCells == as) {
# Line 2633 | Line 2633 | public class ConcurrentHashMap<K,V> exte
2633                  if (init)
2634                      break;
2635              }
2636 <            else if (U.compareAndSwapLong(this, BASECOUNT, v = baseCount, v + x))
2636 >            else if (U.compareAndSetLong(this, BASECOUNT, v = baseCount, v + x))
2637                  break;                          // Fall back on using base
2638          }
2639      }
# Line 2829 | Line 2829 | public class ConcurrentHashMap<K,V> exte
2829           * Acquires write lock for tree restructuring.
2830           */
2831          private final void lockRoot() {
2832 <            if (!U.compareAndSwapInt(this, LOCKSTATE, 0, WRITER))
2832 >            if (!U.compareAndSetInt(this, LOCKSTATE, 0, WRITER))
2833                  contendedLock(); // offload to separate method
2834          }
2835  
# Line 2847 | Line 2847 | public class ConcurrentHashMap<K,V> exte
2847              boolean waiting = false;
2848              for (int s;;) {
2849                  if (((s = lockState) & ~WAITER) == 0) {
2850 <                    if (U.compareAndSwapInt(this, LOCKSTATE, s, WRITER)) {
2850 >                    if (U.compareAndSetInt(this, LOCKSTATE, s, WRITER)) {
2851                          if (waiting)
2852                              waiter = null;
2853                          return;
2854                      }
2855                  }
2856                  else if ((s & WAITER) == 0) {
2857 <                    if (U.compareAndSwapInt(this, LOCKSTATE, s, s | WAITER)) {
2857 >                    if (U.compareAndSetInt(this, LOCKSTATE, s, s | WAITER)) {
2858                          waiting = true;
2859                          waiter = Thread.currentThread();
2860                      }
# Line 2879 | Line 2879 | public class ConcurrentHashMap<K,V> exte
2879                              return e;
2880                          e = e.next;
2881                      }
2882 <                    else if (U.compareAndSwapInt(this, LOCKSTATE, s,
2882 >                    else if (U.compareAndSetInt(this, LOCKSTATE, s,
2883                                                   s + READER)) {
2884                          TreeNode<K,V> r, p;
2885                          try {

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines