377
378 /**
379 * Returns the pseudo-randomly initialized or updated secondary seed.
380 * Copied from ThreadLocalRandom due to package access restrictions.
381 */
382 static final int nextSecondarySeed() {
383 int r;
384 Thread t = Thread.currentThread();
385 if ((r = U.getInt(t, SECONDARY)) != 0) {
386 r ^= r << 13; // xorshift
387 r ^= r >>> 17;
388 r ^= r << 5;
389 }
390 else if ((r = java.util.concurrent.ThreadLocalRandom.current().nextInt()) == 0)
391 r = 1; // avoid zero
392 U.putInt(t, SECONDARY, r);
393 return r;
394 }
395
396 // Hotspot implementation via intrinsics API
397 private static final sun.misc.Unsafe U = sun.misc.Unsafe.getUnsafe();
398 private static final long PARKBLOCKER;
399 private static final long SECONDARY;
400 static {
401 try {
402 PARKBLOCKER = U.objectFieldOffset
403 (Thread.class.getDeclaredField("parkBlocker"));
404 SECONDARY = U.objectFieldOffset
405 (Thread.class.getDeclaredField("threadLocalRandomSecondarySeed"));
406 } catch (ReflectiveOperationException e) {
407 throw new Error(e);
408 }
409 }
410
411 }
|
377
378 /**
379 * Returns the pseudo-randomly initialized or updated secondary seed.
380 * Copied from ThreadLocalRandom due to package access restrictions.
381 */
382 static final int nextSecondarySeed() {
383 int r;
384 Thread t = Thread.currentThread();
385 if ((r = U.getInt(t, SECONDARY)) != 0) {
386 r ^= r << 13; // xorshift
387 r ^= r >>> 17;
388 r ^= r << 5;
389 }
390 else if ((r = java.util.concurrent.ThreadLocalRandom.current().nextInt()) == 0)
391 r = 1; // avoid zero
392 U.putInt(t, SECONDARY, r);
393 return r;
394 }
395
396 // Hotspot implementation via intrinsics API
397 private static final jdk.internal.misc.Unsafe U = jdk.internal.misc.Unsafe.getUnsafe();
398 private static final long PARKBLOCKER;
399 private static final long SECONDARY;
400 static {
401 try {
402 PARKBLOCKER = U.objectFieldOffset
403 (Thread.class.getDeclaredField("parkBlocker"));
404 SECONDARY = U.objectFieldOffset
405 (Thread.class.getDeclaredField("threadLocalRandomSecondarySeed"));
406 } catch (ReflectiveOperationException e) {
407 throw new Error(e);
408 }
409 }
410
411 }
|