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.118 by dl, Sun Dec 1 16:08:12 2013 UTC vs.
Revision 1.125 by jsr166, Sun Sep 13 16:28:14 2015 UTC

# Line 15 | Line 15 | import java.lang.reflect.Type;
15   import java.util.AbstractMap;
16   import java.util.Arrays;
17   import java.util.Collection;
18 import java.util.Comparator;
18   import java.util.ConcurrentModificationException;
19   import java.util.Enumeration;
20   import java.util.HashMap;
# Line 115 | Line 114 | import java.util.concurrent.locks.Reentr
114   * objects do not support method {@code setValue}.
115   *
116   * <ul>
117 < * <li> forEach: Perform a given action on each element.
117 > * <li>forEach: Perform a given action on each element.
118   * A variant form applies a given transformation on each element
119 < * before performing the action.</li>
119 > * before performing the action.
120   *
121 < * <li> search: Return the first available non-null result of
121 > * <li>search: Return the first available non-null result of
122   * applying a given function on each element; skipping further
123 < * search when a result is found.</li>
123 > * search when a result is found.
124   *
125 < * <li> reduce: Accumulate each element.  The supplied reduction
125 > * <li>reduce: Accumulate each element.  The supplied reduction
126   * function cannot rely on ordering (more formally, it should be
127   * both associative and commutative).  There are five variants:
128   *
129   * <ul>
130   *
131 < * <li> Plain reductions. (There is not a form of this method for
131 > * <li>Plain reductions. (There is not a form of this method for
132   * (key, value) function arguments since there is no corresponding
133 < * return type.)</li>
133 > * return type.)
134   *
135 < * <li> Mapped reductions that accumulate the results of a given
136 < * function applied to each element.</li>
135 > * <li>Mapped reductions that accumulate the results of a given
136 > * function applied to each element.
137   *
138 < * <li> Reductions to scalar doubles, longs, and ints, using a
139 < * given basis value.</li>
138 > * <li>Reductions to scalar doubles, longs, and ints, using a
139 > * given basis value.
140   *
141   * </ul>
143 * </li>
142   * </ul>
143   *
144   * <p>These bulk operations accept a {@code parallelismThreshold}
# Line 489 | Line 487 | public class ConcurrentHashMapV8<K,V> ex
487       *
488       * Maintaining API and serialization compatibility with previous
489       * versions of this class introduces several oddities. Mainly: We
490 <     * leave untouched but unused constructor arguments refering to
490 >     * leave untouched but unused constructor arguments referring to
491       * concurrencyLevel. We accept a loadFactor constructor argument,
492       * but apply it only to initial table capacity (which is the only
493       * time that we can guarantee to honor it.) We also declare an
# Line 638 | Line 636 | public class ConcurrentHashMapV8<K,V> ex
636              this.next = next;
637          }
638  
639 <        public final K getKey()       { return key; }
640 <        public final V getValue()     { return val; }
641 <        public final int hashCode()   { return key.hashCode() ^ val.hashCode(); }
642 <        public final String toString(){ return key + "=" + val; }
639 >        public final K getKey()     { return key; }
640 >        public final V getValue()   { return val; }
641 >        public final int hashCode() { return key.hashCode() ^ val.hashCode(); }
642 >        public final String toString() { return key + "=" + val; }
643          public final V setValue(V value) {
644              throw new UnsupportedOperationException();
645          }
# Line 2218 | Line 2216 | public class ConcurrentHashMapV8<K,V> ex
2216       * Must be negative when shifted left by RESIZE_STAMP_SHIFT.
2217       */
2218      static final int resizeStamp(int n) {
2219 <        return Integer.numberOfLeadingZeros(n) | (1 << (RESIZE_STAMP_BITS - 1));
2219 >        return Integer.numberOfLeadingZeros(n) | (1 << (RESIZE_STAMP_BITS - 1));
2220      }
2221  
2222      /**
# Line 2282 | Line 2280 | public class ConcurrentHashMapV8<K,V> ex
2280                  int rs = resizeStamp(n);
2281                  if (sc < 0) {
2282                      if ((sc >>> RESIZE_STAMP_SHIFT) != rs || sc == rs + 1 ||
2283 <                        sc == rs + MAX_RESIZERS || (nt = nextTable) == null ||
2284 <                        transferIndex <= 0)
2283 >                        sc == rs + MAX_RESIZERS || (nt = nextTable) == null ||
2284 >                        transferIndex <= 0)
2285                          break;
2286                      if (U.compareAndSwapInt(this, SIZECTL, sc, sc + 1))
2287                          transfer(tab, nt);
2288                  }
2289                  else if (U.compareAndSwapInt(this, SIZECTL, sc,
2290 <                                             (rs << RESIZE_STAMP_SHIFT) + 2))
2290 >                                             (rs << RESIZE_STAMP_SHIFT) + 2))
2291                      transfer(tab, null);
2292                  s = sumCount();
2293              }
# Line 2303 | Line 2301 | public class ConcurrentHashMapV8<K,V> ex
2301          Node<K,V>[] nextTab; int sc;
2302          if (tab != null && (f instanceof ForwardingNode) &&
2303              (nextTab = ((ForwardingNode<K,V>)f).nextTable) != null) {
2304 <            int rs = resizeStamp(tab.length);
2304 >            int rs = resizeStamp(tab.length);
2305              while (nextTab == nextTable && table == tab &&
2306 <                   (sc = sizeCtl) < 0) {
2307 <                if ((sc >>> RESIZE_STAMP_SHIFT) != rs || sc == rs + 1 ||
2306 >                   (sc = sizeCtl) < 0) {
2307 >                if ((sc >>> RESIZE_STAMP_SHIFT) != rs || sc == rs + 1 ||
2308                      sc == rs + MAX_RESIZERS || transferIndex <= 0)
2309 <                    break;
2310 <                if (U.compareAndSwapInt(this, SIZECTL, sc, sc + 1)) {
2309 >                    break;
2310 >                if (U.compareAndSwapInt(this, SIZECTL, sc, sc + 1)) {
2311                      transfer(tab, nextTab);
2312                      break;
2313                  }
# Line 2350 | Line 2348 | public class ConcurrentHashMapV8<K,V> ex
2348              else if (tab == table) {
2349                  int rs = resizeStamp(n);
2350                  if (sc < 0) {
2351 <                    Node<K,V>[] nt;
2351 >                    Node<K,V>[] nt;
2352                      if ((sc >>> RESIZE_STAMP_SHIFT) != rs || sc == rs + 1 ||
2353                          sc == rs + MAX_RESIZERS || (nt = nextTable) == null ||
2354                          transferIndex <= 0)
# Line 2359 | Line 2357 | public class ConcurrentHashMapV8<K,V> ex
2357                          transfer(tab, nt);
2358                  }
2359                  else if (U.compareAndSwapInt(this, SIZECTL, sc,
2360 <                                             (rs << RESIZE_STAMP_SHIFT) + 2))
2360 >                                             (rs << RESIZE_STAMP_SHIFT) + 2))
2361                      transfer(tab, null);
2362              }
2363          }
# Line 2417 | Line 2415 | public class ConcurrentHashMapV8<K,V> ex
2415                      return;
2416                  }
2417                  if (U.compareAndSwapInt(this, SIZECTL, sc = sizeCtl, sc - 1)) {
2418 <                    if ((sc - 2) != resizeStamp(n))
2418 >                    if ((sc - 2) != resizeStamp(n) << RESIZE_STAMP_SHIFT)
2419                          return;
2420                      finishing = advance = true;
2421                      i = n; // recheck before commit
# Line 2533 | Line 2531 | public class ConcurrentHashMapV8<K,V> ex
2531              }
2532          }
2533      }
2534 +
2535      /**
2536       * Returns a list on non-TreeNodes replacing those in given list.
2537       */
# Line 2578 | Line 2577 | public class ConcurrentHashMapV8<K,V> ex
2577          final TreeNode<K,V> findTreeNode(int h, Object k, Class<?> kc) {
2578              if (k != null) {
2579                  TreeNode<K,V> p = this;
2580 <                do  {
2580 >                do {
2581                      int ph, dir; K pk; TreeNode<K,V> q;
2582                      TreeNode<K,V> pl = p.left, pr = p.right;
2583                      if ((ph = p.hash) > h)
# Line 3027 | Line 3026 | public class ConcurrentHashMapV8<K,V> ex
3026  
3027          static <K,V> TreeNode<K,V> balanceDeletion(TreeNode<K,V> root,
3028                                                     TreeNode<K,V> x) {
3029 <            for (TreeNode<K,V> xp, xpl, xpr;;)  {
3029 >            for (TreeNode<K,V> xp, xpl, xpr;;) {
3030                  if (x == null || x == root)
3031                      return root;
3032                  else if ((xp = x.parent) == null) {

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines