# HG changeset patch # User dl # Date 1460049128 25200 # Node ID 8a320111d9fe7ac25e7a592df7bde0f6e334c8b4 # Parent 96f46df4ac4809c91f48d6e46f8f10d5ccd29472 8151579: Optimize ConcurrentHashMap.Node Reviewed-by: martin, psandoz, forax diff -r 96f46df4ac48 -r 8a320111d9fe jdk/src/java.base/share/classes/java/util/concurrent/ConcurrentHashMap.java --- a/jdk/src/java.base/share/classes/java/util/concurrent/ConcurrentHashMap.java Thu Apr 07 10:09:03 2016 -0700 +++ b/jdk/src/java.base/share/classes/java/util/concurrent/ConcurrentHashMap.java Thu Apr 07 10:12:08 2016 -0700 @@ -628,10 +628,14 @@ volatile V val; volatile Node next; - Node(int hash, K key, V val, Node next) { + Node(int hash, K key, V val) { this.hash = hash; this.key = key; this.val = val; + } + + Node(int hash, K key, V val, Node next) { + this(hash, key, val); this.next = next; } @@ -1024,8 +1028,7 @@ if (tab == null || (n = tab.length) == 0) tab = initTable(); else if ((f = tabAt(tab, i = (n - 1) & hash)) == null) { - if (casTabAt(tab, i, null, - new Node(hash, key, value, null))) + if (casTabAt(tab, i, null, new Node(hash, key, value))) break; // no lock when adding to empty bin } else if ((fh = f.hash) == MOVED) @@ -1048,8 +1051,7 @@ } Node pred = e; if ((e = e.next) == null) { - pred.next = new Node(hash, key, - value, null); + pred.next = new Node(hash, key, value); break; } } @@ -1709,7 +1711,7 @@ Node node = null; try { if ((val = mappingFunction.apply(key)) != null) - node = new Node(h, key, val, null); + node = new Node(h, key, val); } finally { setTabAt(tab, i, node); } @@ -1740,7 +1742,7 @@ if (pred.next != null) throw new IllegalStateException("Recursive update"); added = true; - pred.next = new Node(h, key, val, null); + pred.next = new Node(h, key, val); } break; } @@ -1909,7 +1911,7 @@ try { if ((val = remappingFunction.apply(key, null)) != null) { delta = 1; - node = new Node(h, key, val, null); + node = new Node(h, key, val); } } finally { setTabAt(tab, i, node); @@ -1951,8 +1953,7 @@ if (pred.next != null) throw new IllegalStateException("Recursive update"); delta = 1; - pred.next = - new Node(h, key, val, null); + pred.next = new Node(h, key, val); } break; } @@ -2030,7 +2031,7 @@ if (tab == null || (n = tab.length) == 0) tab = initTable(); else if ((f = tabAt(tab, i = (n - 1) & h)) == null) { - if (casTabAt(tab, i, null, new Node(h, key, value, null))) { + if (casTabAt(tab, i, null, new Node(h, key, value))) { delta = 1; val = value; break; @@ -2065,8 +2066,7 @@ if ((e = e.next) == null) { delta = 1; val = value; - pred.next = - new Node(h, key, val, null); + pred.next = new Node(h, key, val); break; } } @@ -2227,7 +2227,7 @@ static final class ForwardingNode extends Node { final Node[] nextTable; ForwardingNode(Node[] tab) { - super(MOVED, null, null, null); + super(MOVED, null, null); this.nextTable = tab; } @@ -2263,7 +2263,7 @@ */ static final class ReservationNode extends Node { ReservationNode() { - super(RESERVED, null, null, null); + super(RESERVED, null, null); } Node find(int h, Object k) { @@ -2690,12 +2690,12 @@ } /** - * Returns a list on non-TreeNodes replacing those in given list. + * Returns a list of non-TreeNodes replacing those in given list. */ static Node untreeify(Node b) { Node hd = null, tl = null; for (Node q = b; q != null; q = q.next) { - Node p = new Node(q.hash, q.key, q.val, null); + Node p = new Node(q.hash, q.key, q.val); if (tl == null) hd = p; else @@ -2801,7 +2801,7 @@ * Creates bin with initial set of nodes headed by b. */ TreeBin(TreeNode b) { - super(TREEBIN, null, null, null); + super(TREEBIN, null, null); this.first = b; TreeNode r = null; for (TreeNode x = b, next; x != null; x = next) {