test/jdk/java/util/concurrent/ConcurrentHashMap/MapLoops.java
author iignatyev
Fri, 14 Sep 2018 14:02:57 -0700
changeset 51754 594919232b8f
parent 50764 5637aca18f1d
child 58138 1e4270f875ee
permissions -rw-r--r--
8210732: remove jdk.testlibrary.Utils Reviewed-by: alanb, jcbeyler
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
     2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * under the terms of the GNU General Public License version 2 only, as
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * published by the Free Software Foundation.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     7
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
     9
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4347
diff changeset
    18
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4347
diff changeset
    19
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4347
diff changeset
    20
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    21
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    22
90ce3da70b43 Initial load
duke
parents:
diff changeset
    23
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 * This file is available under and governed by the GNU General Public
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
 * License version 2 only, as published by the Free Software Foundation.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
 * However, the following notice accompanied the original version of this
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
 * file:
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
 * Written by Doug Lea with assistance from members of JCP JSR-166
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
 * Expert Group and released to the public domain, as explained at
9242
ef138d47df58 7034657: Update Creative Commons license URL in legal notices
dl
parents: 7518
diff changeset
    31
 * http://creativecommons.org/publicdomain/zero/1.0/
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
 * @test
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
 * @bug 4486658
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
 * @summary Exercise multithreaded maps, by default ConcurrentHashMap.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
 * Multithreaded hash table test.  Each thread does a random walk
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
 * though elements of "key" array. On each iteration, it checks if
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
 * table includes key.  If absent, with probability pinsert it
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
 * inserts it, and if present, with probability premove it removes
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
 * it.  (pinsert and premove are expressed as percentages to simplify
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
 * parsing from command line.)
51754
594919232b8f 8210732: remove jdk.testlibrary.Utils
iignatyev
parents: 50764
diff changeset
    44
 * @library /test/lib
36233
f85ed703cf7e 8150523: improve jtreg test timeout handling, especially -timeout:
dl
parents: 34347
diff changeset
    45
 * @run main/timeout=1600 MapLoops
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
36233
f85ed703cf7e 8150523: improve jtreg test timeout handling, especially -timeout:
dl
parents: 34347
diff changeset
    48
import static java.util.concurrent.TimeUnit.MILLISECONDS;
34347
4a17f9e90a0f 8142441: Improve jtreg tests for java.util.concurrent
dl
parents: 32991
diff changeset
    49
4a17f9e90a0f 8142441: Improve jtreg tests for java.util.concurrent
dl
parents: 32991
diff changeset
    50
import java.util.List;
4a17f9e90a0f 8142441: Improve jtreg tests for java.util.concurrent
dl
parents: 32991
diff changeset
    51
import java.util.Map;
4a17f9e90a0f 8142441: Improve jtreg tests for java.util.concurrent
dl
parents: 32991
diff changeset
    52
import java.util.SplittableRandom;
4a17f9e90a0f 8142441: Improve jtreg tests for java.util.concurrent
dl
parents: 32991
diff changeset
    53
import java.util.concurrent.CopyOnWriteArrayList;
4a17f9e90a0f 8142441: Improve jtreg tests for java.util.concurrent
dl
parents: 32991
diff changeset
    54
import java.util.concurrent.CyclicBarrier;
4a17f9e90a0f 8142441: Improve jtreg tests for java.util.concurrent
dl
parents: 32991
diff changeset
    55
import java.util.concurrent.ExecutorService;
4a17f9e90a0f 8142441: Improve jtreg tests for java.util.concurrent
dl
parents: 32991
diff changeset
    56
import java.util.concurrent.Executors;
51754
594919232b8f 8210732: remove jdk.testlibrary.Utils
iignatyev
parents: 50764
diff changeset
    57
