代码略...
因为 java8 里面扩容会整体调整,可能扩容的时候还不是一个红黑树,只是一个链表。
if (fh >= 0) {int runBit = fh & n;Node<K,V> lastRun = f;for (Node<K,V> p = f.next; p != null; p = p.next) {int b = p.hash & n;if (b != runBit) {runBit = b;lastRun = p;}}if (runBit == 0) {ln = lastRun;hn = null;}else {hn = lastRun;ln = null;}// <1>for (Node<K,V> p = f; p != lastRun; p = p.next) {int ph = p.hash; K pk = p.key; V pv = p.val;if ((ph & n) == 0)ln = new Node<K,V>(ph, pk, pv, ln);elsehn = new Node<K,V>(ph, pk, pv, hn);}// ln lastNode// hn headerNode// <2> lastNode 放到扩容的当前未知setTabAt(nextTab, i, ln);// <3> headNode 放到扩容的最后面setTabAt(nextTab, i + n, hn);setTabAt(tab, i, fwd);advance = true;}
// ConcurrentHashMap.classstatic final class ForwardingNode<K,V> extends Node<K,V> {final Node<K,V>[] nextTable;ForwardingNode(Node<K,V>[] tab) {super(MOVED, null, null, null);this.nextTable = tab;}// 略...}
TreeBin 是 ConcurrentHashMap 里面用来保存红黑树的。