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

Comparing jsr166/src/jsr166y/LinkedTransferQueue.java (file contents):
Revision 1.12 by dl, Mon Jan 12 17:16:18 2009 UTC vs.
Revision 1.13 by jsr166, Thu Mar 19 04:36:54 2009 UTC

# Line 739 | Line 739 | public class LinkedTransferQueue<E> exte
739      }
740  
741      // Temporary Unsafe mechanics for preliminary release
742 +    private static Unsafe getUnsafe() throws Throwable {
743 +        try {
744 +            return Unsafe.getUnsafe();
745 +        } catch (SecurityException se) {
746 +            try {
747 +                return java.security.AccessController.doPrivileged
748 +                    (new java.security.PrivilegedExceptionAction<Unsafe>() {
749 +                        public Unsafe run() throws Exception {
750 +                            return getUnsafePrivileged();
751 +                        }});
752 +            } catch (java.security.PrivilegedActionException e) {
753 +                throw e.getCause();
754 +            }
755 +        }
756 +    }
757 +
758 +    private static Unsafe getUnsafePrivileged()
759 +            throws NoSuchFieldException, IllegalAccessException {
760 +        Field f = Unsafe.class.getDeclaredField("theUnsafe");
761 +        f.setAccessible(true);
762 +        return (Unsafe)f.get(null);
763 +    }
764 +
765 +    private static long fieldOffset(String fieldName)
766 +            throws NoSuchFieldException {
767 +        return _unsafe.objectFieldOffset
768 +            (LinkedTransferQueue.class.getDeclaredField(fieldName));
769 +    }
770 +
771      private static final Unsafe _unsafe;
772      private static final long headOffset;
773      private static final long tailOffset;
774      private static final long cleanMeOffset;
775      static {
776          try {
777 <            if (LinkedTransferQueue.class.getClassLoader() != null) {
778 <                Field f = Unsafe.class.getDeclaredField("theUnsafe");
779 <                f.setAccessible(true);
780 <                _unsafe = (Unsafe)f.get(null);
781 <            }
753 <            else
754 <                _unsafe = Unsafe.getUnsafe();
755 <            headOffset = _unsafe.objectFieldOffset
756 <                (LinkedTransferQueue.class.getDeclaredField("head"));
757 <            tailOffset = _unsafe.objectFieldOffset
758 <                (LinkedTransferQueue.class.getDeclaredField("tail"));
759 <            cleanMeOffset = _unsafe.objectFieldOffset
760 <                (LinkedTransferQueue.class.getDeclaredField("cleanMe"));
761 <        } catch (Exception e) {
777 >            _unsafe = getUnsafe();
778 >            headOffset = fieldOffset("head");
779 >            tailOffset = fieldOffset("tail");
780 >            cleanMeOffset = fieldOffset("cleanMe");
781 >        } catch (Throwable e) {
782              throw new RuntimeException("Could not initialize intrinsics", e);
783          }
784      }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines