jdk/test/java/util/concurrent/ConcurrentQueues/GCRetention.java
author dl
Tue, 28 Jul 2009 13:24:52 -0700
changeset 3414 cdf768813b4d
child 3708 f838f712922e
permissions -rw-r--r--
6785442: ConcurrentLinkedQueue.remove() and poll() can both remove the same element 6493942: ConcurrentLinkedQueue.remove sometimes very slow Summary: new algorithm for handling concurrent linked lists Reviewed-by: martin
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
3414
cdf768813b4d 6785442: ConcurrentLinkedQueue.remove() and poll() can both remove the same element
dl
parents:
diff changeset
     1
/*
cdf768813b4d 6785442: ConcurrentLinkedQueue.remove() and poll() can both remove the same element
dl
parents:
diff changeset
     2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
cdf768813b4d 6785442: ConcurrentLinkedQueue.remove() and poll() can both remove the same element
dl
parents:
diff changeset
     3
 *
cdf768813b4d 6785442: ConcurrentLinkedQueue.remove() and poll() can both remove the same element
dl
parents:
diff changeset
     4
 * This code is free software; you can redistribute it and/or modify it
cdf768813b4d 6785442: ConcurrentLinkedQueue.remove() and poll() can both remove the same element
dl
parents:
diff changeset
     5
 * under the terms of the GNU General Public License version 2 only, as
cdf768813b4d 6785442: ConcurrentLinkedQueue.remove() and poll() can both remove the same element
dl
parents:
diff changeset
     6
 * published by the Free Software Foundation.
cdf768813b4d 6785442: ConcurrentLinkedQueue.remove() and poll() can both remove the same element
dl
parents:
diff changeset
     7
 *
cdf768813b4d 6785442: ConcurrentLinkedQueue.remove() and poll() can both remove the same element
dl
parents:
diff changeset
     8
 * This code is distributed in the hope that it will be useful, but WITHOUT
cdf768813b4d 6785442: ConcurrentLinkedQueue.remove() and poll() can both remove the same element
dl
parents:
diff changeset
     9
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
cdf768813b4d 6785442: ConcurrentLinkedQueue.remove() and poll() can both remove the same element
dl
parents:
diff changeset
    10
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
cdf768813b4d 6785442: ConcurrentLinkedQueue.remove() and poll() can both remove the same element
dl
parents:
diff changeset
    11
 * version 2 for more details (a copy is included in the LICENSE file that
cdf768813b4d 6785442: ConcurrentLinkedQueue.remove() and poll() can both remove the same element
dl
parents:
diff changeset
    12
 * accompanied this code).
cdf768813b4d 6785442: ConcurrentLinkedQueue.remove() and poll() can both remove the same element
dl
parents:
diff changeset
    13
 *
cdf768813b4d 6785442: ConcurrentLinkedQueue.remove() and poll() can both remove the same element
dl
parents:
diff changeset
    14
 * You should have received a copy of the GNU General Public License version
cdf768813b4d 6785442: ConcurrentLinkedQueue.remove() and poll() can both remove the same element
dl
parents:
diff changeset
    15
 * 2 along with this work; if not, write to the Free Software Foundation,
cdf768813b4d 6785442: ConcurrentLinkedQueue.remove() and poll() can both remove the same element
dl
parents:
diff changeset
    16
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
cdf768813b4d 6785442: ConcurrentLinkedQueue.remove() and poll() can both remove the same element
dl
parents:
diff changeset
    17
 *
cdf768813b4d 6785442: ConcurrentLinkedQueue.remove() and poll() can both remove the same element
dl
parents:
diff changeset
    18
 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
cdf768813b4d 6785442: ConcurrentLinkedQueue.remove() and poll() can both remove the same element
dl
parents:
diff changeset
    19
 * CA 95054 USA or visit www.sun.com if you need additional information or
cdf768813b4d 6785442: ConcurrentLinkedQueue.remove() and poll() can both remove the same element
dl
parents:
diff changeset
    20
 * have any questions.
cdf768813b4d 6785442: ConcurrentLinkedQueue.remove() and poll() can both remove the same element
dl
parents:
diff changeset
    21
 */
cdf768813b4d 6785442: ConcurrentLinkedQueue.remove() and poll() can both remove the same element
dl
parents:
diff changeset
    22
cdf768813b4d 6785442: ConcurrentLinkedQueue.remove() and poll() can both remove the same element
dl
parents:
diff changeset
    23
/*
cdf768813b4d 6785442: ConcurrentLinkedQueue.remove() and poll() can both remove the same element
dl
parents:
diff changeset
    24
 * This file is available under and governed by the GNU General Public
cdf768813b4d 6785442: ConcurrentLinkedQueue.remove() and poll() can both remove the same element
dl
parents:
diff changeset
    25
 * License version 2 only, as published by the Free Software Foundation.
cdf768813b4d 6785442: ConcurrentLinkedQueue.remove() and poll() can both remove the same element
dl
parents:
diff changeset
    26
 * However, the following notice accompanied the original version of this
cdf768813b4d 6785442: ConcurrentLinkedQueue.remove() and poll() can both remove the same element
dl
parents:
diff changeset
    27
 * file:
cdf768813b4d 6785442: ConcurrentLinkedQueue.remove() and poll() can both remove the same element
dl
parents:
diff changeset
    28
 *
cdf768813b4d 6785442: ConcurrentLinkedQueue.remove() and poll() can both remove the same element
dl
parents:
diff changeset
    29
 * Written by Doug Lea with assistance from members of JCP JSR-166
cdf768813b4d 6785442: ConcurrentLinkedQueue.remove() and poll() can both remove the same element
dl
parents:
diff changeset
    30
 * Expert Group and released to the public domain, as explained at
cdf768813b4d 6785442: ConcurrentLinkedQueue.remove() and poll() can both remove the same element
dl
parents:
diff changeset
    31
 * http://creativecommons.org/licenses/publicdomain
cdf768813b4d 6785442: ConcurrentLinkedQueue.remove() and poll() can both remove the same element
dl
parents:
diff changeset
    32
 */
cdf768813b4d 6785442: ConcurrentLinkedQueue.remove() and poll() can both remove the same element
dl
parents:
diff changeset
    33
/*
cdf768813b4d 6785442: ConcurrentLinkedQueue.remove() and poll() can both remove the same element
dl
parents:
diff changeset
    34
 * @test
cdf768813b4d 6785442: ConcurrentLinkedQueue.remove() and poll() can both remove the same element
dl
parents:
diff changeset
    35
 * @bug 6785442
cdf768813b4d 6785442: ConcurrentLinkedQueue.remove() and poll() can both remove the same element
dl
parents:
diff changeset
    36
 * @summary Benchmark that tries to GC-tenure head, followed by
cdf768813b4d 6785442: ConcurrentLinkedQueue.remove() and poll() can both remove the same element
dl
parents:
diff changeset
    37
 * many add/remove operations.
cdf768813b4d 6785442: ConcurrentLinkedQueue.remove() and poll() can both remove the same element
dl
parents:
diff changeset
    38
 * @run main GCRetention 12345
cdf768813b4d 6785442: ConcurrentLinkedQueue.remove() and poll() can both remove the same element
dl
parents:
diff changeset
    39
 */
cdf768813b4d 6785442: ConcurrentLinkedQueue.remove() and poll() can both remove the same element
dl
parents:
diff changeset
    40
cdf768813b4d 6785442: ConcurrentLinkedQueue.remove() and poll() can both remove the same element
dl
parents:
diff changeset
    41
import java.util.concurrent.ArrayBlockingQueue;
cdf768813b4d 6785442: ConcurrentLinkedQueue.remove() and poll() can both remove the same element
dl
parents:
diff changeset
    42
import java.util.concurrent.ConcurrentHashMap;
cdf768813b4d 6785442: ConcurrentLinkedQueue.remove() and poll() can both remove the same element
dl
parents:
diff changeset
    43
import java.util.concurrent.ConcurrentLinkedQueue;
cdf768813b4d 6785442: ConcurrentLinkedQueue.remove() and poll() can both remove the same element
dl
parents:
diff changeset
    44
import java.util.concurrent.LinkedBlockingQueue;
cdf768813b4d 6785442: ConcurrentLinkedQueue.remove() and poll() can both remove the same element
dl
parents:
diff changeset
    45
import java.util.concurrent.LinkedBlockingDeque;
cdf768813b4d 6785442: ConcurrentLinkedQueue.remove() and poll() can both remove the same element
dl
parents:
diff changeset
    46
import java.util.concurrent.PriorityBlockingQueue;
cdf768813b4d 6785442: ConcurrentLinkedQueue.remove() and poll() can both remove the same element
dl
parents:
diff changeset
    47
import java.util.LinkedList;
cdf768813b4d 6785442: ConcurrentLinkedQueue.remove() and poll() can both remove the same element
dl
parents:
diff changeset
    48
import java.util.PriorityQueue;
cdf768813b4d 6785442: ConcurrentLinkedQueue.remove() and poll() can both remove the same element
dl
parents:
diff changeset
    49
import java.util.ArrayList;
cdf768813b4d 6785442: ConcurrentLinkedQueue.remove() and poll() can both remove the same element
dl
parents:
diff changeset
    50
import java.util.Collection;
cdf768813b4d 6785442: ConcurrentLinkedQueue.remove() and poll() can both remove the same element
dl
parents:
diff changeset
    51
import java.util.Collections;
cdf768813b4d 6785442: ConcurrentLinkedQueue.remove() and poll() can both remove the same element
dl
parents:
diff changeset
    52
import java.util.List;
cdf768813b4d 6785442: ConcurrentLinkedQueue.remove() and poll() can both remove the same element
dl
parents:
diff changeset
    53
import java.util.Queue;
cdf768813b4d 6785442: ConcurrentLinkedQueue.remove() and poll() can both remove the same element
dl
parents:
diff changeset
    54
import java.util.Map;
cdf768813b4d 6785442: ConcurrentLinkedQueue.remove() and poll() can both remove the same element
dl
parents:
diff changeset
    55
cdf768813b4d 6785442: ConcurrentLinkedQueue.remove() and poll() can both remove the same element
dl
parents:
diff changeset
    56
