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

Print this page

        

*** 328,339 **** * heavily contended queues. And so long as it is relatively * brief and "quiet", spinning does not much impact performance * of less-contended queues. During spins threads check their * interrupt status and generate a thread-local random number * to decide to occasionally perform a Thread.yield. While ! * yield has underdefined specs, we assume that might it help, ! * and will not hurt in limiting impact of spinning on busy * systems. We also use smaller (1/2) spins for nodes that are * not known to be front but whose predecessors have not * blocked -- these "chained" spins avoid artifacts of * front-of-queue rules which otherwise lead to alternating * nodes spinning vs blocking. Further, front threads that --- 328,339 ---- * heavily contended queues. And so long as it is relatively * brief and "quiet", spinning does not much impact performance * of less-contended queues. During spins threads check their * interrupt status and generate a thread-local random number * to decide to occasionally perform a Thread.yield. While ! * yield has underdefined specs, we assume that it might help, ! * and will not hurt, in limiting impact of spinning on busy * systems. We also use smaller (1/2) spins for nodes that are * not known to be front but whose predecessors have not * blocked -- these "chained" spins avoid artifacts of * front-of-queue rules which otherwise lead to alternating * nodes spinning vs blocking. Further, front threads that
*** 540,550 **** private static final long nextOffset; private static final long waiterOffset; static { try { UNSAFE = sun.misc.Unsafe.getUnsafe(); ! Class k = Node.class; itemOffset = UNSAFE.objectFieldOffset (k.getDeclaredField("item")); nextOffset = UNSAFE.objectFieldOffset (k.getDeclaredField("next")); waiterOffset = UNSAFE.objectFieldOffset --- 540,550 ---- private static final long nextOffset; private static final long waiterOffset; static { try { UNSAFE = sun.misc.Unsafe.getUnsafe(); ! Class<?> k = Node.class; itemOffset = UNSAFE.objectFieldOffset (k.getDeclaredField("item")); nextOffset = UNSAFE.objectFieldOffset (k.getDeclaredField("next")); waiterOffset = UNSAFE.objectFieldOffset
*** 625,635 **** if ((h = head) == null || (q = h.next) == null || !q.isMatched()) break; // unless slack < 2 } LockSupport.unpark(p.waiter); ! return this.<E>cast(item); } } Node n = p.next; p = (p != n) ? n : (h = head); // Use head if p offlist } --- 625,635 ---- if ((h = head) == null || (q = h.next) == null || !q.isMatched()) break; // unless slack < 2 } LockSupport.unpark(p.waiter); ! return LinkedTransferQueue.<E>cast(item); } } Node n = p.next; p = (p != n) ? n : (h = head); // Use head if p offlist }
*** 703,713 **** for (;;) { Object item = s.item; if (item != e) { // matched // assert item != s; s.forgetContents(); // avoid garbage ! return this.<E>cast(item); } if ((w.isInterrupted() || (timed && nanos <= 0)) && s.casItem(e, s)) { // cancel unsplice(pred, s); return e; --- 703,713 ---- for (;;) { Object item = s.item; if (item != e) { // matched // assert item != s; s.forgetContents(); // avoid garbage ! return LinkedTransferQueue.<E>cast(item); } if ((w.isInterrupted() || (timed && nanos <= 0)) && s.casItem(e, s)) { // cancel unsplice(pred, s); return e;
*** 784,794 **** private E firstDataItem() { for (Node p = head; p != null; p = succ(p)) { Object item = p.item; if (p.isData) { if (item != null && item != p) ! return this.<E>cast(item); } else if (item == null) return null; } return null; --- 784,794 ---- private E firstDataItem() { for (Node p = head; p != null; p = succ(p)) { Object item = p.item; if (p.isData) { if (item != null && item != p) ! return LinkedTransferQueue.<E>cast(item); } else if (item == null) return null; } return null;
*** 1006,1016 **** } } return false; } - /** * Creates an initially empty {@code LinkedTransferQueue}. */ public LinkedTransferQueue() { } --- 1006,1015 ----
*** 1043,1053 **** * Inserts the specified element at the tail of this queue. * As the queue is unbounded, this method will never block or * return {@code false}. * * @return {@code true} (as specified by ! * {@link BlockingQueue#offer(Object,long,TimeUnit) BlockingQueue.offer}) * @throws NullPointerException if the specified element is null */ public boolean offer(E e, long timeout, TimeUnit unit) { xfer(e, true, ASYNC, 0); return true; --- 1042,1053 ---- * Inserts the specified element at the tail of this queue. * As the queue is unbounded, this method will never block or * return {@code false}. * * @return {@code true} (as specified by ! * {@link java.util.concurrent.BlockingQueue#offer(Object,long,TimeUnit) ! * BlockingQueue.offer}) * @throws NullPointerException if the specified element is null */ public boolean offer(E e, long timeout, TimeUnit unit) { xfer(e, true, ASYNC, 0); return true;
*** 1160,1171 **** if (c == null) throw new NullPointerException(); if (c == this) throw new IllegalArgumentException(); int n = 0; ! E e; ! while ( (e = poll()) != null) { c.add(e); ++n; } return n; } --- 1160,1170 ---- if (c == null) throw new NullPointerException(); if (c == this) throw new IllegalArgumentException(); int n = 0; ! for (E e; (e = poll()) != null;) { c.add(e); ++n; } return n; }
*** 1178,1189 **** if (c == null) throw new NullPointerException(); if (c == this) throw new IllegalArgumentException(); int n = 0; ! E e; ! while (n < maxElements && (e = poll()) != null) { c.add(e); ++n; } return n; } --- 1177,1187 ---- if (c == null) throw new NullPointerException(); if (c == this) throw new IllegalArgumentException(); int n = 0; ! for (E e; n < maxElements && (e = poll()) != null;) { c.add(e); ++n; } return n; }
*** 1286,1296 **** /** * Always returns {@code Integer.MAX_VALUE} because a * {@code LinkedTransferQueue} is not capacity constrained. * * @return {@code Integer.MAX_VALUE} (as specified by ! * {@link BlockingQueue#remainingCapacity()}) */ public int remainingCapacity() { return Integer.MAX_VALUE; } --- 1284,1295 ---- /** * Always returns {@code Integer.MAX_VALUE} because a * {@code LinkedTransferQueue} is not capacity constrained. * * @return {@code Integer.MAX_VALUE} (as specified by ! * {@link java.util.concurrent.BlockingQueue#remainingCapacity() ! * BlockingQueue.remainingCapacity}) */ public int remainingCapacity() { return Integer.MAX_VALUE; }
*** 1335,1345 **** private static final long tailOffset; private static final long sweepVotesOffset; static { try { UNSAFE = sun.misc.Unsafe.getUnsafe(); ! Class k = LinkedTransferQueue.class; headOffset = UNSAFE.objectFieldOffset (k.getDeclaredField("head")); tailOffset = UNSAFE.objectFieldOffset (k.getDeclaredField("tail")); sweepVotesOffset = UNSAFE.objectFieldOffset --- 1334,1344 ---- private static final long tailOffset; private static final long sweepVotesOffset; static { try { UNSAFE = sun.misc.Unsafe.getUnsafe(); ! Class<?> k = LinkedTransferQueue.class; headOffset = UNSAFE.objectFieldOffset (k.getDeclaredField("head")); tailOffset = UNSAFE.objectFieldOffset (k.getDeclaredField("tail")); sweepVotesOffset = UNSAFE.objectFieldOffset