300 |
|
private static sun.misc.Unsafe getUnsafe() { |
301 |
|
try { |
302 |
|
return sun.misc.Unsafe.getUnsafe(); |
303 |
< |
} catch (SecurityException se) { |
304 |
< |
try { |
305 |
< |
return java.security.AccessController.doPrivileged |
306 |
< |
(new java.security |
307 |
< |
.PrivilegedExceptionAction<sun.misc.Unsafe>() { |
308 |
< |
public sun.misc.Unsafe run() throws Exception { |
309 |
< |
java.lang.reflect.Field f = sun.misc |
310 |
< |
.Unsafe.class.getDeclaredField("theUnsafe"); |
311 |
< |
f.setAccessible(true); |
312 |
< |
return (sun.misc.Unsafe) f.get(null); |
313 |
< |
}}); |
314 |
< |
} catch (java.security.PrivilegedActionException e) { |
315 |
< |
throw new RuntimeException("Could not initialize intrinsics", |
316 |
< |
e.getCause()); |
317 |
< |
} |
303 |
> |
} catch (SecurityException tryReflectionInstead) {} |
304 |
> |
try { |
305 |
> |
return java.security.AccessController.doPrivileged |
306 |
> |
(new java.security.PrivilegedExceptionAction<sun.misc.Unsafe>() { |
307 |
> |
public sun.misc.Unsafe run() throws Exception { |
308 |
> |
Class<sun.misc.Unsafe> k = sun.misc.Unsafe.class; |
309 |
> |
for (java.lang.reflect.Field f : k.getDeclaredFields()) { |
310 |
> |
f.setAccessible(true); |
311 |
> |
Object x = f.get(null); |
312 |
> |
if (k.isInstance(x)) |
313 |
> |
return k.cast(x); |
314 |
> |
} |
315 |
> |
throw new NoSuchFieldError("the Unsafe"); |
316 |
> |
}}); |
317 |
> |
} catch (java.security.PrivilegedActionException e) { |
318 |
> |
throw new RuntimeException("Could not initialize intrinsics", |
319 |
> |
e.getCause()); |
320 |
|
} |
321 |
|
} |
322 |
|
} |