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

Print this page

        

*** 34,44 **** */ package java.util.concurrent; import java.util.*; import java.util.concurrent.locks.*; - import sun.misc.Unsafe; /** * A thread-safe variant of {@link java.util.ArrayList} in which all mutative * operations (<tt>add</tt>, <tt>set</tt>, and so on) are implemented by * making a fresh copy of the underlying array. --- 34,43 ----
*** 279,291 **** * * @return a clone of this list */ public Object clone() { try { ! CopyOnWriteArrayList c = (CopyOnWriteArrayList)(super.clone()); ! c.resetLock(); ! return c; } catch (CloneNotSupportedException e) { // this shouldn't happen, since we are Cloneable throw new InternalError(); } } --- 278,292 ---- * * @return a clone of this list */ public Object clone() { try { ! @SuppressWarnings("unchecked") ! CopyOnWriteArrayList<E> clone = ! (CopyOnWriteArrayList<E>) super.clone(); ! clone.resetLock(); ! return clone; } catch (CloneNotSupportedException e) { // this shouldn't happen, since we are Cloneable throw new InternalError(); } }
*** 1328,1338 **** private static final sun.misc.Unsafe UNSAFE; private static final long lockOffset; static { try { UNSAFE = sun.misc.Unsafe.getUnsafe(); ! Class k = CopyOnWriteArrayList.class; lockOffset = UNSAFE.objectFieldOffset (k.getDeclaredField("lock")); } catch (Exception e) { throw new Error(e); } --- 1329,1339 ---- private static final sun.misc.Unsafe UNSAFE; private static final long lockOffset; static { try { UNSAFE = sun.misc.Unsafe.getUnsafe(); ! Class<?> k = CopyOnWriteArrayList.class; lockOffset = UNSAFE.objectFieldOffset (k.getDeclaredField("lock")); } catch (Exception e) { throw new Error(e); }