9 |
|
import java.util.*; |
10 |
|
import java.util.concurrent.*; |
11 |
|
import java.util.concurrent.atomic.*; |
12 |
– |
import sun.misc.Unsafe; |
13 |
– |
import java.lang.reflect.*; |
12 |
|
|
13 |
|
/** |
14 |
|
* Abstract base class for tasks that run within a {@link |
1061 |
|
setDoneExceptionally((Throwable) ex); |
1062 |
|
} |
1063 |
|
|
1064 |
< |
// Temporary Unsafe mechanics for preliminary release |
1065 |
< |
private static Unsafe getUnsafe() throws Throwable { |
1064 |
> |
// Unsafe mechanics for jsr166y 3rd party package. |
1065 |
> |
private static sun.misc.Unsafe getUnsafe() { |
1066 |
|
try { |
1067 |
< |
return Unsafe.getUnsafe(); |
1067 |
> |
return sun.misc.Unsafe.getUnsafe(); |
1068 |
|
} catch (SecurityException se) { |
1069 |
|
try { |
1070 |
|
return java.security.AccessController.doPrivileged |
1071 |
< |
(new java.security.PrivilegedExceptionAction<Unsafe>() { |
1072 |
< |
public Unsafe run() throws Exception { |
1073 |
< |
return getUnsafePrivileged(); |
1071 |
> |
(new java.security.PrivilegedExceptionAction<sun.misc.Unsafe>() { |
1072 |
> |
public sun.misc.Unsafe run() throws Exception { |
1073 |
> |
return getUnsafeByReflection(); |
1074 |
|
}}); |
1075 |
|
} catch (java.security.PrivilegedActionException e) { |
1076 |
< |
throw e.getCause(); |
1076 |
> |
throw new RuntimeException("Could not initialize intrinsics", |
1077 |
> |
e.getCause()); |
1078 |
|
} |
1079 |
|
} |
1080 |
|
} |
1081 |
|
|
1082 |
< |
private static Unsafe getUnsafePrivileged() |
1082 |
> |
private static sun.misc.Unsafe getUnsafeByReflection() |
1083 |
|
throws NoSuchFieldException, IllegalAccessException { |
1084 |
< |
Field f = Unsafe.class.getDeclaredField("theUnsafe"); |
1084 |
> |
java.lang.reflect.Field f = |
1085 |
> |
sun.misc.Unsafe.class.getDeclaredField("theUnsafe"); |
1086 |
|
f.setAccessible(true); |
1087 |
< |
return (Unsafe) f.get(null); |
1087 |
> |
return (sun.misc.Unsafe) f.get(null); |
1088 |
|
} |
1089 |
|
|
1090 |
< |
private static long fieldOffset(String fieldName) |
1091 |
< |
throws NoSuchFieldException { |
1092 |
< |
return UNSAFE.objectFieldOffset |
1093 |
< |
(ForkJoinTask.class.getDeclaredField(fieldName)); |
1094 |
< |
} |
1095 |
< |
|
1096 |
< |
static final Unsafe UNSAFE; |
1097 |
< |
static final long statusOffset; |
1098 |
< |
|
1099 |
< |
static { |
1090 |
> |
private static long fieldOffset(String fieldName, Class<?> klazz) { |
1091 |
|
try { |
1092 |
< |
UNSAFE = getUnsafe(); |
1093 |
< |
statusOffset = fieldOffset("status"); |
1094 |
< |
} catch (Throwable e) { |
1095 |
< |
throw new RuntimeException("Could not initialize intrinsics", e); |
1092 |
> |
return UNSAFE.objectFieldOffset(klazz.getDeclaredField(fieldName)); |
1093 |
> |
} catch (NoSuchFieldException e) { |
1094 |
> |
// Convert Exception to Error |
1095 |
> |
NoSuchFieldError error = new NoSuchFieldError(fieldName); |
1096 |
> |
error.initCause(e); |
1097 |
> |
throw error; |
1098 |
|
} |
1099 |
|
} |
1100 |
|
|
1101 |
+ |
private static final sun.misc.Unsafe UNSAFE = getUnsafe(); |
1102 |
+ |
static final long statusOffset = |
1103 |
+ |
fieldOffset("status", ForkJoinTask.class); |
1104 |
+ |
|
1105 |
|
} |