3292 if (tn != null && tn.prev != t)
3293 return false;
3294 if (tp != null && t != tp.left && t != tp.right)
3295 return false;
3296 if (tl != null && (tl.parent != t || tl.hash > t.hash))
3297 return false;
3298 if (tr != null && (tr.parent != t || tr.hash < t.hash))
3299 return false;
3300 if (t.red && tl != null && tl.red && tr != null && tr.red)
3301 return false;
3302 if (tl != null && !checkInvariants(tl))
3303 return false;
3304 if (tr != null && !checkInvariants(tr))
3305 return false;
3306 return true;
3307 }
3308
3309 private static final Unsafe U = Unsafe.getUnsafe();
3310 private static final long LOCKSTATE;
3311 static {
3312 try {
3313 LOCKSTATE = U.objectFieldOffset
3314 (TreeBin.class.getDeclaredField("lockState"));
3315 } catch (ReflectiveOperationException e) {
3316 throw new Error(e);
3317 }
3318 }
3319 }
3320
3321 /* ----------------Table Traversal -------------- */
3322
3323 /**
3324 * Records the table, its length, and current traversal index for a
3325 * traverser that must process a region of a forwarded table before
3326 * proceeding with current table.
3327 */
3328 static final class TableStack<K,V> {
3329 int length;
3330 int index;
3331 Node<K,V>[] tab;
3332 TableStack<K,V> next;
3333 }
3334
3335 /**
3336 * Encapsulates traversal for methods such as containsValue; also
3337 * serves as a base class for other iterators and spliterators.
6364 while (s != null) {
6365 t.result = reducer.applyAsInt(t.result, s.result);
6366 s = t.rights = s.nextRight;
6367 }
6368 }
6369 }
6370 }
6371 }
6372
6373 // Unsafe mechanics
6374 private static final Unsafe U = Unsafe.getUnsafe();
6375 private static final long SIZECTL;
6376 private static final long TRANSFERINDEX;
6377 private static final long BASECOUNT;
6378 private static final long CELLSBUSY;
6379 private static final long CELLVALUE;
6380 private static final int ABASE;
6381 private static final int ASHIFT;
6382
6383 static {
6384 try {
6385 SIZECTL = U.objectFieldOffset
6386 (ConcurrentHashMap.class.getDeclaredField("sizeCtl"));
6387 TRANSFERINDEX = U.objectFieldOffset
6388 (ConcurrentHashMap.class.getDeclaredField("transferIndex"));
6389 BASECOUNT = U.objectFieldOffset
6390 (ConcurrentHashMap.class.getDeclaredField("baseCount"));
6391 CELLSBUSY = U.objectFieldOffset
6392 (ConcurrentHashMap.class.getDeclaredField("cellsBusy"));
6393
6394 CELLVALUE = U.objectFieldOffset
6395 (CounterCell.class.getDeclaredField("value"));
6396
6397 ABASE = U.arrayBaseOffset(Node[].class);
6398 int scale = U.arrayIndexScale(Node[].class);
6399 if ((scale & (scale - 1)) != 0)
6400 throw new Error("array index scale not a power of two");
6401 ASHIFT = 31 - Integer.numberOfLeadingZeros(scale);
6402 } catch (ReflectiveOperationException e) {
6403 throw new Error(e);
6404 }
6405
6406 // Reduce the risk of rare disastrous classloading in first call to
6407 // LockSupport.park: https://bugs.openjdk.java.net/browse/JDK-8074773
6408 Class<?> ensureLoaded = LockSupport.class;
6409 }
6410 }
|
3292 if (tn != null && tn.prev != t)
3293 return false;
3294 if (tp != null && t != tp.left && t != tp.right)
3295 return false;
3296 if (tl != null && (tl.parent != t || tl.hash > t.hash))
3297 return false;
3298 if (tr != null && (tr.parent != t || tr.hash < t.hash))
3299 return false;
3300 if (t.red && tl != null && tl.red && tr != null && tr.red)
3301 return false;
3302 if (tl != null && !checkInvariants(tl))
3303 return false;
3304 if (tr != null && !checkInvariants(tr))
3305 return false;
3306 return true;
3307 }
3308
3309 private static final Unsafe U = Unsafe.getUnsafe();
3310 private static final long LOCKSTATE;
3311 static {
3312 LOCKSTATE = U.objectFieldOffset
3313 (TreeBin.class, "lockState");
3314 }
3315 }
3316
3317 /* ----------------Table Traversal -------------- */
3318
3319 /**
3320 * Records the table, its length, and current traversal index for a
3321 * traverser that must process a region of a forwarded table before
3322 * proceeding with current table.
3323 */
3324 static final class TableStack<K,V> {
3325 int length;
3326 int index;
3327 Node<K,V>[] tab;
3328 TableStack<K,V> next;
3329 }
3330
3331 /**
3332 * Encapsulates traversal for methods such as containsValue; also
3333 * serves as a base class for other iterators and spliterators.
6360 while (s != null) {
6361 t.result = reducer.applyAsInt(t.result, s.result);
6362 s = t.rights = s.nextRight;
6363 }
6364 }
6365 }
6366 }
6367 }
6368
6369 // Unsafe mechanics
6370 private static final Unsafe U = Unsafe.getUnsafe();
6371 private static final long SIZECTL;
6372 private static final long TRANSFERINDEX;
6373 private static final long BASECOUNT;
6374 private static final long CELLSBUSY;
6375 private static final long CELLVALUE;
6376 private static final int ABASE;
6377 private static final int ASHIFT;
6378
6379 static {
6380 SIZECTL = U.objectFieldOffset
6381 (ConcurrentHashMap.class, "sizeCtl");
6382 TRANSFERINDEX = U.objectFieldOffset
6383 (ConcurrentHashMap.class, "transferIndex");
6384 BASECOUNT = U.objectFieldOffset
6385 (ConcurrentHashMap.class, "baseCount");
6386 CELLSBUSY = U.objectFieldOffset
6387 (ConcurrentHashMap.class, "cellsBusy");
6388
6389 CELLVALUE = U.objectFieldOffset
6390 (CounterCell.class, "value");
6391
6392 ABASE = U.arrayBaseOffset(Node[].class);
6393 int scale = U.arrayIndexScale(Node[].class);
6394 if ((scale & (scale - 1)) != 0)
6395 throw new Error("array index scale not a power of two");
6396 ASHIFT = 31 - Integer.numberOfLeadingZeros(scale);
6397
6398 // Reduce the risk of rare disastrous classloading in first call to
6399 // LockSupport.park: https://bugs.openjdk.java.net/browse/JDK-8074773
6400 Class<?> ensureLoaded = LockSupport.class;
6401 }
6402 }
|