3003 |
|
static final long segmentsBase; |
3004 |
|
static final int segmentsShift; |
3005 |
|
|
3006 |
– |
private static Unsafe getUnsafe() throws Throwable { |
3007 |
– |
try { |
3008 |
– |
return Unsafe.getUnsafe(); |
3009 |
– |
} catch (SecurityException se) { |
3010 |
– |
try { |
3011 |
– |
return java.security.AccessController.doPrivileged |
3012 |
– |
(new java.security.PrivilegedExceptionAction<Unsafe>() { |
3013 |
– |
public Unsafe run() throws Exception { |
3014 |
– |
return getUnsafePrivileged(); |
3015 |
– |
}}); |
3016 |
– |
} catch (java.security.PrivilegedActionException e) { |
3017 |
– |
throw e.getCause(); |
3018 |
– |
} |
3019 |
– |
} |
3020 |
– |
} |
3021 |
– |
|
3022 |
– |
private static Unsafe getUnsafePrivileged() |
3023 |
– |
throws NoSuchFieldException, IllegalAccessException { |
3024 |
– |
Field f = Unsafe.class.getDeclaredField("theUnsafe"); |
3025 |
– |
f.setAccessible(true); |
3026 |
– |
return (Unsafe) f.get(null); |
3027 |
– |
} |
3028 |
– |
|
3006 |
|
static { |
3007 |
|
try { |
3008 |
|
UNSAFE = getUnsafe(); |
3034 |
|
UNSAFE.putOrderedObject(segs, segmentOffset, s); |
3035 |
|
} |
3036 |
|
|
3037 |
< |
|
3037 |
> |
/** |
3038 |
> |
* Returns a sun.misc.Unsafe. Suitable for use in a 3rd party package. |
3039 |
> |
* Replace with a simple call to Unsafe.getUnsafe when integrating |
3040 |
> |
* into a jdk. |
3041 |
> |
* |
3042 |
> |
* @return a sun.misc.Unsafe |
3043 |
> |
*/ |
3044 |
> |
private static sun.misc.Unsafe getUnsafe() { |
3045 |
> |
try { |
3046 |
> |
return sun.misc.Unsafe.getUnsafe(); |
3047 |
> |
} catch (SecurityException tryReflectionInstead) {} |
3048 |
> |
try { |
3049 |
> |
return java.security.AccessController.doPrivileged |
3050 |
> |
(new java.security.PrivilegedExceptionAction<sun.misc.Unsafe>() { |
3051 |
> |
public sun.misc.Unsafe run() throws Exception { |
3052 |
> |
Class<sun.misc.Unsafe> k = sun.misc.Unsafe.class; |
3053 |
> |
for (java.lang.reflect.Field f : k.getDeclaredFields()) { |
3054 |
> |
f.setAccessible(true); |
3055 |
> |
Object x = f.get(null); |
3056 |
> |
if (k.isInstance(x)) |
3057 |
> |
return k.cast(x); |
3058 |
> |
} |
3059 |
> |
throw new NoSuchFieldError("the Unsafe"); |
3060 |
> |
}}); |
3061 |
> |
} catch (java.security.PrivilegedActionException e) { |
3062 |
> |
throw new RuntimeException("Could not initialize intrinsics", |
3063 |
> |
e.getCause()); |
3064 |
> |
} |
3065 |
> |
} |
3066 |
|
} |