jdk/src/java.base/share/classes/java/util/concurrent/ForkJoinWorkerThread.java
changeset 26448 5853628b0e63
parent 25859 3317bb8137f4
child 32988 da3715f8eec3
equal deleted inserted replaced
26367:5da963ed0720 26448:5853628b0e63
    64      * completes. This leads to a visibility race, that is tolerated
    64      * completes. This leads to a visibility race, that is tolerated
    65      * by requiring that the workQueue field is only accessed by the
    65      * by requiring that the workQueue field is only accessed by the
    66      * owning thread.
    66      * owning thread.
    67      *
    67      *
    68      * Support for (non-public) subclass InnocuousForkJoinWorkerThread
    68      * Support for (non-public) subclass InnocuousForkJoinWorkerThread
    69      * requires that we break quite a lot of encapulation (via Unsafe)
    69      * requires that we break quite a lot of encapsulation (via Unsafe)
    70      * both here and in the subclass to access and set Thread fields.
    70      * both here and in the subclass to access and set Thread fields.
    71      */
    71      */
    72 
    72 
    73     final ForkJoinPool pool;                // the pool this thread works in
    73     final ForkJoinPool pool;                // the pool this thread works in
    74     final ForkJoinPool.WorkQueue workQueue; // work-stealing mechanics
    74     final ForkJoinPool.WorkQueue workQueue; // work-stealing mechanics
   116      * per-worker-thread rather than per-task.
   116      * per-worker-thread rather than per-task.
   117      *
   117      *
   118      * @return the index number
   118      * @return the index number
   119      */
   119      */
   120     public int getPoolIndex() {
   120     public int getPoolIndex() {
   121         return workQueue.poolIndex >>> 1; // ignore odd/even tag bit
   121         return workQueue.getPoolIndex();
   122     }
   122     }
   123 
   123 
   124     /**
   124     /**
   125      * Initializes internal state after construction but before
   125      * Initializes internal state after construction but before
   126      * processing any tasks. If you override this method, you must
   126      * processing any tasks. If you override this method, you must
   169             }
   169             }
   170         }
   170         }
   171     }
   171     }
   172 
   172 
   173     /**
   173     /**
   174      * Erases ThreadLocals by nulling out Thread maps
   174      * Erases ThreadLocals by nulling out Thread maps.
   175      */
   175      */
   176     final void eraseThreadLocals() {
   176     final void eraseThreadLocals() {
   177         U.putObject(this, THREADLOCALS, null);
   177         U.putObject(this, THREADLOCALS, null);
   178         U.putObject(this, INHERITABLETHREADLOCALS, null);
   178         U.putObject(this, INHERITABLETHREADLOCALS, null);
   179     }
   179     }
   244             throw new SecurityException("setContextClassLoader");
   244             throw new SecurityException("setContextClassLoader");
   245         }
   245         }
   246 
   246 
   247         /**
   247         /**
   248          * Returns a new group with the system ThreadGroup (the
   248          * Returns a new group with the system ThreadGroup (the
   249          * topmost, parentless group) as parent.  Uses Unsafe to
   249          * topmost, parent-less group) as parent.  Uses Unsafe to
   250          * traverse Thread group and ThreadGroup parent fields.
   250          * traverse Thread.group and ThreadGroup.parent fields.
   251          */
   251          */
   252         private static ThreadGroup createThreadGroup() {
   252         private static ThreadGroup createThreadGroup() {
   253             try {
   253             try {
   254                 sun.misc.Unsafe u = sun.misc.Unsafe.getUnsafe();
   254                 sun.misc.Unsafe u = sun.misc.Unsafe.getUnsafe();
   255                 Class<?> tk = Thread.class;
   255                 Class<?> tk = Thread.class;
   272             throw new Error("Cannot create ThreadGroup");
   272             throw new Error("Cannot create ThreadGroup");
   273         }
   273         }
   274     }
   274     }
   275 
   275 
   276 }
   276 }
   277