44 |
|
* |
45 |
|
* <ul> |
46 |
|
* |
47 |
< |
* <li> <b>Arrival.</b> Methods {@link #arrive} and |
47 |
> |
* <li><b>Arrival.</b> Methods {@link #arrive} and |
48 |
|
* {@link #arriveAndDeregister} record arrival. These methods |
49 |
|
* do not block, but return an associated <em>arrival phase |
50 |
|
* number</em>; that is, the phase number of the phaser to which |
57 |
|
* flexible than, providing a barrier action to a {@code |
58 |
|
* CyclicBarrier}. |
59 |
|
* |
60 |
< |
* <li> <b>Waiting.</b> Method {@link #awaitAdvance} requires an |
60 |
> |
* <li><b>Waiting.</b> Method {@link #awaitAdvance} requires an |
61 |
|
* argument indicating an arrival phase number, and returns when |
62 |
|
* the phaser advances to (or is already at) a different phase. |
63 |
|
* Unlike similar constructions using {@code CyclicBarrier}, |
1142 |
|
private static sun.misc.Unsafe getUnsafe() { |
1143 |
|
try { |
1144 |
|
return sun.misc.Unsafe.getUnsafe(); |
1145 |
< |
} catch (SecurityException se) { |
1146 |
< |
try { |
1147 |
< |
return java.security.AccessController.doPrivileged |
1148 |
< |
(new java.security |
1149 |
< |
.PrivilegedExceptionAction<sun.misc.Unsafe>() { |
1150 |
< |
public sun.misc.Unsafe run() throws Exception { |
1151 |
< |
java.lang.reflect.Field f = sun.misc |
1152 |
< |
.Unsafe.class.getDeclaredField("theUnsafe"); |
1153 |
< |
f.setAccessible(true); |
1154 |
< |
return (sun.misc.Unsafe) f.get(null); |
1155 |
< |
}}); |
1156 |
< |
} catch (java.security.PrivilegedActionException e) { |
1157 |
< |
throw new RuntimeException("Could not initialize intrinsics", |
1158 |
< |
e.getCause()); |
1159 |
< |
} |
1145 |
> |
} catch (SecurityException tryReflectionInstead) {} |
1146 |
> |
try { |
1147 |
> |
return java.security.AccessController.doPrivileged |
1148 |
> |
(new java.security.PrivilegedExceptionAction<sun.misc.Unsafe>() { |
1149 |
> |
public sun.misc.Unsafe run() throws Exception { |
1150 |
> |
Class<sun.misc.Unsafe> k = sun.misc.Unsafe.class; |
1151 |
> |
for (java.lang.reflect.Field f : k.getDeclaredFields()) { |
1152 |
> |
f.setAccessible(true); |
1153 |
> |
Object x = f.get(null); |
1154 |
> |
if (k.isInstance(x)) |
1155 |
> |
return k.cast(x); |
1156 |
> |
} |
1157 |
> |
throw new NoSuchFieldError("the Unsafe"); |
1158 |
> |
}}); |
1159 |
> |
} catch (java.security.PrivilegedActionException e) { |
1160 |
> |
throw new RuntimeException("Could not initialize intrinsics", |
1161 |
> |
e.getCause()); |
1162 |
|
} |
1163 |
|
} |
1164 |
|
} |