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

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


1528         }
1529 
1530         public void add(E e) {
1531             throw new UnsupportedOperationException();
1532         }
1533 
1534         @Override
1535         @SuppressWarnings("unchecked")
1536         public void forEachRemaining(Consumer<? super E> action) {
1537             Objects.requireNonNull(action);
1538             while (nextIndex() < size) {
1539                 action.accept(it.next());
1540             }
1541         }
1542     }
1543 
1544     // Support for resetting lock while deserializing
1545     private void resetLock() {
1546         U.putObjectVolatile(this, LOCK, new Object());
1547     }
1548     private static final sun.misc.Unsafe U = sun.misc.Unsafe.getUnsafe();
1549     private static final long LOCK;
1550     static {
1551         try {
1552             LOCK = U.objectFieldOffset
1553                 (CopyOnWriteArrayList.class.getDeclaredField("lock"));
1554         } catch (ReflectiveOperationException e) {
1555             throw new Error(e);
1556         }
1557     }
1558 }


1528         }
1529 
1530         public void add(E e) {
1531             throw new UnsupportedOperationException();
1532         }
1533 
1534         @Override
1535         @SuppressWarnings("unchecked")
1536         public void forEachRemaining(Consumer<? super E> action) {
1537             Objects.requireNonNull(action);
1538             while (nextIndex() < size) {
1539                 action.accept(it.next());
1540             }
1541         }
1542     }
1543 
1544     // Support for resetting lock while deserializing
1545     private void resetLock() {
1546         U.putObjectVolatile(this, LOCK, new Object());
1547     }
1548     private static final jdk.internal.misc.Unsafe U = jdk.internal.misc.Unsafe.getUnsafe();
1549     private static final long LOCK;
1550     static {
1551         try {
1552             LOCK = U.objectFieldOffset
1553                 (CopyOnWriteArrayList.class.getDeclaredField("lock"));
1554         } catch (ReflectiveOperationException e) {
1555             throw new Error(e);
1556         }
1557     }
1558 }