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

Print this page




 191             return UNSAFE.compareAndSwapObject(this, itemOffset, cmp, val);
 192         }
 193 
 194         void lazySetNext(Node<E> val) {
 195             UNSAFE.putOrderedObject(this, nextOffset, val);
 196         }
 197 
 198         boolean casNext(Node<E> cmp, Node<E> val) {
 199             return UNSAFE.compareAndSwapObject(this, nextOffset, cmp, val);
 200         }
 201 
 202         // Unsafe mechanics
 203 
 204         private static final sun.misc.Unsafe UNSAFE;
 205         private static final long itemOffset;
 206         private static final long nextOffset;
 207 
 208         static {
 209             try {
 210                 UNSAFE = sun.misc.Unsafe.getUnsafe();
 211                 Class k = Node.class;
 212                 itemOffset = UNSAFE.objectFieldOffset
 213                     (k.getDeclaredField("item"));
 214                 nextOffset = UNSAFE.objectFieldOffset
 215                     (k.getDeclaredField("next"));
 216             } catch (Exception e) {
 217                 throw new Error(e);
 218             }
 219         }
 220     }
 221 
 222     /**
 223      * A node from which the first live (non-deleted) node (if any)
 224      * can be reached in O(1) time.
 225      * Invariants:
 226      * - all live nodes are reachable from head via succ()
 227      * - head != null
 228      * - (tmp = head).next != tmp || tmp != head
 229      * Non-invariants:
 230      * - head.item may or may not be null.
 231      * - it is permitted for tail to lag behind head, that is, for tail


 806         if (v == null)
 807             throw new NullPointerException();
 808     }
 809 
 810     private boolean casTail(Node<E> cmp, Node<E> val) {
 811         return UNSAFE.compareAndSwapObject(this, tailOffset, cmp, val);
 812     }
 813 
 814     private boolean casHead(Node<E> cmp, Node<E> val) {
 815         return UNSAFE.compareAndSwapObject(this, headOffset, cmp, val);
 816     }
 817 
 818     // Unsafe mechanics
 819 
 820     private static final sun.misc.Unsafe UNSAFE;
 821     private static final long headOffset;
 822     private static final long tailOffset;
 823     static {
 824         try {
 825             UNSAFE = sun.misc.Unsafe.getUnsafe();
 826             Class k = ConcurrentLinkedQueue.class;
 827             headOffset = UNSAFE.objectFieldOffset
 828                 (k.getDeclaredField("head"));
 829             tailOffset = UNSAFE.objectFieldOffset
 830                 (k.getDeclaredField("tail"));
 831         } catch (Exception e) {
 832             throw new Error(e);
 833         }
 834     }
 835 }


 191             return UNSAFE.compareAndSwapObject(this, itemOffset, cmp, val);
 192         }
 193 
 194         void lazySetNext(Node<E> val) {
 195             UNSAFE.putOrderedObject(this, nextOffset, val);
 196         }
 197 
 198         boolean casNext(Node<E> cmp, Node<E> val) {
 199             return UNSAFE.compareAndSwapObject(this, nextOffset, cmp, val);
 200         }
 201 
 202         // Unsafe mechanics
 203 
 204         private static final sun.misc.Unsafe UNSAFE;
 205         private static final long itemOffset;
 206         private static final long nextOffset;
 207 
 208         static {
 209             try {
 210                 UNSAFE = sun.misc.Unsafe.getUnsafe();
 211                 Class<?> k = Node.class;
 212                 itemOffset = UNSAFE.objectFieldOffset
 213                     (k.getDeclaredField("item"));
 214                 nextOffset = UNSAFE.objectFieldOffset
 215                     (k.getDeclaredField("next"));
 216             } catch (Exception e) {
 217                 throw new Error(e);
 218             }
 219         }
 220     }
 221 
 222     /**
 223      * A node from which the first live (non-deleted) node (if any)
 224      * can be reached in O(1) time.
 225      * Invariants:
 226      * - all live nodes are reachable from head via succ()
 227      * - head != null
 228      * - (tmp = head).next != tmp || tmp != head
 229      * Non-invariants:
 230      * - head.item may or may not be null.
 231      * - it is permitted for tail to lag behind head, that is, for tail


 806         if (v == null)
 807             throw new NullPointerException();
 808     }
 809 
 810     private boolean casTail(Node<E> cmp, Node<E> val) {
 811         return UNSAFE.compareAndSwapObject(this, tailOffset, cmp, val);
 812     }
 813 
 814     private boolean casHead(Node<E> cmp, Node<E> val) {
 815         return UNSAFE.compareAndSwapObject(this, headOffset, cmp, val);
 816     }
 817 
 818     // Unsafe mechanics
 819 
 820     private static final sun.misc.Unsafe UNSAFE;
 821     private static final long headOffset;
 822     private static final long tailOffset;
 823     static {
 824         try {
 825             UNSAFE = sun.misc.Unsafe.getUnsafe();
 826             Class<?> k = ConcurrentLinkedQueue.class;
 827             headOffset = UNSAFE.objectFieldOffset
 828                 (k.getDeclaredField("head"));
 829             tailOffset = UNSAFE.objectFieldOffset
 830                 (k.getDeclaredField("tail"));
 831         } catch (Exception e) {
 832             throw new Error(e);
 833         }
 834     }
 835 }