author | dl |
Fri, 05 Sep 2014 10:54:28 +0200 | |
changeset 26448 | 5853628b0e63 |
parent 25859 | 3317bb8137f4 |
child 32988 | da3715f8eec3 |
permissions | -rw-r--r-- |
4110 | 1 |
/* |
2 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
|
3 |
* |
|
4 |
* This code is free software; you can redistribute it and/or modify it |
|
5 |
* under the terms of the GNU General Public License version 2 only, as |
|
5506 | 6 |
* published by the Free Software Foundation. Oracle designates this |
4110 | 7 |
* particular file as subject to the "Classpath" exception as provided |
5506 | 8 |
* by Oracle in the LICENSE file that accompanied this code. |
4110 | 9 |
* |
10 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
|
11 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
12 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
13 |
* version 2 for more details (a copy is included in the LICENSE file that |
|
14 |
* accompanied this code). |
|
15 |
* |
|
16 |
* You should have received a copy of the GNU General Public License version |
|
17 |
* 2 along with this work; if not, write to the Free Software Foundation, |
|
18 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
|
19 |
* |
|
5506 | 20 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
21 |
* or visit www.oracle.com if you need additional information or have any |
|
22 |
* questions. |
|
4110 | 23 |
*/ |
24 |
||
25 |
/* |
|
26 |
* This file is available under and governed by the GNU General Public |
|
27 |
* License version 2 only, as published by the Free Software Foundation. |
|
28 |
* However, the following notice accompanied the original version of this |
|
29 |
* file: |
|
30 |
* |
|
31 |
* Written by Doug Lea with assistance from members of JCP JSR-166 |
|
32 |
* Expert Group and released to the public domain, as explained at |
|
9242
ef138d47df58
7034657: Update Creative Commons license URL in legal notices
dl
parents:
8765
diff
changeset
|
33 |
* http://creativecommons.org/publicdomain/zero/1.0/ |
4110 | 34 |
*/ |
35 |
||
36 |
package java.util.concurrent; |
|
37 |
||
38 |
import java.io.Serializable; |
|
39 |
import java.util.Collection; |
|
40 |
import java.util.List; |
|
41 |
import java.util.RandomAccess; |
|
8765
dfc2a131d08a
7023006: Reduce unnecessary thread activity in ForkJoinPool
dl
parents:
7976
diff
changeset
|
42 |
import java.lang.ref.WeakReference; |
dfc2a131d08a
7023006: Reduce unnecessary thread activity in ForkJoinPool
dl
parents:
7976
diff
changeset
|
43 |
import java.lang.ref.ReferenceQueue; |
7976
f273c0d04215
7005424: Resync java.util.concurrent classes with Dougs CVS - Jan 2011
dl
parents:
6674
diff
changeset
|
44 |
import java.util.concurrent.Callable; |
f273c0d04215
7005424: Resync java.util.concurrent classes with Dougs CVS - Jan 2011
dl
parents:
6674
diff
changeset
|
45 |
import java.util.concurrent.CancellationException; |
f273c0d04215
7005424: Resync java.util.concurrent classes with Dougs CVS - Jan 2011
dl
parents:
6674
diff
changeset
|
46 |
import java.util.concurrent.ExecutionException; |
f273c0d04215
7005424: Resync java.util.concurrent classes with Dougs CVS - Jan 2011
dl
parents:
6674
diff
changeset
|
47 |
import java.util.concurrent.Future; |
f273c0d04215
7005424: Resync java.util.concurrent classes with Dougs CVS - Jan 2011
dl
parents:
6674
diff
changeset
|
48 |
import java.util.concurrent.RejectedExecutionException; |
f273c0d04215
7005424: Resync java.util.concurrent classes with Dougs CVS - Jan 2011
dl
parents:
6674
diff
changeset
|
49 |
import java.util.concurrent.RunnableFuture; |
f273c0d04215
7005424: Resync java.util.concurrent classes with Dougs CVS - Jan 2011
dl
parents:
6674
diff
changeset
|
50 |
import java.util.concurrent.TimeUnit; |
f273c0d04215
7005424: Resync java.util.concurrent classes with Dougs CVS - Jan 2011
dl
parents:
6674
diff
changeset
|
51 |
import java.util.concurrent.TimeoutException; |
8765
dfc2a131d08a
7023006: Reduce unnecessary thread activity in ForkJoinPool
dl
parents:
7976
diff
changeset
|
52 |
import java.util.concurrent.locks.ReentrantLock; |
dfc2a131d08a
7023006: Reduce unnecessary thread activity in ForkJoinPool
dl
parents:
7976
diff
changeset
|
53 |
import java.lang.reflect.Constructor; |
4110 | 54 |
|
55 |
/** |
|
56 |
* Abstract base class for tasks that run within a {@link ForkJoinPool}. |
|
57 |
* A {@code ForkJoinTask} is a thread-like entity that is much |
|
58 |
* lighter weight than a normal thread. Huge numbers of tasks and |
|
59 |
* subtasks may be hosted by a small number of actual threads in a |
|
60 |
* ForkJoinPool, at the price of some usage limitations. |
|
61 |
* |
|
14914
69bfd88e3ea1
8002356: Add ForkJoin common pool and CountedCompleter
dl
parents:
11279
diff
changeset
|
62 |
* <p>A "main" {@code ForkJoinTask} begins execution when it is |
69bfd88e3ea1
8002356: Add ForkJoin common pool and CountedCompleter
dl
parents:
11279
diff
changeset
|
63 |
* explicitly submitted to a {@link ForkJoinPool}, or, if not already |
69bfd88e3ea1
8002356: Add ForkJoin common pool and CountedCompleter
dl
parents:
11279
diff
changeset
|
64 |
* engaged in a ForkJoin computation, commenced in the {@link |
69bfd88e3ea1
8002356: Add ForkJoin common pool and CountedCompleter
dl
parents:
11279
diff
changeset
|
65 |
* ForkJoinPool#commonPool()} via {@link #fork}, {@link #invoke}, or |
69bfd88e3ea1
8002356: Add ForkJoin common pool and CountedCompleter
dl
parents:
11279
diff
changeset
|
66 |
* related methods. Once started, it will usually in turn start other |
69bfd88e3ea1
8002356: Add ForkJoin common pool and CountedCompleter
dl
parents:
11279
diff
changeset
|
67 |
* subtasks. As indicated by the name of this class, many programs |
69bfd88e3ea1
8002356: Add ForkJoin common pool and CountedCompleter
dl
parents:
11279
diff
changeset
|
68 |
* using {@code ForkJoinTask} employ only methods {@link #fork} and |
69bfd88e3ea1
8002356: Add ForkJoin common pool and CountedCompleter
dl
parents:
11279
diff
changeset
|
69 |
* {@link #join}, or derivatives such as {@link |
6674 | 70 |
* #invokeAll(ForkJoinTask...) invokeAll}. However, this class also |
71 |
* provides a number of other methods that can come into play in |
|
14914
69bfd88e3ea1
8002356: Add ForkJoin common pool and CountedCompleter
dl
parents:
11279
diff
changeset
|
72 |
* advanced usages, as well as extension mechanics that allow support |
69bfd88e3ea1
8002356: Add ForkJoin common pool and CountedCompleter
dl
parents:
11279
diff
changeset
|
73 |
* of new forms of fork/join processing. |
4110 | 74 |
* |
75 |
* <p>A {@code ForkJoinTask} is a lightweight form of {@link Future}. |
|
76 |
* The efficiency of {@code ForkJoinTask}s stems from a set of |
|
77 |
* restrictions (that are only partially statically enforceable) |
|
14914
69bfd88e3ea1
8002356: Add ForkJoin common pool and CountedCompleter
dl
parents:
11279
diff
changeset
|
78 |
* reflecting their main use as computational tasks calculating pure |
69bfd88e3ea1
8002356: Add ForkJoin common pool and CountedCompleter
dl
parents:
11279
diff
changeset
|
79 |
* functions or operating on purely isolated objects. The primary |
69bfd88e3ea1
8002356: Add ForkJoin common pool and CountedCompleter
dl
parents:
11279
diff
changeset
|
80 |
* coordination mechanisms are {@link #fork}, that arranges |
4110 | 81 |
* asynchronous execution, and {@link #join}, that doesn't proceed |
82 |
* until the task's result has been computed. Computations should |
|
14914
69bfd88e3ea1
8002356: Add ForkJoin common pool and CountedCompleter
dl
parents:
11279
diff
changeset
|
83 |
* ideally avoid {@code synchronized} methods or blocks, and should |
69bfd88e3ea1
8002356: Add ForkJoin common pool and CountedCompleter
dl
parents:
11279
diff
changeset
|
84 |
* minimize other blocking synchronization apart from joining other |
69bfd88e3ea1
8002356: Add ForkJoin common pool and CountedCompleter
dl
parents:
11279
diff
changeset
|
85 |
* tasks or using synchronizers such as Phasers that are advertised to |
69bfd88e3ea1
8002356: Add ForkJoin common pool and CountedCompleter
dl
parents:
11279
diff
changeset
|
86 |
* cooperate with fork/join scheduling. Subdividable tasks should also |
69bfd88e3ea1
8002356: Add ForkJoin common pool and CountedCompleter
dl
parents:
11279
diff
changeset
|
87 |
* not perform blocking I/O, and should ideally access variables that |
69bfd88e3ea1
8002356: Add ForkJoin common pool and CountedCompleter
dl
parents:
11279
diff
changeset
|
88 |
* are completely independent of those accessed by other running |
69bfd88e3ea1
8002356: Add ForkJoin common pool and CountedCompleter
dl
parents:
11279
diff
changeset
|
89 |
* tasks. These guidelines are loosely enforced by not permitting |
69bfd88e3ea1
8002356: Add ForkJoin common pool and CountedCompleter
dl
parents:
11279
diff
changeset
|
90 |
* checked exceptions such as {@code IOExceptions} to be |
69bfd88e3ea1
8002356: Add ForkJoin common pool and CountedCompleter
dl
parents:
11279
diff
changeset
|
91 |
* thrown. However, computations may still encounter unchecked |
69bfd88e3ea1
8002356: Add ForkJoin common pool and CountedCompleter
dl
parents:
11279
diff
changeset
|
92 |
* exceptions, that are rethrown to callers attempting to join |
69bfd88e3ea1
8002356: Add ForkJoin common pool and CountedCompleter
dl
parents:
11279
diff
changeset
|
93 |
* them. These exceptions may additionally include {@link |
69bfd88e3ea1
8002356: Add ForkJoin common pool and CountedCompleter
dl
parents:
11279
diff
changeset
|
94 |
* RejectedExecutionException} stemming from internal resource |
69bfd88e3ea1
8002356: Add ForkJoin common pool and CountedCompleter
dl
parents:
11279
diff
changeset
|
95 |
* exhaustion, such as failure to allocate internal task |
69bfd88e3ea1
8002356: Add ForkJoin common pool and CountedCompleter
dl
parents:
11279
diff
changeset
|
96 |
* queues. Rethrown exceptions behave in the same way as regular |
69bfd88e3ea1
8002356: Add ForkJoin common pool and CountedCompleter
dl
parents:
11279
diff
changeset
|
97 |
* exceptions, but, when possible, contain stack traces (as displayed |
69bfd88e3ea1
8002356: Add ForkJoin common pool and CountedCompleter
dl
parents:
11279
diff
changeset
|
98 |
* for example using {@code ex.printStackTrace()}) of both the thread |
69bfd88e3ea1
8002356: Add ForkJoin common pool and CountedCompleter
dl
parents:
11279
diff
changeset
|
99 |
* that initiated the computation as well as the thread actually |
69bfd88e3ea1
8002356: Add ForkJoin common pool and CountedCompleter
dl
parents:
11279
diff
changeset
|
100 |
* encountering the exception; minimally only the latter. |
69bfd88e3ea1
8002356: Add ForkJoin common pool and CountedCompleter
dl
parents:
11279
diff
changeset
|
101 |
* |
69bfd88e3ea1
8002356: Add ForkJoin common pool and CountedCompleter
dl
parents:
11279
diff
changeset
|
102 |
* <p>It is possible to define and use ForkJoinTasks that may block, |
69bfd88e3ea1
8002356: Add ForkJoin common pool and CountedCompleter
dl
parents:
11279
diff
changeset
|
103 |
* but doing do requires three further considerations: (1) Completion |
69bfd88e3ea1
8002356: Add ForkJoin common pool and CountedCompleter
dl
parents:
11279
diff
changeset
|
104 |
* of few if any <em>other</em> tasks should be dependent on a task |
69bfd88e3ea1
8002356: Add ForkJoin common pool and CountedCompleter
dl
parents:
11279
diff
changeset
|
105 |
* that blocks on external synchronization or I/O. Event-style async |
69bfd88e3ea1
8002356: Add ForkJoin common pool and CountedCompleter
dl
parents:
11279
diff
changeset
|
106 |
* tasks that are never joined (for example, those subclassing {@link |
69bfd88e3ea1
8002356: Add ForkJoin common pool and CountedCompleter
dl
parents:
11279
diff
changeset
|
107 |
* CountedCompleter}) often fall into this category. (2) To minimize |
69bfd88e3ea1
8002356: Add ForkJoin common pool and CountedCompleter
dl
parents:
11279
diff
changeset
|
108 |
* resource impact, tasks should be small; ideally performing only the |
69bfd88e3ea1
8002356: Add ForkJoin common pool and CountedCompleter
dl
parents:
11279
diff
changeset
|
109 |
* (possibly) blocking action. (3) Unless the {@link |
69bfd88e3ea1
8002356: Add ForkJoin common pool and CountedCompleter
dl
parents:
11279
diff
changeset
|
110 |
* ForkJoinPool.ManagedBlocker} API is used, or the number of possibly |
69bfd88e3ea1
8002356: Add ForkJoin common pool and CountedCompleter
dl
parents:
11279
diff
changeset
|
111 |
* blocked tasks is known to be less than the pool's {@link |
69bfd88e3ea1
8002356: Add ForkJoin common pool and CountedCompleter
dl
parents:
11279
diff
changeset
|
112 |
* ForkJoinPool#getParallelism} level, the pool cannot guarantee that |
69bfd88e3ea1
8002356: Add ForkJoin common pool and CountedCompleter
dl
parents:
11279
diff
changeset
|
113 |
* enough threads will be available to ensure progress or good |
69bfd88e3ea1
8002356: Add ForkJoin common pool and CountedCompleter
dl
parents:
11279
diff
changeset
|
114 |
* performance. |
4110 | 115 |
* |
116 |
* <p>The primary method for awaiting completion and extracting |
|
117 |
* results of a task is {@link #join}, but there are several variants: |
|
118 |
* The {@link Future#get} methods support interruptible and/or timed |
|
119 |
* waits for completion and report results using {@code Future} |
|
6543 | 120 |
* conventions. Method {@link #invoke} is semantically |
4110 | 121 |
* equivalent to {@code fork(); join()} but always attempts to begin |
122 |
* execution in the current thread. The "<em>quiet</em>" forms of |
|
123 |
* these methods do not extract results or report exceptions. These |
|
124 |
* may be useful when a set of tasks are being executed, and you need |
|
125 |
* to delay processing of results or exceptions until all complete. |
|
126 |
* Method {@code invokeAll} (available in multiple versions) |
|
127 |
* performs the most common form of parallel invocation: forking a set |
|
128 |
* of tasks and joining them all. |
|
129 |
* |
|
14914
69bfd88e3ea1
8002356: Add ForkJoin common pool and CountedCompleter
dl
parents:
11279
diff
changeset
|
130 |
* <p>In the most typical usages, a fork-join pair act like a call |
69bfd88e3ea1
8002356: Add ForkJoin common pool and CountedCompleter
dl
parents:
11279
diff
changeset
|
131 |
* (fork) and return (join) from a parallel recursive function. As is |
69bfd88e3ea1
8002356: Add ForkJoin common pool and CountedCompleter
dl
parents:
11279
diff
changeset
|
132 |
* the case with other forms of recursive calls, returns (joins) |
69bfd88e3ea1
8002356: Add ForkJoin common pool and CountedCompleter
dl
parents:
11279
diff
changeset
|
133 |
* should be performed innermost-first. For example, {@code a.fork(); |
69bfd88e3ea1
8002356: Add ForkJoin common pool and CountedCompleter
dl
parents:
11279
diff
changeset
|
134 |
* b.fork(); b.join(); a.join();} is likely to be substantially more |
69bfd88e3ea1
8002356: Add ForkJoin common pool and CountedCompleter
dl
parents:
11279
diff
changeset
|
135 |
* efficient than joining {@code a} before {@code b}. |
69bfd88e3ea1
8002356: Add ForkJoin common pool and CountedCompleter
dl
parents:
11279
diff
changeset
|
136 |
* |
4110 | 137 |
* <p>The execution status of tasks may be queried at several levels |
138 |
* of detail: {@link #isDone} is true if a task completed in any way |
|
139 |
* (including the case where a task was cancelled without executing); |
|
140 |
* {@link #isCompletedNormally} is true if a task completed without |
|
141 |
* cancellation or encountering an exception; {@link #isCancelled} is |
|
142 |
* true if the task was cancelled (in which case {@link #getException} |
|
143 |
* returns a {@link java.util.concurrent.CancellationException}); and |
|
144 |
* {@link #isCompletedAbnormally} is true if a task was either |
|
145 |
* cancelled or encountered an exception, in which case {@link |
|
146 |
* #getException} will return either the encountered exception or |
|
147 |
* {@link java.util.concurrent.CancellationException}. |
|
148 |
* |
|
149 |
* <p>The ForkJoinTask class is not usually directly subclassed. |
|
150 |
* Instead, you subclass one of the abstract classes that support a |
|
151 |
* particular style of fork/join processing, typically {@link |
|
14914
69bfd88e3ea1
8002356: Add ForkJoin common pool and CountedCompleter
dl
parents:
11279
diff
changeset
|
152 |
* RecursiveAction} for most computations that do not return results, |
69bfd88e3ea1
8002356: Add ForkJoin common pool and CountedCompleter
dl
parents:
11279
diff
changeset
|
153 |
* {@link RecursiveTask} for those that do, and {@link |
69bfd88e3ea1
8002356: Add ForkJoin common pool and CountedCompleter
dl
parents:
11279
diff
changeset
|
154 |
* CountedCompleter} for those in which completed actions trigger |
69bfd88e3ea1
8002356: Add ForkJoin common pool and CountedCompleter
dl
parents:
11279
diff
changeset
|
155 |
* other actions. Normally, a concrete ForkJoinTask subclass declares |
69bfd88e3ea1
8002356: Add ForkJoin common pool and CountedCompleter
dl
parents:
11279
diff
changeset
|
156 |
* fields comprising its parameters, established in a constructor, and |
69bfd88e3ea1
8002356: Add ForkJoin common pool and CountedCompleter
dl
parents:
11279
diff
changeset
|
157 |
* then defines a {@code compute} method that somehow uses the control |
69bfd88e3ea1
8002356: Add ForkJoin common pool and CountedCompleter
dl
parents:
11279
diff
changeset
|
158 |
* methods supplied by this base class. |
4110 | 159 |
* |
7976
f273c0d04215
7005424: Resync java.util.concurrent classes with Dougs CVS - Jan 2011
dl
parents:
6674
diff
changeset
|
160 |
* <p>Method {@link #join} and its variants are appropriate for use |
f273c0d04215
7005424: Resync java.util.concurrent classes with Dougs CVS - Jan 2011
dl
parents:
6674
diff
changeset
|
161 |
* only when completion dependencies are acyclic; that is, the |
f273c0d04215
7005424: Resync java.util.concurrent classes with Dougs CVS - Jan 2011
dl
parents:
6674
diff
changeset
|
162 |
* parallel computation can be described as a directed acyclic graph |
f273c0d04215
7005424: Resync java.util.concurrent classes with Dougs CVS - Jan 2011
dl
parents:
6674
diff
changeset
|
163 |
* (DAG). Otherwise, executions may encounter a form of deadlock as |
f273c0d04215
7005424: Resync java.util.concurrent classes with Dougs CVS - Jan 2011
dl
parents:
6674
diff
changeset
|
164 |
* tasks cyclically wait for each other. However, this framework |
f273c0d04215
7005424: Resync java.util.concurrent classes with Dougs CVS - Jan 2011
dl
parents:
6674
diff
changeset
|
165 |
* supports other methods and techniques (for example the use of |
f273c0d04215
7005424: Resync java.util.concurrent classes with Dougs CVS - Jan 2011
dl
parents:
6674
diff
changeset
|
166 |
* {@link Phaser}, {@link #helpQuiesce}, and {@link #complete}) that |
f273c0d04215
7005424: Resync java.util.concurrent classes with Dougs CVS - Jan 2011
dl
parents:
6674
diff
changeset
|
167 |
* may be of use in constructing custom subclasses for problems that |
18790 | 168 |
* are not statically structured as DAGs. To support such usages, a |
14914
69bfd88e3ea1
8002356: Add ForkJoin common pool and CountedCompleter
dl
parents:
11279
diff
changeset
|
169 |
* ForkJoinTask may be atomically <em>tagged</em> with a {@code short} |
69bfd88e3ea1
8002356: Add ForkJoin common pool and CountedCompleter
dl
parents:
11279
diff
changeset
|
170 |
* value using {@link #setForkJoinTaskTag} or {@link |
69bfd88e3ea1
8002356: Add ForkJoin common pool and CountedCompleter
dl
parents:
11279
diff
changeset
|
171 |
* #compareAndSetForkJoinTaskTag} and checked using {@link |
69bfd88e3ea1
8002356: Add ForkJoin common pool and CountedCompleter
dl
parents:
11279
diff
changeset
|
172 |
* #getForkJoinTaskTag}. The ForkJoinTask implementation does not use |
69bfd88e3ea1
8002356: Add ForkJoin common pool and CountedCompleter
dl
parents:
11279
diff
changeset
|
173 |
* these {@code protected} methods or tags for any purpose, but they |
69bfd88e3ea1
8002356: Add ForkJoin common pool and CountedCompleter
dl
parents:
11279
diff
changeset
|
174 |
* may be of use in the construction of specialized subclasses. For |
69bfd88e3ea1
8002356: Add ForkJoin common pool and CountedCompleter
dl
parents:
11279
diff
changeset
|
175 |
* example, parallel graph traversals can use the supplied methods to |
69bfd88e3ea1
8002356: Add ForkJoin common pool and CountedCompleter
dl
parents:
11279
diff
changeset
|
176 |
* avoid revisiting nodes/tasks that have already been processed. |
69bfd88e3ea1
8002356: Add ForkJoin common pool and CountedCompleter
dl
parents:
11279
diff
changeset
|
177 |
* (Method names for tagging are bulky in part to encourage definition |
69bfd88e3ea1
8002356: Add ForkJoin common pool and CountedCompleter
dl
parents:
11279
diff
changeset
|
178 |
* of methods that reflect their usage patterns.) |
7976
f273c0d04215
7005424: Resync java.util.concurrent classes with Dougs CVS - Jan 2011
dl
parents:
6674
diff
changeset
|
179 |
* |
4110 | 180 |
* <p>Most base support methods are {@code final}, to prevent |
181 |
* overriding of implementations that are intrinsically tied to the |
|
182 |
* underlying lightweight task scheduling framework. Developers |
|
183 |
* creating new basic styles of fork/join processing should minimally |
|
184 |
* implement {@code protected} methods {@link #exec}, {@link |
|
185 |
* #setRawResult}, and {@link #getRawResult}, while also introducing |
|
186 |
* an abstract computational method that can be implemented in its |
|
187 |
* subclasses, possibly relying on other {@code protected} methods |
|
188 |
* provided by this class. |
|
189 |
* |
|
190 |
* <p>ForkJoinTasks should perform relatively small amounts of |
|
191 |
* computation. Large tasks should be split into smaller subtasks, |
|
192 |
* usually via recursive decomposition. As a very rough rule of thumb, |
|
193 |
* a task should perform more than 100 and less than 10000 basic |
|
7976
f273c0d04215
7005424: Resync java.util.concurrent classes with Dougs CVS - Jan 2011
dl
parents:
6674
diff
changeset
|
194 |
* computational steps, and should avoid indefinite looping. If tasks |
f273c0d04215
7005424: Resync java.util.concurrent classes with Dougs CVS - Jan 2011
dl
parents:
6674
diff
changeset
|
195 |
* are too big, then parallelism cannot improve throughput. If too |
f273c0d04215
7005424: Resync java.util.concurrent classes with Dougs CVS - Jan 2011
dl
parents:
6674
diff
changeset
|
196 |
* small, then memory and internal task maintenance overhead may |
f273c0d04215
7005424: Resync java.util.concurrent classes with Dougs CVS - Jan 2011
dl
parents:
6674
diff
changeset
|
197 |
* overwhelm processing. |
4110 | 198 |
* |
199 |
* <p>This class provides {@code adapt} methods for {@link Runnable} |
|
200 |
* and {@link Callable}, that may be of use when mixing execution of |
|
6543 | 201 |
* {@code ForkJoinTasks} with other kinds of tasks. When all tasks are |
202 |
* of this form, consider using a pool constructed in <em>asyncMode</em>. |
|
4110 | 203 |
* |
204 |
* <p>ForkJoinTasks are {@code Serializable}, which enables them to be |
|
205 |
* used in extensions such as remote execution frameworks. It is |
|
206 |
* sensible to serialize tasks only before or after, but not during, |
|
207 |
* execution. Serialization is not relied on during execution itself. |
|
208 |
* |
|
209 |
* @since 1.7 |
|
210 |
* @author Doug Lea |
|
211 |
*/ |
|
212 |
public abstract class ForkJoinTask<V> implements Future<V>, Serializable { |
|
213 |
||
6543 | 214 |
/* |
215 |
* See the internal documentation of class ForkJoinPool for a |
|
216 |
* general implementation overview. ForkJoinTasks are mainly |
|
217 |
* responsible for maintaining their "status" field amidst relays |
|
14914
69bfd88e3ea1
8002356: Add ForkJoin common pool and CountedCompleter
dl
parents:
11279
diff
changeset
|
218 |
* to methods in ForkJoinWorkerThread and ForkJoinPool. |
69bfd88e3ea1
8002356: Add ForkJoin common pool and CountedCompleter
dl
parents:
11279
diff
changeset
|
219 |
* |
69bfd88e3ea1
8002356: Add ForkJoin common pool and CountedCompleter
dl
parents:
11279
diff
changeset
|
220 |
* The methods of this class are more-or-less layered into |
69bfd88e3ea1
8002356: Add ForkJoin common pool and CountedCompleter
dl
parents:
11279
diff
changeset
|
221 |
* (1) basic status maintenance |
69bfd88e3ea1
8002356: Add ForkJoin common pool and CountedCompleter
dl
parents:
11279
diff
changeset
|
222 |
* (2) execution and awaiting completion |
69bfd88e3ea1
8002356: Add ForkJoin common pool and CountedCompleter
dl
parents:
11279
diff
changeset
|
223 |
* (3) user-level methods that additionally report results. |
69bfd88e3ea1
8002356: Add ForkJoin common pool and CountedCompleter
dl
parents:
11279
diff
changeset
|
224 |
* This is sometimes hard to see because this file orders exported |
69bfd88e3ea1
8002356: Add ForkJoin common pool and CountedCompleter
dl
parents:
11279
diff
changeset
|
225 |
* methods in a way that flows well in javadocs. |
4110 | 226 |
*/ |
6543 | 227 |
|
228 |
/* |
|
229 |
* The status field holds run control status bits packed into a |
|
230 |
* single int to minimize footprint and to ensure atomicity (via |
|
231 |
* CAS). Status is initially zero, and takes on nonnegative |
|
14914
69bfd88e3ea1
8002356: Add ForkJoin common pool and CountedCompleter
dl
parents:
11279
diff
changeset
|
232 |
* values until completed, upon which status (anded with |
69bfd88e3ea1
8002356: Add ForkJoin common pool and CountedCompleter
dl
parents:
11279
diff
changeset
|
233 |
* DONE_MASK) holds value NORMAL, CANCELLED, or EXCEPTIONAL. Tasks |
69bfd88e3ea1
8002356: Add ForkJoin common pool and CountedCompleter
dl
parents:
11279
diff
changeset
|
234 |
* undergoing blocking waits by other threads have the SIGNAL bit |
69bfd88e3ea1
8002356: Add ForkJoin common pool and CountedCompleter
dl
parents:
11279
diff
changeset
|
235 |
* set. Completion of a stolen task with SIGNAL set awakens any |
69bfd88e3ea1
8002356: Add ForkJoin common pool and CountedCompleter
dl
parents:
11279
diff
changeset
|
236 |
* waiters via notifyAll. Even though suboptimal for some |
69bfd88e3ea1
8002356: Add ForkJoin common pool and CountedCompleter
dl
parents:
11279
diff
changeset
|
237 |
* purposes, we use basic builtin wait/notify to take advantage of |
69bfd88e3ea1
8002356: Add ForkJoin common pool and CountedCompleter
dl
parents:
11279
diff
changeset
|
238 |
* "monitor inflation" in JVMs that we would otherwise need to |
69bfd88e3ea1
8002356: Add ForkJoin common pool and CountedCompleter
dl
parents:
11279
diff
changeset
|
239 |
* emulate to avoid adding further per-task bookkeeping overhead. |
69bfd88e3ea1
8002356: Add ForkJoin common pool and CountedCompleter
dl
parents:
11279
diff
changeset
|
240 |
* We want these monitors to be "fat", i.e., not use biasing or |
69bfd88e3ea1
8002356: Add ForkJoin common pool and CountedCompleter
dl
parents:
11279
diff
changeset
|
241 |
* thin-lock techniques, so use some odd coding idioms that tend |
69bfd88e3ea1
8002356: Add ForkJoin common pool and CountedCompleter
dl
parents:
11279
diff
changeset
|
242 |
* to avoid them, mainly by arranging that every synchronized |
69bfd88e3ea1
8002356: Add ForkJoin common pool and CountedCompleter
dl
parents:
11279
diff
changeset
|
243 |
* block performs a wait, notifyAll or both. |
69bfd88e3ea1
8002356: Add ForkJoin common pool and CountedCompleter
dl
parents:
11279
diff
changeset
|
244 |
* |
69bfd88e3ea1
8002356: Add ForkJoin common pool and CountedCompleter
dl
parents:
11279
diff
changeset
|
245 |
* These control bits occupy only (some of) the upper half (16 |
69bfd88e3ea1
8002356: Add ForkJoin common pool and CountedCompleter
dl
parents:
11279
diff
changeset
|
246 |
* bits) of status field. The lower bits are used for user-defined |
69bfd88e3ea1
8002356: Add ForkJoin common pool and CountedCompleter
dl
parents:
11279
diff
changeset
|
247 |
* tags. |
6543 | 248 |
*/ |
249 |
||
250 |
/** The run status of this task */ |
|
4110 | 251 |
volatile int status; // accessed directly by pool and workers |
14914
69bfd88e3ea1
8002356: Add ForkJoin common pool and CountedCompleter
dl
parents:
11279
diff
changeset
|
252 |
static final int DONE_MASK = 0xf0000000; // mask out non-completion bits |
69bfd88e3ea1
8002356: Add ForkJoin common pool and CountedCompleter
dl
parents:
11279
diff
changeset
|
253 |
static final int NORMAL = 0xf0000000; // must be negative |
69bfd88e3ea1
8002356: Add ForkJoin common pool and CountedCompleter
dl
parents:
11279
diff
changeset
|
254 |
static final int CANCELLED = 0xc0000000; // must be < NORMAL |
69bfd88e3ea1
8002356: Add ForkJoin common pool and CountedCompleter
dl
parents:
11279
diff
changeset
|
255 |
static final int EXCEPTIONAL = 0x80000000; // must be < CANCELLED |
69bfd88e3ea1
8002356: Add ForkJoin common pool and CountedCompleter
dl
parents:
11279
diff
changeset
|
256 |
static final int SIGNAL = 0x00010000; // must be >= 1 << 16 |
69bfd88e3ea1
8002356: Add ForkJoin common pool and CountedCompleter
dl
parents:
11279
diff
changeset
|
257 |
static final int SMASK = 0x0000ffff; // short bits for tags |
4110 | 258 |
|
259 |
/** |
|
14914
69bfd88e3ea1
8002356: Add ForkJoin common pool and CountedCompleter
dl
parents:
11279
diff
changeset
|
260 |
* Marks completion and wakes up threads waiting to join this |
69bfd88e3ea1
8002356: Add ForkJoin common pool and CountedCompleter
dl
parents:
11279
diff
changeset
|
261 |
* task. |
4110 | 262 |
* |
263 |
* @param completion one of NORMAL, CANCELLED, EXCEPTIONAL |
|
8765
dfc2a131d08a
7023006: Reduce unnecessary thread activity in ForkJoinPool
dl
parents:
7976
diff
changeset
|
264 |
* @return completion status on exit |
4110 | 265 |
*/ |
8765
dfc2a131d08a
7023006: Reduce unnecessary thread activity in ForkJoinPool
dl
parents:
7976
diff
changeset
|
266 |
private int setCompletion(int completion) { |
dfc2a131d08a
7023006: Reduce unnecessary thread activity in ForkJoinPool
dl
parents:
7976
diff
changeset
|
267 |
for (int s;;) { |
dfc2a131d08a
7023006: Reduce unnecessary thread activity in ForkJoinPool
dl
parents:
7976
diff
changeset
|
268 |
if ((s = status) < 0) |
dfc2a131d08a
7023006: Reduce unnecessary thread activity in ForkJoinPool
dl
parents:
7976
diff
changeset
|
269 |
return s; |
14914
69bfd88e3ea1
8002356: Add ForkJoin common pool and CountedCompleter
dl
parents:
11279
diff
changeset
|
270 |
if (U.compareAndSwapInt(this, STATUS, s, s | completion)) { |
69bfd88e3ea1
8002356: Add ForkJoin common pool and CountedCompleter
dl
parents:
11279
diff
changeset
|
271 |
if ((s >>> 16) != 0) |
6543 | 272 |
synchronized (this) { notifyAll(); } |
8765
dfc2a131d08a
7023006: Reduce unnecessary thread activity in ForkJoinPool
dl
parents:
7976
diff
changeset
|
273 |
return completion; |
6543 | 274 |
} |
4110 | 275 |
} |
276 |
} |
|
277 |
||
278 |
/** |
|
14914
69bfd88e3ea1
8002356: Add ForkJoin common pool and CountedCompleter
dl
parents:
11279
diff
changeset
|
279 |
* Primary execution method for stolen tasks. Unless done, calls |
69bfd88e3ea1
8002356: Add ForkJoin common pool and CountedCompleter
dl
parents:
11279
diff
changeset
|
280 |
* exec and records status if completed, but doesn't wait for |
69bfd88e3ea1
8002356: Add ForkJoin common pool and CountedCompleter
dl
parents:
11279
diff
changeset
|
281 |
* completion otherwise. |
6543 | 282 |
* |
14914
69bfd88e3ea1
8002356: Add ForkJoin common pool and CountedCompleter
dl
parents:
11279
diff
changeset
|
283 |
* @return status on exit from this method |
4110 | 284 |
*/ |
14914
69bfd88e3ea1
8002356: Add ForkJoin common pool and CountedCompleter
dl
parents:
11279
diff
changeset
|
285 |
final int doExec() { |
69bfd88e3ea1
8002356: Add ForkJoin common pool and CountedCompleter
dl
parents:
11279
diff
changeset
|
286 |
int s; boolean completed; |
69bfd88e3ea1
8002356: Add ForkJoin common pool and CountedCompleter
dl
parents:
11279
diff
changeset
|
287 |
if ((s = status) >= 0) { |
69bfd88e3ea1
8002356: Add ForkJoin common pool and CountedCompleter
dl
parents:
11279
diff
changeset
|
288 |
try { |
69bfd88e3ea1
8002356: Add ForkJoin common pool and CountedCompleter
dl
parents:
11279
diff
changeset
|
289 |
completed = exec(); |
69bfd88e3ea1
8002356: Add ForkJoin common pool and CountedCompleter
dl
parents:
11279
diff
changeset
|
290 |
} catch (Throwable rex) { |
69bfd88e3ea1
8002356: Add ForkJoin common pool and CountedCompleter
dl
parents:
11279
diff
changeset
|
291 |
return setExceptionalCompletion(rex); |
4110 | 292 |
} |
14914
69bfd88e3ea1
8002356: Add ForkJoin common pool and CountedCompleter
dl
parents:
11279
diff
changeset
|
293 |
if (completed) |
69bfd88e3ea1
8002356: Add ForkJoin common pool and CountedCompleter
dl
parents:
11279
diff
changeset
|
294 |
s = setCompletion(NORMAL); |
4110 | 295 |
} |
14914
69bfd88e3ea1
8002356: Add ForkJoin common pool and CountedCompleter
dl
parents:
11279
diff
changeset
|
296 |
return s; |
69bfd88e3ea1
8002356: Add ForkJoin common pool and CountedCompleter
dl
parents:
11279
diff
changeset
|
297 |
} |
69bfd88e3ea1
8002356: Add ForkJoin common pool and CountedCompleter
dl
parents:
11279
diff
changeset
|
298 |
|
69bfd88e3ea1
8002356: Add ForkJoin common pool and CountedCompleter
dl
parents:
11279
diff
changeset
|
299 |
/** |
26448 | 300 |
* If not done, sets SIGNAL status and performs Object.wait(timeout). |
301 |
* This task may or may not be done on exit. Ignores interrupts. |
|
14914
69bfd88e3ea1
8002356: Add ForkJoin common pool and CountedCompleter
dl
parents:
11279
diff
changeset
|
302 |
* |
26448 | 303 |
* @param timeout using Object.wait conventions. |
14914
69bfd88e3ea1
8002356: Add ForkJoin common pool and CountedCompleter
dl
parents:
11279
diff
changeset
|
304 |
*/ |
26448 | 305 |
final void internalWait(long timeout) { |
306 |
int s; |
|
307 |
if ((s = status) >= 0 && // force completer to issue notify |
|
308 |
U.compareAndSwapInt(this, STATUS, s, s | SIGNAL)) { |
|
309 |
synchronized (this) { |
|
310 |
if (status >= 0) |
|
311 |
try { wait(timeout); } catch (InterruptedException ie) { } |
|
312 |
else |
|
313 |
notifyAll(); |
|
314 |
} |
|
315 |
} |
|
4110 | 316 |
} |
317 |
||
318 |
/** |
|
6543 | 319 |
* Blocks a non-worker-thread until completion. |
8765
dfc2a131d08a
7023006: Reduce unnecessary thread activity in ForkJoinPool
dl
parents:
7976
diff
changeset
|
320 |
* @return status upon completion |
4110 | 321 |
*/ |
8765
dfc2a131d08a
7023006: Reduce unnecessary thread activity in ForkJoinPool
dl
parents:
7976
diff
changeset
|
322 |
private int externalAwaitDone() { |
26448 | 323 |
int s = ((this instanceof CountedCompleter) ? // try helping |
324 |
ForkJoinPool.common.externalHelpComplete( |
|
325 |
(CountedCompleter<?>)this, 0) : |
|
326 |
ForkJoinPool.common.tryExternalUnpush(this) ? doExec() : 0); |
|
327 |
if (s >= 0 && (s = status) >= 0) { |
|
328 |
boolean interrupted = false; |
|
329 |
do { |
|
330 |
if (U.compareAndSwapInt(this, STATUS, s, s | SIGNAL)) { |
|
331 |
synchronized (this) { |
|
332 |
if (status >= 0) { |
|
333 |
try { |
|
334 |
wait(0L); |
|
335 |
} catch (InterruptedException ie) { |
|
336 |
interrupted = true; |
|
18790 | 337 |
} |
6543 | 338 |
} |
26448 | 339 |
else |
340 |
notifyAll(); |
|
6543 | 341 |
} |
26448 | 342 |
} |
343 |
} while ((s = status) >= 0); |
|
344 |
if (interrupted) |
|
345 |
Thread.currentThread().interrupt(); |
|
7976
f273c0d04215
7005424: Resync java.util.concurrent classes with Dougs CVS - Jan 2011
dl
parents:
6674
diff
changeset
|
346 |
} |
8765
dfc2a131d08a
7023006: Reduce unnecessary thread activity in ForkJoinPool
dl
parents:
7976
diff
changeset
|
347 |
return s; |
7976
f273c0d04215
7005424: Resync java.util.concurrent classes with Dougs CVS - Jan 2011
dl
parents:
6674
diff
changeset
|
348 |
} |
f273c0d04215
7005424: Resync java.util.concurrent classes with Dougs CVS - Jan 2011
dl
parents:
6674
diff
changeset
|
349 |
|
f273c0d04215
7005424: Resync java.util.concurrent classes with Dougs CVS - Jan 2011
dl
parents:
6674
diff
changeset
|
350 |
/** |
14914
69bfd88e3ea1
8002356: Add ForkJoin common pool and CountedCompleter
dl
parents:
11279
diff
changeset
|
351 |
* Blocks a non-worker-thread until completion or interruption. |
7976
f273c0d04215
7005424: Resync java.util.concurrent classes with Dougs CVS - Jan 2011
dl
parents:
6674
diff
changeset
|
352 |
*/ |
14914
69bfd88e3ea1
8002356: Add ForkJoin common pool and CountedCompleter
dl
parents:
11279
diff
changeset
|
353 |
private int externalInterruptibleAwaitDone() throws InterruptedException { |
8765
dfc2a131d08a
7023006: Reduce unnecessary thread activity in ForkJoinPool
dl
parents:
7976
diff
changeset
|
354 |
int s; |
7976
f273c0d04215
7005424: Resync java.util.concurrent classes with Dougs CVS - Jan 2011
dl
parents:
6674
diff
changeset
|
355 |
if (Thread.interrupted()) |
f273c0d04215
7005424: Resync java.util.concurrent classes with Dougs CVS - Jan 2011
dl
parents:
6674
diff
changeset
|
356 |
throw new InterruptedException(); |
26448 | 357 |
if ((s = status) >= 0 && |
358 |
(s = ((this instanceof CountedCompleter) ? |
|
359 |
ForkJoinPool.common.externalHelpComplete( |
|
360 |
(CountedCompleter<?>)this, 0) : |
|
361 |
ForkJoinPool.common.tryExternalUnpush(this) ? doExec() : |
|
362 |
0)) >= 0) { |
|
363 |
while ((s = status) >= 0) { |
|
364 |
if (U.compareAndSwapInt(this, STATUS, s, s | SIGNAL)) { |
|
365 |
synchronized (this) { |
|
366 |
if (status >= 0) |
|
367 |
wait(0L); |
|
368 |
else |
|
369 |
notifyAll(); |
|
370 |
} |
|
8765
dfc2a131d08a
7023006: Reduce unnecessary thread activity in ForkJoinPool
dl
parents:
7976
diff
changeset
|
371 |
} |
dfc2a131d08a
7023006: Reduce unnecessary thread activity in ForkJoinPool
dl
parents:
7976
diff
changeset
|
372 |
} |
dfc2a131d08a
7023006: Reduce unnecessary thread activity in ForkJoinPool
dl
parents:
7976
diff
changeset
|
373 |
} |
dfc2a131d08a
7023006: Reduce unnecessary thread activity in ForkJoinPool
dl
parents:
7976
diff
changeset
|
374 |
return s; |
dfc2a131d08a
7023006: Reduce unnecessary thread activity in ForkJoinPool
dl
parents:
7976
diff
changeset
|
375 |
} |
dfc2a131d08a
7023006: Reduce unnecessary thread activity in ForkJoinPool
dl
parents:
7976
diff
changeset
|
376 |
|
dfc2a131d08a
7023006: Reduce unnecessary thread activity in ForkJoinPool
dl
parents:
7976
diff
changeset
|
377 |
/** |
14914
69bfd88e3ea1
8002356: Add ForkJoin common pool and CountedCompleter
dl
parents:
11279
diff
changeset
|
378 |
* Implementation for join, get, quietlyJoin. Directly handles |
69bfd88e3ea1
8002356: Add ForkJoin common pool and CountedCompleter
dl
parents:
11279
diff
changeset
|
379 |
* only cases of already-completed, external wait, and |
69bfd88e3ea1
8002356: Add ForkJoin common pool and CountedCompleter
dl
parents:
11279
diff
changeset
|
380 |
* unfork+exec. Others are relayed to ForkJoinPool.awaitJoin. |
69bfd88e3ea1
8002356: Add ForkJoin common pool and CountedCompleter
dl
parents:
11279
diff
changeset
|
381 |
* |
8765
dfc2a131d08a
7023006: Reduce unnecessary thread activity in ForkJoinPool
dl
parents:
7976
diff
changeset
|
382 |
* @return status upon completion |
dfc2a131d08a
7023006: Reduce unnecessary thread activity in ForkJoinPool
dl
parents:
7976
diff
changeset
|
383 |
*/ |
dfc2a131d08a
7023006: Reduce unnecessary thread activity in ForkJoinPool
dl
parents:
7976
diff
changeset
|
384 |
private int doJoin() { |
14914
69bfd88e3ea1
8002356: Add ForkJoin common pool and CountedCompleter
dl
parents:
11279
diff
changeset
|
385 |
int s; Thread t; ForkJoinWorkerThread wt; ForkJoinPool.WorkQueue w; |
69bfd88e3ea1
8002356: Add ForkJoin common pool and CountedCompleter
dl
parents:
11279
diff
changeset
|
386 |
return (s = status) < 0 ? s : |
69bfd88e3ea1
8002356: Add ForkJoin common pool and CountedCompleter
dl
parents:
11279
diff
changeset
|
387 |
((t = Thread.currentThread()) instanceof ForkJoinWorkerThread) ? |
69bfd88e3ea1
8002356: Add ForkJoin common pool and CountedCompleter
dl
parents:
11279
diff
changeset
|
388 |
(w = (wt = (ForkJoinWorkerThread)t).workQueue). |
69bfd88e3ea1
8002356: Add ForkJoin common pool and CountedCompleter
dl
parents:
11279
diff
changeset
|
389 |
tryUnpush(this) && (s = doExec()) < 0 ? s : |
26448 | 390 |
wt.pool.awaitJoin(w, this, 0L) : |
14914
69bfd88e3ea1
8002356: Add ForkJoin common pool and CountedCompleter
dl
parents:
11279
diff
changeset
|
391 |
externalAwaitDone(); |
8765
dfc2a131d08a
7023006: Reduce unnecessary thread activity in ForkJoinPool
dl
parents:
7976
diff
changeset
|
392 |
} |
dfc2a131d08a
7023006: Reduce unnecessary thread activity in ForkJoinPool
dl
parents:
7976
diff
changeset
|
393 |
|
dfc2a131d08a
7023006: Reduce unnecessary thread activity in ForkJoinPool
dl
parents:
7976
diff
changeset
|
394 |
/** |
14914
69bfd88e3ea1
8002356: Add ForkJoin common pool and CountedCompleter
dl
parents:
11279
diff
changeset
|
395 |
* Implementation for invoke, quietlyInvoke. |
69bfd88e3ea1
8002356: Add ForkJoin common pool and CountedCompleter
dl
parents:
11279
diff
changeset
|
396 |
* |
8765
dfc2a131d08a
7023006: Reduce unnecessary thread activity in ForkJoinPool
dl
parents:
7976
diff
changeset
|
397 |
* @return status upon completion |
dfc2a131d08a
7023006: Reduce unnecessary thread activity in ForkJoinPool
dl
parents:
7976
diff
changeset
|
398 |
*/ |
dfc2a131d08a
7023006: Reduce unnecessary thread activity in ForkJoinPool
dl
parents:
7976
diff
changeset
|
399 |
private int doInvoke() { |
14914
69bfd88e3ea1
8002356: Add ForkJoin common pool and CountedCompleter
dl
parents:
11279
diff
changeset
|
400 |
int s; Thread t; ForkJoinWorkerThread wt; |
69bfd88e3ea1
8002356: Add ForkJoin common pool and CountedCompleter
dl
parents:
11279
diff
changeset
|
401 |
return (s = doExec()) < 0 ? s : |
69bfd88e3ea1
8002356: Add ForkJoin common pool and CountedCompleter
dl
parents:
11279
diff
changeset
|
402 |
((t = Thread.currentThread()) instanceof ForkJoinWorkerThread) ? |
26448 | 403 |
(wt = (ForkJoinWorkerThread)t).pool. |
404 |
awaitJoin(wt.workQueue, this, 0L) : |
|
14914
69bfd88e3ea1
8002356: Add ForkJoin common pool and CountedCompleter
dl
parents:
11279
diff
changeset
|
405 |
externalAwaitDone(); |
8765
dfc2a131d08a
7023006: Reduce unnecessary thread activity in ForkJoinPool
dl
parents:
7976
diff
changeset
|
406 |
} |
dfc2a131d08a
7023006: Reduce unnecessary thread activity in ForkJoinPool
dl
parents:
7976
diff
changeset
|
407 |
|
dfc2a131d08a
7023006: Reduce unnecessary thread activity in ForkJoinPool
dl
parents:
7976
diff
changeset
|
408 |
// Exception table support |
dfc2a131d08a
7023006: Reduce unnecessary thread activity in ForkJoinPool
dl
parents:
7976
diff
changeset
|
409 |
|
dfc2a131d08a
7023006: Reduce unnecessary thread activity in ForkJoinPool
dl
parents:
7976
diff
changeset
|
410 |
/** |
dfc2a131d08a
7023006: Reduce unnecessary thread activity in ForkJoinPool
dl
parents:
7976
diff
changeset
|
411 |
* Table of exceptions thrown by tasks, to enable reporting by |
dfc2a131d08a
7023006: Reduce unnecessary thread activity in ForkJoinPool
dl
parents:
7976
diff
changeset
|
412 |
* callers. Because exceptions are rare, we don't directly keep |
dfc2a131d08a
7023006: Reduce unnecessary thread activity in ForkJoinPool
dl
parents:
7976
diff
changeset
|
413 |
* them with task objects, but instead use a weak ref table. Note |
dfc2a131d08a
7023006: Reduce unnecessary thread activity in ForkJoinPool
dl
parents:
7976
diff
changeset
|
414 |
* that cancellation exceptions don't appear in the table, but are |
dfc2a131d08a
7023006: Reduce unnecessary thread activity in ForkJoinPool
dl
parents:
7976
diff
changeset
|
415 |
* instead recorded as status values. |
dfc2a131d08a
7023006: Reduce unnecessary thread activity in ForkJoinPool
dl
parents:
7976
diff
changeset
|
416 |
* |
dfc2a131d08a
7023006: Reduce unnecessary thread activity in ForkJoinPool
dl
parents:
7976
diff
changeset
|
417 |
* Note: These statics are initialized below in static block. |
dfc2a131d08a
7023006: Reduce unnecessary thread activity in ForkJoinPool
dl
parents:
7976
diff
changeset
|
418 |
*/ |
dfc2a131d08a
7023006: Reduce unnecessary thread activity in ForkJoinPool
dl
parents:
7976
diff
changeset
|
419 |
private static final ExceptionNode[] exceptionTable; |
dfc2a131d08a
7023006: Reduce unnecessary thread activity in ForkJoinPool
dl
parents:
7976
diff
changeset
|
420 |
private static final ReentrantLock exceptionTableLock; |
dfc2a131d08a
7023006: Reduce unnecessary thread activity in ForkJoinPool
dl
parents:
7976
diff
changeset
|
421 |
private static final ReferenceQueue<Object> exceptionTableRefQueue; |
dfc2a131d08a
7023006: Reduce unnecessary thread activity in ForkJoinPool
dl
parents:
7976
diff
changeset
|
422 |
|
dfc2a131d08a
7023006: Reduce unnecessary thread activity in ForkJoinPool
dl
parents:
7976
diff
changeset
|
423 |
/** |
dfc2a131d08a
7023006: Reduce unnecessary thread activity in ForkJoinPool
dl
parents:
7976
diff
changeset
|
424 |
* Fixed capacity for exceptionTable. |
dfc2a131d08a
7023006: Reduce unnecessary thread activity in ForkJoinPool
dl
parents:
7976
diff
changeset
|
425 |
*/ |
dfc2a131d08a
7023006: Reduce unnecessary thread activity in ForkJoinPool
dl
parents:
7976
diff
changeset
|
426 |
private static final int EXCEPTION_MAP_CAPACITY = 32; |
dfc2a131d08a
7023006: Reduce unnecessary thread activity in ForkJoinPool
dl
parents:
7976
diff
changeset
|
427 |
|
dfc2a131d08a
7023006: Reduce unnecessary thread activity in ForkJoinPool
dl
parents:
7976
diff
changeset
|
428 |
/** |
dfc2a131d08a
7023006: Reduce unnecessary thread activity in ForkJoinPool
dl
parents:
7976
diff
changeset
|
429 |
* Key-value nodes for exception table. The chained hash table |
dfc2a131d08a
7023006: Reduce unnecessary thread activity in ForkJoinPool
dl
parents:
7976
diff
changeset
|
430 |
* uses identity comparisons, full locking, and weak references |
dfc2a131d08a
7023006: Reduce unnecessary thread activity in ForkJoinPool
dl
parents:
7976
diff
changeset
|
431 |
* for keys. The table has a fixed capacity because it only |
dfc2a131d08a
7023006: Reduce unnecessary thread activity in ForkJoinPool
dl
parents:
7976
diff
changeset
|
432 |
* maintains task exceptions long enough for joiners to access |
dfc2a131d08a
7023006: Reduce unnecessary thread activity in ForkJoinPool
dl
parents:
7976
diff
changeset
|
433 |
* them, so should never become very large for sustained |
dfc2a131d08a
7023006: Reduce unnecessary thread activity in ForkJoinPool
dl
parents:
7976
diff
changeset
|
434 |
* periods. However, since we do not know when the last joiner |
dfc2a131d08a
7023006: Reduce unnecessary thread activity in ForkJoinPool
dl
parents:
7976
diff
changeset
|
435 |
* completes, we must use weak references and expunge them. We do |
dfc2a131d08a
7023006: Reduce unnecessary thread activity in ForkJoinPool
dl
parents:
7976
diff
changeset
|
436 |
* so on each operation (hence full locking). Also, some thread in |
dfc2a131d08a
7023006: Reduce unnecessary thread activity in ForkJoinPool
dl
parents:
7976
diff
changeset
|
437 |
* any ForkJoinPool will call helpExpungeStaleExceptions when its |
dfc2a131d08a
7023006: Reduce unnecessary thread activity in ForkJoinPool
dl
parents:
7976
diff
changeset
|
438 |
* pool becomes isQuiescent. |
dfc2a131d08a
7023006: Reduce unnecessary thread activity in ForkJoinPool
dl
parents:
7976
diff
changeset
|
439 |
*/ |
14914
69bfd88e3ea1
8002356: Add ForkJoin common pool and CountedCompleter
dl
parents:
11279
diff
changeset
|
440 |
static final class ExceptionNode extends WeakReference<ForkJoinTask<?>> { |
8765
dfc2a131d08a
7023006: Reduce unnecessary thread activity in ForkJoinPool
dl
parents:
7976
diff
changeset
|
441 |
final Throwable ex; |
dfc2a131d08a
7023006: Reduce unnecessary thread activity in ForkJoinPool
dl
parents:
7976
diff
changeset
|
442 |
ExceptionNode next; |
dfc2a131d08a
7023006: Reduce unnecessary thread activity in ForkJoinPool
dl
parents:
7976
diff
changeset
|
443 |
final long thrower; // use id not ref to avoid weak cycles |
20882 | 444 |
final int hashCode; // store task hashCode before weak ref disappears |
8765
dfc2a131d08a
7023006: Reduce unnecessary thread activity in ForkJoinPool
dl
parents:
7976
diff
changeset
|
445 |
ExceptionNode(ForkJoinTask<?> task, Throwable ex, ExceptionNode next) { |
dfc2a131d08a
7023006: Reduce unnecessary thread activity in ForkJoinPool
dl
parents:
7976
diff
changeset
|
446 |
super(task, exceptionTableRefQueue); |
dfc2a131d08a
7023006: Reduce unnecessary thread activity in ForkJoinPool
dl
parents:
7976
diff
changeset
|
447 |
this.ex = ex; |
dfc2a131d08a
7023006: Reduce unnecessary thread activity in ForkJoinPool
dl
parents:
7976
diff
changeset
|
448 |
this.next = next; |
dfc2a131d08a
7023006: Reduce unnecessary thread activity in ForkJoinPool
dl
parents:
7976
diff
changeset
|
449 |
this.thrower = Thread.currentThread().getId(); |
20882 | 450 |
this.hashCode = System.identityHashCode(task); |
8765
dfc2a131d08a
7023006: Reduce unnecessary thread activity in ForkJoinPool
dl
parents:
7976
diff
changeset
|
451 |
} |
dfc2a131d08a
7023006: Reduce unnecessary thread activity in ForkJoinPool
dl
parents:
7976
diff
changeset
|
452 |
} |
dfc2a131d08a
7023006: Reduce unnecessary thread activity in ForkJoinPool
dl
parents:
7976
diff
changeset
|
453 |
|
dfc2a131d08a
7023006: Reduce unnecessary thread activity in ForkJoinPool
dl
parents:
7976
diff
changeset
|
454 |
/** |
14914
69bfd88e3ea1
8002356: Add ForkJoin common pool and CountedCompleter
dl
parents:
11279
diff
changeset
|
455 |
* Records exception and sets status. |
69bfd88e3ea1
8002356: Add ForkJoin common pool and CountedCompleter
dl
parents:
11279
diff
changeset
|
456 |
* |
69bfd88e3ea1
8002356: Add ForkJoin common pool and CountedCompleter
dl
parents:
11279
diff
changeset
|
457 |
* @return status on exit |
69bfd88e3ea1
8002356: Add ForkJoin common pool and CountedCompleter
dl
parents:
11279
diff
changeset
|
458 |
*/ |
69bfd88e3ea1
8002356: Add ForkJoin common pool and CountedCompleter
dl
parents:
11279
diff
changeset
|
459 |
final int recordExceptionalCompletion(Throwable ex) { |
69bfd88e3ea1
8002356: Add ForkJoin common pool and CountedCompleter
dl
parents:
11279
diff
changeset
|
460 |
int s; |
69bfd88e3ea1
8002356: Add ForkJoin common pool and CountedCompleter
dl
parents:
11279
diff
changeset
|
461 |
if ((s = status) >= 0) { |
69bfd88e3ea1
8002356: Add ForkJoin common pool and CountedCompleter
dl
parents:
11279
diff
changeset
|
462 |
int h = System.identityHashCode(this); |
69bfd88e3ea1
8002356: Add ForkJoin common pool and CountedCompleter
dl
parents:
11279
diff
changeset
|
463 |
final ReentrantLock lock = exceptionTableLock; |
69bfd88e3ea1
8002356: Add ForkJoin common pool and CountedCompleter
dl
parents:
11279
diff
changeset
|
464 |
lock.lock(); |
69bfd88e3ea1
8002356: Add ForkJoin common pool and CountedCompleter
dl
parents:
11279
diff
changeset
|
465 |
try { |
69bfd88e3ea1
8002356: Add ForkJoin common pool and CountedCompleter
dl
parents:
11279
diff
changeset
|
466 |
expungeStaleExceptions(); |
69bfd88e3ea1
8002356: Add ForkJoin common pool and CountedCompleter
dl
parents:
11279
diff
changeset
|
467 |
ExceptionNode[] t = exceptionTable; |
69bfd88e3ea1
8002356: Add ForkJoin common pool and CountedCompleter
dl
parents:
11279
diff
changeset
|
468 |
int i = h & (t.length - 1); |
69bfd88e3ea1
8002356: Add ForkJoin common pool and CountedCompleter
dl
parents:
11279
diff
changeset
|
469 |
for (ExceptionNode e = t[i]; ; e = e.next) { |
69bfd88e3ea1
8002356: Add ForkJoin common pool and CountedCompleter
dl
parents:
11279
diff
changeset
|
470 |
if (e == null) { |
69bfd88e3ea1
8002356: Add ForkJoin common pool and CountedCompleter
dl
parents:
11279
diff
changeset
|
471 |
t[i] = new ExceptionNode(this, ex, t[i]); |
69bfd88e3ea1
8002356: Add ForkJoin common pool and CountedCompleter
dl
parents:
11279
diff
changeset
|
472 |
break; |
69bfd88e3ea1
8002356: Add ForkJoin common pool and CountedCompleter
dl
parents:
11279
diff
changeset
|
473 |
} |
69bfd88e3ea1
8002356: Add ForkJoin common pool and CountedCompleter
dl
parents:
11279
diff
changeset
|
474 |
if (e.get() == this) // already present |
69bfd88e3ea1
8002356: Add ForkJoin common pool and CountedCompleter
dl
parents:
11279
diff
changeset
|
475 |
break; |
69bfd88e3ea1
8002356: Add ForkJoin common pool and CountedCompleter
dl
parents:
11279
diff
changeset
|
476 |
} |
69bfd88e3ea1
8002356: Add ForkJoin common pool and CountedCompleter
dl
parents:
11279
diff
changeset
|
477 |
} finally { |
69bfd88e3ea1
8002356: Add ForkJoin common pool and CountedCompleter
dl
parents:
11279
diff
changeset
|
478 |
lock.unlock(); |
69bfd88e3ea1
8002356: Add ForkJoin common pool and CountedCompleter
dl
parents:
11279
diff
changeset
|
479 |
} |
69bfd88e3ea1
8002356: Add ForkJoin common pool and CountedCompleter
dl
parents:
11279
diff
changeset
|
480 |
s = setCompletion(EXCEPTIONAL); |
69bfd88e3ea1
8002356: Add ForkJoin common pool and CountedCompleter
dl
parents:
11279
diff
changeset
|
481 |
} |
69bfd88e3ea1
8002356: Add ForkJoin common pool and CountedCompleter
dl
parents:
11279
diff
changeset
|
482 |
return s; |
69bfd88e3ea1
8002356: Add ForkJoin common pool and CountedCompleter
dl
parents:
11279
diff
changeset
|
483 |
} |
69bfd88e3ea1
8002356: Add ForkJoin common pool and CountedCompleter
dl
parents:
11279
diff
changeset
|
484 |
|
69bfd88e3ea1
8002356: Add ForkJoin common pool and CountedCompleter
dl
parents:
11279
diff
changeset
|
485 |
/** |
16049
92a3a919d4dc
8008378: FJP.commonPool support parallelism 0, add awaitQuiescence
chegar
parents:
14914
diff
changeset
|
486 |
* Records exception and possibly propagates. |
8765
dfc2a131d08a
7023006: Reduce unnecessary thread activity in ForkJoinPool
dl
parents:
7976
diff
changeset
|
487 |
* |
dfc2a131d08a
7023006: Reduce unnecessary thread activity in ForkJoinPool
dl
parents:
7976
diff
changeset
|
488 |
* @return status on exit |
dfc2a131d08a
7023006: Reduce unnecessary thread activity in ForkJoinPool
dl
parents:
7976
diff
changeset
|
489 |
*/ |
dfc2a131d08a
7023006: Reduce unnecessary thread activity in ForkJoinPool
dl
parents:
7976
diff
changeset
|
490 |
private int setExceptionalCompletion(Throwable ex) { |
14914
69bfd88e3ea1
8002356: Add ForkJoin common pool and CountedCompleter
dl
parents:
11279
diff
changeset
|
491 |
int s = recordExceptionalCompletion(ex); |
69bfd88e3ea1
8002356: Add ForkJoin common pool and CountedCompleter
dl
parents:
11279
diff
changeset
|
492 |
if ((s & DONE_MASK) == EXCEPTIONAL) |
69bfd88e3ea1
8002356: Add ForkJoin common pool and CountedCompleter
dl
parents:
11279
diff
changeset
|
493 |
internalPropagateException(ex); |
69bfd88e3ea1
8002356: Add ForkJoin common pool and CountedCompleter
dl
parents:
11279
diff
changeset
|
494 |
return s; |
69bfd88e3ea1
8002356: Add ForkJoin common pool and CountedCompleter
dl
parents:
11279
diff
changeset
|
495 |
} |
69bfd88e3ea1
8002356: Add ForkJoin common pool and CountedCompleter
dl
parents:
11279
diff
changeset
|
496 |
|
69bfd88e3ea1
8002356: Add ForkJoin common pool and CountedCompleter
dl
parents:
11279
diff
changeset
|
497 |
/** |
69bfd88e3ea1
8002356: Add ForkJoin common pool and CountedCompleter
dl
parents:
11279
diff
changeset
|
498 |
* Hook for exception propagation support for tasks with completers. |
69bfd88e3ea1
8002356: Add ForkJoin common pool and CountedCompleter
dl
parents:
11279
diff
changeset
|
499 |
*/ |
69bfd88e3ea1
8002356: Add ForkJoin common pool and CountedCompleter
dl
parents:
11279
diff
changeset
|
500 |
void internalPropagateException(Throwable ex) { |
69bfd88e3ea1
8002356: Add ForkJoin common pool and CountedCompleter
dl
parents:
11279
diff
changeset
|
501 |
} |
69bfd88e3ea1
8002356: Add ForkJoin common pool and CountedCompleter
dl
parents:
11279
diff
changeset
|
502 |
|
69bfd88e3ea1
8002356: Add ForkJoin common pool and CountedCompleter
dl
parents:
11279
diff
changeset
|
503 |
/** |
69bfd88e3ea1
8002356: Add ForkJoin common pool and CountedCompleter
dl
parents:
11279
diff
changeset
|
504 |
* Cancels, ignoring any exceptions thrown by cancel. Used during |
69bfd88e3ea1
8002356: Add ForkJoin common pool and CountedCompleter
dl
parents:
11279
diff
changeset
|
505 |
* worker and pool shutdown. Cancel is spec'ed not to throw any |
69bfd88e3ea1
8002356: Add ForkJoin common pool and CountedCompleter
dl
parents:
11279
diff
changeset
|
506 |
* exceptions, but if it does anyway, we have no recourse during |
69bfd88e3ea1
8002356: Add ForkJoin common pool and CountedCompleter
dl
parents:
11279
diff
changeset
|
507 |
* shutdown, so guard against this case. |
69bfd88e3ea1
8002356: Add ForkJoin common pool and CountedCompleter
dl
parents:
11279
diff
changeset
|
508 |
*/ |
69bfd88e3ea1
8002356: Add ForkJoin common pool and CountedCompleter
dl
parents:
11279
diff
changeset
|
509 |
static final void cancelIgnoringExceptions(ForkJoinTask<?> t) { |
69bfd88e3ea1
8002356: Add ForkJoin common pool and CountedCompleter
dl
parents:
11279
diff
changeset
|
510 |
if (t != null && t.status >= 0) { |
69bfd88e3ea1
8002356: Add ForkJoin common pool and CountedCompleter
dl
parents:
11279
diff
changeset
|
511 |
try { |
69bfd88e3ea1
8002356: Add ForkJoin common pool and CountedCompleter
dl
parents:
11279
diff
changeset
|
512 |
t.cancel(false); |
69bfd88e3ea1
8002356: Add ForkJoin common pool and CountedCompleter
dl
parents:
11279
diff
changeset
|
513 |
} catch (Throwable ignore) { |
8765
dfc2a131d08a
7023006: Reduce unnecessary thread activity in ForkJoinPool
dl
parents:
7976
diff
changeset
|
514 |
} |
dfc2a131d08a
7023006: Reduce unnecessary thread activity in ForkJoinPool
dl
parents:
7976
diff
changeset
|
515 |
} |
dfc2a131d08a
7023006: Reduce unnecessary thread activity in ForkJoinPool
dl
parents:
7976
diff
changeset
|
516 |
} |
dfc2a131d08a
7023006: Reduce unnecessary thread activity in ForkJoinPool
dl
parents:
7976
diff
changeset
|
517 |
|
dfc2a131d08a
7023006: Reduce unnecessary thread activity in ForkJoinPool
dl
parents:
7976
diff
changeset
|
518 |
/** |
16049
92a3a919d4dc
8008378: FJP.commonPool support parallelism 0, add awaitQuiescence
chegar
parents:
14914
diff
changeset
|
519 |
* Removes exception node and clears status. |
8765
dfc2a131d08a
7023006: Reduce unnecessary thread activity in ForkJoinPool
dl
parents:
7976
diff
changeset
|
520 |
*/ |
dfc2a131d08a
7023006: Reduce unnecessary thread activity in ForkJoinPool
dl
parents:
7976
diff
changeset
|
521 |
private void clearExceptionalCompletion() { |
dfc2a131d08a
7023006: Reduce unnecessary thread activity in ForkJoinPool
dl
parents:
7976
diff
changeset
|
522 |
int h = System.identityHashCode(this); |
dfc2a131d08a
7023006: Reduce unnecessary thread activity in ForkJoinPool
dl
parents:
7976
diff
changeset
|
523 |
final ReentrantLock lock = exceptionTableLock; |
dfc2a131d08a
7023006: Reduce unnecessary thread activity in ForkJoinPool
dl
parents:
7976
diff
changeset
|
524 |
lock.lock(); |
dfc2a131d08a
7023006: Reduce unnecessary thread activity in ForkJoinPool
dl
parents:
7976
diff
changeset
|
525 |
try { |
dfc2a131d08a
7023006: Reduce unnecessary thread activity in ForkJoinPool
dl
parents:
7976
diff
changeset
|
526 |
ExceptionNode[] t = exceptionTable; |
dfc2a131d08a
7023006: Reduce unnecessary thread activity in ForkJoinPool
dl
parents:
7976
diff
changeset
|
527 |
int i = h & (t.length - 1); |
dfc2a131d08a
7023006: Reduce unnecessary thread activity in ForkJoinPool
dl
parents:
7976
diff
changeset
|
528 |
ExceptionNode e = t[i]; |
dfc2a131d08a
7023006: Reduce unnecessary thread activity in ForkJoinPool
dl
parents:
7976
diff
changeset
|
529 |
ExceptionNode pred = null; |
dfc2a131d08a
7023006: Reduce unnecessary thread activity in ForkJoinPool
dl
parents:
7976
diff
changeset
|
530 |
while (e != null) { |
dfc2a131d08a
7023006: Reduce unnecessary thread activity in ForkJoinPool
dl
parents:
7976
diff
changeset
|
531 |
ExceptionNode next = e.next; |
dfc2a131d08a
7023006: Reduce unnecessary thread activity in ForkJoinPool
dl
parents:
7976
diff
changeset
|
532 |
if (e.get() == this) { |
dfc2a131d08a
7023006: Reduce unnecessary thread activity in ForkJoinPool
dl
parents:
7976
diff
changeset
|
533 |
if (pred == null) |
dfc2a131d08a
7023006: Reduce unnecessary thread activity in ForkJoinPool
dl
parents:
7976
diff
changeset
|
534 |
t[i] = next; |
dfc2a131d08a
7023006: Reduce unnecessary thread activity in ForkJoinPool
dl
parents:
7976
diff
changeset
|
535 |
else |
dfc2a131d08a
7023006: Reduce unnecessary thread activity in ForkJoinPool
dl
parents:
7976
diff
changeset
|
536 |
pred.next = next; |
dfc2a131d08a
7023006: Reduce unnecessary thread activity in ForkJoinPool
dl
parents:
7976
diff
changeset
|
537 |
break; |
dfc2a131d08a
7023006: Reduce unnecessary thread activity in ForkJoinPool
dl
parents:
7976
diff
changeset
|
538 |
} |
dfc2a131d08a
7023006: Reduce unnecessary thread activity in ForkJoinPool
dl
parents:
7976
diff
changeset
|
539 |
pred = e; |
dfc2a131d08a
7023006: Reduce unnecessary thread activity in ForkJoinPool
dl
parents:
7976
diff
changeset
|
540 |
e = next; |
dfc2a131d08a
7023006: Reduce unnecessary thread activity in ForkJoinPool
dl
parents:
7976
diff
changeset
|
541 |
} |
dfc2a131d08a
7023006: Reduce unnecessary thread activity in ForkJoinPool
dl
parents:
7976
diff
changeset
|
542 |
expungeStaleExceptions(); |
dfc2a131d08a
7023006: Reduce unnecessary thread activity in ForkJoinPool
dl
parents:
7976
diff
changeset
|
543 |
status = 0; |
dfc2a131d08a
7023006: Reduce unnecessary thread activity in ForkJoinPool
dl
parents:
7976
diff
changeset
|
544 |
} finally { |
dfc2a131d08a
7023006: Reduce unnecessary thread activity in ForkJoinPool
dl
parents:
7976
diff
changeset
|
545 |
lock.unlock(); |
dfc2a131d08a
7023006: Reduce unnecessary thread activity in ForkJoinPool
dl
parents:
7976
diff
changeset
|
546 |
} |
dfc2a131d08a
7023006: Reduce unnecessary thread activity in ForkJoinPool
dl
parents:
7976
diff
changeset
|
547 |
} |
dfc2a131d08a
7023006: Reduce unnecessary thread activity in ForkJoinPool
dl
parents:
7976
diff
changeset
|
548 |
|
dfc2a131d08a
7023006: Reduce unnecessary thread activity in ForkJoinPool
dl
parents:
7976
diff
changeset
|
549 |
/** |
dfc2a131d08a
7023006: Reduce unnecessary thread activity in ForkJoinPool
dl
parents:
7976
diff
changeset
|
550 |
* Returns a rethrowable exception for the given task, if |
dfc2a131d08a
7023006: Reduce unnecessary thread activity in ForkJoinPool
dl
parents:
7976
diff
changeset
|
551 |
* available. To provide accurate stack traces, if the exception |
dfc2a131d08a
7023006: Reduce unnecessary thread activity in ForkJoinPool
dl
parents:
7976
diff
changeset
|
552 |
* was not thrown by the current thread, we try to create a new |
dfc2a131d08a
7023006: Reduce unnecessary thread activity in ForkJoinPool
dl
parents:
7976
diff
changeset
|
553 |
* exception of the same type as the one thrown, but with the |
dfc2a131d08a
7023006: Reduce unnecessary thread activity in ForkJoinPool
dl
parents:
7976
diff
changeset
|
554 |
* recorded exception as its cause. If there is no such |
dfc2a131d08a
7023006: Reduce unnecessary thread activity in ForkJoinPool
dl
parents:
7976
diff
changeset
|
555 |
* constructor, we instead try to use a no-arg constructor, |
dfc2a131d08a
7023006: Reduce unnecessary thread activity in ForkJoinPool
dl
parents:
7976
diff
changeset
|
556 |
* followed by initCause, to the same effect. If none of these |
dfc2a131d08a
7023006: Reduce unnecessary thread activity in ForkJoinPool
dl
parents:
7976
diff
changeset
|
557 |
* apply, or any fail due to other exceptions, we return the |
dfc2a131d08a
7023006: Reduce unnecessary thread activity in ForkJoinPool
dl
parents:
7976
diff
changeset
|
558 |
* recorded exception, which is still correct, although it may |
dfc2a131d08a
7023006: Reduce unnecessary thread activity in ForkJoinPool
dl
parents:
7976
diff
changeset
|
559 |
* contain a misleading stack trace. |
dfc2a131d08a
7023006: Reduce unnecessary thread activity in ForkJoinPool
dl
parents:
7976
diff
changeset
|
560 |
* |
dfc2a131d08a
7023006: Reduce unnecessary thread activity in ForkJoinPool
dl
parents:
7976
diff
changeset
|
561 |
* @return the exception, or null if none |
dfc2a131d08a
7023006: Reduce unnecessary thread activity in ForkJoinPool
dl
parents:
7976
diff
changeset
|
562 |
*/ |
dfc2a131d08a
7023006: Reduce unnecessary thread activity in ForkJoinPool
dl
parents:
7976
diff
changeset
|
563 |
private Throwable getThrowableException() { |
14914
69bfd88e3ea1
8002356: Add ForkJoin common pool and CountedCompleter
dl
parents:
11279
diff
changeset
|
564 |
if ((status & DONE_MASK) != EXCEPTIONAL) |
8765
dfc2a131d08a
7023006: Reduce unnecessary thread activity in ForkJoinPool
dl
parents:
7976
diff
changeset
|
565 |
return null; |
dfc2a131d08a
7023006: Reduce unnecessary thread activity in ForkJoinPool
dl
parents:
7976
diff
changeset
|
566 |
int h = System.identityHashCode(this); |
dfc2a131d08a
7023006: Reduce unnecessary thread activity in ForkJoinPool
dl
parents:
7976
diff
changeset
|
567 |
ExceptionNode e; |
dfc2a131d08a
7023006: Reduce unnecessary thread activity in ForkJoinPool
dl
parents:
7976
diff
changeset
|
568 |
final ReentrantLock lock = exceptionTableLock; |
dfc2a131d08a
7023006: Reduce unnecessary thread activity in ForkJoinPool
dl
parents:
7976
diff
changeset
|
569 |
lock.lock(); |
dfc2a131d08a
7023006: Reduce unnecessary thread activity in ForkJoinPool
dl
parents:
7976
diff
changeset
|
570 |
try { |
dfc2a131d08a
7023006: Reduce unnecessary thread activity in ForkJoinPool
dl
parents:
7976
diff
changeset
|
571 |
expungeStaleExceptions(); |
dfc2a131d08a
7023006: Reduce unnecessary thread activity in ForkJoinPool
dl
parents:
7976
diff
changeset
|
572 |
ExceptionNode[] t = exceptionTable; |
dfc2a131d08a
7023006: Reduce unnecessary thread activity in ForkJoinPool
dl
parents:
7976
diff
changeset
|
573 |
e = t[h & (t.length - 1)]; |
dfc2a131d08a
7023006: Reduce unnecessary thread activity in ForkJoinPool
dl
parents:
7976
diff
changeset
|
574 |
while (e != null && e.get() != this) |
dfc2a131d08a
7023006: Reduce unnecessary thread activity in ForkJoinPool
dl
parents:
7976
diff
changeset
|
575 |
e = e.next; |
dfc2a131d08a
7023006: Reduce unnecessary thread activity in ForkJoinPool
dl
parents:
7976
diff
changeset
|
576 |
} finally { |
dfc2a131d08a
7023006: Reduce unnecessary thread activity in ForkJoinPool
dl
parents:
7976
diff
changeset
|
577 |
lock.unlock(); |
dfc2a131d08a
7023006: Reduce unnecessary thread activity in ForkJoinPool
dl
parents:
7976
diff
changeset
|
578 |
} |
dfc2a131d08a
7023006: Reduce unnecessary thread activity in ForkJoinPool
dl
parents:
7976
diff
changeset
|
579 |
Throwable ex; |
dfc2a131d08a
7023006: Reduce unnecessary thread activity in ForkJoinPool
dl
parents:
7976
diff
changeset
|
580 |
if (e == null || (ex = e.ex) == null) |
dfc2a131d08a
7023006: Reduce unnecessary thread activity in ForkJoinPool
dl
parents:
7976
diff
changeset
|
581 |
return null; |
26448 | 582 |
if (e.thrower != Thread.currentThread().getId()) { |
11279 | 583 |
Class<? extends Throwable> ec = ex.getClass(); |
8765
dfc2a131d08a
7023006: Reduce unnecessary thread activity in ForkJoinPool
dl
parents:
7976
diff
changeset
|
584 |
try { |
dfc2a131d08a
7023006: Reduce unnecessary thread activity in ForkJoinPool
dl
parents:
7976
diff
changeset
|
585 |
Constructor<?> noArgCtor = null; |
dfc2a131d08a
7023006: Reduce unnecessary thread activity in ForkJoinPool
dl
parents:
7976
diff
changeset
|
586 |
Constructor<?>[] cs = ec.getConstructors();// public ctors only |
dfc2a131d08a
7023006: Reduce unnecessary thread activity in ForkJoinPool
dl
parents:
7976
diff
changeset
|
587 |
for (int i = 0; i < cs.length; ++i) { |
dfc2a131d08a
7023006: Reduce unnecessary thread activity in ForkJoinPool
dl
parents:
7976
diff
changeset
|
588 |
Constructor<?> c = cs[i]; |
dfc2a131d08a
7023006: Reduce unnecessary thread activity in ForkJoinPool
dl
parents:
7976
diff
changeset
|
589 |
Class<?>[] ps = c.getParameterTypes(); |
dfc2a131d08a
7023006: Reduce unnecessary thread activity in ForkJoinPool
dl
parents:
7976
diff
changeset
|
590 |
if (ps.length == 0) |
dfc2a131d08a
7023006: Reduce unnecessary thread activity in ForkJoinPool
dl
parents:
7976
diff
changeset
|
591 |
noArgCtor = c; |
26448 | 592 |
else if (ps.length == 1 && ps[0] == Throwable.class) { |
593 |
Throwable wx = (Throwable)c.newInstance(ex); |
|
594 |
return (wx == null) ? ex : wx; |
|
595 |
} |
|
8765
dfc2a131d08a
7023006: Reduce unnecessary thread activity in ForkJoinPool
dl
parents:
7976
diff
changeset
|
596 |
} |
dfc2a131d08a
7023006: Reduce unnecessary thread activity in ForkJoinPool
dl
parents:
7976
diff
changeset
|
597 |
if (noArgCtor != null) { |
dfc2a131d08a
7023006: Reduce unnecessary thread activity in ForkJoinPool
dl
parents:
7976
diff
changeset
|
598 |
Throwable wx = (Throwable)(noArgCtor.newInstance()); |
26448 | 599 |
if (wx != null) { |
600 |
wx.initCause(ex); |
|
601 |
return wx; |
|
602 |
} |
|
8765
dfc2a131d08a
7023006: Reduce unnecessary thread activity in ForkJoinPool
dl
parents:
7976
diff
changeset
|
603 |
} |
dfc2a131d08a
7023006: Reduce unnecessary thread activity in ForkJoinPool
dl
parents:
7976
diff
changeset
|
604 |
} catch (Exception ignore) { |
dfc2a131d08a
7023006: Reduce unnecessary thread activity in ForkJoinPool
dl
parents:
7976
diff
changeset
|
605 |
} |
dfc2a131d08a
7023006: Reduce unnecessary thread activity in ForkJoinPool
dl
parents:
7976
diff
changeset
|
606 |
} |
dfc2a131d08a
7023006: Reduce unnecessary thread activity in ForkJoinPool
dl
parents:
7976
diff
changeset
|
607 |
return ex; |
dfc2a131d08a
7023006: Reduce unnecessary thread activity in ForkJoinPool
dl
parents:
7976
diff
changeset
|
608 |
} |
dfc2a131d08a
7023006: Reduce unnecessary thread activity in ForkJoinPool
dl
parents:
7976
diff
changeset
|
609 |
|
dfc2a131d08a
7023006: Reduce unnecessary thread activity in ForkJoinPool
dl
parents:
7976
diff
changeset
|
610 |
/** |
dfc2a131d08a
7023006: Reduce unnecessary thread activity in ForkJoinPool
dl
parents:
7976
diff
changeset
|
611 |
* Poll stale refs and remove them. Call only while holding lock. |
dfc2a131d08a
7023006: Reduce unnecessary thread activity in ForkJoinPool
dl
parents:
7976
diff
changeset
|
612 |
*/ |
dfc2a131d08a
7023006: Reduce unnecessary thread activity in ForkJoinPool
dl
parents:
7976
diff
changeset
|
613 |
private static void expungeStaleExceptions() { |
dfc2a131d08a
7023006: Reduce unnecessary thread activity in ForkJoinPool
dl
parents:
7976
diff
changeset
|
614 |
for (Object x; (x = exceptionTableRefQueue.poll()) != null;) { |
dfc2a131d08a
7023006: Reduce unnecessary thread activity in ForkJoinPool
dl
parents:
7976
diff
changeset
|
615 |
if (x instanceof ExceptionNode) { |
20882 | 616 |
int hashCode = ((ExceptionNode)x).hashCode; |
8765
dfc2a131d08a
7023006: Reduce unnecessary thread activity in ForkJoinPool
dl
parents:
7976
diff
changeset
|
617 |
ExceptionNode[] t = exceptionTable; |
20882 | 618 |
int i = hashCode & (t.length - 1); |
8765
dfc2a131d08a
7023006: Reduce unnecessary thread activity in ForkJoinPool
dl
parents:
7976
diff
changeset
|
619 |
ExceptionNode e = t[i]; |
dfc2a131d08a
7023006: Reduce unnecessary thread activity in ForkJoinPool
dl
parents:
7976
diff
changeset
|
620 |
ExceptionNode pred = null; |
dfc2a131d08a
7023006: Reduce unnecessary thread activity in ForkJoinPool
dl
parents:
7976
diff
changeset
|
621 |
while (e != null) { |
dfc2a131d08a
7023006: Reduce unnecessary thread activity in ForkJoinPool
dl
parents:
7976
diff
changeset
|
622 |
ExceptionNode next = e.next; |
dfc2a131d08a
7023006: Reduce unnecessary thread activity in ForkJoinPool
dl
parents:
7976
diff
changeset
|
623 |
if (e == x) { |
dfc2a131d08a
7023006: Reduce unnecessary thread activity in ForkJoinPool
dl
parents:
7976
diff
changeset
|
624 |
if (pred == null) |
dfc2a131d08a
7023006: Reduce unnecessary thread activity in ForkJoinPool
dl
parents:
7976
diff
changeset
|
625 |
t[i] = next; |
dfc2a131d08a
7023006: Reduce unnecessary thread activity in ForkJoinPool
dl
parents:
7976
diff
changeset
|
626 |
else |
dfc2a131d08a
7023006: Reduce unnecessary thread activity in ForkJoinPool
dl
parents:
7976
diff
changeset
|
627 |
pred.next = next; |
7976
f273c0d04215
7005424: Resync java.util.concurrent classes with Dougs CVS - Jan 2011
dl
parents:
6674
diff
changeset
|
628 |
break; |
f273c0d04215
7005424: Resync java.util.concurrent classes with Dougs CVS - Jan 2011
dl
parents:
6674
diff
changeset
|
629 |
} |
8765
dfc2a131d08a
7023006: Reduce unnecessary thread activity in ForkJoinPool
dl
parents:
7976
diff
changeset
|
630 |
pred = e; |
dfc2a131d08a
7023006: Reduce unnecessary thread activity in ForkJoinPool
dl
parents:
7976
diff
changeset
|
631 |
e = next; |
4110 | 632 |
} |
633 |
} |
|
634 |
} |
|
635 |
} |
|
636 |
||
637 |
/** |
|
8765
dfc2a131d08a
7023006: Reduce unnecessary thread activity in ForkJoinPool
dl
parents:
7976
diff
changeset
|
638 |
* If lock is available, poll stale refs and remove them. |
dfc2a131d08a
7023006: Reduce unnecessary thread activity in ForkJoinPool
dl
parents:
7976
diff
changeset
|
639 |
* Called from ForkJoinPool when pools become quiescent. |
4110 | 640 |
*/ |
8765
dfc2a131d08a
7023006: Reduce unnecessary thread activity in ForkJoinPool
dl
parents:
7976
diff
changeset
|
641 |
static final void helpExpungeStaleExceptions() { |
dfc2a131d08a
7023006: Reduce unnecessary thread activity in ForkJoinPool
dl
parents:
7976
diff
changeset
|
642 |
final ReentrantLock lock = exceptionTableLock; |
dfc2a131d08a
7023006: Reduce unnecessary thread activity in ForkJoinPool
dl
parents:
7976
diff
changeset
|
643 |
if (lock.tryLock()) { |
dfc2a131d08a
7023006: Reduce unnecessary thread activity in ForkJoinPool
dl
parents:
7976
diff
changeset
|
644 |
try { |
dfc2a131d08a
7023006: Reduce unnecessary thread activity in ForkJoinPool
dl
parents:
7976
diff
changeset
|
645 |
expungeStaleExceptions(); |
dfc2a131d08a
7023006: Reduce unnecessary thread activity in ForkJoinPool
dl
parents:
7976
diff
changeset
|
646 |
} finally { |
dfc2a131d08a
7023006: Reduce unnecessary thread activity in ForkJoinPool
dl
parents:
7976
diff
changeset
|
647 |
lock.unlock(); |
dfc2a131d08a
7023006: Reduce unnecessary thread activity in ForkJoinPool
dl
parents:
7976
diff
changeset
|
648 |
} |
4110 | 649 |
} |
8765
dfc2a131d08a
7023006: Reduce unnecessary thread activity in ForkJoinPool
dl
parents:
7976
diff
changeset
|
650 |
} |
dfc2a131d08a
7023006: Reduce unnecessary thread activity in ForkJoinPool
dl
parents:
7976
diff
changeset
|
651 |
|
dfc2a131d08a
7023006: Reduce unnecessary thread activity in ForkJoinPool
dl
parents:
7976
diff
changeset
|
652 |
/** |
14914
69bfd88e3ea1
8002356: Add ForkJoin common pool and CountedCompleter
dl
parents:
11279
diff
changeset
|
653 |
* A version of "sneaky throw" to relay exceptions |
8765
dfc2a131d08a
7023006: Reduce unnecessary thread activity in ForkJoinPool
dl
parents:
7976
diff
changeset
|
654 |
*/ |
18790 | 655 |
static void rethrow(Throwable ex) { |
656 |
if (ex != null) |
|
16049
92a3a919d4dc
8008378: FJP.commonPool support parallelism 0, add awaitQuiescence
chegar
parents:
14914
diff
changeset
|
657 |
ForkJoinTask.<RuntimeException>uncheckedThrow(ex); |
14914
69bfd88e3ea1
8002356: Add ForkJoin common pool and CountedCompleter
dl
parents:
11279
diff
changeset
|
658 |
} |
69bfd88e3ea1
8002356: Add ForkJoin common pool and CountedCompleter
dl
parents:
11279
diff
changeset
|
659 |
|
69bfd88e3ea1
8002356: Add ForkJoin common pool and CountedCompleter
dl
parents:
11279
diff
changeset
|
660 |
/** |
69bfd88e3ea1
8002356: Add ForkJoin common pool and CountedCompleter
dl
parents:
11279
diff
changeset
|
661 |
* The sneaky part of sneaky throw, relying on generics |
69bfd88e3ea1
8002356: Add ForkJoin common pool and CountedCompleter
dl
parents:
11279
diff
changeset
|
662 |
* limitations to evade compiler complaints about rethrowing |
69bfd88e3ea1
8002356: Add ForkJoin common pool and CountedCompleter
dl
parents:
11279
diff
changeset
|
663 |
* unchecked exceptions |
69bfd88e3ea1
8002356: Add ForkJoin common pool and CountedCompleter
dl
parents:
11279
diff
changeset
|
664 |
*/ |
69bfd88e3ea1
8002356: Add ForkJoin common pool and CountedCompleter
dl
parents:
11279
diff
changeset
|
665 |
@SuppressWarnings("unchecked") static <T extends Throwable> |
16049
92a3a919d4dc
8008378: FJP.commonPool support parallelism 0, add awaitQuiescence
chegar
parents:
14914
diff
changeset
|
666 |
void uncheckedThrow(Throwable t) throws T { |
18790 | 667 |
throw (T)t; // rely on vacuous cast |
14914
69bfd88e3ea1
8002356: Add ForkJoin common pool and CountedCompleter
dl
parents:
11279
diff
changeset
|
668 |
} |
69bfd88e3ea1
8002356: Add ForkJoin common pool and CountedCompleter
dl
parents:
11279
diff
changeset
|
669 |
|
69bfd88e3ea1
8002356: Add ForkJoin common pool and CountedCompleter
dl
parents:
11279
diff
changeset
|
670 |
/** |
69bfd88e3ea1
8002356: Add ForkJoin common pool and CountedCompleter
dl
parents:
11279
diff
changeset
|
671 |
* Throws exception, if any, associated with the given status. |
69bfd88e3ea1
8002356: Add ForkJoin common pool and CountedCompleter
dl
parents:
11279
diff
changeset
|
672 |
*/ |
69bfd88e3ea1
8002356: Add ForkJoin common pool and CountedCompleter
dl
parents:
11279
diff
changeset
|
673 |
private void reportException(int s) { |
69bfd88e3ea1
8002356: Add ForkJoin common pool and CountedCompleter
dl
parents:
11279
diff
changeset
|
674 |
if (s == CANCELLED) |
8765
dfc2a131d08a
7023006: Reduce unnecessary thread activity in ForkJoinPool
dl
parents:
7976
diff
changeset
|
675 |
throw new CancellationException(); |
14914
69bfd88e3ea1
8002356: Add ForkJoin common pool and CountedCompleter
dl
parents:
11279
diff
changeset
|
676 |
if (s == EXCEPTIONAL) |
69bfd88e3ea1
8002356: Add ForkJoin common pool and CountedCompleter
dl
parents:
11279
diff
changeset
|
677 |
rethrow(getThrowableException()); |
4110 | 678 |
} |
679 |
||
680 |
// public methods |
|
681 |
||
682 |
/** |
|
14914
69bfd88e3ea1
8002356: Add ForkJoin common pool and CountedCompleter
dl
parents:
11279
diff
changeset
|
683 |
* Arranges to asynchronously execute this task in the pool the |
69bfd88e3ea1
8002356: Add ForkJoin common pool and CountedCompleter
dl
parents:
11279
diff
changeset
|
684 |
* current task is running in, if applicable, or using the {@link |
69bfd88e3ea1
8002356: Add ForkJoin common pool and CountedCompleter
dl
parents:
11279
diff
changeset
|
685 |
* ForkJoinPool#commonPool()} if not {@link #inForkJoinPool}. While |
69bfd88e3ea1
8002356: Add ForkJoin common pool and CountedCompleter
dl
parents:
11279
diff
changeset
|
686 |
* it is not necessarily enforced, it is a usage error to fork a |
69bfd88e3ea1
8002356: Add ForkJoin common pool and CountedCompleter
dl
parents:
11279
diff
changeset
|
687 |
* task more than once unless it has completed and been |
69bfd88e3ea1
8002356: Add ForkJoin common pool and CountedCompleter
dl
parents:
11279
diff
changeset
|
688 |
* reinitialized. Subsequent modifications to the state of this |
69bfd88e3ea1
8002356: Add ForkJoin common pool and CountedCompleter
dl
parents:
11279
diff
changeset
|
689 |
* task or any data it operates on are not necessarily |
69bfd88e3ea1
8002356: Add ForkJoin common pool and CountedCompleter
dl
parents:
11279
diff
changeset
|
690 |
* consistently observable by any thread other than the one |
69bfd88e3ea1
8002356: Add ForkJoin common pool and CountedCompleter
dl
parents:
11279
diff
changeset
|
691 |
* executing it unless preceded by a call to {@link #join} or |
69bfd88e3ea1
8002356: Add ForkJoin common pool and CountedCompleter
dl
parents:
11279
diff
changeset
|
692 |
* related methods, or a call to {@link #isDone} returning {@code |
69bfd88e3ea1
8002356: Add ForkJoin common pool and CountedCompleter
dl
parents:
11279
diff
changeset
|
693 |
* true}. |
4110 | 694 |
* |
695 |
* @return {@code this}, to simplify usage |
|
696 |
*/ |
|
697 |
public final ForkJoinTask<V> fork() { |
|
14914
69bfd88e3ea1
8002356: Add ForkJoin common pool and CountedCompleter
dl
parents:
11279
diff
changeset
|
698 |
Thread t; |
69bfd88e3ea1
8002356: Add ForkJoin common pool and CountedCompleter
dl
parents:
11279
diff
changeset
|
699 |
if ((t = Thread.currentThread()) instanceof ForkJoinWorkerThread) |
69bfd88e3ea1
8002356: Add ForkJoin common pool and CountedCompleter
dl
parents:
11279
diff
changeset
|
700 |
((ForkJoinWorkerThread)t).workQueue.push(this); |
69bfd88e3ea1
8002356: Add ForkJoin common pool and CountedCompleter
dl
parents:
11279
diff
changeset
|
701 |
else |
16049
92a3a919d4dc
8008378: FJP.commonPool support parallelism 0, add awaitQuiescence
chegar
parents:
14914
diff
changeset
|
702 |
ForkJoinPool.common.externalPush(this); |
4110 | 703 |
return this; |
704 |
} |
|
705 |
||
706 |
/** |
|
7976
f273c0d04215
7005424: Resync java.util.concurrent classes with Dougs CVS - Jan 2011
dl
parents:
6674
diff
changeset
|
707 |
* Returns the result of the computation when it {@link #isDone is |
f273c0d04215
7005424: Resync java.util.concurrent classes with Dougs CVS - Jan 2011
dl
parents:
6674
diff
changeset
|
708 |
* done}. This method differs from {@link #get()} in that |
4110 | 709 |
* abnormal completion results in {@code RuntimeException} or |
7976
f273c0d04215
7005424: Resync java.util.concurrent classes with Dougs CVS - Jan 2011
dl
parents:
6674
diff
changeset
|
710 |
* {@code Error}, not {@code ExecutionException}, and that |
f273c0d04215
7005424: Resync java.util.concurrent classes with Dougs CVS - Jan 2011
dl
parents:
6674
diff
changeset
|
711 |
* interrupts of the calling thread do <em>not</em> cause the |
f273c0d04215
7005424: Resync java.util.concurrent classes with Dougs CVS - Jan 2011
dl
parents:
6674
diff
changeset
|
712 |
* method to abruptly return by throwing {@code |
f273c0d04215
7005424: Resync java.util.concurrent classes with Dougs CVS - Jan 2011
dl
parents:
6674
diff
changeset
|
713 |
* InterruptedException}. |
4110 | 714 |
* |
715 |
* @return the computed result |
|
716 |
*/ |
|
717 |
public final V join() { |
|
14914
69bfd88e3ea1
8002356: Add ForkJoin common pool and CountedCompleter
dl
parents:
11279
diff
changeset
|
718 |
int s; |
69bfd88e3ea1
8002356: Add ForkJoin common pool and CountedCompleter
dl
parents:
11279
diff
changeset
|
719 |
if ((s = doJoin() & DONE_MASK) != NORMAL) |
69bfd88e3ea1
8002356: Add ForkJoin common pool and CountedCompleter
dl
parents:
11279
diff
changeset
|
720 |
reportException(s); |
69bfd88e3ea1
8002356: Add ForkJoin common pool and CountedCompleter
dl
parents:
11279
diff
changeset
|
721 |
return getRawResult(); |
4110 | 722 |
} |
723 |
||
724 |
/** |
|
725 |
* Commences performing this task, awaits its completion if |
|
6543 | 726 |
* necessary, and returns its result, or throws an (unchecked) |
727 |
* {@code RuntimeException} or {@code Error} if the underlying |
|
728 |
* computation did so. |
|
4110 | 729 |
* |
730 |
* @return the computed result |
|
731 |
*/ |
|
732 |
public final V invoke() { |
|
14914
69bfd88e3ea1
8002356: Add ForkJoin common pool and CountedCompleter
dl
parents:
11279
diff
changeset
|
733 |
int s; |
69bfd88e3ea1
8002356: Add ForkJoin common pool and CountedCompleter
dl
parents:
11279
diff
changeset
|
734 |
if ((s = doInvoke() & DONE_MASK) != NORMAL) |
69bfd88e3ea1
8002356: Add ForkJoin common pool and CountedCompleter
dl
parents:
11279
diff
changeset
|
735 |
reportException(s); |
69bfd88e3ea1
8002356: Add ForkJoin common pool and CountedCompleter
dl
parents:
11279
diff
changeset
|
736 |
return getRawResult(); |
4110 | 737 |
} |
738 |
||
739 |
/** |
|
740 |
* Forks the given tasks, returning when {@code isDone} holds for |
|
741 |
* each task or an (unchecked) exception is encountered, in which |
|
6543 | 742 |
* case the exception is rethrown. If more than one task |
743 |
* encounters an exception, then this method throws any one of |
|
744 |
* these exceptions. If any task encounters an exception, the |
|
745 |
* other may be cancelled. However, the execution status of |
|
746 |
* individual tasks is not guaranteed upon exceptional return. The |
|
747 |
* status of each task may be obtained using {@link |
|
748 |
* #getException()} and related methods to check if they have been |
|
749 |
* cancelled, completed normally or exceptionally, or left |
|
750 |
* unprocessed. |
|
4110 | 751 |
* |
752 |
* @param t1 the first task |
|
753 |
* @param t2 the second task |
|
754 |
* @throws NullPointerException if any task is null |
|
755 |
*/ |
|
756 |
public static void invokeAll(ForkJoinTask<?> t1, ForkJoinTask<?> t2) { |
|
14914
69bfd88e3ea1
8002356: Add ForkJoin common pool and CountedCompleter
dl
parents:
11279
diff
changeset
|
757 |
int s1, s2; |
4110 | 758 |
t2.fork(); |
14914
69bfd88e3ea1
8002356: Add ForkJoin common pool and CountedCompleter
dl
parents:
11279
diff
changeset
|
759 |
if ((s1 = t1.doInvoke() & DONE_MASK) != NORMAL) |
69bfd88e3ea1
8002356: Add ForkJoin common pool and CountedCompleter
dl
parents:
11279
diff
changeset
|
760 |
t1.reportException(s1); |
69bfd88e3ea1
8002356: Add ForkJoin common pool and CountedCompleter
dl
parents:
11279
diff
changeset
|
761 |
if ((s2 = t2.doJoin() & DONE_MASK) != NORMAL) |
69bfd88e3ea1
8002356: Add ForkJoin common pool and CountedCompleter
dl
parents:
11279
diff
changeset
|
762 |
t2.reportException(s2); |
4110 | 763 |
} |
764 |
||
765 |
/** |
|
766 |
* Forks the given tasks, returning when {@code isDone} holds for |
|
767 |
* each task or an (unchecked) exception is encountered, in which |
|
6543 | 768 |
* case the exception is rethrown. If more than one task |
769 |
* encounters an exception, then this method throws any one of |
|
770 |
* these exceptions. If any task encounters an exception, others |
|
771 |
* may be cancelled. However, the execution status of individual |
|
772 |
* tasks is not guaranteed upon exceptional return. The status of |
|
773 |
* each task may be obtained using {@link #getException()} and |
|
774 |
* related methods to check if they have been cancelled, completed |
|
775 |
* normally or exceptionally, or left unprocessed. |
|
4110 | 776 |
* |
777 |
* @param tasks the tasks |
|
778 |
* @throws NullPointerException if any task is null |
|
779 |
*/ |
|
780 |
public static void invokeAll(ForkJoinTask<?>... tasks) { |
|
781 |
Throwable ex = null; |
|
782 |
int last = tasks.length - 1; |
|
783 |
for (int i = last; i >= 0; --i) { |
|
784 |
ForkJoinTask<?> t = tasks[i]; |
|
785 |
if (t == null) { |
|
786 |
if (ex == null) |
|
787 |
ex = new NullPointerException(); |
|
788 |
} |
|
789 |
else if (i != 0) |
|
790 |
t.fork(); |
|
8765
dfc2a131d08a
7023006: Reduce unnecessary thread activity in ForkJoinPool
dl
parents:
7976
diff
changeset
|
791 |
else if (t.doInvoke() < NORMAL && ex == null) |
dfc2a131d08a
7023006: Reduce unnecessary thread activity in ForkJoinPool
dl
parents:
7976
diff
changeset
|
792 |
ex = t.getException(); |
4110 | 793 |
} |
794 |
for (int i = 1; i <= last; ++i) { |
|
795 |
ForkJoinTask<?> t = tasks[i]; |
|
796 |
if (t != null) { |
|
797 |
if (ex != null) |
|
798 |
t.cancel(false); |
|
14914
69bfd88e3ea1
8002356: Add ForkJoin common pool and CountedCompleter
dl
parents:
11279
diff
changeset
|
799 |
else if (t.doJoin() < NORMAL) |
8765
dfc2a131d08a
7023006: Reduce unnecessary thread activity in ForkJoinPool
dl
parents:
7976
diff
changeset
|
800 |
ex = t.getException(); |
4110 | 801 |
} |
802 |
} |
|
803 |
if (ex != null) |
|
14914
69bfd88e3ea1
8002356: Add ForkJoin common pool and CountedCompleter
dl
parents:
11279
diff
changeset
|
804 |
rethrow(ex); |
4110 | 805 |
} |
806 |
||
807 |
/** |
|
808 |
* Forks all tasks in the specified collection, returning when |
|
809 |
* {@code isDone} holds for each task or an (unchecked) exception |
|
6543 | 810 |
* is encountered, in which case the exception is rethrown. If |
811 |
* more than one task encounters an exception, then this method |
|
812 |
* throws any one of these exceptions. If any task encounters an |
|
813 |
* exception, others may be cancelled. However, the execution |
|
814 |
* status of individual tasks is not guaranteed upon exceptional |
|
815 |
* return. The status of each task may be obtained using {@link |
|
816 |
* #getException()} and related methods to check if they have been |
|
817 |
* cancelled, completed normally or exceptionally, or left |
|
818 |
* unprocessed. |
|
4110 | 819 |
* |
820 |
* @param tasks the collection of tasks |
|
19048
7d0a94c79779
8021417: Fix doclint issues in java.util.concurrent
chegar
parents:
18790
diff
changeset
|
821 |
* @param <T> the type of the values returned from the tasks |
4110 | 822 |
* @return the tasks argument, to simplify usage |
823 |
* @throws NullPointerException if tasks or any element are null |
|
824 |
*/ |
|
825 |
public static <T extends ForkJoinTask<?>> Collection<T> invokeAll(Collection<T> tasks) { |
|
826 |
if (!(tasks instanceof RandomAccess) || !(tasks instanceof List<?>)) { |
|
827 |
invokeAll(tasks.toArray(new ForkJoinTask<?>[tasks.size()])); |
|
828 |
return tasks; |
|
829 |
} |
|
830 |
@SuppressWarnings("unchecked") |
|
831 |
List<? extends ForkJoinTask<?>> ts = |
|
832 |
(List<? extends ForkJoinTask<?>>) tasks; |
|
833 |
Throwable ex = null; |
|
834 |
int last = ts.size() - 1; |
|
835 |
for (int i = last; i >= 0; --i) { |
|
836 |
ForkJoinTask<?> t = ts.get(i); |
|
837 |
if (t == null) { |
|
838 |
if (ex == null) |
|
839 |
ex = new NullPointerException(); |
|
840 |
} |
|
841 |
else if (i != 0) |
|
842 |
t.fork(); |
|
8765
dfc2a131d08a
7023006: Reduce unnecessary thread activity in ForkJoinPool
dl
parents:
7976
diff
changeset
|
843 |
else if (t.doInvoke() < NORMAL && ex == null) |
dfc2a131d08a
7023006: Reduce unnecessary thread activity in ForkJoinPool
dl
parents:
7976
diff
changeset
|
844 |
ex = t.getException(); |
4110 | 845 |
} |
846 |
for (int i = 1; i <= last; ++i) { |
|
847 |
ForkJoinTask<?> t = ts.get(i); |
|
848 |
if (t != null) { |
|
849 |
if (ex != null) |
|
850 |
t.cancel(false); |
|
14914
69bfd88e3ea1
8002356: Add ForkJoin common pool and CountedCompleter
dl
parents:
11279
diff
changeset
|
851 |
else if (t.doJoin() < NORMAL) |
8765
dfc2a131d08a
7023006: Reduce unnecessary thread activity in ForkJoinPool
dl
parents:
7976
diff
changeset
|
852 |
ex = t.getException(); |
4110 | 853 |
} |
854 |
} |
|
855 |
if (ex != null) |
|
14914
69bfd88e3ea1
8002356: Add ForkJoin common pool and CountedCompleter
dl
parents:
11279
diff
changeset
|
856 |
rethrow(ex); |
4110 | 857 |
return tasks; |
858 |
} |
|
859 |
||
860 |
/** |
|
861 |
* Attempts to cancel execution of this task. This attempt will |
|
7976
f273c0d04215
7005424: Resync java.util.concurrent classes with Dougs CVS - Jan 2011
dl
parents:
6674
diff
changeset
|
862 |
* fail if the task has already completed or could not be |
f273c0d04215
7005424: Resync java.util.concurrent classes with Dougs CVS - Jan 2011
dl
parents:
6674
diff
changeset
|
863 |
* cancelled for some other reason. If successful, and this task |
f273c0d04215
7005424: Resync java.util.concurrent classes with Dougs CVS - Jan 2011
dl
parents:
6674
diff
changeset
|
864 |
* has not started when {@code cancel} is called, execution of |
f273c0d04215
7005424: Resync java.util.concurrent classes with Dougs CVS - Jan 2011
dl
parents:
6674
diff
changeset
|
865 |
* this task is suppressed. After this method returns |
f273c0d04215
7005424: Resync java.util.concurrent classes with Dougs CVS - Jan 2011
dl
parents:
6674
diff
changeset
|
866 |
* successfully, unless there is an intervening call to {@link |
f273c0d04215
7005424: Resync java.util.concurrent classes with Dougs CVS - Jan 2011
dl
parents:
6674
diff
changeset
|
867 |
* #reinitialize}, subsequent calls to {@link #isCancelled}, |
f273c0d04215
7005424: Resync java.util.concurrent classes with Dougs CVS - Jan 2011
dl
parents:
6674
diff
changeset
|
868 |
* {@link #isDone}, and {@code cancel} will return {@code true} |
f273c0d04215
7005424: Resync java.util.concurrent classes with Dougs CVS - Jan 2011
dl
parents:
6674
diff
changeset
|
869 |
* and calls to {@link #join} and related methods will result in |
f273c0d04215
7005424: Resync java.util.concurrent classes with Dougs CVS - Jan 2011
dl
parents:
6674
diff
changeset
|
870 |
* {@code CancellationException}. |
4110 | 871 |
* |
872 |
* <p>This method may be overridden in subclasses, but if so, must |
|
7976
f273c0d04215
7005424: Resync java.util.concurrent classes with Dougs CVS - Jan 2011
dl
parents:
6674
diff
changeset
|
873 |
* still ensure that these properties hold. In particular, the |
f273c0d04215
7005424: Resync java.util.concurrent classes with Dougs CVS - Jan 2011
dl
parents:
6674
diff
changeset
|
874 |
* {@code cancel} method itself must not throw exceptions. |
4110 | 875 |
* |
876 |
* <p>This method is designed to be invoked by <em>other</em> |
|
877 |
* tasks. To terminate the current task, you can just return or |
|
878 |
* throw an unchecked exception from its computation method, or |
|
16049
92a3a919d4dc
8008378: FJP.commonPool support parallelism 0, add awaitQuiescence
chegar
parents:
14914
diff
changeset
|
879 |
* invoke {@link #completeExceptionally(Throwable)}. |
4110 | 880 |
* |
7976
f273c0d04215
7005424: Resync java.util.concurrent classes with Dougs CVS - Jan 2011
dl
parents:
6674
diff
changeset
|
881 |
* @param mayInterruptIfRunning this value has no effect in the |
f273c0d04215
7005424: Resync java.util.concurrent classes with Dougs CVS - Jan 2011
dl
parents:
6674
diff
changeset
|
882 |
* default implementation because interrupts are not used to |
f273c0d04215
7005424: Resync java.util.concurrent classes with Dougs CVS - Jan 2011
dl
parents:
6674
diff
changeset
|
883 |
* control cancellation. |
4110 | 884 |
* |
885 |
* @return {@code true} if this task is now cancelled |
|
886 |
*/ |
|
887 |
public boolean cancel(boolean mayInterruptIfRunning) { |
|
14914
69bfd88e3ea1
8002356: Add ForkJoin common pool and CountedCompleter
dl
parents:
11279
diff
changeset
|
888 |
return (setCompletion(CANCELLED) & DONE_MASK) == CANCELLED; |
6543 | 889 |
} |
890 |
||
4110 | 891 |
public final boolean isDone() { |
892 |
return status < 0; |
|
893 |
} |
|
894 |
||
895 |
public final boolean isCancelled() { |
|
14914
69bfd88e3ea1
8002356: Add ForkJoin common pool and CountedCompleter
dl
parents:
11279
diff
changeset
|
896 |
return (status & DONE_MASK) == CANCELLED; |
4110 | 897 |
} |
898 |
||
899 |
/** |
|
900 |
* Returns {@code true} if this task threw an exception or was cancelled. |
|
901 |
* |
|
902 |
* @return {@code true} if this task threw an exception or was cancelled |
|
903 |
*/ |
|
904 |
public final boolean isCompletedAbnormally() { |
|
6543 | 905 |
return status < NORMAL; |
4110 | 906 |
} |
907 |
||
908 |
/** |
|
909 |
* Returns {@code true} if this task completed without throwing an |
|
910 |
* exception and was not cancelled. |
|
911 |
* |
|
912 |
* @return {@code true} if this task completed without throwing an |
|
913 |
* exception and was not cancelled |
|
914 |
*/ |
|
915 |
public final boolean isCompletedNormally() { |
|
14914
69bfd88e3ea1
8002356: Add ForkJoin common pool and CountedCompleter
dl
parents:
11279
diff
changeset
|
916 |
return (status & DONE_MASK) == NORMAL; |
4110 | 917 |
} |
918 |
||
919 |
/** |
|
920 |
* Returns the exception thrown by the base computation, or a |
|
921 |
* {@code CancellationException} if cancelled, or {@code null} if |
|
922 |
* none or if the method has not yet completed. |
|
923 |
* |
|
924 |
* @return the exception, or {@code null} if none |
|
925 |
*/ |
|
926 |
public final Throwable getException() { |
|
14914
69bfd88e3ea1
8002356: Add ForkJoin common pool and CountedCompleter
dl
parents:
11279
diff
changeset
|
927 |
int s = status & DONE_MASK; |
4110 | 928 |
return ((s >= NORMAL) ? null : |
929 |
(s == CANCELLED) ? new CancellationException() : |
|
8765
dfc2a131d08a
7023006: Reduce unnecessary thread activity in ForkJoinPool
dl
parents:
7976
diff
changeset
|
930 |
getThrowableException()); |
4110 | 931 |
} |
932 |
||
933 |
/** |
|
934 |
* Completes this task abnormally, and if not already aborted or |
|
935 |
* cancelled, causes it to throw the given exception upon |
|
936 |
* {@code join} and related operations. This method may be used |
|
937 |
* to induce exceptions in asynchronous tasks, or to force |
|
938 |
* completion of tasks that would not otherwise complete. Its use |
|
939 |
* in other situations is discouraged. This method is |
|
940 |
* overridable, but overridden versions must invoke {@code super} |
|
941 |
* implementation to maintain guarantees. |
|
942 |
* |
|
943 |
* @param ex the exception to throw. If this exception is not a |
|
944 |
* {@code RuntimeException} or {@code Error}, the actual exception |
|
945 |
* thrown will be a {@code RuntimeException} with cause {@code ex}. |
|
946 |
*/ |
|
947 |
public void completeExceptionally(Throwable ex) { |
|
6543 | 948 |
setExceptionalCompletion((ex instanceof RuntimeException) || |
949 |
(ex instanceof Error) ? ex : |
|
950 |
new RuntimeException(ex)); |
|
4110 | 951 |
} |
952 |
||
953 |
/** |
|
954 |
* Completes this task, and if not already aborted or cancelled, |
|
6543 | 955 |
* returning the given value as the result of subsequent |
956 |
* invocations of {@code join} and related operations. This method |
|
957 |
* may be used to provide results for asynchronous tasks, or to |
|
958 |
* provide alternative handling for tasks that would not otherwise |
|
959 |
* complete normally. Its use in other situations is |
|
960 |
* discouraged. This method is overridable, but overridden |
|
961 |
* versions must invoke {@code super} implementation to maintain |
|
962 |
* guarantees. |
|
4110 | 963 |
* |
964 |
* @param value the result value for this task |
|
965 |
*/ |
|
966 |
public void complete(V value) { |
|
967 |
try { |
|
968 |
setRawResult(value); |
|
969 |
} catch (Throwable rex) { |
|
6543 | 970 |
setExceptionalCompletion(rex); |
4110 | 971 |
return; |
972 |
} |
|
6543 | 973 |
setCompletion(NORMAL); |
4110 | 974 |
} |
975 |
||
6674 | 976 |
/** |
14914
69bfd88e3ea1
8002356: Add ForkJoin common pool and CountedCompleter
dl
parents:
11279
diff
changeset
|
977 |
* Completes this task normally without setting a value. The most |
69bfd88e3ea1
8002356: Add ForkJoin common pool and CountedCompleter
dl
parents:
11279
diff
changeset
|
978 |
* recent value established by {@link #setRawResult} (or {@code |
69bfd88e3ea1
8002356: Add ForkJoin common pool and CountedCompleter
dl
parents:
11279
diff
changeset
|
979 |
* null} by default) will be returned as the result of subsequent |
69bfd88e3ea1
8002356: Add ForkJoin common pool and CountedCompleter
dl
parents:
11279
diff
changeset
|
980 |
* invocations of {@code join} and related operations. |
69bfd88e3ea1
8002356: Add ForkJoin common pool and CountedCompleter
dl
parents:
11279
diff
changeset
|
981 |
* |
69bfd88e3ea1
8002356: Add ForkJoin common pool and CountedCompleter
dl
parents:
11279
diff
changeset
|
982 |
* @since 1.8 |
69bfd88e3ea1
8002356: Add ForkJoin common pool and CountedCompleter
dl
parents:
11279
diff
changeset
|
983 |
*/ |
69bfd88e3ea1
8002356: Add ForkJoin common pool and CountedCompleter
dl
parents:
11279
diff
changeset
|
984 |
public final void quietlyComplete() { |
69bfd88e3ea1
8002356: Add ForkJoin common pool and CountedCompleter
dl
parents:
11279
diff
changeset
|
985 |
setCompletion(NORMAL); |
69bfd88e3ea1
8002356: Add ForkJoin common pool and CountedCompleter
dl
parents:
11279
diff
changeset
|
986 |
} |
69bfd88e3ea1
8002356: Add ForkJoin common pool and CountedCompleter
dl
parents:
11279
diff
changeset
|
987 |
|
69bfd88e3ea1
8002356: Add ForkJoin common pool and CountedCompleter
dl
parents:
11279
diff
changeset
|
988 |
/** |
6674 | 989 |
* Waits if necessary for the computation to complete, and then |
990 |
* retrieves its result. |
|
991 |
* |
|
992 |
* @return the computed result |
|
993 |
* @throws CancellationException if the computation was cancelled |
|
994 |
* @throws ExecutionException if the computation threw an |
|
995 |
* exception |
|
996 |
* @throws InterruptedException if the current thread is not a |
|
997 |
* member of a ForkJoinPool and was interrupted while waiting |
|
998 |
*/ |
|
4110 | 999 |
public final V get() throws InterruptedException, ExecutionException { |
8765
dfc2a131d08a
7023006: Reduce unnecessary thread activity in ForkJoinPool
dl
parents:
7976
diff
changeset
|
1000 |
int s = (Thread.currentThread() instanceof ForkJoinWorkerThread) ? |
14914
69bfd88e3ea1
8002356: Add ForkJoin common pool and CountedCompleter
dl
parents:
11279
diff
changeset
|
1001 |
doJoin() : externalInterruptibleAwaitDone(); |
8765
dfc2a131d08a
7023006: Reduce unnecessary thread activity in ForkJoinPool
dl
parents:
7976
diff
changeset
|
1002 |
Throwable ex; |
14914
69bfd88e3ea1
8002356: Add ForkJoin common pool and CountedCompleter
dl
parents:
11279
diff
changeset
|
1003 |
if ((s &= DONE_MASK) == CANCELLED) |
8765
dfc2a131d08a
7023006: Reduce unnecessary thread activity in ForkJoinPool
dl
parents:
7976
diff
changeset
|
1004 |
throw new CancellationException(); |
dfc2a131d08a
7023006: Reduce unnecessary thread activity in ForkJoinPool
dl
parents:
7976
diff
changeset
|
1005 |
if (s == EXCEPTIONAL && (ex = getThrowableException()) != null) |
dfc2a131d08a
7023006: Reduce unnecessary thread activity in ForkJoinPool
dl
parents:
7976
diff
changeset
|
1006 |
throw new ExecutionException(ex); |
6543 | 1007 |
return getRawResult(); |
4110 | 1008 |
} |
1009 |
||
6674 | 1010 |
/** |
1011 |
* Waits if necessary for at most the given time for the computation |
|
1012 |
* to complete, and then retrieves its result, if available. |
|
1013 |
* |
|
1014 |
* @param timeout the maximum time to wait |
|
1015 |
* @param unit the time unit of the timeout argument |
|
1016 |
* @return the computed result |
|
1017 |
* @throws CancellationException if the computation was cancelled |
|
1018 |
* @throws ExecutionException if the computation threw an |
|
1019 |
* exception |
|
1020 |
* @throws InterruptedException if the current thread is not a |
|
1021 |
* member of a ForkJoinPool and was interrupted while waiting |
|
1022 |
* @throws TimeoutException if the wait timed out |
|
1023 |
*/ |
|
4110 | 1024 |
public final V get(long timeout, TimeUnit unit) |
1025 |
throws InterruptedException, ExecutionException, TimeoutException { |
|
26448 | 1026 |
int s; |
1027 |
long nanos = unit.toNanos(timeout); |
|
14914
69bfd88e3ea1
8002356: Add ForkJoin common pool and CountedCompleter
dl
parents:
11279
diff
changeset
|
1028 |
if (Thread.interrupted()) |
69bfd88e3ea1
8002356: Add ForkJoin common pool and CountedCompleter
dl
parents:
11279
diff
changeset
|
1029 |
throw new InterruptedException(); |
26448 | 1030 |
if ((s = status) >= 0 && nanos > 0L) { |
1031 |
long d = System.nanoTime() + nanos; |
|
1032 |
long deadline = (d == 0L) ? 1L : d; // avoid 0 |
|
14914
69bfd88e3ea1
8002356: Add ForkJoin common pool and CountedCompleter
dl
parents:
11279
diff
changeset
|
1033 |
Thread t = Thread.currentThread(); |
69bfd88e3ea1
8002356: Add ForkJoin common pool and CountedCompleter
dl
parents:
11279
diff
changeset
|
1034 |
if (t instanceof ForkJoinWorkerThread) { |
69bfd88e3ea1
8002356: Add ForkJoin common pool and CountedCompleter
dl
parents:
11279
diff
changeset
|
1035 |
ForkJoinWorkerThread wt = (ForkJoinWorkerThread)t; |
26448 | 1036 |
s = wt.pool.awaitJoin(wt.workQueue, this, deadline); |
18790 | 1037 |
} |
26448 | 1038 |
else if ((s = ((this instanceof CountedCompleter) ? |
1039 |
ForkJoinPool.common.externalHelpComplete( |
|
1040 |
(CountedCompleter<?>)this, 0) : |
|
1041 |
ForkJoinPool.common.tryExternalUnpush(this) ? |
|
1042 |
doExec() : 0)) >= 0) { |
|
1043 |
long ns, ms; // measure in nanosecs, but wait in millisecs |
|
1044 |
while ((s = status) >= 0 && |
|
1045 |
(ns = deadline - System.nanoTime()) > 0L) { |
|
1046 |
if ((ms = TimeUnit.NANOSECONDS.toMillis(ns)) > 0L && |
|
1047 |
U.compareAndSwapInt(this, STATUS, s, s | SIGNAL)) { |
|
1048 |
synchronized (this) { |
|
1049 |
if (status >= 0) |
|
1050 |
wait(ms); // OK to throw InterruptedException |
|
1051 |
else |
|
1052 |
notifyAll(); |
|
14914
69bfd88e3ea1
8002356: Add ForkJoin common pool and CountedCompleter
dl
parents:
11279
diff
changeset
|
1053 |
} |
8765
dfc2a131d08a
7023006: Reduce unnecessary thread activity in ForkJoinPool
dl
parents:
7976
diff
changeset
|
1054 |
} |
dfc2a131d08a
7023006: Reduce unnecessary thread activity in ForkJoinPool
dl
parents:
7976
diff
changeset
|
1055 |
} |
dfc2a131d08a
7023006: Reduce unnecessary thread activity in ForkJoinPool
dl
parents:
7976
diff
changeset
|
1056 |
} |
dfc2a131d08a
7023006: Reduce unnecessary thread activity in ForkJoinPool
dl
parents:
7976
diff
changeset
|
1057 |
} |
26448 | 1058 |
if (s >= 0) |
1059 |
s = status; |
|
14914
69bfd88e3ea1
8002356: Add ForkJoin common pool and CountedCompleter
dl
parents:
11279
diff
changeset
|
1060 |
if ((s &= DONE_MASK) != NORMAL) { |
6543 | 1061 |
Throwable ex; |
7976
f273c0d04215
7005424: Resync java.util.concurrent classes with Dougs CVS - Jan 2011
dl
parents:
6674
diff
changeset
|
1062 |
if (s == CANCELLED) |
6543 | 1063 |
throw new CancellationException(); |
8765
dfc2a131d08a
7023006: Reduce unnecessary thread activity in ForkJoinPool
dl
parents:
7976
diff
changeset
|
1064 |
if (s != EXCEPTIONAL) |
dfc2a131d08a
7023006: Reduce unnecessary thread activity in ForkJoinPool
dl
parents:
7976
diff
changeset
|
1065 |
throw new TimeoutException(); |
dfc2a131d08a
7023006: Reduce unnecessary thread activity in ForkJoinPool
dl
parents:
7976
diff
changeset
|
1066 |
if ((ex = getThrowableException()) != null) |
6543 | 1067 |
throw new ExecutionException(ex); |
1068 |
} |
|
4110 | 1069 |
return getRawResult(); |
1070 |
} |
|
1071 |
||
1072 |
/** |
|
6543 | 1073 |
* Joins this task, without returning its result or throwing its |
4110 | 1074 |
* exception. This method may be useful when processing |
1075 |
* collections of tasks when some have been cancelled or otherwise |
|
1076 |
* known to have aborted. |
|
1077 |
*/ |
|
1078 |
public final void quietlyJoin() { |
|
8765
dfc2a131d08a
7023006: Reduce unnecessary thread activity in ForkJoinPool
dl
parents:
7976
diff
changeset
|
1079 |
doJoin(); |
4110 | 1080 |
} |
1081 |
||
1082 |
/** |
|
1083 |
* Commences performing this task and awaits its completion if |
|
6543 | 1084 |
* necessary, without returning its result or throwing its |
1085 |
* exception. |
|
4110 | 1086 |
*/ |
1087 |
public final void quietlyInvoke() { |
|
8765
dfc2a131d08a
7023006: Reduce unnecessary thread activity in ForkJoinPool
dl
parents:
7976
diff
changeset
|
1088 |
doInvoke(); |
4110 | 1089 |
} |
1090 |
||
1091 |
/** |
|
1092 |
* Possibly executes tasks until the pool hosting the current task |
|
1093 |
* {@link ForkJoinPool#isQuiescent is quiescent}. This method may |
|
1094 |
* be of use in designs in which many tasks are forked, but none |
|
1095 |
* are explicitly joined, instead executing them until all are |
|
1096 |
* processed. |
|
1097 |
*/ |
|
1098 |
public static void helpQuiesce() { |
|
14914
69bfd88e3ea1
8002356: Add ForkJoin common pool and CountedCompleter
dl
parents:
11279
diff
changeset
|
1099 |
Thread t; |
69bfd88e3ea1
8002356: Add ForkJoin common pool and CountedCompleter
dl
parents:
11279
diff
changeset
|
1100 |
if ((t = Thread.currentThread()) instanceof ForkJoinWorkerThread) { |
69bfd88e3ea1
8002356: Add ForkJoin common pool and CountedCompleter
dl
parents:
11279
diff
changeset
|
1101 |
ForkJoinWorkerThread wt = (ForkJoinWorkerThread)t; |
69bfd88e3ea1
8002356: Add ForkJoin common pool and CountedCompleter
dl
parents:
11279
diff
changeset
|
1102 |
wt.pool.helpQuiescePool(wt.workQueue); |
69bfd88e3ea1
8002356: Add ForkJoin common pool and CountedCompleter
dl
parents:
11279
diff
changeset
|
1103 |
} |
69bfd88e3ea1
8002356: Add ForkJoin common pool and CountedCompleter
dl
parents:
11279
diff
changeset
|
1104 |
else |
16049
92a3a919d4dc
8008378: FJP.commonPool support parallelism 0, add awaitQuiescence
chegar
parents:
14914
diff
changeset
|
1105 |
ForkJoinPool.quiesceCommonPool(); |
4110 | 1106 |
} |
1107 |
||
1108 |
/** |
|
1109 |
* Resets the internal bookkeeping state of this task, allowing a |
|
1110 |
* subsequent {@code fork}. This method allows repeated reuse of |
|
1111 |
* this task, but only if reuse occurs when this task has either |
|
1112 |
* never been forked, or has been forked, then completed and all |
|
1113 |
* outstanding joins of this task have also completed. Effects |
|
1114 |
* under any other usage conditions are not guaranteed. |
|
1115 |
* This method may be useful when executing |
|
1116 |
* pre-constructed trees of subtasks in loops. |
|
7976
f273c0d04215
7005424: Resync java.util.concurrent classes with Dougs CVS - Jan 2011
dl
parents:
6674
diff
changeset
|
1117 |
* |
f273c0d04215
7005424: Resync java.util.concurrent classes with Dougs CVS - Jan 2011
dl
parents:
6674
diff
changeset
|
1118 |
* <p>Upon completion of this method, {@code isDone()} reports |
f273c0d04215
7005424: Resync java.util.concurrent classes with Dougs CVS - Jan 2011
dl
parents:
6674
diff
changeset
|
1119 |
* {@code false}, and {@code getException()} reports {@code |
f273c0d04215
7005424: Resync java.util.concurrent classes with Dougs CVS - Jan 2011
dl
parents:
6674
diff
changeset
|
1120 |
* null}. However, the value returned by {@code getRawResult} is |
f273c0d04215
7005424: Resync java.util.concurrent classes with Dougs CVS - Jan 2011
dl
parents:
6674
diff
changeset
|
1121 |
* unaffected. To clear this value, you can invoke {@code |
f273c0d04215
7005424: Resync java.util.concurrent classes with Dougs CVS - Jan 2011
dl
parents:
6674
diff
changeset
|
1122 |
* setRawResult(null)}. |
4110 | 1123 |
*/ |
1124 |
public void reinitialize() { |
|
14914
69bfd88e3ea1
8002356: Add ForkJoin common pool and CountedCompleter
dl
parents:
11279
diff
changeset
|
1125 |
if ((status & DONE_MASK) == EXCEPTIONAL) |
8765
dfc2a131d08a
7023006: Reduce unnecessary thread activity in ForkJoinPool
dl
parents:
7976
diff
changeset
|
1126 |
clearExceptionalCompletion(); |
dfc2a131d08a
7023006: Reduce unnecessary thread activity in ForkJoinPool
dl
parents:
7976
diff
changeset
|
1127 |
else |
dfc2a131d08a
7023006: Reduce unnecessary thread activity in ForkJoinPool
dl
parents:
7976
diff
changeset
|
1128 |
status = 0; |
4110 | 1129 |
} |
1130 |
||
1131 |
/** |
|
1132 |
* Returns the pool hosting the current task execution, or null |
|
1133 |
* if this task is executing outside of any ForkJoinPool. |
|
1134 |
* |
|
1135 |
* @see #inForkJoinPool |
|
1136 |
* @return the pool, or {@code null} if none |
|
1137 |
*/ |
|
1138 |
public static ForkJoinPool getPool() { |
|
1139 |
Thread t = Thread.currentThread(); |
|
1140 |
return (t instanceof ForkJoinWorkerThread) ? |
|
1141 |
((ForkJoinWorkerThread) t).pool : null; |
|
1142 |
} |
|
1143 |
||
1144 |
/** |
|
7976
f273c0d04215
7005424: Resync java.util.concurrent classes with Dougs CVS - Jan 2011
dl
parents:
6674
diff
changeset
|
1145 |
* Returns {@code true} if the current thread is a {@link |
f273c0d04215
7005424: Resync java.util.concurrent classes with Dougs CVS - Jan 2011
dl
parents:
6674
diff
changeset
|
1146 |
* ForkJoinWorkerThread} executing as a ForkJoinPool computation. |
4110 | 1147 |
* |
7976
f273c0d04215
7005424: Resync java.util.concurrent classes with Dougs CVS - Jan 2011
dl
parents:
6674
diff
changeset
|
1148 |
* @return {@code true} if the current thread is a {@link |
f273c0d04215
7005424: Resync java.util.concurrent classes with Dougs CVS - Jan 2011
dl
parents:
6674
diff
changeset
|
1149 |
* ForkJoinWorkerThread} executing as a ForkJoinPool computation, |
f273c0d04215
7005424: Resync java.util.concurrent classes with Dougs CVS - Jan 2011
dl
parents:
6674
diff
changeset
|
1150 |
* or {@code false} otherwise |
4110 | 1151 |
*/ |
1152 |
public static boolean inForkJoinPool() { |
|
1153 |
return Thread.currentThread() instanceof ForkJoinWorkerThread; |
|
1154 |
} |
|
1155 |
||
1156 |
/** |
|
1157 |
* Tries to unschedule this task for execution. This method will |
|
14914
69bfd88e3ea1
8002356: Add ForkJoin common pool and CountedCompleter
dl
parents:
11279
diff
changeset
|
1158 |
* typically (but is not guaranteed to) succeed if this task is |
69bfd88e3ea1
8002356: Add ForkJoin common pool and CountedCompleter
dl
parents:
11279
diff
changeset
|
1159 |
* the most recently forked task by the current thread, and has |
69bfd88e3ea1
8002356: Add ForkJoin common pool and CountedCompleter
dl
parents:
11279
diff
changeset
|
1160 |
* not commenced executing in another thread. This method may be |
69bfd88e3ea1
8002356: Add ForkJoin common pool and CountedCompleter
dl
parents:
11279
diff
changeset
|
1161 |
* useful when arranging alternative local processing of tasks |
69bfd88e3ea1
8002356: Add ForkJoin common pool and CountedCompleter
dl
parents:
11279
diff
changeset
|
1162 |
* that could have been, but were not, stolen. |
4110 | 1163 |
* |
1164 |
* @return {@code true} if unforked |
|
1165 |
*/ |
|
1166 |
public boolean tryUnfork() { |
|
14914
69bfd88e3ea1
8002356: Add ForkJoin common pool and CountedCompleter
dl
parents:
11279
diff
changeset
|
1167 |
Thread t; |
69bfd88e3ea1
8002356: Add ForkJoin common pool and CountedCompleter
dl
parents:
11279
diff
changeset
|
1168 |
return (((t = Thread.currentThread()) instanceof ForkJoinWorkerThread) ? |
69bfd88e3ea1
8002356: Add ForkJoin common pool and CountedCompleter
dl
parents:
11279
diff
changeset
|
1169 |
((ForkJoinWorkerThread)t).workQueue.tryUnpush(this) : |
18790 | 1170 |
ForkJoinPool.common.tryExternalUnpush(this)); |
4110 | 1171 |
} |
1172 |
||
1173 |
/** |
|
1174 |
* Returns an estimate of the number of tasks that have been |
|
1175 |
* forked by the current worker thread but not yet executed. This |
|
1176 |
* value may be useful for heuristic decisions about whether to |
|
1177 |
* fork other tasks. |
|
1178 |
* |
|
1179 |
* @return the number of tasks |
|
1180 |
*/ |
|
1181 |
public static int getQueuedTaskCount() { |
|
14914
69bfd88e3ea1
8002356: Add ForkJoin common pool and CountedCompleter
dl
parents:
11279
diff
changeset
|
1182 |
Thread t; ForkJoinPool.WorkQueue q; |
69bfd88e3ea1
8002356: Add ForkJoin common pool and CountedCompleter
dl
parents:
11279
diff
changeset
|
1183 |
if ((t = Thread.currentThread()) instanceof ForkJoinWorkerThread) |
69bfd88e3ea1
8002356: Add ForkJoin common pool and CountedCompleter
dl
parents:
11279
diff
changeset
|
1184 |
q = ((ForkJoinWorkerThread)t).workQueue; |
69bfd88e3ea1
8002356: Add ForkJoin common pool and CountedCompleter
dl
parents:
11279
diff
changeset
|
1185 |
else |
69bfd88e3ea1
8002356: Add ForkJoin common pool and CountedCompleter
dl
parents:
11279
diff
changeset
|
1186 |
q = ForkJoinPool.commonSubmitterQueue(); |
69bfd88e3ea1
8002356: Add ForkJoin common pool and CountedCompleter
dl
parents:
11279
diff
changeset
|
1187 |
return (q == null) ? 0 : q.queueSize(); |
4110 | 1188 |
} |
1189 |
||
1190 |
/** |
|
1191 |
* Returns an estimate of how many more locally queued tasks are |
|
1192 |
* held by the current worker thread than there are other worker |
|
14914
69bfd88e3ea1
8002356: Add ForkJoin common pool and CountedCompleter
dl
parents:
11279
diff
changeset
|
1193 |
* threads that might steal them, or zero if this thread is not |
69bfd88e3ea1
8002356: Add ForkJoin common pool and CountedCompleter
dl
parents:
11279
diff
changeset
|
1194 |
* operating in a ForkJoinPool. This value may be useful for |
4110 | 1195 |
* heuristic decisions about whether to fork other tasks. In many |
1196 |
* usages of ForkJoinTasks, at steady state, each worker should |
|
1197 |
* aim to maintain a small constant surplus (for example, 3) of |
|
1198 |
* tasks, and to process computations locally if this threshold is |
|
1199 |
* exceeded. |
|
1200 |
* |
|
1201 |
* @return the surplus number of tasks, which may be negative |
|
1202 |
*/ |
|
1203 |
public static int getSurplusQueuedTaskCount() { |
|
14914
69bfd88e3ea1
8002356: Add ForkJoin common pool and CountedCompleter
dl
parents:
11279
diff
changeset
|
1204 |
return ForkJoinPool.getSurplusQueuedTaskCount(); |
4110 | 1205 |
} |
1206 |
||
1207 |
// Extension methods |
|
1208 |
||
1209 |
/** |
|
1210 |
* Returns the result that would be returned by {@link #join}, even |
|
1211 |
* if this task completed abnormally, or {@code null} if this task |
|
1212 |
* is not known to have been completed. This method is designed |
|
1213 |
* to aid debugging, as well as to support extensions. Its use in |
|
1214 |
* any other context is discouraged. |
|
1215 |
* |
|
1216 |
* @return the result, or {@code null} if not completed |
|
1217 |
*/ |
|
1218 |
public abstract V getRawResult(); |
|
1219 |
||
1220 |
/** |
|
1221 |
* Forces the given value to be returned as a result. This method |
|
1222 |
* is designed to support extensions, and should not in general be |
|
1223 |
* called otherwise. |
|
1224 |
* |
|
1225 |
* @param value the value |
|
1226 |
*/ |
|
1227 |
protected abstract void setRawResult(V value); |
|
1228 |
||
1229 |
/** |
|
14914
69bfd88e3ea1
8002356: Add ForkJoin common pool and CountedCompleter
dl
parents:
11279
diff
changeset
|
1230 |
* Immediately performs the base action of this task and returns |
69bfd88e3ea1
8002356: Add ForkJoin common pool and CountedCompleter
dl
parents:
11279
diff
changeset
|
1231 |
* true if, upon return from this method, this task is guaranteed |
69bfd88e3ea1
8002356: Add ForkJoin common pool and CountedCompleter
dl
parents:
11279
diff
changeset
|
1232 |
* to have completed normally. This method may return false |
69bfd88e3ea1
8002356: Add ForkJoin common pool and CountedCompleter
dl
parents:
11279
diff
changeset
|
1233 |
* otherwise, to indicate that this task is not necessarily |
69bfd88e3ea1
8002356: Add ForkJoin common pool and CountedCompleter
dl
parents:
11279
diff
changeset
|
1234 |
* complete (or is not known to be complete), for example in |
4110 | 1235 |
* asynchronous actions that require explicit invocations of |
14914
69bfd88e3ea1
8002356: Add ForkJoin common pool and CountedCompleter
dl
parents:
11279
diff
changeset
|
1236 |
* completion methods. This method may also throw an (unchecked) |
69bfd88e3ea1
8002356: Add ForkJoin common pool and CountedCompleter
dl
parents:
11279
diff
changeset
|
1237 |
* exception to indicate abnormal exit. This method is designed to |
69bfd88e3ea1
8002356: Add ForkJoin common pool and CountedCompleter
dl
parents:
11279
diff
changeset
|
1238 |
* support extensions, and should not in general be called |
69bfd88e3ea1
8002356: Add ForkJoin common pool and CountedCompleter
dl
parents:
11279
diff
changeset
|
1239 |
* otherwise. |
4110 | 1240 |
* |
14914
69bfd88e3ea1
8002356: Add ForkJoin common pool and CountedCompleter
dl
parents:
11279
diff
changeset
|
1241 |
* @return {@code true} if this task is known to have completed normally |
4110 | 1242 |
*/ |
1243 |
protected abstract boolean exec(); |
|
1244 |
||
1245 |
/** |
|
1246 |
* Returns, but does not unschedule or execute, a task queued by |
|
1247 |
* the current thread but not yet executed, if one is immediately |
|
1248 |
* available. There is no guarantee that this task will actually |
|
1249 |
* be polled or executed next. Conversely, this method may return |
|
1250 |
* null even if a task exists but cannot be accessed without |
|
1251 |
* contention with other threads. This method is designed |
|
1252 |
* primarily to support extensions, and is unlikely to be useful |
|
1253 |
* otherwise. |
|
1254 |
* |
|
1255 |
* @return the next task, or {@code null} if none are available |
|
1256 |
*/ |
|
1257 |
protected static ForkJoinTask<?> peekNextLocalTask() { |
|
14914
69bfd88e3ea1
8002356: Add ForkJoin common pool and CountedCompleter
dl
parents:
11279
diff
changeset
|
1258 |
Thread t; ForkJoinPool.WorkQueue q; |
69bfd88e3ea1
8002356: Add ForkJoin common pool and CountedCompleter
dl
parents:
11279
diff
changeset
|
1259 |
if ((t = Thread.currentThread()) instanceof ForkJoinWorkerThread) |
69bfd88e3ea1
8002356: Add ForkJoin common pool and CountedCompleter
dl
parents:
11279
diff
changeset
|
1260 |
q = ((ForkJoinWorkerThread)t).workQueue; |
69bfd88e3ea1
8002356: Add ForkJoin common pool and CountedCompleter
dl
parents:
11279
diff
changeset
|
1261 |
else |
69bfd88e3ea1
8002356: Add ForkJoin common pool and CountedCompleter
dl
parents:
11279
diff
changeset
|
1262 |
q = ForkJoinPool.commonSubmitterQueue(); |
69bfd88e3ea1
8002356: Add ForkJoin common pool and CountedCompleter
dl
parents:
11279
diff
changeset
|
1263 |
return (q == null) ? null : q.peek(); |
4110 | 1264 |
} |
1265 |
||
1266 |
/** |
|
1267 |
* Unschedules and returns, without executing, the next task |
|
14914
69bfd88e3ea1
8002356: Add ForkJoin common pool and CountedCompleter
dl
parents:
11279
diff
changeset
|
1268 |
* queued by the current thread but not yet executed, if the |
69bfd88e3ea1
8002356: Add ForkJoin common pool and CountedCompleter
dl
parents:
11279
diff
changeset
|
1269 |
* current thread is operating in a ForkJoinPool. This method is |
69bfd88e3ea1
8002356: Add ForkJoin common pool and CountedCompleter
dl
parents:
11279
diff
changeset
|
1270 |
* designed primarily to support extensions, and is unlikely to be |
69bfd88e3ea1
8002356: Add ForkJoin common pool and CountedCompleter
dl
parents:
11279
diff
changeset
|
1271 |
* useful otherwise. |
4110 | 1272 |
* |
1273 |
* @return the next task, or {@code null} if none are available |
|
1274 |
*/ |
|
1275 |
protected static ForkJoinTask<?> pollNextLocalTask() { |
|
14914
69bfd88e3ea1
8002356: Add ForkJoin common pool and CountedCompleter
dl
parents:
11279
diff
changeset
|
1276 |
Thread t; |
69bfd88e3ea1
8002356: Add ForkJoin common pool and CountedCompleter
dl
parents:
11279
diff
changeset
|
1277 |
return ((t = Thread.currentThread()) instanceof ForkJoinWorkerThread) ? |
69bfd88e3ea1
8002356: Add ForkJoin common pool and CountedCompleter
dl
parents:
11279
diff
changeset
|
1278 |
((ForkJoinWorkerThread)t).workQueue.nextLocalTask() : |
69bfd88e3ea1
8002356: Add ForkJoin common pool and CountedCompleter
dl
parents:
11279
diff
changeset
|
1279 |
null; |
4110 | 1280 |
} |
1281 |
||
1282 |
/** |
|
14914
69bfd88e3ea1
8002356: Add ForkJoin common pool and CountedCompleter
dl
parents:
11279
diff
changeset
|
1283 |
* If the current thread is operating in a ForkJoinPool, |
69bfd88e3ea1
8002356: Add ForkJoin common pool and CountedCompleter
dl
parents:
11279
diff
changeset
|
1284 |
* unschedules and returns, without executing, the next task |
4110 | 1285 |
* queued by the current thread but not yet executed, if one is |
1286 |
* available, or if not available, a task that was forked by some |
|
1287 |
* other thread, if available. Availability may be transient, so a |
|
14914
69bfd88e3ea1
8002356: Add ForkJoin common pool and CountedCompleter
dl
parents:
11279
diff
changeset
|
1288 |
* {@code null} result does not necessarily imply quiescence of |
69bfd88e3ea1
8002356: Add ForkJoin common pool and CountedCompleter
dl
parents:
11279
diff
changeset
|
1289 |
* the pool this task is operating in. This method is designed |
4110 | 1290 |
* primarily to support extensions, and is unlikely to be useful |
1291 |
* otherwise. |
|
1292 |
* |
|
1293 |
* @return a task, or {@code null} if none are available |
|
1294 |
*/ |
|
1295 |
protected static ForkJoinTask<?> pollTask() { |
|
14914
69bfd88e3ea1
8002356: Add ForkJoin common pool and CountedCompleter
dl
parents:
11279
diff
changeset
|
1296 |
Thread t; ForkJoinWorkerThread wt; |
69bfd88e3ea1
8002356: Add ForkJoin common pool and CountedCompleter
dl
parents:
11279
diff
changeset
|
1297 |
return ((t = Thread.currentThread()) instanceof ForkJoinWorkerThread) ? |
69bfd88e3ea1
8002356: Add ForkJoin common pool and CountedCompleter
dl
parents:
11279
diff
changeset
|
1298 |
(wt = (ForkJoinWorkerThread)t).pool.nextTaskFor(wt.workQueue) : |
69bfd88e3ea1
8002356: Add ForkJoin common pool and CountedCompleter
dl
parents:
11279
diff
changeset
|
1299 |
null; |
69bfd88e3ea1
8002356: Add ForkJoin common pool and CountedCompleter
dl
parents:
11279
diff
changeset
|
1300 |
} |
69bfd88e3ea1
8002356: Add ForkJoin common pool and CountedCompleter
dl
parents:
11279
diff
changeset
|
1301 |
|
69bfd88e3ea1
8002356: Add ForkJoin common pool and CountedCompleter
dl
parents:
11279
diff
changeset
|
1302 |
// tag operations |
69bfd88e3ea1
8002356: Add ForkJoin common pool and CountedCompleter
dl
parents:
11279
diff
changeset
|
1303 |
|
69bfd88e3ea1
8002356: Add ForkJoin common pool and CountedCompleter
dl
parents:
11279
diff
changeset
|
1304 |
/** |
69bfd88e3ea1
8002356: Add ForkJoin common pool and CountedCompleter
dl
parents:
11279
diff
changeset
|
1305 |
* Returns the tag for this task. |
69bfd88e3ea1
8002356: Add ForkJoin common pool and CountedCompleter
dl
parents:
11279
diff
changeset
|
1306 |
* |
69bfd88e3ea1
8002356: Add ForkJoin common pool and CountedCompleter
dl
parents:
11279
diff
changeset
|
1307 |
* @return the tag for this task |
69bfd88e3ea1
8002356: Add ForkJoin common pool and CountedCompleter
dl
parents:
11279
diff
changeset
|
1308 |
* @since 1.8 |
69bfd88e3ea1
8002356: Add ForkJoin common pool and CountedCompleter
dl
parents:
11279
diff
changeset
|
1309 |
*/ |
69bfd88e3ea1
8002356: Add ForkJoin common pool and CountedCompleter
dl
parents:
11279
diff
changeset
|
1310 |
public final short getForkJoinTaskTag() { |
69bfd88e3ea1
8002356: Add ForkJoin common pool and CountedCompleter
dl
parents:
11279
diff
changeset
|
1311 |
return (short)status; |
69bfd88e3ea1
8002356: Add ForkJoin common pool and CountedCompleter
dl
parents:
11279
diff
changeset
|
1312 |
} |
69bfd88e3ea1
8002356: Add ForkJoin common pool and CountedCompleter
dl
parents:
11279
diff
changeset
|
1313 |
|
69bfd88e3ea1
8002356: Add ForkJoin common pool and CountedCompleter
dl
parents:
11279
diff
changeset
|
1314 |
/** |
69bfd88e3ea1
8002356: Add ForkJoin common pool and CountedCompleter
dl
parents:
11279
diff
changeset
|
1315 |
* Atomically sets the tag value for this task. |
69bfd88e3ea1
8002356: Add ForkJoin common pool and CountedCompleter
dl
parents:
11279
diff
changeset
|
1316 |
* |
69bfd88e3ea1
8002356: Add ForkJoin common pool and CountedCompleter
dl
parents:
11279
diff
changeset
|
1317 |
* @param tag the tag value |
69bfd88e3ea1
8002356: Add ForkJoin common pool and CountedCompleter
dl
parents:
11279
diff
changeset
|
1318 |
* @return the previous value of the tag |
69bfd88e3ea1
8002356: Add ForkJoin common pool and CountedCompleter
dl
parents:
11279
diff
changeset
|
1319 |
* @since 1.8 |
69bfd88e3ea1
8002356: Add ForkJoin common pool and CountedCompleter
dl
parents:
11279
diff
changeset
|
1320 |
*/ |
69bfd88e3ea1
8002356: Add ForkJoin common pool and CountedCompleter
dl
parents:
11279
diff
changeset
|
1321 |
public final short setForkJoinTaskTag(short tag) { |
69bfd88e3ea1
8002356: Add ForkJoin common pool and CountedCompleter
dl
parents:
11279
diff
changeset
|
1322 |
for (int s;;) { |
69bfd88e3ea1
8002356: Add ForkJoin common pool and CountedCompleter
dl
parents:
11279
diff
changeset
|
1323 |
if (U.compareAndSwapInt(this, STATUS, s = status, |
69bfd88e3ea1
8002356: Add ForkJoin common pool and CountedCompleter
dl
parents:
11279
diff
changeset
|
1324 |
(s & ~SMASK) | (tag & SMASK))) |
69bfd88e3ea1
8002356: Add ForkJoin common pool and CountedCompleter
dl
parents:
11279
diff
changeset
|
1325 |
return (short)s; |
69bfd88e3ea1
8002356: Add ForkJoin common pool and CountedCompleter
dl
parents:
11279
diff
changeset
|
1326 |
} |
69bfd88e3ea1
8002356: Add ForkJoin common pool and CountedCompleter
dl
parents:
11279
diff
changeset
|
1327 |
} |
69bfd88e3ea1
8002356: Add ForkJoin common pool and CountedCompleter
dl
parents:
11279
diff
changeset
|
1328 |
|
69bfd88e3ea1
8002356: Add ForkJoin common pool and CountedCompleter
dl
parents:
11279
diff
changeset
|
1329 |
/** |
69bfd88e3ea1
8002356: Add ForkJoin common pool and CountedCompleter
dl
parents:
11279
diff
changeset
|
1330 |
* Atomically conditionally sets the tag value for this task. |
69bfd88e3ea1
8002356: Add ForkJoin common pool and CountedCompleter
dl
parents:
11279
diff
changeset
|
1331 |
* Among other applications, tags can be used as visit markers |
69bfd88e3ea1
8002356: Add ForkJoin common pool and CountedCompleter
dl
parents:
11279
diff
changeset
|
1332 |
* in tasks operating on graphs, as in methods that check: {@code |
69bfd88e3ea1
8002356: Add ForkJoin common pool and CountedCompleter
dl
parents:
11279
diff
changeset
|
1333 |
* if (task.compareAndSetForkJoinTaskTag((short)0, (short)1))} |
69bfd88e3ea1
8002356: Add ForkJoin common pool and CountedCompleter
dl
parents:
11279
diff
changeset
|
1334 |
* before processing, otherwise exiting because the node has |
69bfd88e3ea1
8002356: Add ForkJoin common pool and CountedCompleter
dl
parents:
11279
diff
changeset
|
1335 |
* already been visited. |
69bfd88e3ea1
8002356: Add ForkJoin common pool and CountedCompleter
dl
parents:
11279
diff
changeset
|
1336 |
* |
69bfd88e3ea1
8002356: Add ForkJoin common pool and CountedCompleter
dl
parents:
11279
diff
changeset
|
1337 |
* @param e the expected tag value |
69bfd88e3ea1
8002356: Add ForkJoin common pool and CountedCompleter
dl
parents:
11279
diff
changeset
|
1338 |
* @param tag the new tag value |
18790 | 1339 |
* @return {@code true} if successful; i.e., the current value was |
14914
69bfd88e3ea1
8002356: Add ForkJoin common pool and CountedCompleter
dl
parents:
11279
diff
changeset
|
1340 |
* equal to e and is now tag. |
69bfd88e3ea1
8002356: Add ForkJoin common pool and CountedCompleter
dl
parents:
11279
diff
changeset
|
1341 |
* @since 1.8 |
69bfd88e3ea1
8002356: Add ForkJoin common pool and CountedCompleter
dl
parents:
11279
diff
changeset
|
1342 |
*/ |
69bfd88e3ea1
8002356: Add ForkJoin common pool and CountedCompleter
dl
parents:
11279
diff
changeset
|
1343 |
public final boolean compareAndSetForkJoinTaskTag(short e, short tag) { |
69bfd88e3ea1
8002356: Add ForkJoin common pool and CountedCompleter
dl
parents:
11279
diff
changeset
|
1344 |
for (int s;;) { |
69bfd88e3ea1
8002356: Add ForkJoin common pool and CountedCompleter
dl
parents:
11279
diff
changeset
|
1345 |
if ((short)(s = status) != e) |
69bfd88e3ea1
8002356: Add ForkJoin common pool and CountedCompleter
dl
parents:
11279
diff
changeset
|
1346 |
return false; |
69bfd88e3ea1
8002356: Add ForkJoin common pool and CountedCompleter
dl
parents:
11279
diff
changeset
|
1347 |
if (U.compareAndSwapInt(this, STATUS, s, |
69bfd88e3ea1
8002356: Add ForkJoin common pool and CountedCompleter
dl
parents:
11279
diff
changeset
|
1348 |
(s & ~SMASK) | (tag & SMASK))) |
69bfd88e3ea1
8002356: Add ForkJoin common pool and CountedCompleter
dl
parents:
11279
diff
changeset
|
1349 |
return true; |
69bfd88e3ea1
8002356: Add ForkJoin common pool and CountedCompleter
dl
parents:
11279
diff
changeset
|
1350 |
} |
4110 | 1351 |
} |
1352 |
||
1353 |
/** |
|
1354 |
* Adaptor for Runnables. This implements RunnableFuture |
|
1355 |
* to be compliant with AbstractExecutorService constraints |
|
1356 |
* when used in ForkJoinPool. |
|
1357 |
*/ |
|
1358 |
static final class AdaptedRunnable<T> extends ForkJoinTask<T> |
|
1359 |
implements RunnableFuture<T> { |
|
1360 |
final Runnable runnable; |
|
1361 |
T result; |
|
1362 |
AdaptedRunnable(Runnable runnable, T result) { |
|
1363 |
if (runnable == null) throw new NullPointerException(); |
|
1364 |
this.runnable = runnable; |
|
14914
69bfd88e3ea1
8002356: Add ForkJoin common pool and CountedCompleter
dl
parents:
11279
diff
changeset
|
1365 |
this.result = result; // OK to set this even before completion |
4110 | 1366 |
} |
14914
69bfd88e3ea1
8002356: Add ForkJoin common pool and CountedCompleter
dl
parents:
11279
diff
changeset
|
1367 |
public final T getRawResult() { return result; } |
69bfd88e3ea1
8002356: Add ForkJoin common pool and CountedCompleter
dl
parents:
11279
diff
changeset
|
1368 |
public final void setRawResult(T v) { result = v; } |
69bfd88e3ea1
8002356: Add ForkJoin common pool and CountedCompleter
dl
parents:
11279
diff
changeset
|
1369 |
public final boolean exec() { runnable.run(); return true; } |
69bfd88e3ea1
8002356: Add ForkJoin common pool and CountedCompleter
dl
parents:
11279
diff
changeset
|
1370 |
public final void run() { invoke(); } |
69bfd88e3ea1
8002356: Add ForkJoin common pool and CountedCompleter
dl
parents:
11279
diff
changeset
|
1371 |
private static final long serialVersionUID = 5232453952276885070L; |
69bfd88e3ea1
8002356: Add ForkJoin common pool and CountedCompleter
dl
parents:
11279
diff
changeset
|
1372 |
} |
69bfd88e3ea1
8002356: Add ForkJoin common pool and CountedCompleter
dl
parents:
11279
diff
changeset
|
1373 |
|
69bfd88e3ea1
8002356: Add ForkJoin common pool and CountedCompleter
dl
parents:
11279
diff
changeset
|
1374 |
/** |
69bfd88e3ea1
8002356: Add ForkJoin common pool and CountedCompleter
dl
parents:
11279
diff
changeset
|
1375 |
* Adaptor for Runnables without results |
69bfd88e3ea1
8002356: Add ForkJoin common pool and CountedCompleter
dl
parents:
11279
diff
changeset
|
1376 |
*/ |
69bfd88e3ea1
8002356: Add ForkJoin common pool and CountedCompleter
dl
parents:
11279
diff
changeset
|
1377 |
static final class AdaptedRunnableAction extends ForkJoinTask<Void> |
69bfd88e3ea1
8002356: Add ForkJoin common pool and CountedCompleter
dl
parents:
11279
diff
changeset
|
1378 |
implements RunnableFuture<Void> { |
69bfd88e3ea1
8002356: Add ForkJoin common pool and CountedCompleter
dl
parents:
11279
diff
changeset
|
1379 |
final Runnable runnable; |
69bfd88e3ea1
8002356: Add ForkJoin common pool and CountedCompleter
dl
parents:
11279
diff
changeset
|
1380 |
AdaptedRunnableAction(Runnable runnable) { |
69bfd88e3ea1
8002356: Add ForkJoin common pool and CountedCompleter
dl
parents:
11279
diff
changeset
|
1381 |
if (runnable == null) throw new NullPointerException(); |
69bfd88e3ea1
8002356: Add ForkJoin common pool and CountedCompleter
dl
parents:
11279
diff
changeset
|
1382 |
this.runnable = runnable; |
4110 | 1383 |
} |
14914
69bfd88e3ea1
8002356: Add ForkJoin common pool and CountedCompleter
dl
parents:
11279
diff
changeset
|
1384 |
public final Void getRawResult() { return null; } |
69bfd88e3ea1
8002356: Add ForkJoin common pool and CountedCompleter
dl
parents:
11279
diff
changeset
|
1385 |
public final void setRawResult(Void v) { } |
69bfd88e3ea1
8002356: Add ForkJoin common pool and CountedCompleter
dl
parents:
11279
diff
changeset
|
1386 |
public final boolean exec() { runnable.run(); return true; } |
69bfd88e3ea1
8002356: Add ForkJoin common pool and CountedCompleter
dl
parents:
11279
diff
changeset
|
1387 |
public final void run() { invoke(); } |
4110 | 1388 |
private static final long serialVersionUID = 5232453952276885070L; |
1389 |
} |
|
1390 |
||
1391 |
/** |
|
16049
92a3a919d4dc
8008378: FJP.commonPool support parallelism 0, add awaitQuiescence
chegar
parents:
14914
diff
changeset
|
1392 |
* Adaptor for Runnables in which failure forces worker exception |
92a3a919d4dc
8008378: FJP.commonPool support parallelism 0, add awaitQuiescence
chegar
parents:
14914
diff
changeset
|
1393 |
*/ |
92a3a919d4dc
8008378: FJP.commonPool support parallelism 0, add awaitQuiescence
chegar
parents:
14914
diff
changeset
|
1394 |
static final class RunnableExecuteAction extends ForkJoinTask<Void> { |
92a3a919d4dc
8008378: FJP.commonPool support parallelism 0, add awaitQuiescence
chegar
parents:
14914
diff
changeset
|
1395 |
final Runnable runnable; |
92a3a919d4dc
8008378: FJP.commonPool support parallelism 0, add awaitQuiescence
chegar
parents:
14914
diff
changeset
|
1396 |
RunnableExecuteAction(Runnable runnable) { |
92a3a919d4dc
8008378: FJP.commonPool support parallelism 0, add awaitQuiescence
chegar
parents:
14914
diff
changeset
|
1397 |
if (runnable == null) throw new NullPointerException(); |
92a3a919d4dc
8008378: FJP.commonPool support parallelism 0, add awaitQuiescence
chegar
parents:
14914
diff
changeset
|
1398 |
this.runnable = runnable; |
92a3a919d4dc
8008378: FJP.commonPool support parallelism 0, add awaitQuiescence
chegar
parents:
14914
diff
changeset
|
1399 |
} |
92a3a919d4dc
8008378: FJP.commonPool support parallelism 0, add awaitQuiescence
chegar
parents:
14914
diff
changeset
|
1400 |
public final Void getRawResult() { return null; } |
92a3a919d4dc
8008378: FJP.commonPool support parallelism 0, add awaitQuiescence
chegar
parents:
14914
diff
changeset
|
1401 |
public final void setRawResult(Void v) { } |
92a3a919d4dc
8008378: FJP.commonPool support parallelism 0, add awaitQuiescence
chegar
parents:
14914
diff
changeset
|
1402 |
public final boolean exec() { runnable.run(); return true; } |
92a3a919d4dc
8008378: FJP.commonPool support parallelism 0, add awaitQuiescence
chegar
parents:
14914
diff
changeset
|
1403 |
void internalPropagateException(Throwable ex) { |
92a3a919d4dc
8008378: FJP.commonPool support parallelism 0, add awaitQuiescence
chegar
parents:
14914
diff
changeset
|
1404 |
rethrow(ex); // rethrow outside exec() catches. |
92a3a919d4dc
8008378: FJP.commonPool support parallelism 0, add awaitQuiescence
chegar
parents:
14914
diff
changeset
|
1405 |
} |
92a3a919d4dc
8008378: FJP.commonPool support parallelism 0, add awaitQuiescence
chegar
parents:
14914
diff
changeset
|
1406 |
private static final long serialVersionUID = 5232453952276885070L; |
92a3a919d4dc
8008378: FJP.commonPool support parallelism 0, add awaitQuiescence
chegar
parents:
14914
diff
changeset
|
1407 |
} |
92a3a919d4dc
8008378: FJP.commonPool support parallelism 0, add awaitQuiescence
chegar
parents:
14914
diff
changeset
|
1408 |
|
92a3a919d4dc
8008378: FJP.commonPool support parallelism 0, add awaitQuiescence
chegar
parents:
14914
diff
changeset
|
1409 |
/** |
4110 | 1410 |
* Adaptor for Callables |
1411 |
*/ |
|
1412 |
static final class AdaptedCallable<T> extends ForkJoinTask<T> |
|
1413 |
implements RunnableFuture<T> { |
|
1414 |
final Callable<? extends T> callable; |
|
1415 |
T result; |
|
1416 |
AdaptedCallable(Callable<? extends T> callable) { |
|
1417 |
if (callable == null) throw new NullPointerException(); |
|
1418 |
this.callable = callable; |
|
1419 |
} |
|
14914
69bfd88e3ea1
8002356: Add ForkJoin common pool and CountedCompleter
dl
parents:
11279
diff
changeset
|
1420 |
public final T getRawResult() { return result; } |
69bfd88e3ea1
8002356: Add ForkJoin common pool and CountedCompleter
dl
parents:
11279
diff
changeset
|
1421 |
public final void setRawResult(T v) { result = v; } |
69bfd88e3ea1
8002356: Add ForkJoin common pool and CountedCompleter
dl
parents:
11279
diff
changeset
|
1422 |
public final boolean exec() { |
4110 | 1423 |
try { |
1424 |
result = callable.call(); |
|
1425 |
return true; |
|
1426 |
} catch (Error err) { |
|
1427 |
throw err; |
|
1428 |
} catch (RuntimeException rex) { |
|
1429 |
throw rex; |
|
1430 |
} catch (Exception ex) { |
|
1431 |
throw new RuntimeException(ex); |
|
1432 |
} |
|
1433 |
} |
|
14914
69bfd88e3ea1
8002356: Add ForkJoin common pool and CountedCompleter
dl
parents:
11279
diff
changeset
|
1434 |
public final void run() { invoke(); } |
4110 | 1435 |
private static final long serialVersionUID = 2838392045355241008L; |
1436 |
} |
|
1437 |
||
1438 |
/** |
|
1439 |
* Returns a new {@code ForkJoinTask} that performs the {@code run} |
|
1440 |
* method of the given {@code Runnable} as its action, and returns |
|
1441 |
* a null result upon {@link #join}. |
|
1442 |
* |
|
1443 |
* @param runnable the runnable action |
|
1444 |
* @return the task |
|
1445 |
*/ |
|
1446 |
public static ForkJoinTask<?> adapt(Runnable runnable) { |
|
14914
69bfd88e3ea1
8002356: Add ForkJoin common pool and CountedCompleter
dl
parents:
11279
diff
changeset
|
1447 |
return new AdaptedRunnableAction(runnable); |
4110 | 1448 |
} |
1449 |
||
1450 |
/** |
|
1451 |
* Returns a new {@code ForkJoinTask} that performs the {@code run} |
|
1452 |
* method of the given {@code Runnable} as its action, and returns |
|
1453 |
* the given result upon {@link #join}. |
|
1454 |
* |
|
1455 |
* @param runnable the runnable action |
|
1456 |
* @param result the result upon completion |
|
19048
7d0a94c79779
8021417: Fix doclint issues in java.util.concurrent
chegar
parents:
18790
diff
changeset
|
1457 |
* @param <T> the type of the result |
4110 | 1458 |
* @return the task |
1459 |
*/ |
|
1460 |
public static <T> ForkJoinTask<T> adapt(Runnable runnable, T result) { |
|
1461 |
return new AdaptedRunnable<T>(runnable, result); |
|
1462 |
} |
|
1463 |
||
1464 |
/** |
|
1465 |
* Returns a new {@code ForkJoinTask} that performs the {@code call} |
|
1466 |
* method of the given {@code Callable} as its action, and returns |
|
1467 |
* its result upon {@link #join}, translating any checked exceptions |
|
1468 |
* encountered into {@code RuntimeException}. |
|
1469 |
* |
|
1470 |
* @param callable the callable action |
|
19048
7d0a94c79779
8021417: Fix doclint issues in java.util.concurrent
chegar
parents:
18790
diff
changeset
|
1471 |
* @param <T> the type of the callable's result |
4110 | 1472 |
* @return the task |
1473 |
*/ |
|
1474 |
public static <T> ForkJoinTask<T> adapt(Callable<? extends T> callable) { |
|
1475 |
return new AdaptedCallable<T>(callable); |
|
1476 |
} |
|
1477 |
||
1478 |
// Serialization support |
|
1479 |
||
1480 |
private static final long serialVersionUID = -7721805057305804111L; |
|
1481 |
||
1482 |
/** |
|
14914
69bfd88e3ea1
8002356: Add ForkJoin common pool and CountedCompleter
dl
parents:
11279
diff
changeset
|
1483 |
* Saves this task to a stream (that is, serializes it). |
4110 | 1484 |
* |
19048
7d0a94c79779
8021417: Fix doclint issues in java.util.concurrent
chegar
parents:
18790
diff
changeset
|
1485 |
* @param s the stream |
7d0a94c79779
8021417: Fix doclint issues in java.util.concurrent
chegar
parents:
18790
diff
changeset
|
1486 |
* @throws java.io.IOException if an I/O error occurs |
4110 | 1487 |
* @serialData the current run status and the exception thrown |
1488 |
* during execution, or {@code null} if none |
|
1489 |
*/ |
|
1490 |
private void writeObject(java.io.ObjectOutputStream s) |
|
1491 |
throws java.io.IOException { |
|
1492 |
s.defaultWriteObject(); |
|
1493 |
s.writeObject(getException()); |
|
1494 |
} |
|
1495 |
||
1496 |
/** |
|
14914
69bfd88e3ea1
8002356: Add ForkJoin common pool and CountedCompleter
dl
parents:
11279
diff
changeset
|
1497 |
* Reconstitutes this task from a stream (that is, deserializes it). |
19048
7d0a94c79779
8021417: Fix doclint issues in java.util.concurrent
chegar
parents:
18790
diff
changeset
|
1498 |
* @param s the stream |
7d0a94c79779
8021417: Fix doclint issues in java.util.concurrent
chegar
parents:
18790
diff
changeset
|
1499 |
* @throws ClassNotFoundException if the class of a serialized object |
7d0a94c79779
8021417: Fix doclint issues in java.util.concurrent
chegar
parents:
18790
diff
changeset
|
1500 |
* could not be found |
7d0a94c79779
8021417: Fix doclint issues in java.util.concurrent
chegar
parents:
18790
diff
changeset
|
1501 |
* @throws java.io.IOException if an I/O error occurs |
4110 | 1502 |
*/ |
1503 |
private void readObject(java.io.ObjectInputStream s) |
|
1504 |
throws java.io.IOException, ClassNotFoundException { |
|
1505 |
s.defaultReadObject(); |
|
1506 |
Object ex = s.readObject(); |
|
1507 |
if (ex != null) |
|
8765
dfc2a131d08a
7023006: Reduce unnecessary thread activity in ForkJoinPool
dl
parents:
7976
diff
changeset
|
1508 |
setExceptionalCompletion((Throwable)ex); |
4110 | 1509 |
} |
1510 |
||
1511 |
// Unsafe mechanics |
|
14914
69bfd88e3ea1
8002356: Add ForkJoin common pool and CountedCompleter
dl
parents:
11279
diff
changeset
|
1512 |
private static final sun.misc.Unsafe U; |
69bfd88e3ea1
8002356: Add ForkJoin common pool and CountedCompleter
dl
parents:
11279
diff
changeset
|
1513 |
private static final long STATUS; |
69bfd88e3ea1
8002356: Add ForkJoin common pool and CountedCompleter
dl
parents:
11279
diff
changeset
|
1514 |
|
8765
dfc2a131d08a
7023006: Reduce unnecessary thread activity in ForkJoinPool
dl
parents:
7976
diff
changeset
|
1515 |
static { |
dfc2a131d08a
7023006: Reduce unnecessary thread activity in ForkJoinPool
dl
parents:
7976
diff
changeset
|
1516 |
exceptionTableLock = new ReentrantLock(); |
dfc2a131d08a
7023006: Reduce unnecessary thread activity in ForkJoinPool
dl
parents:
7976
diff
changeset
|
1517 |
exceptionTableRefQueue = new ReferenceQueue<Object>(); |
dfc2a131d08a
7023006: Reduce unnecessary thread activity in ForkJoinPool
dl
parents:
7976
diff
changeset
|
1518 |
exceptionTable = new ExceptionNode[EXCEPTION_MAP_CAPACITY]; |
4110 | 1519 |
try { |
14914
69bfd88e3ea1
8002356: Add ForkJoin common pool and CountedCompleter
dl
parents:
11279
diff
changeset
|
1520 |
U = sun.misc.Unsafe.getUnsafe(); |
69bfd88e3ea1
8002356: Add ForkJoin common pool and CountedCompleter
dl
parents:
11279
diff
changeset
|
1521 |
Class<?> k = ForkJoinTask.class; |
69bfd88e3ea1
8002356: Add ForkJoin common pool and CountedCompleter
dl
parents:
11279
diff
changeset
|
1522 |
STATUS = U.objectFieldOffset |
69bfd88e3ea1
8002356: Add ForkJoin common pool and CountedCompleter
dl
parents:
11279
diff
changeset
|
1523 |
(k.getDeclaredField("status")); |
8765
dfc2a131d08a
7023006: Reduce unnecessary thread activity in ForkJoinPool
dl
parents:
7976
diff
changeset
|
1524 |
} catch (Exception e) { |
dfc2a131d08a
7023006: Reduce unnecessary thread activity in ForkJoinPool
dl
parents:
7976
diff
changeset
|
1525 |
throw new Error(e); |
4110 | 1526 |
} |
1527 |
} |
|
8765
dfc2a131d08a
7023006: Reduce unnecessary thread activity in ForkJoinPool
dl
parents:
7976
diff
changeset
|
1528 |
|
4110 | 1529 |
} |