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.106 by jsr166, Wed Jun 19 17:11:57 2013 UTC vs.
Revision 1.109 by dl, Wed Jul 3 18:16:31 2013 UTC

# Line 299 | Line 299 | public class ConcurrentHashMapV8<K,V>
299       * because they have negative hash fields and null key and value
300       * fields. (These special nodes are either uncommon or transient,
301       * so the impact of carrying around some unused fields is
302 <     * insignficant.)
302 >     * insignificant.)
303       *
304       * The table is lazily initialized to a power-of-two size upon the
305       * first insertion.  Each bin in the table normally contains a
# Line 462 | Line 462 | public class ConcurrentHashMapV8<K,V>
462       *
463       * TreeBins also require an additional locking mechanism.  While
464       * list traversal is always possible by readers even during
465 <     * updates, tree traversal is not, mainly beause of tree-rotations
465 >     * updates, tree traversal is not, mainly because of tree-rotations
466       * that may change the root node and/or its linkages.  TreeBins
467       * include a simple read-write lock mechanism parasitic on the
468       * main bin-synchronization strategy: Structural adjustments
# Line 568 | Line 568 | public class ConcurrentHashMapV8<K,V>
568      /*
569       * Encodings for Node hash fields. See above for explanation.
570       */
571 <    static final int MOVED     = 0x8fffffff; // (-1) hash for forwarding nodes
572 <    static final int TREEBIN   = 0x80000000; // hash for heads of treea
573 <    static final int RESERVED  = 0x80000001; // hash for transient reservations
571 >    static final int MOVED     = -1; // hash for forwarding nodes
572 >    static final int TREEBIN   = -2; // hash for roots of trees
573 >    static final int RESERVED  = -3; // hash for transient reservations
574      static final int HASH_BITS = 0x7fffffff; // usable bits of normal node hash
575  
576      /** Number of CPUS, to place bounds on some sizings */
# Line 589 | Line 589 | public class ConcurrentHashMapV8<K,V>
589       * Key-value entry.  This class is never exported out as a
590       * user-mutable Map.Entry (i.e., one supporting setValue; see
591       * MapEntry below), but can be used for read-only traversals used
592 <     * in bulk tasks.  Subclasses of Node with a negativehash field
592 >     * in bulk tasks.  Subclasses of Node with a negative hash field
593       * are special, and contain null keys and values (but are never
594       * exported).  Otherwise, keys and vals are never null.
595       */
# Line 597 | Line 597 | public class ConcurrentHashMapV8<K,V>
597          final int hash;
598          final K key;
599          volatile V val;
600 <        Node<K,V> next;
600 >        volatile Node<K,V> next;
601  
602          Node(int hash, K key, V val, Node<K,V> next) {
603              this.hash = hash;
# Line 722 | Line 722 | public class ConcurrentHashMapV8<K,V>
722       * errors by users, these checks must operate on local variables,
723       * which accounts for some odd-looking inline assignments below.
724       * Note that calls to setTabAt always occur within locked regions,
725 <     * and so do not need full volatile semantics, but still require
726 <     * ordering to maintain concurrent readability.
725 >     * and so in principle require only release ordering, not need
726 >     * full volatile semantics, but are currently coded as volatile
727 >     * writes to be conservative.
728       */
729  
730      @SuppressWarnings("unchecked")
# Line 737 | Line 738 | public class ConcurrentHashMapV8<K,V>
738      }
739  
740      static final <K,V> void setTabAt(Node<K,V>[] tab, int i, Node<K,V> v) {
741 <        U.putOrderedObject(tab, ((long)i << ASHIFT) + ABASE, v);
741 >        U.putObjectVolatile(tab, ((long)i << ASHIFT) + ABASE, v);
742      }
743  
744      /* ---------------- Fields -------------- */
# Line 2395 | Line 2396 | public class ConcurrentHashMapV8<K,V>
2396                                  else
2397                                      hn = new Node<K,V>(ph, pk, pv, hn);
2398                              }
2399 +                            setTabAt(nextTab, i, ln);
2400 +                            setTabAt(nextTab, i + n, hn);
2401 +                            setTabAt(tab, i, fwd);
2402 +                            advance = true;
2403                          }
2404                          else if (f instanceof TreeBin) {
2405                              TreeBin<K,V> t = (TreeBin<K,V>)f;
# Line 2426 | Line 2431 | public class ConcurrentHashMapV8<K,V>
2431                                  (hc != 0) ? new TreeBin<K,V>(lo) : t;
2432                              hn = (hc <= UNTREEIFY_THRESHOLD) ? untreeify(hi) :
2433                                  (lc != 0) ? new TreeBin<K,V>(hi) : t;
2434 +                            setTabAt(nextTab, i, ln);
2435 +                            setTabAt(nextTab, i + n, hn);
2436 +                            setTabAt(tab, i, fwd);
2437 +                            advance = true;
2438                          }
2430                        else
2431                            ln = hn = null;
2432                        setTabAt(nextTab, i, ln);
2433                        setTabAt(nextTab, i + n, hn);
2434                        setTabAt(tab, i, fwd);
2435                        advance = true;
2439                      }
2440                  }
2441              }
# Line 2453 | Line 2456 | public class ConcurrentHashMapV8<K,V>
2456                      U.compareAndSwapInt(this, SIZECTL, sc, -2))
2457                      transfer(tab, null);
2458              }
2459 <            else if ((b = tabAt(tab, index)) != null) {
2459 >            else if ((b = tabAt(tab, index)) != null && b.hash >= 0) {
2460                  synchronized (b) {
2461                      if (tabAt(tab, index) == b) {
2462                          TreeNode<K,V> hd = null, tl = null;
# Line 2653 | Line 2656 | public class ConcurrentHashMapV8<K,V>
2656  
2657          /**
2658           * Returns matching node or null if none. Tries to search
2659 <         * using tree compareisons from root, but continues linear
2659 >         * using tree comparisons from root, but continues linear
2660           * search when lock not available.
2661           */
2662          final Node<K,V> find(int h, Object k) {
# Line 3498 | Line 3501 | public class ConcurrentHashMapV8<K,V>
3501       * of all (key, value) pairs
3502       * @since 1.8
3503       */
3504 <    public double reduceToDoubleIn(long parallelismThreshold,
3505 <                                   ObjectByObjectToDouble<? super K, ? super V> transformer,
3506 <                                   double basis,
3507 <                                   DoubleByDoubleToDouble reducer) {
3504 >    public double reduceToDouble(long parallelismThreshold,
3505 >                                 ObjectByObjectToDouble<? super K, ? super V> transformer,
3506 >                                 double basis,
3507 >                                 DoubleByDoubleToDouble reducer) {
3508          if (transformer == null || reducer == null)
3509              throw new NullPointerException();
3510          return new MapReduceMappingsToDoubleTask<K,V>

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines