test/jdk/java/util/Collection/RemoveMicroBenchmark.java
author pli
Tue, 16 Jul 2019 00:57:00 +0000
changeset 55689 8c5c9d86e1d6
parent 53781 940046624bf8
permissions -rw-r--r--
8227512: [TESTBUG] Fix JTReg javac test failures with Graal Reviewed-by: mcimadamore
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
42319
0193886267c3 8143577: optimize ArrayList.removeIf
dl
parents:
diff changeset
     1
/*
0193886267c3 8143577: optimize ArrayList.removeIf
dl
parents:
diff changeset
     2
 * Copyright (c) 2007, Oracle and/or its affiliates. All rights reserved.
0193886267c3 8143577: optimize ArrayList.removeIf
dl
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
0193886267c3 8143577: optimize ArrayList.removeIf
dl
parents:
diff changeset
     4
 *
0193886267c3 8143577: optimize ArrayList.removeIf
dl
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
0193886267c3 8143577: optimize ArrayList.removeIf
dl
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
0193886267c3 8143577: optimize ArrayList.removeIf
dl
parents:
diff changeset
     7
 * published by the Free Software Foundation.
0193886267c3 8143577: optimize ArrayList.removeIf
dl
parents:
diff changeset
     8
 *
0193886267c3 8143577: optimize ArrayList.removeIf
dl
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
0193886267c3 8143577: optimize ArrayList.removeIf
dl
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
0193886267c3 8143577: optimize ArrayList.removeIf
dl
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
0193886267c3 8143577: optimize ArrayList.removeIf
dl
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
0193886267c3 8143577: optimize ArrayList.removeIf
dl
parents:
diff changeset
    13
 * accompanied this code).
0193886267c3 8143577: optimize ArrayList.removeIf
dl
parents:
diff changeset
    14
 *
0193886267c3 8143577: optimize ArrayList.removeIf
dl
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
0193886267c3 8143577: optimize ArrayList.removeIf
dl
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
0193886267c3 8143577: optimize ArrayList.removeIf
dl
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
0193886267c3 8143577: optimize ArrayList.removeIf
dl
parents:
diff changeset
    18
 *
0193886267c3 8143577: optimize ArrayList.removeIf
dl
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
0193886267c3 8143577: optimize ArrayList.removeIf
dl
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
0193886267c3 8143577: optimize ArrayList.removeIf
dl
parents:
diff changeset
    21
 * questions.
0193886267c3 8143577: optimize ArrayList.removeIf
dl
parents:
diff changeset
    22
 */
0193886267c3 8143577: optimize ArrayList.removeIf
dl
parents:
diff changeset
    23
0193886267c3 8143577: optimize ArrayList.removeIf
dl
parents:
diff changeset
    24
/*
0193886267c3 8143577: optimize ArrayList.removeIf
dl
parents:
diff changeset
    25
 * @test
0193886267c3 8143577: optimize ArrayList.removeIf
dl
parents:
diff changeset
    26
 * @summary micro-benchmark correctness mode
0193886267c3 8143577: optimize ArrayList.removeIf
dl
parents:
diff changeset
    27
 * @run main RemoveMicroBenchmark iterations=1 size=8 warmup=0
0193886267c3 8143577: optimize ArrayList.removeIf
dl
parents:
diff changeset
    28
 */
0193886267c3 8143577: optimize ArrayList.removeIf
dl
parents:
diff changeset
    29
50229
6b29ef846c5c 8201386: Miscellaneous changes imported from jsr166 CVS 2018-05
dl
parents: 49564
diff changeset
    30
import static java.util.concurrent.TimeUnit.MILLISECONDS;
49564
260bf39376a4 8200258: Improve CopyOnWriteArrayList subList code
dl
parents: 48541
diff changeset
    31
import static java.util.stream.Collectors.toCollection;
48541
946e34c2dec9 8193300: Miscellaneous changes imported from jsr166 CVS 2018-01
dl
parents: 47730
diff changeset
    32
50229
6b29ef846c5c 8201386: Miscellaneous changes imported from jsr166 CVS 2018-05
dl
parents: 49564
diff changeset
    33
import java.lang.ref.ReferenceQueue;
42319
0193886267c3 8143577: optimize ArrayList.removeIf
dl
parents:
diff changeset
    34
import java.lang.ref.WeakReference;
0193886267c3 8143577: optimize ArrayList.removeIf
dl
parents:
diff changeset
    35
import java.util.ArrayDeque;
0193886267c3 8143577: optimize ArrayList.removeIf
dl
parents:
diff changeset
    36
import java.util.ArrayList;
0193886267c3 8143577: optimize ArrayList.removeIf
dl
parents:
diff changeset
    37
import java.util.Collection;
0193886267c3 8143577: optimize ArrayList.removeIf
dl
parents:
diff changeset
    38
import java.util.Collections;
0193886267c3 8143577: optimize ArrayList.removeIf
dl
parents:
diff changeset
    39
import java.util.Deque;
49564
260bf39376a4 8200258: Improve CopyOnWriteArrayList subList code
dl
parents: 48541
diff changeset
    40
import java.util.HashMap;
42319
0193886267c3 8143577: optimize ArrayList.removeIf
dl
parents:
diff changeset
    41
import java.util.Iterator;
0193886267c3 8143577: optimize ArrayList.removeIf
dl
parents:
diff changeset
    42
import java.util.LinkedList;
0193886267c3 8143577: optimize ArrayList.removeIf
dl
parents:
diff changeset
    43
import java.util.List;
0193886267c3 8143577: optimize ArrayList.removeIf
dl
parents:
diff changeset
    44
import java.util.ListIterator;
0193886267c3 8143577: optimize ArrayList.removeIf
dl
parents:
diff changeset
    45
import java.util.PriorityQueue;
0193886267c3 8143577: optimize ArrayList.removeIf
dl
parents:
diff changeset
    46
import java.util.Queue;
0193886267c3 8143577: optimize ArrayList.removeIf
dl
parents:
diff changeset
    47
import java.util.Vector;
0193886267c3 8143577: optimize ArrayList.removeIf
dl
parents:
diff changeset
    48
import java.util.concurrent.ArrayBlockingQueue;
0193886267c3 8143577: optimize ArrayList.removeIf
dl
parents:
diff changeset
    49
import java.util.concurrent.BlockingDeque;
0193886267c3 8143577: optimize ArrayList.removeIf
dl
parents:
diff changeset
    50
import java.util.concurrent.BlockingQueue;
0193886267c3 8143577: optimize ArrayList.removeIf
dl
parents:
diff changeset
    51
import java.util.concurrent.ConcurrentLinkedDeque;
0193886267c3 8143577: optimize ArrayList.removeIf
dl
parents:
diff changeset
    52
import java.util.concurrent.ConcurrentLinkedQueue;
49564
260bf39376a4 8200258: Improve CopyOnWriteArrayList subList code
dl
parents: 48541
diff changeset
    53
import java.util.concurrent.CopyOnWriteArrayList;
42319
0193886267c3 8143577: optimize ArrayList.removeIf
dl
parents:
diff changeset
    54
import java.util.concurrent.CountDownLatch;
0193886267c3 8143577: optimize ArrayList.removeIf
dl
parents:
diff changeset
    55
import java.util.concurrent.LinkedBlockingDeque;
0193886267c3 8143577: optimize ArrayList.removeIf
dl
parents:
diff changeset
    56
import java.util.concurrent.LinkedBlockingQueue;
0193886267c3 8143577: optimize ArrayList.removeIf
dl
parents:
diff changeset
    57
import java.util.concurrent.LinkedTransferQueue;
0193886267c3 8143577: optimize ArrayList.removeIf
dl
parents:
diff changeset
    58
import java.util.concurrent.PriorityBlockingQueue;
0193886267c3 8143577: optimize ArrayList.removeIf
dl
parents:
diff changeset
    59
import java.util.concurrent.ThreadLocalRandom;
0193886267c3 8143577: optimize ArrayList.removeIf
dl
parents:
diff changeset
    60
import java.util.concurrent.TimeUnit;
0193886267c3 8143577: optimize ArrayList.removeIf
dl
parents:
diff changeset
    61
import java.util.regex.Pattern;
49564
260bf39376a4 8200258: Improve CopyOnWriteArrayList subList code
dl
parents: 48541
diff changeset
    62
import java.util.stream.Stream;
42319
0193886267c3 8143577: optimize ArrayList.removeIf
dl
parents:
diff changeset
    63
0193886267c3 8143577: optimize ArrayList.removeIf
dl
parents:
diff changeset
    64
/**
0193886267c3 8143577: optimize ArrayList.removeIf
dl
parents:
diff changeset
    65
 * Usage: [iterations=N] [size=N] [filter=REGEXP] [warmup=SECONDS]
0193886267c3 8143577: optimize ArrayList.removeIf
dl
parents:
diff changeset
    66
 *
0193886267c3 8143577: optimize ArrayList.removeIf
dl
parents:
diff changeset
    67
 * To run this in micro-benchmark mode, simply run as a normal java program.
0193886267c3 8143577: optimize ArrayList.removeIf
dl
parents:
diff changeset
    68
 * Be patient; this program runs for a very long time.
0193886267c3 8143577: optimize ArrayList.removeIf
dl
parents:
diff changeset
    69
 * For faster runs, restrict execution using command line args.
0193886267c3 8143577: optimize ArrayList.removeIf
dl
parents:
diff changeset
    70
 *
0193886267c3 8143577: optimize ArrayList.removeIf
dl
parents:
diff changeset
    71
 * @author Martin Buchholz
0193886267c3 8143577: optimize ArrayList.removeIf
dl
parents:
diff changeset
    72
 */
0193886267c3 8143577: optimize ArrayList.removeIf
dl
parents:
diff changeset
    73
public class RemoveMicroBenchmark {
0193886267c3 8143577: optimize ArrayList.removeIf
dl
parents:
diff changeset
    74
    abstract static class Job {
0193886267c3 8143577: optimize ArrayList.removeIf
dl
parents:
diff changeset
    75
        private final String name;
0193886267c3 8143577: optimize ArrayList.removeIf
dl
parents:
diff changeset
    76
        public Job(String name) { this.name = name; }
0193886267c3 8143577: optimize ArrayList.removeIf
dl
parents:
diff changeset
    77
        public String name() { return name; }
0193886267c3 8143577: optimize ArrayList.removeIf
dl
parents:
diff changeset
    78
        public abstract void work() throws Throwable;
49564
260bf39376a4 8200258: Improve CopyOnWriteArrayList subList code
dl
parents: 48541
diff changeset
    79
        public void run() {
260bf39376a4 8200258: Improve CopyOnWriteArrayList subList code
dl
parents: 48541
diff changeset
    80
            try { work(); }
260bf39376a4 8200258: Improve CopyOnWriteArrayList subList code
dl
parents: 48541
diff changeset
    81
            catch (Throwable ex) {
260bf39376a4 8200258: Improve CopyOnWriteArrayList subList code
dl
parents: 48541
diff changeset
    82
                // current job cannot always be deduced from stacktrace.
260bf39376a4 8200258: Improve CopyOnWriteArrayList subList code
dl
parents: 48541
diff changeset
    83
                throw new RuntimeException("Job failed: " + name(), ex);
260bf39376a4 8200258: Improve CopyOnWriteArrayList subList code
dl
parents: 48541
diff changeset
    84
            }
260bf39376a4 8200258: Improve CopyOnWriteArrayList subList code
dl
parents: 48541
diff changeset
    85
        }
42319
0193886267c3 8143577: optimize ArrayList.removeIf
dl
parents:
diff changeset
    86
    }
0193886267c3 8143577: optimize ArrayList.removeIf
dl
parents:
diff changeset
    87
0193886267c3 8143577: optimize ArrayList.removeIf
dl
parents:
diff changeset
    88
    final int iterations;
0193886267c3 8143577: optimize ArrayList.removeIf
dl
parents:
diff changeset
    89
    final int size;             // number of elements in collections
0193886267c3 8143577: optimize ArrayList.removeIf
dl
parents:
diff changeset
    90
    final double warmupSeconds;
0193886267c3 8143577: optimize ArrayList.removeIf
dl
parents:
diff changeset
    91
    final long warmupNanos;
49564
260bf39376a4 8200258: Improve CopyOnWriteArrayList subList code
dl
parents: 48541
diff changeset
    92
    final Pattern nameFilter;   // select subset of Jobs to run
42319
0193886267c3 8143577: optimize ArrayList.removeIf
dl
parents:
diff changeset
    93
    final boolean reverse;      // reverse order of Jobs
0193886267c3 8143577: optimize ArrayList.removeIf
dl
parents:
diff changeset
    94
    final boolean shuffle;      // randomize order of Jobs
0193886267c3 8143577: optimize ArrayList.removeIf
dl
parents:
diff changeset
    95
49564
260bf39376a4 8200258: Improve CopyOnWriteArrayList subList code
dl
parents: 48541
diff changeset
    96
    final ArrayList<Integer> elements; // contains size random Integers
260bf39376a4 8200258: Improve CopyOnWriteArrayList subList code
dl
parents: 48541
diff changeset
    97
42319
0193886267c3 8143577: optimize ArrayList.removeIf
dl
parents:
diff changeset
    98
    RemoveMicroBenchmark(String[] args) {
0193886267c3 8143577: optimize ArrayList.removeIf
dl
parents:
diff changeset
    99
        iterations    = intArg(args, "iterations", 10_000);
0193886267c3 8143577: optimize ArrayList.removeIf
dl
parents:
diff changeset
   100
        size          = intArg(args, "size", 1000);
0193886267c3 8143577: optimize ArrayList.removeIf
dl
parents:
diff changeset
   101
        warmupSeconds = doubleArg(args, "warmup", 7.0);
49564
260bf39376a4 8200258: Improve CopyOnWriteArrayList subList code
dl
parents: 48541
diff changeset
   102
        nameFilter    = patternArg(args, "filter");
42319
0193886267c3 8143577: optimize ArrayList.removeIf
dl
parents:
diff changeset
   103
        reverse       = booleanArg(args, "reverse");
0193886267c3 8143577: optimize ArrayList.removeIf
dl
parents:
diff changeset
   104
        shuffle       = booleanArg(args, "shuffle");
0193886267c3 8143577: optimize ArrayList.removeIf
dl
parents:
diff changeset
   105
0193886267c3 8143577: optimize ArrayList.removeIf
dl
parents:
diff changeset
   106
        warmupNanos = (long) (warmupSeconds * (1000L * 1000L * 1000L));
49564
260bf39376a4 8200258: Improve CopyOnWriteArrayList subList code
dl
parents: 48541
diff changeset
   107
260bf39376a4 8200258: Improve CopyOnWriteArrayList subList code
dl
parents: 48541
diff changeset
   108
        elements = ThreadLocalRandom.current().ints(size)
260bf39376a4 8200258: Improve CopyOnWriteArrayList subList code
dl
parents: 48541
diff changeset
   109
            .mapToObj(x -> x)
260bf39376a4 8200258: Improve CopyOnWriteArrayList subList code
dl
parents: 48541
diff changeset
   110
            .collect(toCollection(ArrayList::new));
42319
0193886267c3 8143577: optimize ArrayList.removeIf
dl
parents:
diff changeset
   111
    }
0193886267c3 8143577: optimize ArrayList.removeIf
dl
parents:
diff changeset
   112
0193886267c3 8143577: optimize ArrayList.removeIf
dl
parents:
diff changeset
   113
    // --------------- GC finalization infrastructure ---------------
0193886267c3 8143577: optimize ArrayList.removeIf
dl
parents:
diff changeset
   114
0193886267c3 8143577: optimize ArrayList.removeIf
dl
parents:
diff changeset
   115
    /** No guarantees, but effective in practice. */
0193886267c3 8143577: optimize ArrayList.removeIf
dl
parents:
diff changeset
   116
    static void forceFullGc() {
50229
6b29ef846c5c 8201386: Miscellaneous changes imported from jsr166 CVS 2018-05
dl
parents: 49564
diff changeset
   117
        long timeoutMillis = 1000L;
6b29ef846c5c 8201386: Miscellaneous changes imported from jsr166 CVS 2018-05
dl
parents: 49564
diff changeset
   118
        CountDownLatch finalized = new CountDownLatch(1);
6b29ef846c5c 8201386: Miscellaneous changes imported from jsr166 CVS 2018-05
dl
parents: 49564
diff changeset
   119
        ReferenceQueue<Object> queue = new ReferenceQueue<>();
6b29ef846c5c 8201386: Miscellaneous changes imported from jsr166 CVS 2018-05
dl
parents: 49564
diff changeset
   120
        WeakReference<Object> ref = new WeakReference<>(
6b29ef846c5c 8201386: Miscellaneous changes imported from jsr166 CVS 2018-05
dl
parents: 49564
diff changeset
   121
            new Object() { protected void finalize() { finalized.countDown(); }},
6b29ef846c5c 8201386: Miscellaneous changes imported from jsr166 CVS 2018-05
dl
parents: 49564
diff changeset
   122
            queue);
42319
0193886267c3 8143577: optimize ArrayList.removeIf
dl
parents:
diff changeset
   123
        try {
50229
6b29ef846c5c 8201386: Miscellaneous changes imported from jsr166 CVS 2018-05
dl
parents: 49564
diff changeset
   124
            for (int tries = 3; tries--> 0; ) {
42319
0193886267c3 8143577: optimize ArrayList.removeIf
dl
parents:
diff changeset
   125
                System.gc();
50229
6b29ef846c5c 8201386: Miscellaneous changes imported from jsr166 CVS 2018-05
dl
parents: 49564
diff changeset
   126
                if (finalized.await(timeoutMillis, MILLISECONDS)
6b29ef846c5c 8201386: Miscellaneous changes imported from jsr166 CVS 2018-05
dl
parents: 49564
diff changeset
   127
                    && queue.remove(timeoutMillis) != null
6b29ef846c5c 8201386: Miscellaneous changes imported from jsr166 CVS 2018-05
dl
parents: 49564
diff changeset
   128
                    && ref.get() == null) {
42319
0193886267c3 8143577: optimize ArrayList.removeIf
dl
parents:
diff changeset
   129
                    System.runFinalization(); // try to pick up stragglers
0193886267c3 8143577: optimize ArrayList.removeIf
dl
parents:
diff changeset
   130
                    return;
0193886267c3 8143577: optimize ArrayList.removeIf
dl
parents:
diff changeset
   131
                }
50229
6b29ef846c5c 8201386: Miscellaneous changes imported from jsr166 CVS 2018-05
dl
parents: 49564
diff changeset
   132
                timeoutMillis *= 4;
42319
0193886267c3 8143577: optimize ArrayList.removeIf
dl
parents:
diff changeset
   133
            }
0193886267c3 8143577: optimize ArrayList.removeIf
dl
parents:
diff changeset
   134
        } catch (InterruptedException unexpected) {
0193886267c3 8143577: optimize ArrayList.removeIf
dl
parents:
diff changeset
   135
            throw new AssertionError("unexpected InterruptedException");
0193886267c3 8143577: optimize ArrayList.removeIf
dl
parents:
diff changeset
   136
        }
0193886267c3 8143577: optimize ArrayList.removeIf
dl
parents:
diff changeset
   137
        throw new AssertionError("failed to do a \"full\" gc");
0193886267c3 8143577: optimize ArrayList.removeIf
dl
parents:
diff changeset
   138
    }
0193886267c3 8143577: optimize ArrayList.removeIf
dl
parents:
diff changeset
   139
0193886267c3 8143577: optimize ArrayList.removeIf
dl
parents:
diff changeset
   140
    /**
0193886267c3 8143577: optimize ArrayList.removeIf
dl
parents:
diff changeset
   141
     * Runs each job for long enough that all the runtime compilers
0193886267c3 8143577: optimize ArrayList.removeIf
dl
parents:
diff changeset
   142
     * have had plenty of time to warm up, i.e. get around to
0193886267c3 8143577: optimize ArrayList.removeIf
dl
parents:
diff changeset
   143
     * compiling everything worth compiling.
0193886267c3 8143577: optimize ArrayList.removeIf
dl
parents:
diff changeset
   144
     * Returns array of average times per job per run.
0193886267c3 8143577: optimize ArrayList.removeIf
dl
parents:
diff changeset
   145
     */
49564
260bf39376a4 8200258: Improve CopyOnWriteArrayList subList code
dl
parents: 48541
diff changeset
   146
    long[] time0(List<Job> jobs) {
42319
0193886267c3 8143577: optimize ArrayList.removeIf
dl
parents:
diff changeset
   147
        final int size = jobs.size();
0193886267c3 8143577: optimize ArrayList.removeIf
dl
parents:
diff changeset
   148
        long[] nanoss = new long[size];
0193886267c3 8143577: optimize ArrayList.removeIf
dl
parents:
diff changeset
   149
        for (int i = 0; i < size; i++) {
0193886267c3 8143577: optimize ArrayList.removeIf
dl
parents:
diff changeset
   150
            if (warmupNanos > 0) forceFullGc();
0193886267c3 8143577: optimize ArrayList.removeIf
dl
parents:
diff changeset
   151
            Job job = jobs.get(i);
0193886267c3 8143577: optimize ArrayList.removeIf
dl
parents:
diff changeset
   152
            long totalTime;
0193886267c3 8143577: optimize ArrayList.removeIf
dl
parents:
diff changeset
   153
            int runs = 0;
0193886267c3 8143577: optimize ArrayList.removeIf
dl
parents:
diff changeset
   154
            long startTime = System.nanoTime();
49564
260bf39376a4 8200258: Improve CopyOnWriteArrayList subList code
dl
parents: 48541
diff changeset
   155
            do { job.run(); runs++; }
42319
0193886267c3 8143577: optimize ArrayList.removeIf
dl
parents:
diff changeset
   156
            while ((totalTime = System.nanoTime() - startTime) < warmupNanos);
0193886267c3 8143577: optimize ArrayList.removeIf
dl
parents:
diff changeset
   157
            nanoss[i] = totalTime/runs;
0193886267c3 8143577: optimize ArrayList.removeIf
dl
parents:
diff changeset
   158
        }
0193886267c3 8143577: optimize ArrayList.removeIf
dl
parents:
diff changeset
   159
        return nanoss;
0193886267c3 8143577: optimize ArrayList.removeIf
dl
parents:
diff changeset
   160
    }
0193886267c3 8143577: optimize ArrayList.removeIf
dl
parents:
diff changeset
   161
0193886267c3 8143577: optimize ArrayList.removeIf
dl
parents:
diff changeset
   162
    void time(List<Job> jobs) throws Throwable {
0193886267c3 8143577: optimize ArrayList.removeIf
dl
parents:
diff changeset
   163
        if (warmupNanos > 0) time0(jobs); // Warm up run
0193886267c3 8143577: optimize ArrayList.removeIf
dl
parents:
diff changeset
   164
        final int size = jobs.size();
0193886267c3 8143577: optimize ArrayList.removeIf
dl
parents:
diff changeset
   165
        final long[] nanoss = time0(jobs); // Real timing run
0193886267c3 8143577: optimize ArrayList.removeIf
dl
parents:
diff changeset
   166
        final long[] milliss = new long[size];
0193886267c3 8143577: optimize ArrayList.removeIf
dl
parents:
diff changeset
   167
        final double[] ratios = new double[size];
0193886267c3 8143577: optimize ArrayList.removeIf
dl
parents:
diff changeset
   168
0193886267c3 8143577: optimize ArrayList.removeIf
dl
parents:
diff changeset
   169
        final String nameHeader   = "Method";
0193886267c3 8143577: optimize ArrayList.removeIf
dl
parents:
diff changeset
   170
        final String millisHeader = "Millis";
0193886267c3 8143577: optimize ArrayList.removeIf
dl
parents:
diff changeset
   171
        final String ratioHeader  = "Ratio";
0193886267c3 8143577: optimize ArrayList.removeIf
dl
parents:
diff changeset
   172
0193886267c3 8143577: optimize ArrayList.removeIf
dl
parents:
diff changeset
   173
        int nameWidth   = nameHeader.length();
0193886267c3 8143577: optimize ArrayList.removeIf
dl
parents:
diff changeset
   174
        int millisWidth = millisHeader.length();
0193886267c3 8143577: optimize ArrayList.removeIf
dl
parents:
diff changeset
   175
        int ratioWidth  = ratioHeader.length();
0193886267c3 8143577: optimize ArrayList.removeIf
dl
parents:
diff changeset
   176
0193886267c3 8143577: optimize ArrayList.removeIf
dl
parents:
diff changeset
   177
        for (int i = 0; i < size; i++) {
0193886267c3 8143577: optimize ArrayList.removeIf
dl
parents:
diff changeset
   178
            nameWidth = Math.max(nameWidth, jobs.get(i).name().length());
0193886267c3 8143577: optimize ArrayList.removeIf
dl
parents:
diff changeset
   179
0193886267c3 8143577: optimize ArrayList.removeIf
dl
parents:
diff changeset
   180
            milliss[i] = nanoss[i]/(1000L * 1000L);
0193886267c3 8143577: optimize ArrayList.removeIf
dl
parents:
diff changeset
   181
            millisWidth = Math.max(millisWidth,
0193886267c3 8143577: optimize ArrayList.removeIf
dl
parents:
diff changeset
   182
                                   String.format("%d", milliss[i]).length());
0193886267c3 8143577: optimize ArrayList.removeIf
dl
parents:
diff changeset
   183
0193886267c3 8143577: optimize ArrayList.removeIf
dl
parents:
diff changeset
   184
            ratios[i] = (double) nanoss[i] / (double) nanoss[0];
0193886267c3 8143577: optimize ArrayList.removeIf
dl
parents:
diff changeset
   185
            ratioWidth = Math.max(ratioWidth,
0193886267c3 8143577: optimize ArrayList.removeIf
dl
parents:
diff changeset
   186
                                  String.format("%.3f", ratios[i]).length());
0193886267c3 8143577: optimize ArrayList.removeIf
dl
parents:
diff changeset
   187
        }
0193886267c3 8143577: optimize ArrayList.removeIf
dl
parents:
diff changeset
   188
0193886267c3 8143577: optimize ArrayList.removeIf
dl
parents:
diff changeset
   189
        String format = String.format("%%-%ds %%%dd %%%d.3f%%n",
0193886267c3 8143577: optimize ArrayList.removeIf
dl
parents:
diff changeset
   190
                                      nameWidth, millisWidth, ratioWidth);
0193886267c3 8143577: optimize ArrayList.removeIf
dl
parents:
diff changeset
   191
        String headerFormat = String.format("%%-%ds %%%ds %%%ds%%n",
0193886267c3 8143577: optimize ArrayList.removeIf
dl
parents:
diff changeset
   192
                                            nameWidth, millisWidth, ratioWidth);
0193886267c3 8143577: optimize ArrayList.removeIf
dl
parents:
diff changeset
   193
        System.out.printf(headerFormat, "Method", "Millis", "Ratio");
0193886267c3 8143577: optimize ArrayList.removeIf
dl
parents:
diff changeset
   194
0193886267c3 8143577: optimize ArrayList.removeIf
dl
parents:
diff changeset
   195
        // Print out absolute and relative times, calibrated against first job
0193886267c3 8143577: optimize ArrayList.removeIf
dl
parents:
diff changeset
   196
        for (int i = 0; i < size; i++)
0193886267c3 8143577: optimize ArrayList.removeIf
dl
parents:
diff changeset
   197
            System.out.printf(format, jobs.get(i).name(), milliss[i], ratios[i]);
0193886267c3 8143577: optimize ArrayList.removeIf
dl
parents:
diff changeset
   198
    }
0193886267c3 8143577: optimize ArrayList.removeIf
dl
parents:
diff changeset
   199
0193886267c3 8143577: optimize ArrayList.removeIf
dl
parents:
diff changeset
   200
    private static String keywordValue(String[] args, String keyword) {
0193886267c3 8143577: optimize ArrayList.removeIf
dl
parents:
diff changeset
   201
        for (String arg : args)
0193886267c3 8143577: optimize ArrayList.removeIf
dl
parents:
diff changeset
   202
            if (arg.startsWith(keyword))
0193886267c3 8143577: optimize ArrayList.removeIf
dl
parents:
diff changeset
   203
                return arg.substring(keyword.length() + 1);
0193886267c3 8143577: optimize ArrayList.removeIf
dl
parents:
diff changeset
   204
        return null;
0193886267c3 8143577: optimize ArrayList.removeIf
dl
parents:
diff changeset
   205
    }
0193886267c3 8143577: optimize ArrayList.removeIf
dl
parents:
diff changeset
   206
0193886267c3 8143577: optimize ArrayList.removeIf
dl
parents:
diff changeset
   207
    private static int intArg(String[] args, String keyword, int defaultValue) {
0193886267c3 8143577: optimize ArrayList.removeIf
dl
parents:
diff changeset
   208
        String val = keywordValue(args, keyword);
0193886267c3 8143577: optimize ArrayList.removeIf
dl
parents:
diff changeset
   209
        return (val == null) ? defaultValue : Integer.parseInt(val);
0193886267c3 8143577: optimize ArrayList.removeIf
dl
parents:
diff changeset
   210
    }
0193886267c3 8143577: optimize ArrayList.removeIf
dl
parents:
diff changeset
   211
0193886267c3 8143577: optimize ArrayList.removeIf
dl
parents:
diff changeset
   212
    private static double doubleArg(String[] args, String keyword, double defaultValue) {
0193886267c3 8143577: optimize ArrayList.removeIf
dl
parents:
diff changeset
   213
        String val = keywordValue(args, keyword);
0193886267c3 8143577: optimize ArrayList.removeIf
dl
parents:
diff changeset
   214
        return (val == null) ? defaultValue : Double.parseDouble(val);
0193886267c3 8143577: optimize ArrayList.removeIf
dl
parents:
diff changeset
   215
    }
0193886267c3 8143577: optimize ArrayList.removeIf
dl
parents:
diff changeset
   216
0193886267c3 8143577: optimize ArrayList.removeIf
dl
parents:
diff changeset
   217
    private static Pattern patternArg(String[] args, String keyword) {
0193886267c3 8143577: optimize ArrayList.removeIf
dl
parents:
diff changeset
   218
        String val = keywordValue(args, keyword);
0193886267c3 8143577: optimize ArrayList.removeIf
dl
parents:
diff changeset
   219
        return (val == null) ? null : Pattern.compile(val);
0193886267c3 8143577: optimize ArrayList.removeIf
dl
parents:
diff changeset
   220
    }
0193886267c3 8143577: optimize ArrayList.removeIf
dl
parents:
diff changeset
   221
0193886267c3 8143577: optimize ArrayList.removeIf
dl
parents:
diff changeset
   222
    private static boolean booleanArg(String[] args, String keyword) {
0193886267c3 8143577: optimize ArrayList.removeIf
dl
parents:
diff changeset
   223
        String val = keywordValue(args, keyword);
0193886267c3 8143577: optimize ArrayList.removeIf
dl
parents:
diff changeset
   224
        if (val == null || val.equals("false")) return false;
0193886267c3 8143577: optimize ArrayList.removeIf
dl
parents:
diff changeset
   225
        if (val.equals("true")) return true;
0193886267c3 8143577: optimize ArrayList.removeIf
dl
parents:
diff changeset
   226
        throw new IllegalArgumentException(val);
0193886267c3 8143577: optimize ArrayList.removeIf
dl
parents:
diff changeset
   227
    }
0193886267c3 8143577: optimize ArrayList.removeIf
dl
parents:
diff changeset
   228
0193886267c3 8143577: optimize ArrayList.removeIf
dl
parents:
diff changeset
   229
    private static void deoptimize(int sum) {
0193886267c3 8143577: optimize ArrayList.removeIf
dl
parents:
diff changeset
   230
        if (sum == 42)
0193886267c3 8143577: optimize ArrayList.removeIf
dl
parents:
diff changeset
   231
            System.out.println("the answer");
0193886267c3 8143577: optimize ArrayList.removeIf
dl
parents:
diff changeset
   232
    }
0193886267c3 8143577: optimize ArrayList.removeIf
dl
parents:
diff changeset
   233
0193886267c3 8143577: optimize ArrayList.removeIf
dl
parents:
diff changeset
   234
    private static <T> Iterable<T> backwards(final List<T> list) {
0193886267c3 8143577: optimize ArrayList.removeIf
dl
parents:
diff changeset
   235
        return new Iterable<T>() {
0193886267c3 8143577: optimize ArrayList.removeIf
dl
parents:
diff changeset
   236
            public Iterator<T> iterator() {
0193886267c3 8143577: optimize ArrayList.removeIf
dl
parents:
diff changeset
   237
                return new Iterator<T>() {
0193886267c3 8143577: optimize ArrayList.removeIf
dl
parents:
diff changeset
   238
                    final ListIterator<T> it = list.listIterator(list.size());
0193886267c3 8143577: optimize ArrayList.removeIf
dl
parents:
diff changeset
   239
                    public boolean hasNext() { return it.hasPrevious(); }
0193886267c3 8143577: optimize ArrayList.removeIf
dl
parents:
diff changeset
   240
                    public T next()          { return it.previous(); }
0193886267c3 8143577: optimize ArrayList.removeIf
dl
parents:
diff changeset
   241
                    public void remove()     {        it.remove(); }};}};
0193886267c3 8143577: optimize ArrayList.removeIf
dl
parents:
diff changeset
   242
    }
0193886267c3 8143577: optimize ArrayList.removeIf
dl
parents:
diff changeset
   243
0193886267c3 8143577: optimize ArrayList.removeIf
dl
parents:
diff changeset
   244
    // Checks for correctness *and* prevents loop optimizations
47730
c7b5b1ce8145 8189764: Miscellaneous changes imported from jsr166 CVS 2017-11
dl
parents: 47307
diff changeset
   245
    static class Check {
42319
0193886267c3 8143577: optimize ArrayList.removeIf
dl
parents:
diff changeset
   246
        private int sum;
0193886267c3 8143577: optimize ArrayList.removeIf
dl
parents:
diff changeset
   247
        public void sum(int sum) {
0193886267c3 8143577: optimize ArrayList.removeIf
dl
parents:
diff changeset
   248
            if (this.sum == 0)
0193886267c3 8143577: optimize ArrayList.removeIf
dl
parents:
diff changeset
   249
                this.sum = sum;
0193886267c3 8143577: optimize ArrayList.removeIf
dl
parents:
diff changeset
   250
            if (this.sum != sum)
0193886267c3 8143577: optimize ArrayList.removeIf
dl
parents:
diff changeset
   251
                throw new AssertionError("Sum mismatch");
0193886267c3 8143577: optimize ArrayList.removeIf
dl
parents:
diff changeset
   252
        }
0193886267c3 8143577: optimize ArrayList.removeIf
dl
parents:
diff changeset
   253
    }
0193886267c3 8143577: optimize ArrayList.removeIf
dl
parents:
diff changeset
   254
    volatile Check check = new Check();
0193886267c3 8143577: optimize ArrayList.removeIf
dl
parents:
diff changeset
   255
0193886267c3 8143577: optimize ArrayList.removeIf
dl
parents:
diff changeset
   256
    public static void main(String[] args) throws Throwable {
0193886267c3 8143577: optimize ArrayList.removeIf
dl
parents:
diff changeset
   257
        new RemoveMicroBenchmark(args).run();
0193886267c3 8143577: optimize ArrayList.removeIf
dl
parents:
diff changeset
   258
    }
0193886267c3 8143577: optimize ArrayList.removeIf
dl
parents:
diff changeset
   259
49564
260bf39376a4 8200258: Improve CopyOnWriteArrayList subList code
dl
parents: 48541
diff changeset
   260
    HashMap<Class<?>, String> goodClassName = new HashMap<>();
42319
0193886267c3 8143577: optimize ArrayList.removeIf
dl
parents:
diff changeset
   261
49564
260bf39376a4 8200258: Improve CopyOnWriteArrayList subList code
dl
parents: 48541
diff changeset
   262
    String goodClassName(Class<?> klazz) {
260bf39376a4 8200258: Improve CopyOnWriteArrayList subList code
dl
parents: 48541
diff changeset
   263
        return goodClassName.computeIfAbsent(
260bf39376a4 8200258: Improve CopyOnWriteArrayList subList code
dl
parents: 48541
diff changeset
   264
            klazz,
260bf39376a4 8200258: Improve CopyOnWriteArrayList subList code
dl
parents: 48541
diff changeset
   265
            k -> {
260bf39376a4 8200258: Improve CopyOnWriteArrayList subList code
dl
parents: 48541
diff changeset
   266
                String simple = k.getSimpleName();
260bf39376a4 8200258: Improve CopyOnWriteArrayList subList code
dl
parents: 48541
diff changeset
   267
                return (simple.equals("SubList")) // too simple!
260bf39376a4 8200258: Improve CopyOnWriteArrayList subList code
dl
parents: 48541
diff changeset
   268
                    ? k.getName().replaceFirst(".*\\.", "")
260bf39376a4 8200258: Improve CopyOnWriteArrayList subList code
dl
parents: 48541
diff changeset
   269
                    : simple;
260bf39376a4 8200258: Improve CopyOnWriteArrayList subList code
dl
parents: 48541
diff changeset
   270
            });
260bf39376a4 8200258: Improve CopyOnWriteArrayList subList code
dl
parents: 48541
diff changeset
   271
    }
42319
0193886267c3 8143577: optimize ArrayList.removeIf
dl
parents:
diff changeset
   272
53781
940046624bf8 8215249: Miscellaneous changes imported from jsr166 CVS 2019-02
dl
parents: 50764
diff changeset
   273
    String goodClassName(Object x) {
940046624bf8 8215249: Miscellaneous changes imported from jsr166 CVS 2019-02
dl
parents: 50764
diff changeset
   274
        return goodClassName(x.getClass());
940046624bf8 8215249: Miscellaneous changes imported from jsr166 CVS 2019-02
dl
parents: 50764
diff changeset
   275
    }
940046624bf8 8215249: Miscellaneous changes imported from jsr166 CVS 2019-02
dl
parents: 50764
diff changeset
   276
49564
260bf39376a4 8200258: Improve CopyOnWriteArrayList subList code
dl
parents: 48541
diff changeset
   277
    static List<Integer> makeSubList(List<Integer> list) {
42319
0193886267c3 8143577: optimize ArrayList.removeIf
dl
parents:
diff changeset
   278
        final ThreadLocalRandom rnd = ThreadLocalRandom.current();
49564
260bf39376a4 8200258: Improve CopyOnWriteArrayList subList code
dl
parents: 48541
diff changeset
   279
        int size = rnd.nextInt(4);
260bf39376a4 8200258: Improve CopyOnWriteArrayList subList code
dl
parents: 48541
diff changeset
   280
        for (int i = size; i--> 0; )
260bf39376a4 8200258: Improve CopyOnWriteArrayList subList code
dl
parents: 48541
diff changeset
   281
            list.add(rnd.nextInt());
260bf39376a4 8200258: Improve CopyOnWriteArrayList subList code
dl
parents: 48541
diff changeset
   282
        int index = rnd.nextInt(size + 1);
260bf39376a4 8200258: Improve CopyOnWriteArrayList subList code
dl
parents: 48541
diff changeset
   283
        return list.subList(index, index);
260bf39376a4 8200258: Improve CopyOnWriteArrayList subList code
dl
parents: 48541
diff changeset
   284
    }
42319
0193886267c3 8143577: optimize ArrayList.removeIf
dl
parents:
diff changeset
   285
49564
260bf39376a4 8200258: Improve CopyOnWriteArrayList subList code
dl
parents: 48541
diff changeset
   286
    private static <T> List<T> asSubList(List<T> list) {
260bf39376a4 8200258: Improve CopyOnWriteArrayList subList code
dl
parents: 48541
diff changeset
   287
        return list.subList(0, list.size());
260bf39376a4 8200258: Improve CopyOnWriteArrayList subList code
dl
parents: 48541
diff changeset
   288
    }
260bf39376a4 8200258: Improve CopyOnWriteArrayList subList code
dl
parents: 48541
diff changeset
   289
260bf39376a4 8200258: Improve CopyOnWriteArrayList subList code
dl
parents: 48541
diff changeset
   290
    @SafeVarargs @SuppressWarnings("varargs")
50764
5637aca18f1d 8203681: Miscellaneous changes imported from jsr166 CVS 2018-06
dl
parents: 50229
diff changeset
   291
    private static <T> Stream<T> concatStreams(Stream<T> ... streams) {
49564
260bf39376a4 8200258: Improve CopyOnWriteArrayList subList code
dl
parents: 48541
diff changeset
   292
        return Stream.of(streams).flatMap(s -> s);
260bf39376a4 8200258: Improve CopyOnWriteArrayList subList code
dl
parents: 48541
diff changeset
   293
    }
42319
0193886267c3 8143577: optimize ArrayList.removeIf
dl
parents:
diff changeset
   294
49564
260bf39376a4 8200258: Improve CopyOnWriteArrayList subList code
dl
parents: 48541
diff changeset
   295
    Class<?> topLevelClass(Object x) {
260bf39376a4 8200258: Improve CopyOnWriteArrayList subList code
dl
parents: 48541
diff changeset
   296
        for (Class<?> k = x.getClass();; ) {
260bf39376a4 8200258: Improve CopyOnWriteArrayList subList code
dl
parents: 48541
diff changeset
   297
            Class<?> enclosing = k.getEnclosingClass();
260bf39376a4 8200258: Improve CopyOnWriteArrayList subList code
dl
parents: 48541
diff changeset
   298
            if (enclosing == null)
260bf39376a4 8200258: Improve CopyOnWriteArrayList subList code
dl
parents: 48541
diff changeset
   299
                return k;
260bf39376a4 8200258: Improve CopyOnWriteArrayList subList code
dl
parents: 48541
diff changeset
   300
            k = enclosing;
260bf39376a4 8200258: Improve CopyOnWriteArrayList subList code
dl
parents: 48541
diff changeset
   301
        }
260bf39376a4 8200258: Improve CopyOnWriteArrayList subList code
dl
parents: 48541
diff changeset
   302
    }
260bf39376a4 8200258: Improve CopyOnWriteArrayList subList code
dl
parents: 48541
diff changeset
   303
260bf39376a4 8200258: Improve CopyOnWriteArrayList subList code
dl
parents: 48541
diff changeset
   304
    void run() throws Throwable {
260bf39376a4 8200258: Improve CopyOnWriteArrayList subList code
dl
parents: 48541
diff changeset
   305
        ArrayList<Job> jobs = Stream.<Collection<Integer>>of(
260bf39376a4 8200258: Improve CopyOnWriteArrayList subList code
dl
parents: 48541
diff changeset
   306
                new ArrayList<>(),
260bf39376a4 8200258: Improve CopyOnWriteArrayList subList code
dl
parents: 48541
diff changeset
   307
                makeSubList(new ArrayList<>()),
260bf39376a4 8200258: Improve CopyOnWriteArrayList subList code
dl
parents: 48541
diff changeset
   308
                new LinkedList<>(),
260bf39376a4 8200258: Improve CopyOnWriteArrayList subList code
dl
parents: 48541
diff changeset
   309
                makeSubList(new LinkedList<>()),
260bf39376a4 8200258: Improve CopyOnWriteArrayList subList code
dl
parents: 48541
diff changeset
   310
                new Vector<>(),
260bf39376a4 8200258: Improve CopyOnWriteArrayList subList code
dl
parents: 48541
diff changeset
   311
                makeSubList(new Vector<>()),
260bf39376a4 8200258: Improve CopyOnWriteArrayList subList code
dl
parents: 48541
diff changeset
   312
                new CopyOnWriteArrayList<>(),
260bf39376a4 8200258: Improve CopyOnWriteArrayList subList code
dl
parents: 48541
diff changeset
   313
                makeSubList(new CopyOnWriteArrayList<>()),
260bf39376a4 8200258: Improve CopyOnWriteArrayList subList code
dl
parents: 48541
diff changeset
   314
                new ArrayDeque<>(),
260bf39376a4 8200258: Improve CopyOnWriteArrayList subList code
dl
parents: 48541
diff changeset
   315
                new PriorityQueue<>(),
260bf39376a4 8200258: Improve CopyOnWriteArrayList subList code
dl
parents: 48541
diff changeset
   316
                new ArrayBlockingQueue<>(elements.size()),
260bf39376a4 8200258: Improve CopyOnWriteArrayList subList code
dl
parents: 48541
diff changeset
   317
                new ConcurrentLinkedQueue<>(),
260bf39376a4 8200258: Improve CopyOnWriteArrayList subList code
dl
parents: 48541
diff changeset
   318
                new ConcurrentLinkedDeque<>(),
260bf39376a4 8200258: Improve CopyOnWriteArrayList subList code
dl
parents: 48541
diff changeset
   319
                new LinkedBlockingQueue<>(),
260bf39376a4 8200258: Improve CopyOnWriteArrayList subList code
dl
parents: 48541
diff changeset
   320
                new LinkedBlockingDeque<>(),
260bf39376a4 8200258: Improve CopyOnWriteArrayList subList code
dl
parents: 48541
diff changeset
   321
                new LinkedTransferQueue<>(),
260bf39376a4 8200258: Improve CopyOnWriteArrayList subList code
dl
parents: 48541
diff changeset
   322
                new PriorityBlockingQueue<>())
260bf39376a4 8200258: Improve CopyOnWriteArrayList subList code
dl
parents: 48541
diff changeset
   323
            .flatMap(x -> jobs(x))
260bf39376a4 8200258: Improve CopyOnWriteArrayList subList code
dl
parents: 48541
diff changeset
   324
            .filter(job ->
260bf39376a4 8200258: Improve CopyOnWriteArrayList subList code
dl
parents: 48541
diff changeset
   325
                nameFilter == null || nameFilter.matcher(job.name()).find())
260bf39376a4 8200258: Improve CopyOnWriteArrayList subList code
dl
parents: 48541
diff changeset
   326
            .collect(toCollection(ArrayList::new));
42319
0193886267c3 8143577: optimize ArrayList.removeIf
dl
parents:
diff changeset
   327
0193886267c3 8143577: optimize ArrayList.removeIf
dl
parents:
diff changeset
   328
        if (reverse) Collections.reverse(jobs);
0193886267c3 8143577: optimize ArrayList.removeIf
dl
parents:
diff changeset
   329
        if (shuffle) Collections.shuffle(jobs);
0193886267c3 8143577: optimize ArrayList.removeIf
dl
parents:
diff changeset
   330
49564
260bf39376a4 8200258: Improve CopyOnWriteArrayList subList code
dl
parents: 48541
diff changeset
   331
        time(jobs);
260bf39376a4 8200258: Improve CopyOnWriteArrayList subList code
dl
parents: 48541
diff changeset
   332
    }
260bf39376a4 8200258: Improve CopyOnWriteArrayList subList code
dl
parents: 48541
diff changeset
   333
260bf39376a4 8200258: Improve CopyOnWriteArrayList subList code
dl
parents: 48541
diff changeset
   334
    Stream<Job> jobs(Collection<Integer> x) {
260bf39376a4 8200258: Improve CopyOnWriteArrayList subList code
dl
parents: 48541
diff changeset
   335
        return concatStreams(
260bf39376a4 8200258: Improve CopyOnWriteArrayList subList code
dl
parents: 48541
diff changeset
   336
            collectionJobs(x),
260bf39376a4 8200258: Improve CopyOnWriteArrayList subList code
dl
parents: 48541
diff changeset
   337
260bf39376a4 8200258: Improve CopyOnWriteArrayList subList code
dl
parents: 48541
diff changeset
   338
            (CopyOnWriteArrayList.class.isAssignableFrom(topLevelClass(x)))
260bf39376a4 8200258: Improve CopyOnWriteArrayList subList code
dl
parents: 48541
diff changeset
   339
            ? Stream.empty()
260bf39376a4 8200258: Improve CopyOnWriteArrayList subList code
dl
parents: 48541
diff changeset
   340
            : iteratorRemoveJobs(x),
260bf39376a4 8200258: Improve CopyOnWriteArrayList subList code
dl
parents: 48541
diff changeset
   341
260bf39376a4 8200258: Improve CopyOnWriteArrayList subList code
dl
parents: 48541
diff changeset
   342
            (x instanceof Queue)
260bf39376a4 8200258: Improve CopyOnWriteArrayList subList code
dl
parents: 48541
diff changeset
   343
            ? queueJobs((Queue<Integer>)x)
260bf39376a4 8200258: Improve CopyOnWriteArrayList subList code
dl
parents: 48541
diff changeset
   344
            : Stream.empty(),
260bf39376a4 8200258: Improve CopyOnWriteArrayList subList code
dl
parents: 48541
diff changeset
   345
260bf39376a4 8200258: Improve CopyOnWriteArrayList subList code
dl
parents: 48541
diff changeset
   346
            (x instanceof Deque)
260bf39376a4 8200258: Improve CopyOnWriteArrayList subList code
dl
parents: 48541
diff changeset
   347
            ? dequeJobs((Deque<Integer>)x)
260bf39376a4 8200258: Improve CopyOnWriteArrayList subList code
dl
parents: 48541
diff changeset
   348
            : Stream.empty(),
260bf39376a4 8200258: Improve CopyOnWriteArrayList subList code
dl
parents: 48541
diff changeset
   349
260bf39376a4 8200258: Improve CopyOnWriteArrayList subList code
dl
parents: 48541
diff changeset
   350
            (x instanceof BlockingQueue)
260bf39376a4 8200258: Improve CopyOnWriteArrayList subList code
dl
parents: 48541
diff changeset
   351
            ? blockingQueueJobs((BlockingQueue<Integer>)x)
260bf39376a4 8200258: Improve CopyOnWriteArrayList subList code
dl
parents: 48541
diff changeset
   352
            : Stream.empty(),
260bf39376a4 8200258: Improve CopyOnWriteArrayList subList code
dl
parents: 48541
diff changeset
   353
260bf39376a4 8200258: Improve CopyOnWriteArrayList subList code
dl
parents: 48541
diff changeset
   354
            (x instanceof BlockingDeque)
260bf39376a4 8200258: Improve CopyOnWriteArrayList subList code
dl
parents: 48541
diff changeset
   355
            ? blockingDequeJobs((BlockingDeque<Integer>)x)
260bf39376a4 8200258: Improve CopyOnWriteArrayList subList code
dl
parents: 48541
diff changeset
   356
            : Stream.empty());
42319
0193886267c3 8143577: optimize ArrayList.removeIf
dl
parents:
diff changeset
   357
    }
0193886267c3 8143577: optimize ArrayList.removeIf
dl
parents:
diff changeset
   358
0193886267c3 8143577: optimize ArrayList.removeIf
dl
parents:
diff changeset
   359
    Collection<Integer> universeRecorder(int[] sum) {
0193886267c3 8143577: optimize ArrayList.removeIf
dl
parents:
diff changeset
   360
        return new ArrayList<>() {
0193886267c3 8143577: optimize ArrayList.removeIf
dl
parents:
diff changeset
   361
            public boolean contains(Object x) {
0193886267c3 8143577: optimize ArrayList.removeIf
dl
parents:
diff changeset
   362
                sum[0] += (Integer) x;
0193886267c3 8143577: optimize ArrayList.removeIf
dl
parents:
diff changeset
   363
                return true;
0193886267c3 8143577: optimize ArrayList.removeIf
dl
parents:
diff changeset
   364
            }};
0193886267c3 8143577: optimize ArrayList.removeIf
dl
parents:
diff changeset
   365
    }
0193886267c3 8143577: optimize ArrayList.removeIf
dl
parents:
diff changeset
   366
0193886267c3 8143577: optimize ArrayList.removeIf
dl
parents:
diff changeset
   367
    Collection<Integer> emptyRecorder(int[] sum) {
0193886267c3 8143577: optimize ArrayList.removeIf
dl
parents:
diff changeset
   368
        return new ArrayList<>() {
0193886267c3 8143577: optimize ArrayList.removeIf
dl
parents:
diff changeset
   369
            public boolean contains(Object x) {
0193886267c3 8143577: optimize ArrayList.removeIf
dl
parents:
diff changeset
   370
                sum[0] += (Integer) x;
0193886267c3 8143577: optimize ArrayList.removeIf
dl
parents:
diff changeset
   371
                return false;
0193886267c3 8143577: optimize ArrayList.removeIf
dl
parents:
diff changeset
   372
            }};
0193886267c3 8143577: optimize ArrayList.removeIf
dl
parents:
diff changeset
   373
    }
0193886267c3 8143577: optimize ArrayList.removeIf
dl
parents:
diff changeset
   374
49564
260bf39376a4 8200258: Improve CopyOnWriteArrayList subList code
dl
parents: 48541
diff changeset
   375
    Stream<Job> collectionJobs(Collection<Integer> x) {
53781
940046624bf8 8215249: Miscellaneous changes imported from jsr166 CVS 2019-02
dl
parents: 50764
diff changeset
   376
        final String klazz = goodClassName(x);
49564
260bf39376a4 8200258: Improve CopyOnWriteArrayList subList code
dl
parents: 48541
diff changeset
   377
        return Stream.of(
260bf39376a4 8200258: Improve CopyOnWriteArrayList subList code
dl
parents: 48541
diff changeset
   378
            new Job(klazz + " removeIf") {
42319
0193886267c3 8143577: optimize ArrayList.removeIf
dl
parents:
diff changeset
   379
                public void work() throws Throwable {
0193886267c3 8143577: optimize ArrayList.removeIf
dl
parents:
diff changeset
   380
                    int[] sum = new int[1];
0193886267c3 8143577: optimize ArrayList.removeIf
dl
parents:
diff changeset
   381
                    for (int i = 0; i < iterations; i++) {
0193886267c3 8143577: optimize ArrayList.removeIf
dl
parents:
diff changeset
   382
                        sum[0] = 0;
49564
260bf39376a4 8200258: Improve CopyOnWriteArrayList subList code
dl
parents: 48541
diff changeset
   383
                        x.addAll(elements);
42319
0193886267c3 8143577: optimize ArrayList.removeIf
dl
parents:
diff changeset
   384
                        x.removeIf(n -> { sum[0] += n; return true; });
0193886267c3 8143577: optimize ArrayList.removeIf
dl
parents:
diff changeset
   385
                        check.sum(sum[0]);}}},
49564
260bf39376a4 8200258: Improve CopyOnWriteArrayList subList code
dl
parents: 48541
diff changeset
   386
            new Job(klazz + " removeIf rnd-two-pass") {
43521
60e247b8d9a4 8169748: LinkedTransferQueue bulk remove is O(n^2)
dl
parents: 42319
diff changeset
   387
                public void work() throws Throwable {
60e247b8d9a4 8169748: LinkedTransferQueue bulk remove is O(n^2)
dl
parents: 42319
diff changeset
   388
                    ThreadLocalRandom rnd = ThreadLocalRandom.current();
60e247b8d9a4 8169748: LinkedTransferQueue bulk remove is O(n^2)
dl
parents: 42319
diff changeset
   389
                    int[] sum = new int[1];
60e247b8d9a4 8169748: LinkedTransferQueue bulk remove is O(n^2)
dl
parents: 42319
diff changeset
   390
                    for (int i = 0; i < iterations; i++) {
60e247b8d9a4 8169748: LinkedTransferQueue bulk remove is O(n^2)
dl
parents: 42319
diff changeset
   391
                        sum[0] = 0;
49564
260bf39376a4 8200258: Improve CopyOnWriteArrayList subList code
dl
parents: 48541
diff changeset
   392
                        x.addAll(elements);
43521
60e247b8d9a4 8169748: LinkedTransferQueue bulk remove is O(n^2)
dl
parents: 42319
diff changeset
   393
                        x.removeIf(n -> {
60e247b8d9a4 8169748: LinkedTransferQueue bulk remove is O(n^2)
dl
parents: 42319
diff changeset
   394
                            boolean b = rnd.nextBoolean();
60e247b8d9a4 8169748: LinkedTransferQueue bulk remove is O(n^2)
dl
parents: 42319
diff changeset
   395
                            if (b) sum[0] += n;
60e247b8d9a4 8169748: LinkedTransferQueue bulk remove is O(n^2)
dl
parents: 42319
diff changeset
   396
                            return b; });
60e247b8d9a4 8169748: LinkedTransferQueue bulk remove is O(n^2)
dl
parents: 42319
diff changeset
   397
                        x.removeIf(n -> { sum[0] += n; return true; });
60e247b8d9a4 8169748: LinkedTransferQueue bulk remove is O(n^2)
dl
parents: 42319
diff changeset
   398
                        check.sum(sum[0]);}}},
49564
260bf39376a4 8200258: Improve CopyOnWriteArrayList subList code
dl
parents: 48541
diff changeset
   399
            new Job(klazz + " removeAll") {
42319
0193886267c3 8143577: optimize ArrayList.removeIf
dl
parents:
diff changeset
   400
                public void work() throws Throwable {
0193886267c3 8143577: optimize ArrayList.removeIf
dl
parents:
diff changeset
   401
                    int[] sum = new int[1];
0193886267c3 8143577: optimize ArrayList.removeIf
dl
parents:
diff changeset
   402
                    Collection<Integer> universe = universeRecorder(sum);
0193886267c3 8143577: optimize ArrayList.removeIf
dl
parents:
diff changeset
   403
                    for (int i = 0; i < iterations; i++) {
0193886267c3 8143577: optimize ArrayList.removeIf
dl
parents:
diff changeset
   404
                        sum[0] = 0;
49564
260bf39376a4 8200258: Improve CopyOnWriteArrayList subList code
dl
parents: 48541
diff changeset
   405
                        x.addAll(elements);
42319
0193886267c3 8143577: optimize ArrayList.removeIf
dl
parents:
diff changeset
   406
                        x.removeAll(universe);
0193886267c3 8143577: optimize ArrayList.removeIf
dl
parents:
diff changeset
   407
                        check.sum(sum[0]);}}},
49564
260bf39376a4 8200258: Improve CopyOnWriteArrayList subList code
dl
parents: 48541
diff changeset
   408
            new Job(klazz + " retainAll") {
42319
0193886267c3 8143577: optimize ArrayList.removeIf
dl
parents:
diff changeset
   409
                public void work() throws Throwable {
0193886267c3 8143577: optimize ArrayList.removeIf
dl
parents:
diff changeset
   410
                    int[] sum = new int[1];
0193886267c3 8143577: optimize ArrayList.removeIf
dl
parents:
diff changeset
   411
                    Collection<Integer> empty = emptyRecorder(sum);
0193886267c3 8143577: optimize ArrayList.removeIf
dl
parents:
diff changeset
   412
                    for (int i = 0; i < iterations; i++) {
0193886267c3 8143577: optimize ArrayList.removeIf
dl
parents:
diff changeset
   413
                        sum[0] = 0;
49564
260bf39376a4 8200258: Improve CopyOnWriteArrayList subList code
dl
parents: 48541
diff changeset
   414
                        x.addAll(elements);
42319
0193886267c3 8143577: optimize ArrayList.removeIf
dl
parents:
diff changeset
   415
                        x.retainAll(empty);
0193886267c3 8143577: optimize ArrayList.removeIf
dl
parents:
diff changeset
   416
                        check.sum(sum[0]);}}},
49564
260bf39376a4 8200258: Improve CopyOnWriteArrayList subList code
dl
parents: 48541
diff changeset
   417
            new Job(klazz + " clear") {
42319
0193886267c3 8143577: optimize ArrayList.removeIf
dl
parents:
diff changeset
   418
                public void work() throws Throwable {
0193886267c3 8143577: optimize ArrayList.removeIf
dl
parents:
diff changeset
   419
                    int[] sum = new int[1];
0193886267c3 8143577: optimize ArrayList.removeIf
dl
parents:
diff changeset
   420
                    for (int i = 0; i < iterations; i++) {
0193886267c3 8143577: optimize ArrayList.removeIf
dl
parents:
diff changeset
   421
                        sum[0] = 0;
49564
260bf39376a4 8200258: Improve CopyOnWriteArrayList subList code
dl
parents: 48541
diff changeset
   422
                        x.addAll(elements);
260bf39376a4 8200258: Improve CopyOnWriteArrayList subList code
dl
parents: 48541
diff changeset
   423
                        x.forEach(e -> sum[0] += e);
260bf39376a4 8200258: Improve CopyOnWriteArrayList subList code
dl
parents: 48541
diff changeset
   424
                        x.clear();
260bf39376a4 8200258: Improve CopyOnWriteArrayList subList code
dl
parents: 48541
diff changeset
   425
                        check.sum(sum[0]);}}});
260bf39376a4 8200258: Improve CopyOnWriteArrayList subList code
dl
parents: 48541
diff changeset
   426
    }
260bf39376a4 8200258: Improve CopyOnWriteArrayList subList code
dl
parents: 48541
diff changeset
   427
260bf39376a4 8200258: Improve CopyOnWriteArrayList subList code
dl
parents: 48541
diff changeset
   428
    Stream<Job> iteratorRemoveJobs(Collection<Integer> x) {
53781
940046624bf8 8215249: Miscellaneous changes imported from jsr166 CVS 2019-02
dl
parents: 50764
diff changeset
   429
        final String klazz = goodClassName(x);
49564
260bf39376a4 8200258: Improve CopyOnWriteArrayList subList code
dl
parents: 48541
diff changeset
   430
        return Stream.of(
260bf39376a4 8200258: Improve CopyOnWriteArrayList subList code
dl
parents: 48541
diff changeset
   431
             new Job(klazz + " Iterator.remove") {
260bf39376a4 8200258: Improve CopyOnWriteArrayList subList code
dl
parents: 48541
diff changeset
   432
                public void work() throws Throwable {
260bf39376a4 8200258: Improve CopyOnWriteArrayList subList code
dl
parents: 48541
diff changeset
   433
                    int[] sum = new int[1];
260bf39376a4 8200258: Improve CopyOnWriteArrayList subList code
dl
parents: 48541
diff changeset
   434
                    for (int i = 0; i < iterations; i++) {
260bf39376a4 8200258: Improve CopyOnWriteArrayList subList code
dl
parents: 48541
diff changeset
   435
                        sum[0] = 0;
260bf39376a4 8200258: Improve CopyOnWriteArrayList subList code
dl
parents: 48541
diff changeset
   436
                        x.addAll(elements);
42319
0193886267c3 8143577: optimize ArrayList.removeIf
dl
parents:
diff changeset
   437
                        Iterator<Integer> it = x.iterator();
0193886267c3 8143577: optimize ArrayList.removeIf
dl
parents:
diff changeset
   438
                        while (it.hasNext()) {
0193886267c3 8143577: optimize ArrayList.removeIf
dl
parents:
diff changeset
   439
                            sum[0] += it.next();
0193886267c3 8143577: optimize ArrayList.removeIf
dl
parents:
diff changeset
   440
                            it.remove();
0193886267c3 8143577: optimize ArrayList.removeIf
dl
parents:
diff changeset
   441
                        }
0193886267c3 8143577: optimize ArrayList.removeIf
dl
parents:
diff changeset
   442
                        check.sum(sum[0]);}}},
49564
260bf39376a4 8200258: Improve CopyOnWriteArrayList subList code
dl
parents: 48541
diff changeset
   443
            new Job(klazz + " Iterator.remove-rnd-two-pass") {
43521
60e247b8d9a4 8169748: LinkedTransferQueue bulk remove is O(n^2)
dl
parents: 42319
diff changeset
   444
                public void work() throws Throwable {
60e247b8d9a4 8169748: LinkedTransferQueue bulk remove is O(n^2)
dl
parents: 42319
diff changeset
   445
                    ThreadLocalRandom rnd = ThreadLocalRandom.current();
60e247b8d9a4 8169748: LinkedTransferQueue bulk remove is O(n^2)
dl
parents: 42319
diff changeset
   446
                    int[] sum = new int[1];
60e247b8d9a4 8169748: LinkedTransferQueue bulk remove is O(n^2)
dl
parents: 42319
diff changeset
   447
                    for (int i = 0; i < iterations; i++) {
60e247b8d9a4 8169748: LinkedTransferQueue bulk remove is O(n^2)
dl
parents: 42319
diff changeset
   448
                        sum[0] = 0;
49564
260bf39376a4 8200258: Improve CopyOnWriteArrayList subList code
dl
parents: 48541
diff changeset
   449
                        x.addAll(elements);
43521
60e247b8d9a4 8169748: LinkedTransferQueue bulk remove is O(n^2)
dl
parents: 42319
diff changeset
   450
                        for (Iterator<Integer> it = x.iterator();
60e247b8d9a4 8169748: LinkedTransferQueue bulk remove is O(n^2)
dl
parents: 42319
diff changeset
   451
                             it.hasNext(); ) {
60e247b8d9a4 8169748: LinkedTransferQueue bulk remove is O(n^2)
dl
parents: 42319
diff changeset
   452
                            Integer e = it.next();
60e247b8d9a4 8169748: LinkedTransferQueue bulk remove is O(n^2)
dl
parents: 42319
diff changeset
   453
                            if (rnd.nextBoolean()) {
60e247b8d9a4 8169748: LinkedTransferQueue bulk remove is O(n^2)
dl
parents: 42319
diff changeset
   454
                                sum[0] += e;
60e247b8d9a4 8169748: LinkedTransferQueue bulk remove is O(n^2)
dl
parents: 42319
diff changeset
   455
                                it.remove();
60e247b8d9a4 8169748: LinkedTransferQueue bulk remove is O(n^2)
dl
parents: 42319
diff changeset
   456
                            }
60e247b8d9a4 8169748: LinkedTransferQueue bulk remove is O(n^2)
dl
parents: 42319
diff changeset
   457
                        }
60e247b8d9a4 8169748: LinkedTransferQueue bulk remove is O(n^2)
dl
parents: 42319
diff changeset
   458
                        for (Iterator<Integer> it = x.iterator();
60e247b8d9a4 8169748: LinkedTransferQueue bulk remove is O(n^2)
dl
parents: 42319
diff changeset
   459
                             it.hasNext(); ) {
60e247b8d9a4 8169748: LinkedTransferQueue bulk remove is O(n^2)
dl
parents: 42319
diff changeset
   460
                            sum[0] += it.next();
60e247b8d9a4 8169748: LinkedTransferQueue bulk remove is O(n^2)
dl
parents: 42319
diff changeset
   461
                            it.remove();
60e247b8d9a4 8169748: LinkedTransferQueue bulk remove is O(n^2)
dl
parents: 42319
diff changeset
   462
                        }
42319
0193886267c3 8143577: optimize ArrayList.removeIf
dl
parents:
diff changeset
   463
                        check.sum(sum[0]);}}});
0193886267c3 8143577: optimize ArrayList.removeIf
dl
parents:
diff changeset
   464
    }
0193886267c3 8143577: optimize ArrayList.removeIf
dl
parents:
diff changeset
   465
49564
260bf39376a4 8200258: Improve CopyOnWriteArrayList subList code
dl
parents: 48541
diff changeset
   466
    Stream<Job> queueJobs(Queue<Integer> x) {
53781
940046624bf8 8215249: Miscellaneous changes imported from jsr166 CVS 2019-02
dl
parents: 50764
diff changeset
   467
        final String klazz = goodClassName(x);
49564
260bf39376a4 8200258: Improve CopyOnWriteArrayList subList code
dl
parents: 48541
diff changeset
   468
        return Stream.of(
260bf39376a4 8200258: Improve CopyOnWriteArrayList subList code
dl
parents: 48541
diff changeset
   469
            new Job(klazz + " poll()") {
42319
0193886267c3 8143577: optimize ArrayList.removeIf
dl
parents:
diff changeset
   470
                public void work() throws Throwable {
0193886267c3 8143577: optimize ArrayList.removeIf
dl
parents:
diff changeset
   471
                    int[] sum = new int[1];
0193886267c3 8143577: optimize ArrayList.removeIf
dl
parents:
diff changeset
   472
                    for (int i = 0; i < iterations; i++) {
0193886267c3 8143577: optimize ArrayList.removeIf
dl
parents:
diff changeset
   473
                        sum[0] = 0;
49564
260bf39376a4 8200258: Improve CopyOnWriteArrayList subList code
dl
parents: 48541
diff changeset
   474
                        x.addAll(elements);
42319
0193886267c3 8143577: optimize ArrayList.removeIf
dl
parents:
diff changeset
   475
                        for (Integer e; (e = x.poll()) != null; )
0193886267c3 8143577: optimize ArrayList.removeIf
dl
parents:
diff changeset
   476
                            sum[0] += e;
0193886267c3 8143577: optimize ArrayList.removeIf
dl
parents:
diff changeset
   477
                        check.sum(sum[0]);}}});
0193886267c3 8143577: optimize ArrayList.removeIf
dl
parents:
diff changeset
   478
    }
0193886267c3 8143577: optimize ArrayList.removeIf
dl
parents:
diff changeset
   479
49564
260bf39376a4 8200258: Improve CopyOnWriteArrayList subList code
dl
parents: 48541
diff changeset
   480
    Stream<Job> dequeJobs(Deque<Integer> x) {
53781
940046624bf8 8215249: Miscellaneous changes imported from jsr166 CVS 2019-02
dl
parents: 50764
diff changeset
   481
        final String klazz = goodClassName(x);
49564
260bf39376a4 8200258: Improve CopyOnWriteArrayList subList code
dl
parents: 48541
diff changeset
   482
        return Stream.of(
260bf39376a4 8200258: Improve CopyOnWriteArrayList subList code
dl
parents: 48541
diff changeset
   483
            new Job(klazz + " descendingIterator().remove") {
42319
0193886267c3 8143577: optimize ArrayList.removeIf
dl
parents:
diff changeset
   484
                public void work() throws Throwable {
0193886267c3 8143577: optimize ArrayList.removeIf
dl
parents:
diff changeset
   485
                    int[] sum = new int[1];
0193886267c3 8143577: optimize ArrayList.removeIf
dl
parents:
diff changeset
   486
                    for (int i = 0; i < iterations; i++) {
0193886267c3 8143577: optimize ArrayList.removeIf
dl
parents:
diff changeset
   487
                        sum[0] = 0;
49564
260bf39376a4 8200258: Improve CopyOnWriteArrayList subList code
dl
parents: 48541
diff changeset
   488
                        x.addAll(elements);
42319
0193886267c3 8143577: optimize ArrayList.removeIf
dl
parents:
diff changeset
   489
                        Iterator<Integer> it = x.descendingIterator();
0193886267c3 8143577: optimize ArrayList.removeIf
dl
parents:
diff changeset
   490
                        while (it.hasNext()) {
0193886267c3 8143577: optimize ArrayList.removeIf
dl
parents:
diff changeset
   491
                            sum[0] += it.next();
0193886267c3 8143577: optimize ArrayList.removeIf
dl
parents:
diff changeset
   492
                            it.remove();
0193886267c3 8143577: optimize ArrayList.removeIf
dl
parents:
diff changeset
   493
                        }
0193886267c3 8143577: optimize ArrayList.removeIf
dl
parents:
diff changeset
   494
                        check.sum(sum[0]);}}},
49564
260bf39376a4 8200258: Improve CopyOnWriteArrayList subList code
dl
parents: 48541
diff changeset
   495
            new Job(klazz + " pollFirst()") {
42319
0193886267c3 8143577: optimize ArrayList.removeIf
dl
parents:
diff changeset
   496
                public void work() throws Throwable {
0193886267c3 8143577: optimize ArrayList.removeIf
dl
parents:
diff changeset
   497
                    int[] sum = new int[1];
0193886267c3 8143577: optimize ArrayList.removeIf
dl
parents:
diff changeset
   498
                    for (int i = 0; i < iterations; i++) {
0193886267c3 8143577: optimize ArrayList.removeIf
dl
parents:
diff changeset
   499
                        sum[0] = 0;
49564
260bf39376a4 8200258: Improve CopyOnWriteArrayList subList code
dl
parents: 48541
diff changeset
   500
                        x.addAll(elements);
42319
0193886267c3 8143577: optimize ArrayList.removeIf
dl
parents:
diff changeset
   501
                        for (Integer e; (e = x.pollFirst()) != null; )
0193886267c3 8143577: optimize ArrayList.removeIf
dl
parents:
diff changeset
   502
                            sum[0] += e;
0193886267c3 8143577: optimize ArrayList.removeIf
dl
parents:
diff changeset
   503
                        check.sum(sum[0]);}}},
49564
260bf39376a4 8200258: Improve CopyOnWriteArrayList subList code
dl
parents: 48541
diff changeset
   504
            new Job(klazz + " pollLast()") {
42319
0193886267c3 8143577: optimize ArrayList.removeIf
dl
parents:
diff changeset
   505
                public void work() throws Throwable {
0193886267c3 8143577: optimize ArrayList.removeIf
dl
parents:
diff changeset
   506
                    int[] sum = new int[1];
0193886267c3 8143577: optimize ArrayList.removeIf
dl
parents:
diff changeset
   507
                    for (int i = 0; i < iterations; i++) {
0193886267c3 8143577: optimize ArrayList.removeIf
dl
parents:
diff changeset
   508
                        sum[0] = 0;
49564
260bf39376a4 8200258: Improve CopyOnWriteArrayList subList code
dl
parents: 48541
diff changeset
   509
                        x.addAll(elements);
42319
0193886267c3 8143577: optimize ArrayList.removeIf
dl
parents:
diff changeset
   510
                        for (Integer e; (e = x.pollLast()) != null; )
0193886267c3 8143577: optimize ArrayList.removeIf
dl
parents:
diff changeset
   511
                            sum[0] += e;
0193886267c3 8143577: optimize ArrayList.removeIf
dl
parents:
diff changeset
   512
                        check.sum(sum[0]);}}});
0193886267c3 8143577: optimize ArrayList.removeIf
dl
parents:
diff changeset
   513
    }
0193886267c3 8143577: optimize ArrayList.removeIf
dl
parents:
diff changeset
   514
49564
260bf39376a4 8200258: Improve CopyOnWriteArrayList subList code
dl
parents: 48541
diff changeset
   515
    Stream<Job> blockingQueueJobs(BlockingQueue<Integer> x) {
53781
940046624bf8 8215249: Miscellaneous changes imported from jsr166 CVS 2019-02
dl
parents: 50764
diff changeset
   516
        final String klazz = goodClassName(x);
49564
260bf39376a4 8200258: Improve CopyOnWriteArrayList subList code
dl
parents: 48541
diff changeset
   517
        return Stream.of(
50229
6b29ef846c5c 8201386: Miscellaneous changes imported from jsr166 CVS 2018-05
dl
parents: 49564
diff changeset
   518
            new Job(klazz + " timed poll()") {
6b29ef846c5c 8201386: Miscellaneous changes imported from jsr166 CVS 2018-05
dl
parents: 49564
diff changeset
   519
                public void work() throws Throwable {
6b29ef846c5c 8201386: Miscellaneous changes imported from jsr166 CVS 2018-05
dl
parents: 49564
diff changeset
   520
                    int[] sum = new int[1];
6b29ef846c5c 8201386: Miscellaneous changes imported from jsr166 CVS 2018-05
dl
parents: 49564
diff changeset
   521
                    for (int i = 0; i < iterations; i++) {
6b29ef846c5c 8201386: Miscellaneous changes imported from jsr166 CVS 2018-05
dl
parents: 49564
diff changeset
   522
                        sum[0] = 0;
6b29ef846c5c 8201386: Miscellaneous changes imported from jsr166 CVS 2018-05
dl
parents: 49564
diff changeset
   523
                        x.addAll(elements);
6b29ef846c5c 8201386: Miscellaneous changes imported from jsr166 CVS 2018-05
dl
parents: 49564
diff changeset
   524
                        for (Integer e; (e = x.poll(0L, TimeUnit.DAYS)) != null; )
6b29ef846c5c 8201386: Miscellaneous changes imported from jsr166 CVS 2018-05
dl
parents: 49564
diff changeset
   525
                            sum[0] += e;
6b29ef846c5c 8201386: Miscellaneous changes imported from jsr166 CVS 2018-05
dl
parents: 49564
diff changeset
   526
                        check.sum(sum[0]);}}},
49564
260bf39376a4 8200258: Improve CopyOnWriteArrayList subList code
dl
parents: 48541
diff changeset
   527
            new Job(klazz + " drainTo(sink)") {
42319
0193886267c3 8143577: optimize ArrayList.removeIf
dl
parents:
diff changeset
   528
                public void work() throws Throwable {
0193886267c3 8143577: optimize ArrayList.removeIf
dl
parents:
diff changeset
   529
                    ArrayList<Integer> sink = new ArrayList<>();
0193886267c3 8143577: optimize ArrayList.removeIf
dl
parents:
diff changeset
   530
                    int[] sum = new int[1];
0193886267c3 8143577: optimize ArrayList.removeIf
dl
parents:
diff changeset
   531
                    for (int i = 0; i < iterations; i++) {
0193886267c3 8143577: optimize ArrayList.removeIf
dl
parents:
diff changeset
   532
                        sum[0] = 0;
0193886267c3 8143577: optimize ArrayList.removeIf
dl
parents:
diff changeset
   533
                        sink.clear();
49564
260bf39376a4 8200258: Improve CopyOnWriteArrayList subList code
dl
parents: 48541
diff changeset
   534
                        x.addAll(elements);
42319
0193886267c3 8143577: optimize ArrayList.removeIf
dl
parents:
diff changeset
   535
                        x.drainTo(sink);
0193886267c3 8143577: optimize ArrayList.removeIf
dl
parents:
diff changeset
   536
                        sink.forEach(e -> sum[0] += e);
0193886267c3 8143577: optimize ArrayList.removeIf
dl
parents:
diff changeset
   537
                        check.sum(sum[0]);}}},
49564
260bf39376a4 8200258: Improve CopyOnWriteArrayList subList code
dl
parents: 48541
diff changeset
   538
            new Job(klazz + " drainTo(sink, n)") {
42319
0193886267c3 8143577: optimize ArrayList.removeIf
dl
parents:
diff changeset
   539
                public void work() throws Throwable {
0193886267c3 8143577: optimize ArrayList.removeIf
dl
parents:
diff changeset
   540
                    ArrayList<Integer> sink = new ArrayList<>();
0193886267c3 8143577: optimize ArrayList.removeIf
dl
parents:
diff changeset
   541
                    int[] sum = new int[1];
0193886267c3 8143577: optimize ArrayList.removeIf
dl
parents:
diff changeset
   542
                    for (int i = 0; i < iterations; i++) {
0193886267c3 8143577: optimize ArrayList.removeIf
dl
parents:
diff changeset
   543
                        sum[0] = 0;
0193886267c3 8143577: optimize ArrayList.removeIf
dl
parents:
diff changeset
   544
                        sink.clear();
49564
260bf39376a4 8200258: Improve CopyOnWriteArrayList subList code
dl
parents: 48541
diff changeset
   545
                        x.addAll(elements);
260bf39376a4 8200258: Improve CopyOnWriteArrayList subList code
dl
parents: 48541
diff changeset
   546
                        x.drainTo(sink, elements.size());
42319
0193886267c3 8143577: optimize ArrayList.removeIf
dl
parents:
diff changeset
   547
                        sink.forEach(e -> sum[0] += e);
0193886267c3 8143577: optimize ArrayList.removeIf
dl
parents:
diff changeset
   548
                        check.sum(sum[0]);}}});
0193886267c3 8143577: optimize ArrayList.removeIf
dl
parents:
diff changeset
   549
    }
0193886267c3 8143577: optimize ArrayList.removeIf
dl
parents:
diff changeset
   550
49564
260bf39376a4 8200258: Improve CopyOnWriteArrayList subList code
dl
parents: 48541
diff changeset
   551
    Stream<Job> blockingDequeJobs(BlockingDeque<Integer> x) {
53781
940046624bf8 8215249: Miscellaneous changes imported from jsr166 CVS 2019-02
dl
parents: 50764
diff changeset
   552
        final String klazz = goodClassName(x);
49564
260bf39376a4 8200258: Improve CopyOnWriteArrayList subList code
dl
parents: 48541
diff changeset
   553
        return Stream.of(
260bf39376a4 8200258: Improve CopyOnWriteArrayList subList code
dl
parents: 48541
diff changeset
   554
            new Job(klazz + " timed pollFirst()") {
42319
0193886267c3 8143577: optimize ArrayList.removeIf
dl
parents:
diff changeset
   555
                public void work() throws Throwable {
0193886267c3 8143577: optimize ArrayList.removeIf
dl
parents:
diff changeset
   556
                    int[] sum = new int[1];
0193886267c3 8143577: optimize ArrayList.removeIf
dl
parents:
diff changeset
   557
                    for (int i = 0; i < iterations; i++) {
0193886267c3 8143577: optimize ArrayList.removeIf
dl
parents:
diff changeset
   558
                        sum[0] = 0;
49564
260bf39376a4 8200258: Improve CopyOnWriteArrayList subList code
dl
parents: 48541
diff changeset
   559
                        x.addAll(elements);
42319
0193886267c3 8143577: optimize ArrayList.removeIf
dl
parents:
diff changeset
   560
                        for (Integer e; (e = x.pollFirst(0L, TimeUnit.DAYS)) != null; )
0193886267c3 8143577: optimize ArrayList.removeIf
dl
parents:
diff changeset
   561
                            sum[0] += e;
0193886267c3 8143577: optimize ArrayList.removeIf
dl
parents:
diff changeset
   562
                        check.sum(sum[0]);}}},
49564
260bf39376a4 8200258: Improve CopyOnWriteArrayList subList code
dl
parents: 48541
diff changeset
   563
            new Job(klazz + " timed pollLast()") {
42319
0193886267c3 8143577: optimize ArrayList.removeIf
dl
parents:
diff changeset
   564
                public void work() throws Throwable {
0193886267c3 8143577: optimize ArrayList.removeIf
dl
parents:
diff changeset
   565
                    int[] sum = new int[1];
0193886267c3 8143577: optimize ArrayList.removeIf
dl
parents:
diff changeset
   566
                    for (int i = 0; i < iterations; i++) {
0193886267c3 8143577: optimize ArrayList.removeIf
dl
parents:
diff changeset
   567
                        sum[0] = 0;
49564
260bf39376a4 8200258: Improve CopyOnWriteArrayList subList code
dl
parents: 48541
diff changeset
   568
                        x.addAll(elements);
42319
0193886267c3 8143577: optimize ArrayList.removeIf
dl
parents:
diff changeset
   569
                        for (Integer e; (e = x.pollLast(0L, TimeUnit.DAYS)) != null; )
0193886267c3 8143577: optimize ArrayList.removeIf
dl
parents:
diff changeset
   570
                            sum[0] += e;
0193886267c3 8143577: optimize ArrayList.removeIf
dl
parents:
diff changeset
   571
                        check.sum(sum[0]);}}});
0193886267c3 8143577: optimize ArrayList.removeIf
dl
parents:
diff changeset
   572
    }
0193886267c3 8143577: optimize ArrayList.removeIf
dl
parents:
diff changeset
   573
}