ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/jsr166/jsr166/src/main/java/util/concurrent/ForkJoinWorkerThread.java
(Generate patch)

Comparing jsr166/src/main/java/util/concurrent/ForkJoinWorkerThread.java (file contents):
Revision 1.82 by jsr166, Sun Dec 6 18:10:00 2020 UTC vs.
Revision 1.83 by dl, Fri Mar 18 16:01:42 2022 UTC

# Line 7 | Line 7
7   package java.util.concurrent;
8  
9   import java.security.AccessController;
10 + import java.security.AccessControlContext;
11   import java.security.PrivilegedAction;
12 + import java.security.ProtectionDomain;
13  
14   /**
15   * A thread managed by a {@link ForkJoinPool}, which executes
# Line 41 | Line 43 | public class ForkJoinWorkerThread extend
43       * Full nonpublic constructor.
44       */
45      ForkJoinWorkerThread(ThreadGroup group, ForkJoinPool pool,
46 <                         boolean useSystemClassLoader, boolean isInnocuous) {
46 >                         boolean useSystemClassLoader) {
47          super(group, null, pool.nextWorkerThreadName(), 0L);
48          UncaughtExceptionHandler handler = (this.pool = pool).ueh;
49 <        this.workQueue = new ForkJoinPool.WorkQueue(this, isInnocuous);
49 >        this.workQueue = new ForkJoinPool.WorkQueue(this, 0);
50          super.setDaemon(true);
51          if (handler != null)
52              super.setUncaughtExceptionHandler(handler);
# Line 60 | Line 62 | public class ForkJoinWorkerThread extend
62       * @param pool the pool this thread works in
63       * @throws NullPointerException if pool is null
64       */
65 <    /* TODO: protected */ ForkJoinWorkerThread(ThreadGroup group, ForkJoinPool pool) {
66 <        this(group, pool, false, false);
65 >    ForkJoinWorkerThread(ThreadGroup group, ForkJoinPool pool) {
66 >        this(group, pool, false);
67      }
68  
69      /**
# Line 71 | Line 73 | public class ForkJoinWorkerThread extend
73       * @throws NullPointerException if pool is null
74       */
75      protected ForkJoinWorkerThread(ForkJoinPool pool) {
76 <        this(null, pool, false, false);
76 >        this(null, pool, false);
77      }
78  
79      /**
# Line 157 | Line 159 | public class ForkJoinWorkerThread extend
159       */
160      static final class InnocuousForkJoinWorkerThread extends ForkJoinWorkerThread {
161          /** The ThreadGroup for all InnocuousForkJoinWorkerThreads */
162 <        private static final ThreadGroup innocuousThreadGroup =
163 <            AccessController.doPrivileged(new PrivilegedAction<>() {
164 <                public ThreadGroup run() {
163 <                    ThreadGroup group = Thread.currentThread().getThreadGroup();
164 <                    for (ThreadGroup p; (p = group.getParent()) != null; )
165 <                        group = p;
166 <                    return new ThreadGroup(
167 <                        group, "InnocuousForkJoinWorkerThreadGroup");
168 <                }});
169 <
162 >        private static final ThreadGroup innocuousThreadGroup;
163 >        @SuppressWarnings("removal")
164 >        private static final AccessControlContext innocuousACC;
165          InnocuousForkJoinWorkerThread(ForkJoinPool pool) {
166 <            super(innocuousThreadGroup, pool, true, true);
166 >            super(innocuousThreadGroup, pool, true);
167 >        }
168 >
169 >        @Override @SuppressWarnings("removal")
170 >        protected void onStart() {
171 >            ForkJoinPool.WorkQueue w = workQueue;
172 >            if (w != null)
173 >                w.setInnocuous();
174 >            Thread t = Thread.currentThread();
175 >            ThreadLocalRandom.setInheritedAccessControlContext(t, innocuousACC);
176 >            ThreadLocalRandom.eraseThreadLocals(t);
177          }
178  
179          @Override // to silently fail
# Line 179 | Line 184 | public class ForkJoinWorkerThread extend
184              if (cl != null && ClassLoader.getSystemClassLoader() != cl)
185                  throw new SecurityException("setContextClassLoader");
186          }
187 +
188 +        @SuppressWarnings("removal")
189 +        static AccessControlContext createACC() {
190 +            return new AccessControlContext(
191 +                new ProtectionDomain[] { new ProtectionDomain(null, null) });
192 +        }
193 +        static ThreadGroup createGroup() {
194 +            ThreadGroup group = Thread.currentThread().getThreadGroup();
195 +            for (ThreadGroup p; (p = group.getParent()) != null; )
196 +                group = p;
197 +            return new ThreadGroup(group, "InnocuousForkJoinWorkerThreadGroup");
198 +        }
199 +        static {
200 +            @SuppressWarnings("removal")
201 +            SecurityManager sm = System.getSecurityManager();
202 +            @SuppressWarnings("removal")
203 +            ThreadGroup g = innocuousThreadGroup =
204 +                (sm == null) ? createGroup() :
205 +                AccessController.doPrivileged(new PrivilegedAction<>() {
206 +                        public ThreadGroup run() {
207 +                            return createGroup(); }});
208 +            @SuppressWarnings("removal")
209 +            AccessControlContext a = innocuousACC =
210 +                (sm == null) ? createACC() :
211 +                AccessController.doPrivileged(new PrivilegedAction<>() {
212 +                        public AccessControlContext run() {
213 +                            return createACC(); }});
214 +        }
215      }
216   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines