39 |
|
private static final sun.misc.Unsafe unsafe = getUnsafe(); |
40 |
|
private static final long valueOffset; |
41 |
|
|
42 |
– |
/** |
43 |
– |
* Records whether the underlying JVM supports lockless |
44 |
– |
* compareAndSwap for longs. While the Unsafe.compareAndSwapLong |
45 |
– |
* method works in either case, some constructions should be |
46 |
– |
* handled at Java level to avoid locking user-visible locks. |
47 |
– |
*/ |
48 |
– |
static final boolean VM_SUPPORTS_LONG_CAS = VMSupportsCS8(); |
49 |
– |
|
50 |
– |
/** |
51 |
– |
* Returns whether underlying JVM supports lockless CompareAndSet |
52 |
– |
* for longs. Called only once and cached in VM_SUPPORTS_LONG_CAS. |
53 |
– |
*/ |
54 |
– |
private static boolean VMSupportsCS8() { |
55 |
– |
final Class<?> klazz = java.util.concurrent.atomic.AtomicLong.class; |
56 |
– |
return java.security.AccessController.doPrivileged |
57 |
– |
(new java.security.PrivilegedAction<Boolean>() { |
58 |
– |
public Boolean run() { |
59 |
– |
try { |
60 |
– |
java.lang.reflect.Method m = |
61 |
– |
klazz.getDeclaredMethod("VMSupportsCS8", new Class<?>[0]); |
62 |
– |
m.setAccessible(true); |
63 |
– |
return (Boolean) m.invoke(new Class<?>[0]); |
64 |
– |
} catch (Throwable t) { throw new Error(t); } |
65 |
– |
}}); |
66 |
– |
} |
67 |
– |
|
42 |
|
static { |
43 |
|
try { |
44 |
|
valueOffset = unsafe.objectFieldOffset |