399 |
|
phase = phaseOf(s); |
400 |
|
int unarrived = unarrivedOf(s) + registrations; |
401 |
|
int parties = partiesOf(s) + registrations; |
402 |
< |
if (phase < 0) |
402 |
> |
if (phase < 0) |
403 |
|
break; |
404 |
|
if (parties > ushortMask || unarrived > ushortMask) |
405 |
|
throw new IllegalStateException(badBounds(parties, unarrived)); |
557 |
|
* @return the phase on exit from this method |
558 |
|
* @throws InterruptedException if thread interrupted while waiting |
559 |
|
*/ |
560 |
< |
public int awaitAdvanceInterruptibly(int phase) |
560 |
> |
public int awaitAdvanceInterruptibly(int phase) |
561 |
|
throws InterruptedException { |
562 |
|
if (phase < 0) |
563 |
|
return phase; |
795 |
|
try { |
796 |
|
ForkJoinPool.managedBlock(this, false); |
797 |
|
} catch (InterruptedException ie) { |
798 |
< |
} |
798 |
> |
} |
799 |
|
} |
800 |
|
return wasInterrupted; |
801 |
|
} |
913 |
|
} |
914 |
|
|
915 |
|
// Temporary Unsafe mechanics for preliminary release |
916 |
+ |
private static Unsafe getUnsafe() throws Throwable { |
917 |
+ |
try { |
918 |
+ |
return Unsafe.getUnsafe(); |
919 |
+ |
} catch (SecurityException se) { |
920 |
+ |
try { |
921 |
+ |
return java.security.AccessController.doPrivileged |
922 |
+ |
(new java.security.PrivilegedExceptionAction<Unsafe>() { |
923 |
+ |
public Unsafe run() throws Exception { |
924 |
+ |
return getUnsafePrivileged(); |
925 |
+ |
}}); |
926 |
+ |
} catch (java.security.PrivilegedActionException e) { |
927 |
+ |
throw e.getCause(); |
928 |
+ |
} |
929 |
+ |
} |
930 |
+ |
} |
931 |
+ |
|
932 |
+ |
private static Unsafe getUnsafePrivileged() |
933 |
+ |
throws NoSuchFieldException, IllegalAccessException { |
934 |
+ |
Field f = Unsafe.class.getDeclaredField("theUnsafe"); |
935 |
+ |
f.setAccessible(true); |
936 |
+ |
return (Unsafe) f.get(null); |
937 |
+ |
} |
938 |
+ |
|
939 |
+ |
private static long fieldOffset(String fieldName) |
940 |
+ |
throws NoSuchFieldException { |
941 |
+ |
return _unsafe.objectFieldOffset |
942 |
+ |
(Phaser.class.getDeclaredField(fieldName)); |
943 |
+ |
} |
944 |
|
|
945 |
|
static final Unsafe _unsafe; |
946 |
|
static final long stateOffset; |
947 |
|
|
948 |
|
static { |
949 |
|
try { |
950 |
< |
if (Phaser.class.getClassLoader() != null) { |
951 |
< |
Field f = Unsafe.class.getDeclaredField("theUnsafe"); |
952 |
< |
f.setAccessible(true); |
925 |
< |
_unsafe = (Unsafe)f.get(null); |
926 |
< |
} |
927 |
< |
else |
928 |
< |
_unsafe = Unsafe.getUnsafe(); |
929 |
< |
stateOffset = _unsafe.objectFieldOffset |
930 |
< |
(Phaser.class.getDeclaredField("state")); |
931 |
< |
} catch (Exception e) { |
950 |
> |
_unsafe = getUnsafe(); |
951 |
> |
stateOffset = fieldOffset("state"); |
952 |
> |
} catch (Throwable e) { |
953 |
|
throw new RuntimeException("Could not initialize intrinsics", e); |
954 |
|
} |
955 |
|
} |