< prev index next >

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

Print this page
rev 17358 : 8182487: Add Unsafe.objectFieldOffset(Class, String)
Reviewed-by: dsimms, twisti, bchristi, mgerdin


 402             r ^= r << 5;
 403         }
 404         else if ((r = java.util.concurrent.ThreadLocalRandom.current().nextInt()) == 0)
 405             r = 1; // avoid zero
 406         U.putInt(t, SECONDARY, r);
 407         return r;
 408     }
 409 
 410     /**
 411      * Returns the thread id for the given thread.  We must access
 412      * this directly rather than via method Thread.getId() because
 413      * getId() is not final, and has been known to be overridden in
 414      * ways that do not preserve unique mappings.
 415      */
 416     static final long getThreadId(Thread thread) {
 417         return U.getLongVolatile(thread, TID);
 418     }
 419 
 420     // Hotspot implementation via intrinsics API
 421     private static final Unsafe U = Unsafe.getUnsafe();
 422     private static final long PARKBLOCKER;
 423     private static final long SECONDARY;
 424     private static final long TID;
 425     static {
 426         try {
 427             PARKBLOCKER = U.objectFieldOffset
 428                 (Thread.class.getDeclaredField("parkBlocker"));
 429             SECONDARY = U.objectFieldOffset
 430                 (Thread.class.getDeclaredField("threadLocalRandomSecondarySeed"));
 431             TID = U.objectFieldOffset
 432                 (Thread.class.getDeclaredField("tid"));
 433 
 434         } catch (ReflectiveOperationException e) {
 435             throw new Error(e);
 436         }
 437     }
 438 
 439 }


 402             r ^= r << 5;
 403         }
 404         else if ((r = java.util.concurrent.ThreadLocalRandom.current().nextInt()) == 0)
 405             r = 1; // avoid zero
 406         U.putInt(t, SECONDARY, r);
 407         return r;
 408     }
 409 
 410     /**
 411      * Returns the thread id for the given thread.  We must access
 412      * this directly rather than via method Thread.getId() because
 413      * getId() is not final, and has been known to be overridden in
 414      * ways that do not preserve unique mappings.
 415      */
 416     static final long getThreadId(Thread thread) {
 417         return U.getLongVolatile(thread, TID);
 418     }
 419 
 420     // Hotspot implementation via intrinsics API
 421     private static final Unsafe U = Unsafe.getUnsafe();
 422     private static final long PARKBLOCKER = U.objectFieldOffset
 423             (Thread.class, "parkBlocker");
 424     private static final long SECONDARY = U.objectFieldOffset
 425             (Thread.class, "threadLocalRandomSecondarySeed");
 426     private static final long TID = U.objectFieldOffset
 427             (Thread.class, "tid");










 428 
 429 }
< prev index next >