ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/jsr166/jsr166/src/test/loops/MapLoops.java
(Generate patch)

Comparing jsr166/src/test/loops/MapLoops.java (file contents):
Revision 1.3 by dl, Mon Feb 19 00:46:06 2007 UTC vs.
Revision 1.4 by jsr166, Thu Oct 29 23:09:07 2009 UTC

# Line 8 | Line 8 | import java.util.*;
8   import java.util.concurrent.*;
9  
10   public class MapLoops {
11 <    static int nkeys       = 1000;
11 >    static int nkeys       = 1000;
12      static int pinsert     = 60;
13      static int premove     = 2;
14      static int maxThreads  = 100;
# Line 28 | Line 28 | public class MapLoops {
28                  throw new RuntimeException("Class " + args[0] + " not found.");
29              }
30          }
31 <        else
31 >        else
32              mapClass = java.util.concurrent.ConcurrentHashMap.class;
33  
34 <        if (args.length > 1)
34 >        if (args.length > 1)
35              maxThreads = Integer.parseInt(args[1]);
36  
37 <        if (args.length > 2)
37 >        if (args.length > 2)
38              nkeys = Integer.parseInt(args[2]);
39  
40 <        if (args.length > 3)
40 >        if (args.length > 3)
41              pinsert = Integer.parseInt(args[3]);
42  
43 <        if (args.length > 4)
43 >        if (args.length > 4)
44              premove = Integer.parseInt(args[4]);
45  
46 <        if (args.length > 5)
46 >        if (args.length > 5)
47              nops = Integer.parseInt(args[5]);
48  
49          // normalize probabilities wrt random number generator
50          removesPerMaxRandom = (int)(((double)premove/100.0 * 0x7FFFFFFFL));
51          insertsPerMaxRandom = (int)(((double)pinsert/100.0 * 0x7FFFFFFFL));
52 <        
52 >
53          System.out.print("Class: " + mapClass.getName());
54          System.out.print(" threads: " + maxThreads);
55          System.out.print(" size: " + nkeys);
# Line 68 | Line 68 | public class MapLoops {
68              else if (i == k) {
69                  k = i << 1;
70                  i = i + (i >>> 1);
71 <            }
71 >            }
72              else if (i == 1 && k == 2) {
73                  i = k;
74                  warmups = 1;
75              }
76 <            else
76 >            else
77                  i = k;
78          }
79          pool.shutdown();
# Line 82 | Line 82 | public class MapLoops {
82      static Integer[] makeKeys(int n) {
83          LoopHelpers.SimpleRandom rng = new LoopHelpers.SimpleRandom();
84          Integer[] key = new Integer[n];
85 <        for (int i = 0; i < key.length; ++i)
85 >        for (int i = 0; i < key.length; ++i)
86              key[i] = new Integer(rng.next());
87          return key;
88      }
# Line 107 | Line 107 | public class MapLoops {
107          shuffleKeys(key);
108          LoopHelpers.BarrierTimer timer = new LoopHelpers.BarrierTimer();
109          CyclicBarrier barrier = new CyclicBarrier(i+1, timer);
110 <        for (int t = 0; t < i; ++t)
110 >        for (int t = 0; t < i; ++t)
111              pool.execute(new Runner(t, map, key, barrier));
112          barrier.await();
113          barrier.await();
# Line 128 | Line 128 | public class MapLoops {
128          int total;
129  
130          Runner(int id, Map<Integer,Integer> map, Integer[] key,  CyclicBarrier barrier) {
131 <            this.map = map;
132 <            this.key = key;
131 >            this.map = map;
132 >            this.key = key;
133              this.barrier = barrier;
134 <            position = key.length / 2;
134 >            position = key.length / 2;
135              rng = new LoopHelpers.SimpleRandom((id + 1) * 8862213513L);
136              rng.next();
137          }
# Line 140 | Line 140 | public class MapLoops {
140              // random-walk around key positions,  bunching accesses
141              int r = rng.next();
142              position += (r & 7) - 3;
143 <            while (position >= key.length) position -= key.length;  
143 >            while (position >= key.length) position -= key.length;
144              while (position < 0) position += key.length;
145  
146              Integer k = key[position];
147              Integer x = map.get(k);
148  
149              if (x != null) {
150 <                if (x.intValue() != k.intValue())
150 >                if (x.intValue() != k.intValue())
151                      throw new Error("bad mapping: " + x + " to " + k);
152  
153                  if (r < removesPerMaxRandom) {
# Line 161 | Line 161 | public class MapLoops {
161                  ++position;
162                  map.put(k, k);
163                  return 2;
164 <            }
164 >            }
165  
166              // Uncomment to add a little computation between accesses
167              //            total += LoopHelpers.compute1(k.intValue());
# Line 173 | Line 173 | public class MapLoops {
173              try {
174                  barrier.await();
175                  int ops = nops;
176 <                while (ops > 0)
176 >                while (ops > 0)
177                      ops -= step();
178                  barrier.await();
179              }
# Line 183 | Line 183 | public class MapLoops {
183          }
184      }
185   }
186

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines