--- jsr166/src/test/loops/StringMapLoops.java 2009/10/23 19:57:07 1.3 +++ jsr166/src/test/loops/StringMapLoops.java 2009/10/29 23:09:08 1.4 @@ -8,7 +8,7 @@ import java.util.*; import java.util.concurrent.*; public class StringMapLoops { - static int nkeys = 75000; + static int nkeys = 75000; static int pinsert = 60; static int premove = 2; static int maxThreads = 100; @@ -28,28 +28,28 @@ public class StringMapLoops { throw new RuntimeException("Class " + args[0] + " not found."); } } - else + else mapClass = java.util.concurrent.ConcurrentHashMap.class; - if (args.length > 1) + if (args.length > 1) maxThreads = Integer.parseInt(args[1]); - if (args.length > 2) + if (args.length > 2) nkeys = Integer.parseInt(args[2]); - if (args.length > 3) + if (args.length > 3) pinsert = Integer.parseInt(args[3]); - if (args.length > 4) + if (args.length > 4) premove = Integer.parseInt(args[4]); - if (args.length > 5) + if (args.length > 5) nops = Integer.parseInt(args[5]); // normalize probabilities wrt random number generator removesPerMaxRandom = (int)(((double)premove/100.0 * 0x7FFFFFFFL)); insertsPerMaxRandom = (int)(((double)pinsert/100.0 * 0x7FFFFFFFL)); - + System.out.print("Class: " + mapClass.getName()); System.out.print(" threads: " + maxThreads); System.out.print(" size: " + nkeys); @@ -71,12 +71,12 @@ public class StringMapLoops { else if (i == k) { k = i << 1; i = i + (i >>> 1); - } + } else if (i == 1 && k == 2) { i = k; warmups = 1; } - else + else i = k; } for (int j = 0; j < 10; ++j) { @@ -128,7 +128,7 @@ public class StringMapLoops { LoopHelpers.BarrierTimer timer = new LoopHelpers.BarrierTimer(); CyclicBarrier barrier = new CyclicBarrier(i+1, timer); - for (int t = 0; t < i; ++t) + for (int t = 0; t < i; ++t) pool.execute(new Runner(t, map, key, barrier)); barrier.await(); barrier.await(); @@ -149,10 +149,10 @@ public class StringMapLoops { int total; Runner(int id, Map map, String[] key, CyclicBarrier barrier) { - this.map = map; - this.key = key; + this.map = map; + this.key = key; this.barrier = barrier; - position = key.length / 2; + position = key.length / 2; rng = new LoopHelpers.SimpleRandom((id + 1) * 8862213513L); rng.next(); } @@ -161,7 +161,7 @@ public class StringMapLoops { // random-walk around key positions, bunching accesses int r = rng.next(); position += (r & 7) - 3; - while (position >= key.length) position -= key.length; + while (position >= key.length) position -= key.length; while (position < 0) position += key.length; String k = key[position]; @@ -179,7 +179,7 @@ public class StringMapLoops { ++position; map.put(k, k); return 2; - } + } total += r; return 1; @@ -189,7 +189,7 @@ public class StringMapLoops { try { barrier.await(); int ops = nops; - while (ops > 0) + while (ops > 0) ops -= step(); barrier.await(); } @@ -199,4 +199,3 @@ public class StringMapLoops { } } } -