493 |
|
* #inForkJoinPool}). Attempts to invoke in other contexts result |
494 |
|
* in exceptions or errors, possibly including ClassCastException. |
495 |
|
* |
496 |
< |
* @return <code>this</code>, to simplify usage. |
496 |
> |
* @return {@code this}, to simplify usage. |
497 |
|
*/ |
498 |
|
public final ForkJoinTask<V> fork() { |
499 |
|
((ForkJoinWorkerThread) Thread.currentThread()) |
1042 |
|
// adaptors |
1043 |
|
|
1044 |
|
/** |
1045 |
< |
* Returns a new ForkJoinTask that performs the <code>run</code> |
1045 |
> |
* Returns a new ForkJoinTask that performs the {@code run} |
1046 |
|
* method of the given Runnable as its action, and returns a null |
1047 |
< |
* result upon <code>join</code>. |
1047 |
> |
* result upon {@code join}. |
1048 |
|
* |
1049 |
|
* @param runnable the runnable action |
1050 |
|
* @return the task |
1054 |
|
} |
1055 |
|
|
1056 |
|
/** |
1057 |
< |
* Returns a new ForkJoinTask that performs the <code>run</code> |
1057 |
> |
* Returns a new ForkJoinTask that performs the {@code run} |
1058 |
|
* method of the given Runnable as its action, and returns the |
1059 |
< |
* given result upon <code>join</code>. |
1059 |
> |
* given result upon {@code join}. |
1060 |
|
* |
1061 |
|
* @param runnable the runnable action |
1062 |
|
* @param result the result upon completion |
1067 |
|
} |
1068 |
|
|
1069 |
|
/** |
1070 |
< |
* Returns a new ForkJoinTask that performs the <code>call</code> |
1070 |
> |
* Returns a new ForkJoinTask that performs the {@code call} |
1071 |
|
* method of the given Callable as its action, and returns its |
1072 |
< |
* result upon <code>join</code>, translating any checked |
1073 |
< |
* exceptions encountered into <code>RuntimeException<code>. |
1072 |
> |
* result upon {@code join}, translating any checked |
1073 |
> |
* exceptions encountered into {@code RuntimeException}. |
1074 |
|
* |
1075 |
|
* @param callable the callable action |
1076 |
|
* @return the task |
1111 |
|
setDoneExceptionally((Throwable) ex); |
1112 |
|
} |
1113 |
|
|
1114 |
< |
// Unsafe mechanics for jsr166y 3rd party package. |
1114 |
> |
// Unsafe mechanics |
1115 |
> |
|
1116 |
> |
private static final sun.misc.Unsafe UNSAFE = getUnsafe(); |
1117 |
> |
private static final long statusOffset = |
1118 |
> |
objectFieldOffset("status", ForkJoinTask.class); |
1119 |
> |
|
1120 |
> |
private static long objectFieldOffset(String field, Class<?> klazz) { |
1121 |
> |
try { |
1122 |
> |
return UNSAFE.objectFieldOffset(klazz.getDeclaredField(field)); |
1123 |
> |
} catch (NoSuchFieldException e) { |
1124 |
> |
// Convert Exception to corresponding Error |
1125 |
> |
NoSuchFieldError error = new NoSuchFieldError(field); |
1126 |
> |
error.initCause(e); |
1127 |
> |
throw error; |
1128 |
> |
} |
1129 |
> |
} |
1130 |
> |
|
1131 |
> |
/** |
1132 |
> |
* Returns a sun.misc.Unsafe. Suitable for use in a 3rd party package. |
1133 |
> |
* Replace with a simple call to Unsafe.getUnsafe when integrating |
1134 |
> |
* into a jdk. |
1135 |
> |
* |
1136 |
> |
* @return a sun.misc.Unsafe |
1137 |
> |
*/ |
1138 |
|
private static sun.misc.Unsafe getUnsafe() { |
1139 |
|
try { |
1140 |
|
return sun.misc.Unsafe.getUnsafe(); |
1141 |
|
} catch (SecurityException se) { |
1142 |
|
try { |
1143 |
|
return java.security.AccessController.doPrivileged |
1144 |
< |
(new java.security.PrivilegedExceptionAction<sun.misc.Unsafe>() { |
1144 |
> |
(new java.security |
1145 |
> |
.PrivilegedExceptionAction<sun.misc.Unsafe>() { |
1146 |
|
public sun.misc.Unsafe run() throws Exception { |
1147 |
< |
return getUnsafeByReflection(); |
1147 |
> |
java.lang.reflect.Field f = sun.misc |
1148 |
> |
.Unsafe.class.getDeclaredField("theUnsafe"); |
1149 |
> |
f.setAccessible(true); |
1150 |
> |
return (sun.misc.Unsafe) f.get(null); |
1151 |
|
}}); |
1152 |
|
} catch (java.security.PrivilegedActionException e) { |
1153 |
|
throw new RuntimeException("Could not initialize intrinsics", |
1155 |
|
} |
1156 |
|
} |
1157 |
|
} |
1131 |
– |
|
1132 |
– |
private static sun.misc.Unsafe getUnsafeByReflection() |
1133 |
– |
throws NoSuchFieldException, IllegalAccessException { |
1134 |
– |
java.lang.reflect.Field f = |
1135 |
– |
sun.misc.Unsafe.class.getDeclaredField("theUnsafe"); |
1136 |
– |
f.setAccessible(true); |
1137 |
– |
return (sun.misc.Unsafe) f.get(null); |
1138 |
– |
} |
1139 |
– |
|
1140 |
– |
private static long fieldOffset(String fieldName, Class<?> klazz) { |
1141 |
– |
try { |
1142 |
– |
return UNSAFE.objectFieldOffset(klazz.getDeclaredField(fieldName)); |
1143 |
– |
} catch (NoSuchFieldException e) { |
1144 |
– |
// Convert Exception to Error |
1145 |
– |
NoSuchFieldError error = new NoSuchFieldError(fieldName); |
1146 |
– |
error.initCause(e); |
1147 |
– |
throw error; |
1148 |
– |
} |
1149 |
– |
} |
1150 |
– |
|
1151 |
– |
private static final sun.misc.Unsafe UNSAFE = getUnsafe(); |
1152 |
– |
static final long statusOffset = |
1153 |
– |
fieldOffset("status", ForkJoinTask.class); |
1154 |
– |
|
1158 |
|
} |