import jdk.test.lib.Utils;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
public class MapLoops {
36233
f85ed703cf7e 8150523: improve jtreg test timeout handling, especially -timeout:
dl
parents: 34347
diff changeset
    60
    static final long LONG_DELAY_MS = Utils.adjustTimeout(10_000);
34347
4a17f9e90a0f 8142441: Improve jtreg tests for java.util.concurrent
dl
parents: 32991
diff changeset
    61
    static int nkeys       = 1000; // 10_000
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
    static int pinsert     = 60;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
    static int premove     = 2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
    static int maxThreads  = 100;
34347
4a17f9e90a0f 8142441: Improve jtreg tests for java.util.concurrent
dl
parents: 32991
diff changeset
    65
    static int nops        = 10000; // 100_000
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
    static int removesPerMaxRandom;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
    static int insertsPerMaxRandom;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
    static final ExecutorService pool = Executors.newCachedThreadPool();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
43522
f9c6f543c4db 8171886: Miscellaneous changes imported from jsr166 CVS 2017-02
dl
parents: 36233
diff changeset
    71
    static final List<Throwable> throwables = new CopyOnWriteArrayList<>();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
    public static void main(String[] args) throws Exception {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
        Class mapClass = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
        if (args.length > 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
                mapClass = Class.forName(args[0]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
            } catch (ClassNotFoundException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
                throw new RuntimeException("Class " + args[0] + " not found.");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
        else
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
            mapClass = java.util.concurrent.ConcurrentHashMap.class;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
        if (args.length > 1)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
            maxThreads = Integer.parseInt(args[1]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
        if (args.length > 2)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
            nkeys = Integer.parseInt(args[2]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
        if (args.length > 3)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
            pinsert = Integer.parseInt(args[3]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
        if (args.length > 4)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
            premove = Integer.parseInt(args[4]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
        if (args.length > 5)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
            nops = Integer.parseInt(args[5]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
        // normalize probabilities wrt random number generator
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
        removesPerMaxRandom = (int)(((double)premove/100.0 * 0x7FFFFFFFL));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
        insertsPerMaxRandom = (int)(((double)pinsert/100.0 * 0x7FFFFFFFL));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
        System.out.print("Class: " + mapClass.getName());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
        System.out.print(" threads: " + maxThreads);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
        System.out.print(" size: " + nkeys);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
        System.out.print(" ins: " + pinsert);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
        System.out.print(" rem: " + premove);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
        System.out.print(" ops: " + nops);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
        System.out.println();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
        int k = 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
        int warmups = 2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
        for (int i = 1; i <= maxThreads;) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
            test(i, nkeys, mapClass);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
            if (warmups > 0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
                --warmups;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
            else if (i == k) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
                k = i << 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
                i = i + (i >>> 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
            else if (i == 1 && k == 2) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
                i = k;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
                warmups = 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
            else
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
                i = k;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
        pool.shutdown();
36233
f85ed703cf7e 8150523: improve jtreg test timeout handling, especially -timeout:
dl
parents: 34347
diff changeset
   131
        if (! pool.awaitTermination(LONG_DELAY_MS, MILLISECONDS))
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
            throw new Error();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
        if (! throwables.isEmpty())
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
            throw new Error
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
                (throwables.size() + " thread(s) terminated abruptly.");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
    static Integer[] makeKeys(int n) {
34347
4a17f9e90a0f 8142441: Improve jtreg tests for java.util.concurrent
dl
parents: 32991
diff changeset
   140
        SplittableRandom rnd = new SplittableRandom();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
        Integer[] key = new Integer[n];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
        for (int i = 0; i < key.length; ++i)
34347
4a17f9e90a0f 8142441: Improve jtreg tests for java.util.concurrent
dl
parents: 32991
diff changeset
   143
            key[i] = new Integer(rnd.nextInt());
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
        return key;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
    static void shuffleKeys(Integer[] key) {
34347
4a17f9e90a0f 8142441: Improve jtreg tests for java.util.concurrent
dl
parents: 32991
diff changeset
   148
        SplittableRandom rnd = new SplittableRandom();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
        for (int i = key.length; i > 1; --i) {
34347
4a17f9e90a0f 8142441: Improve jtreg tests for java.util.concurrent
dl
parents: 32991
diff changeset
   150
            int j = rnd.nextInt(i);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
            Integer tmp = key[j];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
            key[j] = key[i-1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
            key[i-1] = tmp;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
    static void test(int i, int nkeys, Class mapClass) throws Exception {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
        System.out.print("Threads: " + i + "\t:");
50764
5637aca18f1d 8203681: Miscellaneous changes imported from jsr166 CVS 2018-06
dl
parents: 47216
diff changeset
   159
        Map<Integer, Integer> map = (Map<Integer, Integer>)
5637aca18f1d 8203681: Miscellaneous changes imported from jsr166 CVS 2018-06
dl
parents: 47216
diff changeset
   160
            mapClass.getDeclaredConstructor().newInstance();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
        Integer[] key = makeKeys(nkeys);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
        // Uncomment to start with a non-empty table
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
        //        for (int j = 0; j < nkeys; j += 4) // start 1/4 occupied
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
        //            map.put(key[j], key[j]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
        LoopHelpers.BarrierTimer timer = new LoopHelpers.BarrierTimer();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
        CyclicBarrier barrier = new CyclicBarrier(i+1, timer);
34347
4a17f9e90a0f 8142441: Improve jtreg tests for java.util.concurrent
dl
parents: 32991
diff changeset
   167
        SplittableRandom rnd = new SplittableRandom();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
        for (int t = 0; t < i; ++t)
34347
4a17f9e90a0f 8142441: Improve jtreg tests for java.util.concurrent
dl
parents: 32991
diff changeset
   169
            pool.execute(new Runner(map, key, barrier, rnd.split()));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
        barrier.await();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
        barrier.await();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
        long time = timer.getTime();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
        long tpo = time / (i * (long)nops);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
        System.out.print(LoopHelpers.rightJustify(tpo) + " ns per op");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
        double secs = (double)(time) / 1000000000.0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
        System.out.println("\t " + secs + "s run time");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
        map.clear();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
    static class Runner implements Runnable {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
        final Map<Integer,Integer> map;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
        final Integer[] key;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
        final CyclicBarrier barrier;
34347
4a17f9e90a0f 8142441: Improve jtreg tests for java.util.concurrent
dl
parents: 32991
diff changeset
   184
        final SplittableRandom rnd;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
        int position;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
        int total;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
34347
4a17f9e90a0f 8142441: Improve jtreg tests for java.util.concurrent
dl
parents: 32991
diff changeset
   188
        Runner(Map<Integer,Integer> map,
4a17f9e90a0f 8142441: Improve jtreg tests for java.util.concurrent
dl
parents: 32991
diff changeset
   189
               Integer[] key,
4a17f9e90a0f 8142441: Improve jtreg tests for java.util.concurrent
dl
parents: 32991
diff changeset
   190
               CyclicBarrier barrier,
4a17f9e90a0f 8142441: Improve jtreg tests for java.util.concurrent
dl
parents: 32991
diff changeset
   191
               SplittableRandom rnd) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
            this.map = map;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
            this.key = key;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
            this.barrier = barrier;
34347
4a17f9e90a0f 8142441: Improve jtreg tests for java.util.concurrent
dl
parents: 32991
diff changeset
   195
            this.rnd = rnd;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
            position = key.length / 2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
        int step() {
32991
b27c76b82713 8134853: Bulk integration of java.util.concurrent classes
dl
parents: 22293
diff changeset
   200
            // random-walk around key positions, bunching accesses
34347
4a17f9e90a0f 8142441: Improve jtreg tests for java.util.concurrent
dl
parents: 32991
diff changeset
   201
            int r = rnd.nextInt(Integer.MAX_VALUE);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
            position += (r & 7) - 3;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
            while (position >= key.length) position -= key.length;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
            while (position < 0) position += key.length;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
            Integer k = key[position];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
            Integer x = map.get(k);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
            if (x != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
                if (x.intValue() != k.intValue())
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
                    throw new Error("bad mapping: " + x + " to " + k);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
                if (r < removesPerMaxRandom) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
                    if (map.remove(k) != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
                        position = total % key.length; // move from position
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
                        return 2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
            else if (r < insertsPerMaxRandom) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
                ++position;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
                map.put(k, k);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
                return 2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
            // Uncomment to add a little computation between accesses
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
            //            total += LoopHelpers.compute1(k.intValue());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
            total += r;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
            return 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
        public void run() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
                barrier.await();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
                int ops = nops;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
                while (ops > 0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
                    ops -= step();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
                barrier.await();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
            catch (Throwable throwable) {
7518
0282db800fe1 7003745: Code style cleanups (sync from Dougs CVS)
dl
parents: 5506
diff changeset
   241
                synchronized (System.err) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
                    System.err.println("--------------------------------");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
                    throwable.printStackTrace();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
                throwables.add(throwable);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
}