--- jsr166/src/test/loops/ConcurrentQueueLoops.java 2005/11/28 15:40:56 1.4 +++ jsr166/src/test/loops/ConcurrentQueueLoops.java 2009/11/03 01:04:02 1.10 @@ -1,14 +1,7 @@ /* - * @test %I% %E% - * @bug 4486658 - * @compile -source 1.5 ConcurrentQueueLoops.java - * @run main/timeout=230 ConcurrentQueueLoops - * @summary Checks that a set of threads can repeatedly get and modify items - */ -/* * Written by Doug Lea with assistance from members of JCP JSR-166 - * Expert Group and released to the public domain. Use, modify, and - * redistribute this code in any way without acknowledgement. + * Expert Group and released to the public domain, as explained at + * http://creativecommons.org/licenses/publicdomain */ import java.util.*; @@ -32,15 +25,15 @@ public class ConcurrentQueueLoops { if (args.length > 0) { try { klass = Class.forName(args[0]); - } catch(ClassNotFoundException e) { + } catch (ClassNotFoundException e) { throw new RuntimeException("Class " + args[0] + " not found."); } } - if (args.length > 1) + if (args.length > 1) maxStages = Integer.parseInt(args[1]); - if (args.length > 2) + if (args.length > 2) work = Integer.parseInt(args[2]); workMask = work - 1; @@ -63,8 +56,8 @@ public class ConcurrentQueueLoops { if (i == k) { k = i << 1; i = i + (i >>> 1); - } - else + } + else i = k; } pool.shutdown(); @@ -75,16 +68,16 @@ public class ConcurrentQueueLoops { final CyclicBarrier barrier; final int nthreads; Stage (Queue q, CyclicBarrier b, int nthreads) { - queue = q; + queue = q; barrier = b; this.nthreads = nthreads; } static int compute(int l) { - if (l == 0) - return (int)System.nanoTime(); + if (l == 0) + return (int) System.nanoTime(); int nn = (l >>> 7) & workMask; - while (nn-- > 0) + while (nn-- > 0) l = LoopHelpers.compute6(l); return l; } @@ -94,7 +87,7 @@ public class ConcurrentQueueLoops { barrier.await(); long now = System.nanoTime(); long stopTime = now + RUN_TIME_NANOS; - int l = (int)now; + int l = (int) now; int takes = 0; int misses = 0; int lmask = 1; @@ -107,17 +100,17 @@ public class ConcurrentQueueLoops { l = LoopHelpers.compute6(l); } else if ((misses++ & 255) == 0 && System.nanoTime() >= stopTime) { - return new Integer(takes); + return Integer.valueOf(takes); } else { for (int i = 0; i < BATCH_SIZE; ++i) { - queue.offer(((l & lmask)== 0)? zero : one); + queue.offer(((l & lmask)== 0) ? zero : one); if ((lmask <<= 1) == 0) lmask = 1; if (i != 0) l = compute(l); } } } } - catch (Exception ie) { + catch (Exception ie) { ie.printStackTrace(); throw new Error("Call loop failed"); } @@ -125,11 +118,11 @@ public class ConcurrentQueueLoops { } static void oneRun(Class klass, int n) throws Exception { - Queue q = (Queue)klass.newInstance(); + Queue q = (Queue) klass.newInstance(); LoopHelpers.BarrierTimer timer = new LoopHelpers.BarrierTimer(); CyclicBarrier barrier = new CyclicBarrier(n + 1, timer); ArrayList> results = new ArrayList>(n); - for (int i = 0; i < n; ++i) + for (int i = 0; i < n; ++i) results.add(pool.submit(new Stage(q, barrier, n))); if (print) @@ -144,8 +137,8 @@ public class ConcurrentQueueLoops { long endTime = System.nanoTime(); long time = endTime - timer.startTime; long ips = 1000000000L * total / time; - - if (print) + + if (print) System.out.print(LoopHelpers.rightJustify(ips) + " items per sec"); if (print) System.out.println();