< prev index next >

src/java.base/share/classes/java/util/concurrent/locks/LockSupport.java

Print this page
8200123: Replace Thread.init with telescoping constructor
Reviewed-by: dholmes, mchung, plevart


 395      * Returns the pseudo-randomly initialized or updated secondary seed.
 396      * Copied from ThreadLocalRandom due to package access restrictions.
 397      */
 398     static final int nextSecondarySeed() {
 399         int r;
 400         Thread t = Thread.currentThread();
 401         if ((r = U.getInt(t, SECONDARY)) != 0) {
 402             r ^= r << 13;   // xorshift
 403             r ^= r >>> 17;
 404             r ^= r << 5;
 405         }
 406         else if ((r = java.util.concurrent.ThreadLocalRandom.current().nextInt()) == 0)
 407             r = 1; // avoid zero
 408         U.putInt(t, SECONDARY, r);
 409         return r;
 410     }
 411 
 412     /**
 413      * Returns the thread id for the given thread.  We must access
 414      * this directly rather than via method Thread.getId() because
 415      * getId() is not final, and has been known to be overridden in
 416      * ways that do not preserve unique mappings.
 417      */
 418     static final long getThreadId(Thread thread) {
 419         return U.getLongVolatile(thread, TID);
 420     }
 421 
 422     // Hotspot implementation via intrinsics API
 423     private static final Unsafe U = Unsafe.getUnsafe();
 424     private static final long PARKBLOCKER = U.objectFieldOffset
 425             (Thread.class, "parkBlocker");
 426     private static final long SECONDARY = U.objectFieldOffset
 427             (Thread.class, "threadLocalRandomSecondarySeed");
 428     private static final long TID = U.objectFieldOffset
 429             (Thread.class, "tid");
 430 
 431 }


 395      * Returns the pseudo-randomly initialized or updated secondary seed.
 396      * Copied from ThreadLocalRandom due to package access restrictions.
 397      */
 398     static final int nextSecondarySeed() {
 399         int r;
 400         Thread t = Thread.currentThread();
 401         if ((r = U.getInt(t, SECONDARY)) != 0) {
 402             r ^= r << 13;   // xorshift
 403             r ^= r >>> 17;
 404             r ^= r << 5;
 405         }
 406         else if ((r = java.util.concurrent.ThreadLocalRandom.current().nextInt()) == 0)
 407             r = 1; // avoid zero
 408         U.putInt(t, SECONDARY, r);
 409         return r;
 410     }
 411 
 412     /**
 413      * Returns the thread id for the given thread.  We must access
 414      * this directly rather than via method Thread.getId() because
 415      * getId() has been known to be overridden in ways that do not
 416      * preserve unique mappings.
 417      */
 418     static final long getThreadId(Thread thread) {
 419         return U.getLong(thread, TID);
 420     }
 421 
 422     // Hotspot implementation via intrinsics API
 423     private static final Unsafe U = Unsafe.getUnsafe();
 424     private static final long PARKBLOCKER = U.objectFieldOffset
 425             (Thread.class, "parkBlocker");
 426     private static final long SECONDARY = U.objectFieldOffset
 427             (Thread.class, "threadLocalRandomSecondarySeed");
 428     private static final long TID = U.objectFieldOffset
 429             (Thread.class, "tid");
 430 
 431 }
< prev index next >