6805775: LinkedBlockingQueue Nodes should unlink themselves before becoming garbage
6815766: LinkedBlockingQueue's iterator can return null if drainTo(c) executes concurrently
Summary: Faster, more correct. Use self-linking trick to avoid gc retention
Reviewed-by: martin, dholmes
diff --git a/test/java/util/Collection/MOAT.java b/test/java/util/Collection/MOAT.java
index f9d30f5..d2b6b68 100644
--- a/test/java/util/Collection/MOAT.java
+++ b/test/java/util/Collection/MOAT.java
@@ -426,6 +426,36 @@
q.poll();
equal(q.size(), 4);
checkFunctionalInvariants(q);
+ if ((q instanceof LinkedBlockingQueue) ||
+ (q instanceof LinkedBlockingDeque) ||
+ (q instanceof ConcurrentLinkedQueue)) {
+ testQueueIteratorRemove(q);
+ }
+ }
+
+ private static void testQueueIteratorRemove(Queue<Integer> q) {
+ System.err.printf("testQueueIteratorRemove %s%n",
+ q.getClass().getSimpleName());
+ q.clear();
+ for (int i = 0; i < 5; i++)
+ q.add(i);
+ Iterator<Integer> it = q.iterator();
+ check(it.hasNext());
+ for (int i = 3; i >= 0; i--)
+ q.remove(i);
+ equal(it.next(), 0);
+ equal(it.next(), 4);
+
+ q.clear();
+ for (int i = 0; i < 5; i++)
+ q.add(i);
+ it = q.iterator();
+ equal(it.next(), 0);
+ check(it.hasNext());
+ for (int i = 1; i < 4; i++)
+ q.remove(i);
+ equal(it.next(), 1);
+ equal(it.next(), 4);
}
private static void testList(final List<Integer> l) {
@@ -451,6 +481,11 @@
}
private static void testCollection(Collection<Integer> c) {
+ try { testCollection1(c); }
+ catch (Throwable t) { unexpected(t); }
+ }
+
+ private static void testCollection1(Collection<Integer> c) {
System.out.println("\n==> " + c.getClass().getName());