src/java.base/share/classes/java/util/concurrent/ConcurrentLinkedQueue.java

Print this page
rev 12972 : 8140606: Update library code to use internal Unsafe
Reviewed-by: duke


 912      * parallelism.
 913      *
 914      * @return a {@code Spliterator} over the elements in this queue
 915      * @since 1.8
 916      */
 917     @Override
 918     public Spliterator<E> spliterator() {
 919         return new CLQSpliterator<E>(this);
 920     }
 921 
 922     private boolean casTail(Node<E> cmp, Node<E> val) {
 923         return U.compareAndSwapObject(this, TAIL, cmp, val);
 924     }
 925 
 926     private boolean casHead(Node<E> cmp, Node<E> val) {
 927         return U.compareAndSwapObject(this, HEAD, cmp, val);
 928     }
 929 
 930     // Unsafe mechanics
 931 
 932     private static final sun.misc.Unsafe U = sun.misc.Unsafe.getUnsafe();
 933     private static final long HEAD;
 934     private static final long TAIL;
 935     private static final long ITEM;
 936     private static final long NEXT;
 937     static {
 938         try {
 939             HEAD = U.objectFieldOffset
 940                 (ConcurrentLinkedQueue.class.getDeclaredField("head"));
 941             TAIL = U.objectFieldOffset
 942                 (ConcurrentLinkedQueue.class.getDeclaredField("tail"));
 943             ITEM = U.objectFieldOffset
 944                 (Node.class.getDeclaredField("item"));
 945             NEXT = U.objectFieldOffset
 946                 (Node.class.getDeclaredField("next"));
 947         } catch (ReflectiveOperationException e) {
 948             throw new Error(e);
 949         }
 950     }
 951 }


 912      * parallelism.
 913      *
 914      * @return a {@code Spliterator} over the elements in this queue
 915      * @since 1.8
 916      */
 917     @Override
 918     public Spliterator<E> spliterator() {
 919         return new CLQSpliterator<E>(this);
 920     }
 921 
 922     private boolean casTail(Node<E> cmp, Node<E> val) {
 923         return U.compareAndSwapObject(this, TAIL, cmp, val);
 924     }
 925 
 926     private boolean casHead(Node<E> cmp, Node<E> val) {
 927         return U.compareAndSwapObject(this, HEAD, cmp, val);
 928     }
 929 
 930     // Unsafe mechanics
 931 
 932     private static final jdk.internal.misc.Unsafe U = jdk.internal.misc.Unsafe.getUnsafe();
 933     private static final long HEAD;
 934     private static final long TAIL;
 935     private static final long ITEM;
 936     private static final long NEXT;
 937     static {
 938         try {
 939             HEAD = U.objectFieldOffset
 940                 (ConcurrentLinkedQueue.class.getDeclaredField("head"));
 941             TAIL = U.objectFieldOffset
 942                 (ConcurrentLinkedQueue.class.getDeclaredField("tail"));
 943             ITEM = U.objectFieldOffset
 944                 (Node.class.getDeclaredField("item"));
 945             NEXT = U.objectFieldOffset
 946                 (Node.class.getDeclaredField("next"));
 947         } catch (ReflectiveOperationException e) {
 948             throw new Error(e);
 949         }
 950     }
 951 }