ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/jsr166/jsr166/src/test/jtreg/util/Collection/IteratorMicroBenchmark.java
Revision: 1.44
Committed: Wed May 9 17:43:01 2018 UTC (6 years ago) by jsr166
Branch: MAIN
Changes since 1.43: +13 -7 lines
Log Message:
forceFullGc: avoid rare failures due to back-to-back GCs, seen only at Google

File Contents

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