< prev index next >

src/java.base/share/classes/java/util/concurrent/ConcurrentHashMap.java

Print this page
8225490: Miscellaneous changes imported from jsr166 CVS 2019-09
Reviewed-by: martin, alanb

*** 383,393 **** * either stay at same index, or move with a power of two * offset. We eliminate unnecessary node creation by catching * cases where old nodes can be reused because their next fields * won't change. On average, only about one-sixth of them need * cloning when a table doubles. The nodes they replace will be ! * garbage collectable as soon as they are no longer referenced by * any reader thread that may be in the midst of concurrently * traversing table. Upon transfer, the old table bin contains * only a special forwarding node (with hash field "MOVED") that * contains the next table as its key. On encountering a * forwarding node, access and update operations restart, using --- 383,393 ---- * either stay at same index, or move with a power of two * offset. We eliminate unnecessary node creation by catching * cases where old nodes can be reused because their next fields * won't change. On average, only about one-sixth of them need * cloning when a table doubles. The nodes they replace will be ! * garbage collectible as soon as they are no longer referenced by * any reader thread that may be in the midst of concurrently * traversing table. Upon transfer, the old table bin contains * only a special forwarding node (with hash field "MOVED") that * contains the next table as its key. On encountering a * forwarding node, access and update operations restart, using
*** 3284,3294 **** if (tr != null && !checkInvariants(tr)) return false; return true; } - private static final Unsafe U = Unsafe.getUnsafe(); private static final long LOCKSTATE = U.objectFieldOffset(TreeBin.class, "lockState"); } /* ----------------Table Traversal -------------- */ --- 3284,3293 ----
*** 6343,6374 **** } } // Unsafe mechanics private static final Unsafe U = Unsafe.getUnsafe(); ! private static final long SIZECTL; ! private static final long TRANSFERINDEX; ! private static final long BASECOUNT; ! private static final long CELLSBUSY; ! private static final long CELLVALUE; ! private static final int ABASE; private static final int ASHIFT; static { - SIZECTL = U.objectFieldOffset - (ConcurrentHashMap.class, "sizeCtl"); - TRANSFERINDEX = U.objectFieldOffset - (ConcurrentHashMap.class, "transferIndex"); - BASECOUNT = U.objectFieldOffset - (ConcurrentHashMap.class, "baseCount"); - CELLSBUSY = U.objectFieldOffset - (ConcurrentHashMap.class, "cellsBusy"); - - CELLVALUE = U.objectFieldOffset - (CounterCell.class, "value"); - - ABASE = U.arrayBaseOffset(Node[].class); int scale = U.arrayIndexScale(Node[].class); if ((scale & (scale - 1)) != 0) throw new ExceptionInInitializerError("array index scale not a power of two"); ASHIFT = 31 - Integer.numberOfLeadingZeros(scale); --- 6342,6365 ---- } } // Unsafe mechanics private static final Unsafe U = Unsafe.getUnsafe(); ! private static final long SIZECTL ! = U.objectFieldOffset(ConcurrentHashMap.class, "sizeCtl"); ! private static final long TRANSFERINDEX ! = U.objectFieldOffset(ConcurrentHashMap.class, "transferIndex"); ! private static final long BASECOUNT ! = U.objectFieldOffset(ConcurrentHashMap.class, "baseCount"); ! private static final long CELLSBUSY ! = U.objectFieldOffset(ConcurrentHashMap.class, "cellsBusy"); ! private static final long CELLVALUE ! = U.objectFieldOffset(CounterCell.class, "value"); ! private static final int ABASE = U.arrayBaseOffset(Node[].class); private static final int ASHIFT; static { int scale = U.arrayIndexScale(Node[].class); if ((scale & (scale - 1)) != 0) throw new ExceptionInInitializerError("array index scale not a power of two"); ASHIFT = 31 - Integer.numberOfLeadingZeros(scale);
< prev index next >