926 |
|
protected abstract boolean exec(); |
927 |
|
|
928 |
|
/** |
929 |
< |
* Returns, but does not unschedule or execute, the task most |
930 |
< |
* recently forked by the current thread but not yet executed, if |
931 |
< |
* one is available. There is no guarantee that this task will |
932 |
< |
* actually be polled or executed next. |
933 |
< |
* This method is designed primarily to support extensions, |
934 |
< |
* and is unlikely to be useful otherwise. |
935 |
< |
* This method may be invoked only from within |
936 |
< |
* ForkJoinTask computations. Attempts to invoke in other contexts |
937 |
< |
* result in exceptions or errors possibly including ClassCastException. |
929 |
> |
* Returns, but does not unschedule or execute, the task queued by |
930 |
> |
* the current thread but not yet executed, if one is |
931 |
> |
* available. There is no guarantee that this task will actually |
932 |
> |
* be polled or executed next. This method is designed primarily |
933 |
> |
* to support extensions, and is unlikely to be useful otherwise. |
934 |
> |
* This method may be invoked only from within ForkJoinTask |
935 |
> |
* computations. Attempts to invoke in other contexts result in |
936 |
> |
* exceptions or errors possibly including ClassCastException. |
937 |
|
* |
938 |
|
* @return the next task, or null if none are available |
939 |
|
*/ |
942 |
|
} |
943 |
|
|
944 |
|
/** |
945 |
< |
* Unschedules and returns, without executing, the task most |
946 |
< |
* recently forked by the current thread but not yet executed. |
947 |
< |
* This method is designed primarily to support extensions, |
948 |
< |
* and is unlikely to be useful otherwise. |
949 |
< |
* This method may be invoked only from within |
950 |
< |
* ForkJoinTask computations. Attempts to invoke in other contexts |
951 |
< |
* result in exceptions or errors possibly including ClassCastException. |
945 |
> |
* Unschedules and returns, without executing, the next task |
946 |
> |
* queued by the current thread but not yet executed. This method |
947 |
> |
* is designed primarily to support extensions, and is unlikely to |
948 |
> |
* be useful otherwise. This method may be invoked only from |
949 |
> |
* within ForkJoinTask computations. Attempts to invoke in other |
950 |
> |
* contexts result in exceptions or errors possibly including |
951 |
> |
* ClassCastException. |
952 |
|
* |
953 |
|
* @return the next task, or null if none are available |
954 |
|
*/ |
955 |
|
protected static ForkJoinTask<?> pollNextLocalTask() { |
956 |
< |
return ((ForkJoinWorkerThread)(Thread.currentThread())).popTask(); |
956 |
> |
return ((ForkJoinWorkerThread)(Thread.currentThread())).pollLocalTask(); |
957 |
|
} |
958 |
< |
|
958 |
> |
|
959 |
|
/** |
960 |
< |
* Unschedules and returns, without executing, the task most |
961 |
< |
* recently forked by the current thread but not yet executed, if |
962 |
< |
* one is available, or if not available, a task that was forked |
963 |
< |
* by some other thread, if available. Availability may be |
964 |
< |
* transient, so a <code>null</code> result does not necessarily |
965 |
< |
* imply quiecence of the pool this task is operating in. |
966 |
< |
* This method is designed primarily to support extensions, |
967 |
< |
* and is unlikely to be useful otherwise. |
969 |
< |
* This method may be invoked only from within |
960 |
> |
* Unschedules and returns, without executing, the next task |
961 |
> |
* queued by the current thread but not yet executed, if one is |
962 |
> |
* available, or if not available, a task that was forked by some |
963 |
> |
* other thread, if available. Availability may be transient, so a |
964 |
> |
* <code>null</code> result does not necessarily imply quiecence |
965 |
> |
* of the pool this task is operating in. This method is designed |
966 |
> |
* primarily to support extensions, and is unlikely to be useful |
967 |
> |
* otherwise. This method may be invoked only from within |
968 |
|
* ForkJoinTask computations. Attempts to invoke in other contexts |
969 |
< |
* result in exceptions or errors possibly including ClassCastException. |
969 |
> |
* result in exceptions or errors possibly including |
970 |
> |
* ClassCastException. |
971 |
|
* |
972 |
|
* @return a task, or null if none are available |
973 |
|
*/ |
1008 |
|
} |
1009 |
|
|
1010 |
|
// Temporary Unsafe mechanics for preliminary release |
1011 |
+ |
private static Unsafe getUnsafe() throws Throwable { |
1012 |
+ |
try { |
1013 |
+ |
return Unsafe.getUnsafe(); |
1014 |
+ |
} catch (SecurityException se) { |
1015 |
+ |
try { |
1016 |
+ |
return java.security.AccessController.doPrivileged |
1017 |
+ |
(new java.security.PrivilegedExceptionAction<Unsafe>() { |
1018 |
+ |
public Unsafe run() throws Exception { |
1019 |
+ |
return getUnsafePrivileged(); |
1020 |
+ |
}}); |
1021 |
+ |
} catch (java.security.PrivilegedActionException e) { |
1022 |
+ |
throw e.getCause(); |
1023 |
+ |
} |
1024 |
+ |
} |
1025 |
+ |
} |
1026 |
+ |
|
1027 |
+ |
private static Unsafe getUnsafePrivileged() |
1028 |
+ |
throws NoSuchFieldException, IllegalAccessException { |
1029 |
+ |
Field f = Unsafe.class.getDeclaredField("theUnsafe"); |
1030 |
+ |
f.setAccessible(true); |
1031 |
+ |
return (Unsafe) f.get(null); |
1032 |
+ |
} |
1033 |
+ |
|
1034 |
+ |
private static long fieldOffset(String fieldName) |
1035 |
+ |
throws NoSuchFieldException { |
1036 |
+ |
return _unsafe.objectFieldOffset |
1037 |
+ |
(ForkJoinTask.class.getDeclaredField(fieldName)); |
1038 |
+ |
} |
1039 |
|
|
1040 |
|
static final Unsafe _unsafe; |
1041 |
|
static final long statusOffset; |
1042 |
|
|
1043 |
|
static { |
1044 |
|
try { |
1045 |
< |
if (ForkJoinTask.class.getClassLoader() != null) { |
1046 |
< |
Field f = Unsafe.class.getDeclaredField("theUnsafe"); |
1047 |
< |
f.setAccessible(true); |
1048 |
< |
_unsafe = (Unsafe)f.get(null); |
1049 |
< |
} |
1023 |
< |
else |
1024 |
< |
_unsafe = Unsafe.getUnsafe(); |
1025 |
< |
statusOffset = _unsafe.objectFieldOffset |
1026 |
< |
(ForkJoinTask.class.getDeclaredField("status")); |
1027 |
< |
} catch (Exception ex) { throw new Error(ex); } |
1045 |
> |
_unsafe = getUnsafe(); |
1046 |
> |
statusOffset = fieldOffset("status"); |
1047 |
> |
} catch (Throwable e) { |
1048 |
> |
throw new RuntimeException("Could not initialize intrinsics", e); |
1049 |
> |
} |
1050 |
|
} |
1051 |
|
|
1052 |
|
} |