< prev index next >

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

Print this page

283         Thread t = Thread.currentThread();
284         if ((r = U.getInt(t, SECONDARY)) != 0) {
285             r ^= r << 13;   // xorshift
286             r ^= r >>> 17;
287             r ^= r << 5;
288         }
289         else if ((r = mix32(seeder.getAndAdd(SEEDER_INCREMENT))) == 0)
290             r = 1; // avoid zero
291         U.putInt(t, SECONDARY, r);
292         return r;
293     }
294 
295     // Support for other package-private ThreadLocal access
296 
297     /**
298      * Erases ThreadLocals by nulling out Thread maps.
299      */
300     static final void eraseThreadLocals(Thread thread) {
301         U.putReference(thread, THREADLOCALS, null);
302         U.putReference(thread, INHERITABLETHREADLOCALS, null);






303     }
304 
305     static final void setInheritedAccessControlContext(Thread thread,
306                                                        @SuppressWarnings("removal") AccessControlContext acc) {
307         U.putReferenceRelease(thread, INHERITEDACCESSCONTROLCONTEXT, acc);
308     }
309 
310     // Serialization support
311 
312     private static final long serialVersionUID = -5851777807851030925L;
313 
314     /**
315      * @serialField rnd long
316      *              seed for random computations
317      * @serialField initialized boolean
318      *              always true
319      */
320     private static final ObjectStreamField[] serialPersistentFields = {
321         new ObjectStreamField("rnd", long.class),
322         new ObjectStreamField("initialized", boolean.class),

283         Thread t = Thread.currentThread();
284         if ((r = U.getInt(t, SECONDARY)) != 0) {
285             r ^= r << 13;   // xorshift
286             r ^= r >>> 17;
287             r ^= r << 5;
288         }
289         else if ((r = mix32(seeder.getAndAdd(SEEDER_INCREMENT))) == 0)
290             r = 1; // avoid zero
291         U.putInt(t, SECONDARY, r);
292         return r;
293     }
294 
295     // Support for other package-private ThreadLocal access
296 
297     /**
298      * Erases ThreadLocals by nulling out Thread maps.
299      */
300     static final void eraseThreadLocals(Thread thread) {
301         U.putReference(thread, THREADLOCALS, null);
302         U.putReference(thread, INHERITABLETHREADLOCALS, null);
303         // Ideally we should also clear the Thread's ScopedCache, but it is
304         // in the VM-internal JavaThread structure. This method is called so
305         // early in the lifetime of a ForkJoinPool thread that we don't expect
306         // any ScopeLocals to have yet been bound by this thread, so the
307         // ScopedCache should be empty at this point.
308         // U.putReference(thread, INHERITABLESCOPELOCALBINDINGS, null);
309     }
310 
311     static final void setInheritedAccessControlContext(Thread thread,
312                                                        @SuppressWarnings("removal") AccessControlContext acc) {
313         U.putReferenceRelease(thread, INHERITEDACCESSCONTROLCONTEXT, acc);
314     }
315 
316     // Serialization support
317 
318     private static final long serialVersionUID = -5851777807851030925L;
319 
320     /**
321      * @serialField rnd long
322      *              seed for random computations
323      * @serialField initialized boolean
324      *              always true
325      */
326     private static final ObjectStreamField[] serialPersistentFields = {
327         new ObjectStreamField("rnd", long.class),
328         new ObjectStreamField("initialized", boolean.class),
< prev index next >