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 |
|
|
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. |
2558 |
|
* exit. |
2559 |
|
* |
2560 |
|
* @return the common pool instance |
2561 |
+ |
* @since 1.8 |
2562 |
|
*/ |
2563 |
|
public static ForkJoinPool commonPool() { |
2564 |
|
// assert common != null : "static init error"; |
2741 |
|
* Returns the targeted parallelism level of the common pool. |
2742 |
|
* |
2743 |
|
* @return the targeted parallelism level of the common pool |
2744 |
+ |
* @since 1.8 |
2745 |
|
*/ |
2746 |
|
public static int getCommonPoolParallelism() { |
2747 |
|
return commonParallelism; |
3002 |
|
* Possibly initiates an orderly shutdown in which previously |
3003 |
|
* submitted tasks are executed, but no new tasks will be |
3004 |
|
* accepted. Invocation has no effect on execution state if this |
3005 |
< |
* is the {@link #commonPool}, and no additional effect if |
3005 |
> |
* is the {@link #commonPool()}, and no additional effect if |
3006 |
|
* already shut down. Tasks that are in the process of being |
3007 |
|
* submitted concurrently during the course of this method may or |
3008 |
|
* may not be rejected. |
3020 |
|
/** |
3021 |
|
* Possibly attempts to cancel and/or stop all tasks, and reject |
3022 |
|
* all subsequently submitted tasks. Invocation has no effect on |
3023 |
< |
* execution state if this is the {@link #commonPool}, and no |
3023 |
> |
* execution state if this is the {@link #commonPool()}, and no |
3024 |
|
* additional effect if already shut down. Otherwise, tasks that |
3025 |
|
* are in the process of being submitted or executed concurrently |
3026 |
|
* during the course of this method may or may not be |
3329 |
|
private static final long QLOCK; |
3330 |
|
|
3331 |
|
static { |
3332 |
< |
int s; // initialize field offsets for CAS etc |
3332 |
> |
// initialize field offsets for CAS etc |
3333 |
|
try { |
3334 |
|
U = getUnsafe(); |
3335 |
|
Class<?> k = ForkJoinPool.class; |
3349 |
|
(wk.getDeclaredField("qlock")); |
3350 |
|
Class<?> ak = ForkJoinTask[].class; |
3351 |
|
ABASE = U.arrayBaseOffset(ak); |
3352 |
< |
s = U.arrayIndexScale(ak); |
3353 |
< |
ASHIFT = 31 - Integer.numberOfLeadingZeros(s); |
3352 |
> |
int scale = U.arrayIndexScale(ak); |
3353 |
> |
if ((scale & (scale - 1)) != 0) |
3354 |
> |
throw new Error("data type scale not a power of two"); |
3355 |
> |
ASHIFT = 31 - Integer.numberOfLeadingZeros(scale); |
3356 |
|
} catch (Exception e) { |
3357 |
|
throw new Error(e); |
3358 |
|
} |
3356 |
– |
if ((s & (s-1)) != 0) |
3357 |
– |
throw new Error("data type scale not a power of two"); |
3359 |
|
|
3360 |
|
submitters = new ThreadLocal<Submitter>(); |
3361 |
|
ForkJoinWorkerThreadFactory fac = defaultForkJoinWorkerThreadFactory = |
3409 |
|
private static sun.misc.Unsafe getUnsafe() { |
3410 |
|
try { |
3411 |
|
return sun.misc.Unsafe.getUnsafe(); |
3412 |
< |
} catch (SecurityException se) { |
3413 |
< |
try { |
3414 |
< |
return java.security.AccessController.doPrivileged |
3415 |
< |
(new java.security |
3416 |
< |
.PrivilegedExceptionAction<sun.misc.Unsafe>() { |
3417 |
< |
public sun.misc.Unsafe run() throws Exception { |
3418 |
< |
java.lang.reflect.Field f = sun.misc |
3419 |
< |
.Unsafe.class.getDeclaredField("theUnsafe"); |
3420 |
< |
f.setAccessible(true); |
3421 |
< |
return (sun.misc.Unsafe) f.get(null); |
3422 |
< |
}}); |
3423 |
< |
} catch (java.security.PrivilegedActionException e) { |
3424 |
< |
throw new RuntimeException("Could not initialize intrinsics", |
3425 |
< |
e.getCause()); |
3426 |
< |
} |
3412 |
> |
} catch (SecurityException tryReflectionInstead) {} |
3413 |
> |
try { |
3414 |
> |
return java.security.AccessController.doPrivileged |
3415 |
> |
(new java.security.PrivilegedExceptionAction<sun.misc.Unsafe>() { |
3416 |
> |
public sun.misc.Unsafe run() throws Exception { |
3417 |
> |
Class<sun.misc.Unsafe> k = sun.misc.Unsafe.class; |
3418 |
> |
for (java.lang.reflect.Field f : k.getDeclaredFields()) { |
3419 |
> |
f.setAccessible(true); |
3420 |
> |
Object x = f.get(null); |
3421 |
> |
if (k.isInstance(x)) |
3422 |
> |
return k.cast(x); |
3423 |
> |
} |
3424 |
> |
throw new NoSuchFieldError("the Unsafe"); |
3425 |
> |
}}); |
3426 |
> |
} catch (java.security.PrivilegedActionException e) { |
3427 |
> |
throw new RuntimeException("Could not initialize intrinsics", |
3428 |
> |
e.getCause()); |
3429 |
|
} |
3430 |
|
} |
3428 |
– |
|
3431 |
|
} |