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 |
– |
private static final long statusOffset = |
1153 |
– |
fieldOffset("status", ForkJoinTask.class); |
1154 |
– |
|
1158 |
|
} |