1009 |
|
} |
1010 |
|
|
1011 |
|
// Temporary Unsafe mechanics for preliminary release |
1012 |
+ |
private static Unsafe getUnsafe() throws Throwable { |
1013 |
+ |
try { |
1014 |
+ |
return Unsafe.getUnsafe(); |
1015 |
+ |
} catch (SecurityException se) { |
1016 |
+ |
try { |
1017 |
+ |
return java.security.AccessController.doPrivileged |
1018 |
+ |
(new java.security.PrivilegedExceptionAction<Unsafe>() { |
1019 |
+ |
public Unsafe run() throws Exception { |
1020 |
+ |
return getUnsafePrivileged(); |
1021 |
+ |
}}); |
1022 |
+ |
} catch (java.security.PrivilegedActionException e) { |
1023 |
+ |
throw e.getCause(); |
1024 |
+ |
} |
1025 |
+ |
} |
1026 |
+ |
} |
1027 |
+ |
|
1028 |
+ |
private static Unsafe getUnsafePrivileged() |
1029 |
+ |
throws NoSuchFieldException, IllegalAccessException { |
1030 |
+ |
Field f = Unsafe.class.getDeclaredField("theUnsafe"); |
1031 |
+ |
f.setAccessible(true); |
1032 |
+ |
return (Unsafe) f.get(null); |
1033 |
+ |
} |
1034 |
+ |
|
1035 |
+ |
private static long fieldOffset(String fieldName) |
1036 |
+ |
throws NoSuchFieldException { |
1037 |
+ |
return _unsafe.objectFieldOffset |
1038 |
+ |
(ForkJoinTask.class.getDeclaredField(fieldName)); |
1039 |
+ |
} |
1040 |
|
|
1041 |
|
static final Unsafe _unsafe; |
1042 |
|
static final long statusOffset; |
1043 |
|
|
1044 |
|
static { |
1045 |
|
try { |
1046 |
< |
if (ForkJoinTask.class.getClassLoader() != null) { |
1047 |
< |
Field f = Unsafe.class.getDeclaredField("theUnsafe"); |
1048 |
< |
f.setAccessible(true); |
1049 |
< |
_unsafe = (Unsafe)f.get(null); |
1050 |
< |
} |
1023 |
< |
else |
1024 |
< |
_unsafe = Unsafe.getUnsafe(); |
1025 |
< |
statusOffset = _unsafe.objectFieldOffset |
1026 |
< |
(ForkJoinTask.class.getDeclaredField("status")); |
1027 |
< |
} catch (Exception ex) { throw new Error(ex); } |
1046 |
> |
_unsafe = getUnsafe(); |
1047 |
> |
statusOffset = fieldOffset("status"); |
1048 |
> |
} catch (Throwable e) { |
1049 |
> |
throw new RuntimeException("Could not initialize intrinsics", e); |
1050 |
> |
} |
1051 |
|
} |
1052 |
|
|
1053 |
|
} |