253 |
|
private static sun.misc.Unsafe getUnsafe() { |
254 |
|
try { |
255 |
|
return sun.misc.Unsafe.getUnsafe(); |
256 |
< |
} catch (SecurityException se) { |
257 |
< |
try { |
258 |
< |
return java.security.AccessController.doPrivileged |
259 |
< |
(new java.security |
260 |
< |
.PrivilegedExceptionAction<sun.misc.Unsafe>() { |
261 |
< |
public sun.misc.Unsafe run() throws Exception { |
262 |
< |
java.lang.reflect.Field f = sun.misc |
263 |
< |
.Unsafe.class.getDeclaredField("theUnsafe"); |
264 |
< |
f.setAccessible(true); |
265 |
< |
return (sun.misc.Unsafe) f.get(null); |
266 |
< |
}}); |
267 |
< |
} catch (java.security.PrivilegedActionException e) { |
268 |
< |
throw new RuntimeException("Could not initialize intrinsics", |
269 |
< |
e.getCause()); |
270 |
< |
} |
256 |
> |
} catch (SecurityException tryReflectionInstead) {} |
257 |
> |
try { |
258 |
> |
return java.security.AccessController.doPrivileged |
259 |
> |
(new java.security.PrivilegedExceptionAction<sun.misc.Unsafe>() { |
260 |
> |
public sun.misc.Unsafe run() throws Exception { |
261 |
> |
Class<sun.misc.Unsafe> k = sun.misc.Unsafe.class; |
262 |
> |
for (java.lang.reflect.Field f : k.getDeclaredFields()) { |
263 |
> |
f.setAccessible(true); |
264 |
> |
Object x = f.get(null); |
265 |
> |
if (k.isInstance(x)) |
266 |
> |
return k.cast(x); |
267 |
> |
} |
268 |
> |
throw new NoSuchFieldError("the Unsafe"); |
269 |
> |
}}); |
270 |
> |
} catch (java.security.PrivilegedActionException e) { |
271 |
> |
throw new RuntimeException("Could not initialize intrinsics", |
272 |
> |
e.getCause()); |
273 |
|
} |
274 |
|
} |
275 |
|
} |