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

Print this page




 318         }
 319 
 320         void lazySetPrev(Node<E> val) {
 321             UNSAFE.putOrderedObject(this, prevOffset, val);
 322         }
 323 
 324         boolean casPrev(Node<E> cmp, Node<E> val) {
 325             return UNSAFE.compareAndSwapObject(this, prevOffset, cmp, val);
 326         }
 327 
 328         // Unsafe mechanics
 329 
 330         private static final sun.misc.Unsafe UNSAFE;
 331         private static final long prevOffset;
 332         private static final long itemOffset;
 333         private static final long nextOffset;
 334 
 335         static {
 336             try {
 337                 UNSAFE = sun.misc.Unsafe.getUnsafe();
 338                 Class k = Node.class;
 339                 prevOffset = UNSAFE.objectFieldOffset
 340                     (k.getDeclaredField("prev"));
 341                 itemOffset = UNSAFE.objectFieldOffset
 342                     (k.getDeclaredField("item"));
 343                 nextOffset = UNSAFE.objectFieldOffset
 344                     (k.getDeclaredField("next"));
 345             } catch (Exception e) {
 346                 throw new Error(e);
 347             }
 348         }
 349     }
 350 
 351     /**
 352      * Links e as first element.
 353      */
 354     private void linkFirst(E e) {
 355         checkNotNull(e);
 356         final Node<E> newNode = new Node<E>(e);
 357 
 358         restartFromHead:


1440     private boolean casHead(Node<E> cmp, Node<E> val) {
1441         return UNSAFE.compareAndSwapObject(this, headOffset, cmp, val);
1442     }
1443 
1444     private boolean casTail(Node<E> cmp, Node<E> val) {
1445         return UNSAFE.compareAndSwapObject(this, tailOffset, cmp, val);
1446     }
1447 
1448     // Unsafe mechanics
1449 
1450     private static final sun.misc.Unsafe UNSAFE;
1451     private static final long headOffset;
1452     private static final long tailOffset;
1453     static {
1454         PREV_TERMINATOR = new Node<Object>();
1455         PREV_TERMINATOR.next = PREV_TERMINATOR;
1456         NEXT_TERMINATOR = new Node<Object>();
1457         NEXT_TERMINATOR.prev = NEXT_TERMINATOR;
1458         try {
1459             UNSAFE = sun.misc.Unsafe.getUnsafe();
1460             Class k = ConcurrentLinkedDeque.class;
1461             headOffset = UNSAFE.objectFieldOffset
1462                 (k.getDeclaredField("head"));
1463             tailOffset = UNSAFE.objectFieldOffset
1464                 (k.getDeclaredField("tail"));
1465         } catch (Exception e) {
1466             throw new Error(e);
1467         }
1468     }
1469 }


 318         }
 319 
 320         void lazySetPrev(Node<E> val) {
 321             UNSAFE.putOrderedObject(this, prevOffset, val);
 322         }
 323 
 324         boolean casPrev(Node<E> cmp, Node<E> val) {
 325             return UNSAFE.compareAndSwapObject(this, prevOffset, cmp, val);
 326         }
 327 
 328         // Unsafe mechanics
 329 
 330         private static final sun.misc.Unsafe UNSAFE;
 331         private static final long prevOffset;
 332         private static final long itemOffset;
 333         private static final long nextOffset;
 334 
 335         static {
 336             try {
 337                 UNSAFE = sun.misc.Unsafe.getUnsafe();
 338                 Class<?> k = Node.class;
 339                 prevOffset = UNSAFE.objectFieldOffset
 340                     (k.getDeclaredField("prev"));
 341                 itemOffset = UNSAFE.objectFieldOffset
 342                     (k.getDeclaredField("item"));
 343                 nextOffset = UNSAFE.objectFieldOffset
 344                     (k.getDeclaredField("next"));
 345             } catch (Exception e) {
 346                 throw new Error(e);
 347             }
 348         }
 349     }
 350 
 351     /**
 352      * Links e as first element.
 353      */
 354     private void linkFirst(E e) {
 355         checkNotNull(e);
 356         final Node<E> newNode = new Node<E>(e);
 357 
 358         restartFromHead:


1440     private boolean casHead(Node<E> cmp, Node<E> val) {
1441         return UNSAFE.compareAndSwapObject(this, headOffset, cmp, val);
1442     }
1443 
1444     private boolean casTail(Node<E> cmp, Node<E> val) {
1445         return UNSAFE.compareAndSwapObject(this, tailOffset, cmp, val);
1446     }
1447 
1448     // Unsafe mechanics
1449 
1450     private static final sun.misc.Unsafe UNSAFE;
1451     private static final long headOffset;
1452     private static final long tailOffset;
1453     static {
1454         PREV_TERMINATOR = new Node<Object>();
1455         PREV_TERMINATOR.next = PREV_TERMINATOR;
1456         NEXT_TERMINATOR = new Node<Object>();
1457         NEXT_TERMINATOR.prev = NEXT_TERMINATOR;
1458         try {
1459             UNSAFE = sun.misc.Unsafe.getUnsafe();
1460             Class<?> k = ConcurrentLinkedDeque.class;
1461             headOffset = UNSAFE.objectFieldOffset
1462                 (k.getDeclaredField("head"));
1463             tailOffset = UNSAFE.objectFieldOffset
1464                 (k.getDeclaredField("tail"));
1465         } catch (Exception e) {
1466             throw new Error(e);
1467         }
1468     }
1469 }