ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/jsr166/jsr166/src/jsr166y/Phaser.java
(Generate patch)

Comparing jsr166/src/jsr166y/Phaser.java (file contents):
Revision 1.10 by dl, Tue Jan 6 14:30:31 2009 UTC vs.
Revision 1.11 by jsr166, Thu Mar 19 04:49:44 2009 UTC

# Line 913 | Line 913 | public class Phaser {
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");
924 <                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"));
950 >            _unsafe = getUnsafe();
951 >            stateOffset = fieldOffset("state");
952          } catch (Exception e) {
953              throw new RuntimeException("Could not initialize intrinsics", e);
954          }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines