708 |
|
* shared-queue version is embedded in method externalPush.) |
709 |
|
* |
710 |
|
* @param task the task. Caller must ensure non-null. |
711 |
< |
* @throw RejectedExecutionException if array cannot be resized |
711 |
> |
* @throws RejectedExecutionException if array cannot be resized |
712 |
|
*/ |
713 |
|
final void push(ForkJoinTask<?> task) { |
714 |
|
ForkJoinTask<?>[] a; ForkJoinPool p; |
1026 |
|
private static final int ABASE; |
1027 |
|
private static final int ASHIFT; |
1028 |
|
static { |
1029 |
– |
int s; |
1029 |
|
try { |
1030 |
|
U = getUnsafe(); |
1031 |
|
Class<?> k = WorkQueue.class; |
1033 |
|
QLOCK = U.objectFieldOffset |
1034 |
|
(k.getDeclaredField("qlock")); |
1035 |
|
ABASE = U.arrayBaseOffset(ak); |
1036 |
< |
s = U.arrayIndexScale(ak); |
1036 |
> |
int scale = U.arrayIndexScale(ak); |
1037 |
> |
if ((scale & (scale - 1)) != 0) |
1038 |
> |
throw new Error("data type scale not a power of two"); |
1039 |
> |
ASHIFT = 31 - Integer.numberOfLeadingZeros(scale); |
1040 |
|
} catch (Exception e) { |
1041 |
|
throw new Error(e); |
1042 |
|
} |
1041 |
– |
if ((s & (s-1)) != 0) |
1042 |
– |
throw new Error("data type scale not a power of two"); |
1043 |
– |
ASHIFT = 31 - Integer.numberOfLeadingZeros(s); |
1043 |
|
} |
1044 |
|
} |
1045 |
|
|
1244 |
|
volatile Object pad10, pad11, pad12, pad13, pad14, pad15, pad16, pad17; |
1245 |
|
volatile Object pad18, pad19, pad1a, pad1b; |
1246 |
|
|
1247 |
< |
/* |
1247 |
> |
/** |
1248 |
|
* Acquires the plock lock to protect worker array and related |
1249 |
|
* updates. This method is called only if an initial CAS on plock |
1250 |
< |
* fails. This acts as a spinLock for normal cases, but falls back |
1250 |
> |
* fails. This acts as a spinlock for normal cases, but falls back |
1251 |
|
* to builtin monitor to block when (rarely) needed. This would be |
1252 |
|
* a terrible idea for a highly contended lock, but works fine as |
1253 |
|
* a more conservative alternative to a pure spinlock. |
2685 |
|
// In previous versions of this class, this method constructed |
2686 |
|
// a task to run ForkJoinTask.invokeAll, but now external |
2687 |
|
// invocation of multiple tasks is at least as efficient. |
2688 |
< |
List<ForkJoinTask<T>> fs = new ArrayList<ForkJoinTask<T>>(tasks.size()); |
2690 |
< |
// Workaround needed because method wasn't declared with |
2691 |
< |
// wildcards in return type but should have been. |
2692 |
< |
@SuppressWarnings({"unchecked", "rawtypes"}) |
2693 |
< |
List<Future<T>> futures = (List<Future<T>>) (List) fs; |
2688 |
> |
ArrayList<Future<T>> futures = new ArrayList<Future<T>>(tasks.size()); |
2689 |
|
|
2690 |
|
boolean done = false; |
2691 |
|
try { |
2692 |
|
for (Callable<T> t : tasks) { |
2693 |
|
ForkJoinTask<T> f = new ForkJoinTask.AdaptedCallable<T>(t); |
2694 |
+ |
futures.add(f); |
2695 |
|
externalPush(f); |
2700 |
– |
fs.add(f); |
2696 |
|
} |
2697 |
< |
for (ForkJoinTask<T> f : fs) |
2698 |
< |
f.quietlyJoin(); |
2697 |
> |
for (int i = 0, size = futures.size(); i < size; i++) |
2698 |
> |
((ForkJoinTask<?>)futures.get(i)).quietlyJoin(); |
2699 |
|
done = true; |
2700 |
|
return futures; |
2701 |
|
} finally { |
2702 |
|
if (!done) |
2703 |
< |
for (ForkJoinTask<T> f : fs) |
2704 |
< |
f.cancel(false); |
2703 |
> |
for (int i = 0, size = futures.size(); i < size; i++) |
2704 |
> |
futures.get(i).cancel(false); |
2705 |
|
} |
2706 |
|
} |
2707 |
|
|
3325 |
|
private static final long QLOCK; |
3326 |
|
|
3327 |
|
static { |
3328 |
< |
int s; // initialize field offsets for CAS etc |
3328 |
> |
// initialize field offsets for CAS etc |
3329 |
|
try { |
3330 |
|
U = getUnsafe(); |
3331 |
|
Class<?> k = ForkJoinPool.class; |
3345 |
|
(wk.getDeclaredField("qlock")); |
3346 |
|
Class<?> ak = ForkJoinTask[].class; |
3347 |
|
ABASE = U.arrayBaseOffset(ak); |
3348 |
< |
s = U.arrayIndexScale(ak); |
3349 |
< |
ASHIFT = 31 - Integer.numberOfLeadingZeros(s); |
3348 |
> |
int scale = U.arrayIndexScale(ak); |
3349 |
> |
if ((scale & (scale - 1)) != 0) |
3350 |
> |
throw new Error("data type scale not a power of two"); |
3351 |
> |
ASHIFT = 31 - Integer.numberOfLeadingZeros(scale); |
3352 |
|
} catch (Exception e) { |
3353 |
|
throw new Error(e); |
3354 |
|
} |
3358 |
– |
if ((s & (s-1)) != 0) |
3359 |
– |
throw new Error("data type scale not a power of two"); |
3355 |
|
|
3356 |
|
submitters = new ThreadLocal<Submitter>(); |
3357 |
|
ForkJoinWorkerThreadFactory fac = defaultForkJoinWorkerThreadFactory = |