public class GCRetention {
cdf768813b4d 6785442: ConcurrentLinkedQueue.remove() and poll() can both remove the same element
dl
parents:
diff changeset
    57
    // Suitable for benchmarking.  Overriden by args[0] for testing.
cdf768813b4d 6785442: ConcurrentLinkedQueue.remove() and poll() can both remove the same element
dl
parents:
diff changeset
    58
    int count = 1024 * 1024;
cdf768813b4d 6785442: ConcurrentLinkedQueue.remove() and poll() can both remove the same element
dl
parents:
diff changeset
    59
cdf768813b4d 6785442: ConcurrentLinkedQueue.remove() and poll() can both remove the same element
dl
parents:
diff changeset
    60
    final Map<String,String> results = new ConcurrentHashMap<String,String>();
cdf768813b4d 6785442: ConcurrentLinkedQueue.remove() and poll() can both remove the same element
dl
parents:
diff changeset
    61
cdf768813b4d 6785442: ConcurrentLinkedQueue.remove() and poll() can both remove the same element
dl
parents:
diff changeset
    62
    Collection<Queue<Boolean>> queues() {
cdf768813b4d 6785442: ConcurrentLinkedQueue.remove() and poll() can both remove the same element
dl
parents:
diff changeset
    63
        List<Queue<Boolean>> queues = new ArrayList<Queue<Boolean>>();
cdf768813b4d 6785442: ConcurrentLinkedQueue.remove() and poll() can both remove the same element
dl
parents:
diff changeset
    64
        queues.add(new ConcurrentLinkedQueue<Boolean>());
cdf768813b4d 6785442: ConcurrentLinkedQueue.remove() and poll() can both remove the same element
dl
parents:
diff changeset
    65
        queues.add(new ArrayBlockingQueue<Boolean>(count, false));
cdf768813b4d 6785442: ConcurrentLinkedQueue.remove() and poll() can both remove the same element
dl
parents:
diff changeset
    66
        queues.add(new ArrayBlockingQueue<Boolean>(count, true));
cdf768813b4d 6785442: ConcurrentLinkedQueue.remove() and poll() can both remove the same element
dl
parents:
diff changeset
    67
        queues.add(new LinkedBlockingQueue<Boolean>());
cdf768813b4d 6785442: ConcurrentLinkedQueue.remove() and poll() can both remove the same element
dl
parents:
diff changeset
    68
        queues.add(new LinkedBlockingDeque<Boolean>());
cdf768813b4d 6785442: ConcurrentLinkedQueue.remove() and poll() can both remove the same element
dl
parents:
diff changeset
    69
        queues.add(new PriorityBlockingQueue<Boolean>());
cdf768813b4d 6785442: ConcurrentLinkedQueue.remove() and poll() can both remove the same element
dl
parents:
diff changeset
    70
        queues.add(new PriorityQueue<Boolean>());
cdf768813b4d 6785442: ConcurrentLinkedQueue.remove() and poll() can both remove the same element
dl
parents:
diff changeset
    71
        queues.add(new LinkedList<Boolean>());
cdf768813b4d 6785442: ConcurrentLinkedQueue.remove() and poll() can both remove the same element
dl
parents:
diff changeset
    72
cdf768813b4d 6785442: ConcurrentLinkedQueue.remove() and poll() can both remove the same element
dl
parents:
diff changeset
    73
        try {
cdf768813b4d 6785442: ConcurrentLinkedQueue.remove() and poll() can both remove the same element
dl
parents:
diff changeset
    74
            queues.add((Queue<Boolean>)
cdf768813b4d 6785442: ConcurrentLinkedQueue.remove() and poll() can both remove the same element
dl
parents:
diff changeset
    75
                       Class.forName("java.util.concurrent.LinkedTransferQueue")
cdf768813b4d 6785442: ConcurrentLinkedQueue.remove() and poll() can both remove the same element
dl
parents:
diff changeset
    76
                       .newInstance());
cdf768813b4d 6785442: ConcurrentLinkedQueue.remove() and poll() can both remove the same element
dl
parents:
diff changeset
    77
        } catch (IllegalAccessException e) {
cdf768813b4d 6785442: ConcurrentLinkedQueue.remove() and poll() can both remove the same element
dl
parents:
diff changeset
    78
        } catch (InstantiationException e) {
cdf768813b4d 6785442: ConcurrentLinkedQueue.remove() and poll() can both remove the same element
dl
parents:
diff changeset
    79
        } catch (ClassNotFoundException e) {
cdf768813b4d 6785442: ConcurrentLinkedQueue.remove() and poll() can both remove the same element
dl
parents:
diff changeset
    80
            // OK; not yet added to JDK
cdf768813b4d 6785442: ConcurrentLinkedQueue.remove() and poll() can both remove the same element
dl
parents:
diff changeset
    81
        }
cdf768813b4d 6785442: ConcurrentLinkedQueue.remove() and poll() can both remove the same element
dl
parents:
diff changeset
    82
cdf768813b4d 6785442: ConcurrentLinkedQueue.remove() and poll() can both remove the same element
dl
parents:
diff changeset
    83
        // Following additional implementations are available from:
cdf768813b4d 6785442: ConcurrentLinkedQueue.remove() and poll() can both remove the same element
dl
parents:
diff changeset
    84
        // http://gee.cs.oswego.edu/dl/concurrency-interest/index.html
cdf768813b4d 6785442: ConcurrentLinkedQueue.remove() and poll() can both remove the same element
dl
parents:
diff changeset
    85
        // queues.add(new LinkedTransferQueue<Boolean>());
cdf768813b4d 6785442: ConcurrentLinkedQueue.remove() and poll() can both remove the same element
dl
parents:
diff changeset
    86
        // queues.add(new SynchronizedLinkedListQueue<Boolean>());
cdf768813b4d 6785442: ConcurrentLinkedQueue.remove() and poll() can both remove the same element
dl
parents:
diff changeset
    87
cdf768813b4d 6785442: ConcurrentLinkedQueue.remove() and poll() can both remove the same element
dl
parents:
diff changeset
    88
        // Avoid "first fast, second slow" benchmark effect.
cdf768813b4d 6785442: ConcurrentLinkedQueue.remove() and poll() can both remove the same element
dl
parents:
diff changeset
    89
        Collections.shuffle(queues);
cdf768813b4d 6785442: ConcurrentLinkedQueue.remove() and poll() can both remove the same element
dl
parents:
diff changeset
    90
        return queues;
cdf768813b4d 6785442: ConcurrentLinkedQueue.remove() and poll() can both remove the same element
dl
parents:
diff changeset
    91
    }
cdf768813b4d 6785442: ConcurrentLinkedQueue.remove() and poll() can both remove the same element
dl
parents:
diff changeset
    92
cdf768813b4d 6785442: ConcurrentLinkedQueue.remove() and poll() can both remove the same element
dl
parents:
diff changeset
    93
    void prettyPrintResults() {
cdf768813b4d 6785442: ConcurrentLinkedQueue.remove() and poll() can both remove the same element
dl
parents:
diff changeset
    94
        List<String> classNames = new ArrayList<String>(results.keySet());
cdf768813b4d 6785442: ConcurrentLinkedQueue.remove() and poll() can both remove the same element
dl
parents:
diff changeset
    95
        Collections.sort(classNames);
cdf768813b4d 6785442: ConcurrentLinkedQueue.remove() and poll() can both remove the same element
dl
parents:
diff changeset
    96
        int maxClassNameLength = 0;
cdf768813b4d 6785442: ConcurrentLinkedQueue.remove() and poll() can both remove the same element
dl
parents:
diff changeset
    97
        int maxNanosLength = 0;
cdf768813b4d 6785442: ConcurrentLinkedQueue.remove() and poll() can both remove the same element
dl
parents:
diff changeset
    98
        for (String name : classNames) {
cdf768813b4d 6785442: ConcurrentLinkedQueue.remove() and poll() can both remove the same element
dl
parents:
diff changeset
    99
            if (maxClassNameLength < name.length())
cdf768813b4d 6785442: ConcurrentLinkedQueue.remove() and poll() can both remove the same element
dl
parents:
diff changeset
   100
                maxClassNameLength = name.length();
cdf768813b4d 6785442: ConcurrentLinkedQueue.remove() and poll() can both remove the same element
dl
parents:
diff changeset
   101
            if (maxNanosLength < results.get(name).length())
cdf768813b4d 6785442: ConcurrentLinkedQueue.remove() and poll() can both remove the same element
dl
parents:
diff changeset
   102
                maxNanosLength = results.get(name).length();
cdf768813b4d 6785442: ConcurrentLinkedQueue.remove() and poll() can both remove the same element
dl
parents:
diff changeset
   103
        }
cdf768813b4d 6785442: ConcurrentLinkedQueue.remove() and poll() can both remove the same element
dl
parents:
diff changeset
   104
        String format = String.format("%%%ds %%%ds nanos/item%%n",
cdf768813b4d 6785442: ConcurrentLinkedQueue.remove() and poll() can both remove the same element
dl
parents:
diff changeset
   105
                                      maxClassNameLength, maxNanosLength);
cdf768813b4d 6785442: ConcurrentLinkedQueue.remove() and poll() can both remove the same element
dl
parents:
diff changeset
   106
        for (String name : classNames)
cdf768813b4d 6785442: ConcurrentLinkedQueue.remove() and poll() can both remove the same element
dl
parents:
diff changeset
   107
            System.out.printf(format, name, results.get(name));
cdf768813b4d 6785442: ConcurrentLinkedQueue.remove() and poll() can both remove the same element
dl
parents:
diff changeset
   108
    }
cdf768813b4d 6785442: ConcurrentLinkedQueue.remove() and poll() can both remove the same element
dl
parents:
diff changeset
   109
cdf768813b4d 6785442: ConcurrentLinkedQueue.remove() and poll() can both remove the same element
dl
parents:
diff changeset
   110
    void test(String[] args) {
cdf768813b4d 6785442: ConcurrentLinkedQueue.remove() and poll() can both remove the same element
dl
parents:
diff changeset
   111
        if (args.length > 0)
cdf768813b4d 6785442: ConcurrentLinkedQueue.remove() and poll() can both remove the same element
dl
parents:
diff changeset
   112
            count = Integer.valueOf(args[0]);
cdf768813b4d 6785442: ConcurrentLinkedQueue.remove() and poll() can both remove the same element
dl
parents:
diff changeset
   113
        // Warmup
cdf768813b4d 6785442: ConcurrentLinkedQueue.remove() and poll() can both remove the same element
dl
parents:
diff changeset
   114
        for (Queue<Boolean> queue : queues())
cdf768813b4d 6785442: ConcurrentLinkedQueue.remove() and poll() can both remove the same element
dl
parents:
diff changeset
   115
            test(queue);
cdf768813b4d 6785442: ConcurrentLinkedQueue.remove() and poll() can both remove the same element
dl
parents:
diff changeset
   116
        results.clear();
cdf768813b4d 6785442: ConcurrentLinkedQueue.remove() and poll() can both remove the same element
dl
parents:
diff changeset
   117
        for (Queue<Boolean> queue : queues())
cdf768813b4d 6785442: ConcurrentLinkedQueue.remove() and poll() can both remove the same element
dl
parents:
diff changeset
   118
            test(queue);
cdf768813b4d 6785442: ConcurrentLinkedQueue.remove() and poll() can both remove the same element
dl
parents:
diff changeset
   119
cdf768813b4d 6785442: ConcurrentLinkedQueue.remove() and poll() can both remove the same element
dl
parents:
diff changeset
   120
        prettyPrintResults();
cdf768813b4d 6785442: ConcurrentLinkedQueue.remove() and poll() can both remove the same element
dl
parents:
diff changeset
   121
    }
cdf768813b4d 6785442: ConcurrentLinkedQueue.remove() and poll() can both remove the same element
dl
parents:
diff changeset
   122
cdf768813b4d 6785442: ConcurrentLinkedQueue.remove() and poll() can both remove the same element
dl
parents:
diff changeset
   123
    void test(Queue<Boolean> q) {
cdf768813b4d 6785442: ConcurrentLinkedQueue.remove() and poll() can both remove the same element
dl
parents:
diff changeset
   124
        long t0 = System.nanoTime();
cdf768813b4d 6785442: ConcurrentLinkedQueue.remove() and poll() can both remove the same element
dl
parents:
diff changeset
   125
        for (int i = 0; i < count; i++)
cdf768813b4d 6785442: ConcurrentLinkedQueue.remove() and poll() can both remove the same element
dl
parents:
diff changeset
   126
            check(q.add(Boolean.TRUE));
cdf768813b4d 6785442: ConcurrentLinkedQueue.remove() and poll() can both remove the same element
dl
parents:
diff changeset
   127
        System.gc();
cdf768813b4d 6785442: ConcurrentLinkedQueue.remove() and poll() can both remove the same element
dl
parents:
diff changeset
   128
        System.gc();
cdf768813b4d 6785442: ConcurrentLinkedQueue.remove() and poll() can both remove the same element
dl
parents:
diff changeset
   129
        Boolean x;
cdf768813b4d 6785442: ConcurrentLinkedQueue.remove() and poll() can both remove the same element
dl
parents:
diff changeset
   130
        while ((x = q.poll()) != null)
cdf768813b4d 6785442: ConcurrentLinkedQueue.remove() and poll() can both remove the same element
dl
parents:
diff changeset
   131
            equal(x, Boolean.TRUE);
cdf768813b4d 6785442: ConcurrentLinkedQueue.remove() and poll() can both remove the same element
dl
parents:
diff changeset
   132
        check(q.isEmpty());
cdf768813b4d 6785442: ConcurrentLinkedQueue.remove() and poll() can both remove the same element
dl
parents:
diff changeset
   133
cdf768813b4d 6785442: ConcurrentLinkedQueue.remove() and poll() can both remove the same element
dl
parents:
diff changeset
   134
        for (int i = 0; i < 10 * count; i++) {
cdf768813b4d 6785442: ConcurrentLinkedQueue.remove() and poll() can both remove the same element
dl
parents:
diff changeset
   135
            for (int k = 0; k < 3; k++)
cdf768813b4d 6785442: ConcurrentLinkedQueue.remove() and poll() can both remove the same element
dl
parents:
diff changeset
   136
                check(q.add(Boolean.TRUE));
cdf768813b4d 6785442: ConcurrentLinkedQueue.remove() and poll() can both remove the same element
dl
parents:
diff changeset
   137
            for (int k = 0; k < 3; k++)
cdf768813b4d 6785442: ConcurrentLinkedQueue.remove() and poll() can both remove the same element
dl
parents:
diff changeset
   138
                if (q.poll() != Boolean.TRUE)
cdf768813b4d 6785442: ConcurrentLinkedQueue.remove() and poll() can both remove the same element
dl
parents:
diff changeset
   139
                    fail();
cdf768813b4d 6785442: ConcurrentLinkedQueue.remove() and poll() can both remove the same element
dl
parents:
diff changeset
   140
        }
cdf768813b4d 6785442: ConcurrentLinkedQueue.remove() and poll() can both remove the same element
dl
parents:
diff changeset
   141
        check(q.isEmpty());
cdf768813b4d 6785442: ConcurrentLinkedQueue.remove() and poll() can both remove the same element
dl
parents:
diff changeset
   142
cdf768813b4d 6785442: ConcurrentLinkedQueue.remove() and poll() can both remove the same element
dl
parents:
diff changeset
   143
        String className = q.getClass().getSimpleName();
cdf768813b4d 6785442: ConcurrentLinkedQueue.remove() and poll() can both remove the same element
dl
parents:
diff changeset
   144
        long elapsed = System.nanoTime() - t0;
cdf768813b4d 6785442: ConcurrentLinkedQueue.remove() and poll() can both remove the same element
dl
parents:
diff changeset
   145
        int nanos = (int) ((double) elapsed / (10 * 3 * count));
cdf768813b4d 6785442: ConcurrentLinkedQueue.remove() and poll() can both remove the same element
dl
parents:
diff changeset
   146
        results.put(className, String.valueOf(nanos));
cdf768813b4d 6785442: ConcurrentLinkedQueue.remove() and poll() can both remove the same element
dl
parents:
diff changeset
   147
    }
cdf768813b4d 6785442: ConcurrentLinkedQueue.remove() and poll() can both remove the same element
dl
parents:
diff changeset
   148
cdf768813b4d 6785442: ConcurrentLinkedQueue.remove() and poll() can both remove the same element
dl
parents:
diff changeset
   149
    //--------------------- Infrastructure ---------------------------
cdf768813b4d 6785442: ConcurrentLinkedQueue.remove() and poll() can both remove the same element
dl
parents:
diff changeset
   150
    volatile int passed = 0, failed = 0;
cdf768813b4d 6785442: ConcurrentLinkedQueue.remove() and poll() can both remove the same element
dl
parents:
diff changeset
   151
    void pass() {passed++;}
cdf768813b4d 6785442: ConcurrentLinkedQueue.remove() and poll() can both remove the same element
dl
parents:
diff changeset
   152
    void fail() {failed++; Thread.dumpStack();}
cdf768813b4d 6785442: ConcurrentLinkedQueue.remove() and poll() can both remove the same element
dl
parents:
diff changeset
   153
    void fail(String msg) {System.err.println(msg); fail();}
cdf768813b4d 6785442: ConcurrentLinkedQueue.remove() and poll() can both remove the same element
dl
parents:
diff changeset
   154
    void unexpected(Throwable t) {failed++; t.printStackTrace();}
cdf768813b4d 6785442: ConcurrentLinkedQueue.remove() and poll() can both remove the same element
dl
parents:
diff changeset
   155
    void check(boolean cond) {if (cond) pass(); else fail();}
cdf768813b4d 6785442: ConcurrentLinkedQueue.remove() and poll() can both remove the same element
dl
parents:
diff changeset
   156
    void equal(Object x, Object y) {
cdf768813b4d 6785442: ConcurrentLinkedQueue.remove() and poll() can both remove the same element
dl
parents:
diff changeset
   157
        if (x == null ? y == null : x.equals(y)) pass();
cdf768813b4d 6785442: ConcurrentLinkedQueue.remove() and poll() can both remove the same element
dl
parents:
diff changeset
   158
        else fail(x + " not equal to " + y);}
cdf768813b4d 6785442: ConcurrentLinkedQueue.remove() and poll() can both remove the same element
dl
parents:
diff changeset
   159
    public static void main(String[] args) throws Throwable {
cdf768813b4d 6785442: ConcurrentLinkedQueue.remove() and poll() can both remove the same element
dl
parents:
diff changeset
   160
        new GCRetention().instanceMain(args);}
cdf768813b4d 6785442: ConcurrentLinkedQueue.remove() and poll() can both remove the same element
dl
parents:
diff changeset
   161
    public void instanceMain(String[] args) throws Throwable {
cdf768813b4d 6785442: ConcurrentLinkedQueue.remove() and poll() can both remove the same element
dl
parents:
diff changeset
   162
        try {test(args);} catch (Throwable t) {unexpected(t);}
cdf768813b4d 6785442: ConcurrentLinkedQueue.remove() and poll() can both remove the same element
dl
parents:
diff changeset
   163
        System.out.printf("%nPassed = %d, failed = %d%n%n", passed, failed);
cdf768813b4d 6785442: ConcurrentLinkedQueue.remove() and poll() can both remove the same element
dl
parents:
diff changeset
   164
        if (failed > 0) throw new AssertionError("Some tests failed");}
cdf768813b4d 6785442: ConcurrentLinkedQueue.remove() and poll() can both remove the same element
dl
parents:
diff changeset
   165
}