10 |
|
/** |
11 |
|
* A package-local class holding common representation and mechanics |
12 |
|
* for classes supporting dynamic striping on 64bit values. The class |
13 |
< |
* extends Number so that concrete subclasses can publicly do so. |
13 |
> |
* extends Number so that concrete subclasses must publicly do so. |
14 |
|
*/ |
15 |
|
abstract class Striped64 extends Number { |
16 |
|
/* |
77 |
|
*/ |
78 |
|
|
79 |
|
/** |
80 |
< |
* Padded variant of AtomicLong supporting only raw accesses plus |
81 |
< |
* CAS The value field is placed between pads, hoping that the JVM |
82 |
< |
* doesn't reorder them. |
80 |
> |
* Padded variant of AtomicLong supporting only raw accesses plus CAS. |
81 |
> |
* The value field is placed between pads, hoping that the JVM doesn't |
82 |
> |
* reorder them. |
83 |
|
* |
84 |
|
* JVM intrinsics note: It would be possible to use a release-only |
85 |
|
* form of CAS here, if it were provided. |
164 |
|
} |
165 |
|
|
166 |
|
/** |
167 |
< |
* CAS the base field |
167 |
> |
* CASes the base field. |
168 |
|
*/ |
169 |
|
final boolean casBase(long cmp, long val) { |
170 |
|
return UNSAFE.compareAndSwapLong(this, baseOffset, cmp, val); |
171 |
|
} |
172 |
|
|
173 |
|
/** |
174 |
< |
* CAS the busy field from 0 to 1 to acquire lock. |
174 |
> |
* CASes the busy field from 0 to 1 to acquire lock. |
175 |
|
*/ |
176 |
|
final boolean casBusy() { |
177 |
|
return UNSAFE.compareAndSwapInt(this, busyOffset, 0, 1); |
277 |
|
|
278 |
|
|
279 |
|
/** |
280 |
< |
* Set base and all cells to the given value |
280 |
> |
* Sets base and all cells to the given value. |
281 |
|
*/ |
282 |
|
final void internalReset(long initialValue) { |
283 |
|
Cell[] as = cells; |
319 |
|
private static sun.misc.Unsafe getUnsafe() { |
320 |
|
try { |
321 |
|
return sun.misc.Unsafe.getUnsafe(); |
322 |
< |
} catch (SecurityException se) { |
323 |
< |
try { |
324 |
< |
return java.security.AccessController.doPrivileged |
325 |
< |
(new java.security |
326 |
< |
.PrivilegedExceptionAction<sun.misc.Unsafe>() { |
327 |
< |
public sun.misc.Unsafe run() throws Exception { |
328 |
< |
java.lang.reflect.Field f = sun.misc |
329 |
< |
.Unsafe.class.getDeclaredField("theUnsafe"); |
330 |
< |
f.setAccessible(true); |
331 |
< |
return (sun.misc.Unsafe) f.get(null); |
332 |
< |
}}); |
333 |
< |
} catch (java.security.PrivilegedActionException e) { |
334 |
< |
throw new RuntimeException("Could not initialize intrinsics", |
335 |
< |
e.getCause()); |
336 |
< |
} |
322 |
> |
} catch (SecurityException tryReflectionInstead) {} |
323 |
> |
try { |
324 |
> |
return java.security.AccessController.doPrivileged |
325 |
> |
(new java.security.PrivilegedExceptionAction<sun.misc.Unsafe>() { |
326 |
> |
public sun.misc.Unsafe run() throws Exception { |
327 |
> |
Class<sun.misc.Unsafe> k = sun.misc.Unsafe.class; |
328 |
> |
for (java.lang.reflect.Field f : k.getDeclaredFields()) { |
329 |
> |
f.setAccessible(true); |
330 |
> |
Object x = f.get(null); |
331 |
> |
if (k.isInstance(x)) |
332 |
> |
return k.cast(x); |
333 |
> |
} |
334 |
> |
throw new NoSuchFieldError("the Unsafe"); |
335 |
> |
}}); |
336 |
> |
} catch (java.security.PrivilegedActionException e) { |
337 |
> |
throw new RuntimeException("Could not initialize intrinsics", |
338 |
> |
e.getCause()); |
339 |
|
} |
340 |
|
} |
339 |
– |
|
341 |
|
} |