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

Comparing jsr166/src/test/loops/CASLoops.java (file contents):
Revision 1.3 by jsr166, Sun Jun 24 21:28:19 2007 UTC vs.
Revision 1.4 by jsr166, Thu Oct 29 23:09:07 2009 UTC

# Line 43 | Line 43 | public class CASLoops {
43      static boolean includeLocks = false;
44  
45      public static void main(String[] args) throws Exception {
46 <        if (args.length > 0)
46 >        if (args.length > 0)
47              maxThreads = Integer.parseInt(args[0]);
48  
49          loopIters = new long[maxThreads+1];
# Line 58 | Line 58 | public class CASLoops {
58              System.out.print(".");
59          }
60  
61 <        for (int i = 1; i <= maxThreads; ++i)
61 >        for (int i = 1; i <= maxThreads; ++i)
62              loopIters[i] = 0;
63  
64          for (int j = 0; j < 2; ++j) {
# Line 69 | Line 69 | public class CASLoops {
69              }
70          }
71  
72 <        for (int i = 1; i <= maxThreads; ++i)
72 >        for (int i = 1; i <= maxThreads; ++i)
73              loopIters[i] = 0;
74  
75          for (int j = 0; j < TRIALS; ++j) {
# Line 111 | Line 111 | public class CASLoops {
111      static final class UpdaterAtomicInteger {
112          volatile int value;
113  
114 <        static final AtomicIntegerFieldUpdater<UpdaterAtomicInteger>
114 >        static final AtomicIntegerFieldUpdater<UpdaterAtomicInteger>
115                  valueUpdater = AtomicIntegerFieldUpdater.newUpdater
116                  (UpdaterAtomicInteger.class, "value");
117  
# Line 191 | Line 191 | public class CASLoops {
191                  unlock();
192              }
193          }
194 <        void set(int val) {
195 <            lock();
194 >        void set(int val) {
195 >            lock();
196              try {
197 <                value = val;
197 >                value = val;
198              } finally {
199                  unlock();
200              }
201          }
202      }
203  
204 <    // All these versions are copy-paste-hacked to avoid
204 >    // All these versions are copy-paste-hacked to avoid
205      // contamination with virtual call resolution etc.
206  
207      // Use fixed-length unrollable inner loops to reduce safepoint checks
# Line 220 | Line 220 | public class CASLoops {
220  
221          public void run() {
222              try {
223 <                barrier.await();
223 >                barrier.await();
224                  long i = iters;
225                  int y = 0;
226                  int succ = 0;
# Line 238 | Line 238 | public class CASLoops {
238                  successes.getAndAdd(succ);
239                  barrier.await();
240              }
241 <            catch (Exception ie) {
242 <                return;
241 >            catch (Exception ie) {
242 >                return;
243              }
244          }
245      }
# Line 257 | Line 257 | public class CASLoops {
257  
258          public void run() {
259              try {
260 <                barrier.await();
260 >                barrier.await();
261                  long i = iters;
262                  int y = 0;
263                  int succ = 0;
# Line 275 | Line 275 | public class CASLoops {
275                  successes.getAndAdd(succ);
276                  barrier.await();
277              }
278 <            catch (Exception ie) {
279 <                return;
278 >            catch (Exception ie) {
279 >                return;
280              }
281          }
282      }
# Line 294 | Line 294 | public class CASLoops {
294  
295          public void run() {
296              try {
297 <                barrier.await();
297 >                barrier.await();
298                  long i = iters;
299                  int y = 0;
300                  int succ = 0;
# Line 312 | Line 312 | public class CASLoops {
312                  successes.getAndAdd(succ);
313                  barrier.await();
314              }
315 <            catch (Exception ie) {
316 <                return;
315 >            catch (Exception ie) {
316 >                return;
317              }
318          }
319      }
# Line 331 | Line 331 | public class CASLoops {
331  
332          public void run() {
333              try {
334 <                barrier.await();
334 >                barrier.await();
335                  long i = iters;
336                  int y = 0;
337                  int succ = 0;
# Line 349 | Line 349 | public class CASLoops {
349                  successes.getAndAdd(succ);
350                  barrier.await();
351              }
352 <            catch (Exception ie) {
353 <                return;
352 >            catch (Exception ie) {
353 >                return;
354              }
355          }
356      }
# Line 368 | Line 368 | public class CASLoops {
368  
369          public void run() {
370              try {
371 <                barrier.await();
371 >                barrier.await();
372                  long i = iters;
373                  int y = 0;
374                  int succ = 0;
# Line 386 | Line 386 | public class CASLoops {
386                  successes.getAndAdd(succ);
387                  barrier.await();
388              }
389 <            catch (Exception ie) {
390 <                return;
389 >            catch (Exception ie) {
390 >                return;
391              }
392          }
393      }
# Line 405 | Line 405 | public class CASLoops {
405  
406          public void run() {
407              try {
408 <                barrier.await();
408 >                barrier.await();
409                  long i = iters;
410                  int y = 0;
411                  int succ = 0;
# Line 423 | Line 423 | public class CASLoops {
423                  successes.getAndAdd(succ);
424                  barrier.await();
425              }
426 <            catch (Exception ie) {
427 <                return;
426 >            catch (Exception ie) {
427 >                return;
428              }
429          }
430      }
# Line 444 | Line 444 | public class CASLoops {
444  
445          public void run() {
446              try {
447 <                barrier.await();
447 >                barrier.await();
448                  long iters = 0;
449                  int y = 0;
450                  int succ = 0;
# Line 467 | Line 467 | public class CASLoops {
467                  successes.getAndAdd(succ);
468                  barrier.await();
469              }
470 <            catch (Exception ie) {
471 <                return;
470 >            catch (Exception ie) {
471 >                return;
472              }
473          }
474      }
# Line 479 | Line 479 | public class CASLoops {
479          CyclicBarrier b = new CyclicBarrier(n+1);
480          totalIters.set(0);
481          NonAtomicInteger a = new NonAtomicInteger();
482 <        for (int j = 0; j < n; ++j)
482 >        for (int j = 0; j < n; ++j)
483              new Thread(new NACalibrationLoop(endTime, a, b)).start();
484          b.await();
485          b.await();
# Line 493 | Line 493 | public class CASLoops {
493          LoopHelpers.BarrierTimer timer = new LoopHelpers.BarrierTimer();
494          CyclicBarrier b = new CyclicBarrier(n+1, timer);
495          NonAtomicInteger a = new NonAtomicInteger();
496 <        for (int j = 0; j < n; ++j)
496 >        for (int j = 0; j < n; ++j)
497              new Thread(new NonAtomicLoop(iters, a, b)).start();
498          b.await();
499          b.await();
# Line 505 | Line 505 | public class CASLoops {
505          LoopHelpers.BarrierTimer timer = new LoopHelpers.BarrierTimer();
506          CyclicBarrier b = new CyclicBarrier(n+1, timer);
507          UpdaterAtomicInteger a = new UpdaterAtomicInteger();
508 <        for (int j = 0; j < n; ++j)
508 >        for (int j = 0; j < n; ++j)
509              new Thread(new UpdaterAtomicLoop(iters, a, b)).start();
510          b.await();
511          b.await();
# Line 517 | Line 517 | public class CASLoops {
517          LoopHelpers.BarrierTimer timer = new LoopHelpers.BarrierTimer();
518          CyclicBarrier b = new CyclicBarrier(n+1, timer);
519          AtomicInteger a = new AtomicInteger();
520 <        for (int j = 0; j < n; ++j)
520 >        for (int j = 0; j < n; ++j)
521              new Thread(new AtomicLoop(iters, a, b)).start();
522          b.await();
523          b.await();
# Line 529 | Line 529 | public class CASLoops {
529          LoopHelpers.BarrierTimer timer = new LoopHelpers.BarrierTimer();
530          CyclicBarrier b = new CyclicBarrier(n+1, timer);
531          VolatileInteger a = new VolatileInteger();
532 <        for (int j = 0; j < n; ++j)
532 >        for (int j = 0; j < n; ++j)
533              new Thread(new VolatileLoop(iters, a, b)).start();
534          b.await();
535          b.await();
# Line 542 | Line 542 | public class CASLoops {
542          LoopHelpers.BarrierTimer timer = new LoopHelpers.BarrierTimer();
543          CyclicBarrier b = new CyclicBarrier(n+1, timer);
544          SynchedInteger a = new SynchedInteger();
545 <        for (int j = 0; j < n; ++j)
545 >        for (int j = 0; j < n; ++j)
546              new Thread(new SynchedLoop(iters, a, b)).start();
547          b.await();
548          b.await();
# Line 554 | Line 554 | public class CASLoops {
554          LoopHelpers.BarrierTimer timer = new LoopHelpers.BarrierTimer();
555          CyclicBarrier b = new CyclicBarrier(n+1, timer);
556          LockedInteger a = new LockedInteger();
557 <        for (int j = 0; j < n; ++j)
557 >        for (int j = 0; j < n; ++j)
558              new Thread(new LockedLoop(iters, a, b)).start();
559          b.await();
560          b.await();
# Line 562 | Line 562 | public class CASLoops {
562          return timer.getTime();
563      }
564  
565 <    static void report(String tag, long runtime, long basetime,
565 >    static void report(String tag, long runtime, long basetime,
566                         int nthreads, long iters) {
567          System.out.print(tag);
568          long t = (runtime - basetime) / iters;
# Line 572 | Line 572 | public class CASLoops {
572          double secs = (double)(runtime) / 1000000000.0;
573          System.out.println("\t " + secs + "s run time");
574      }
575 <        
575 >
576  
577      static void oneRun(int i, long iters, boolean print) throws Exception {
578 <        if (print)
579 <            System.out.println("threads : " + i +
580 <                               " base iters per thread per run : " +
578 >        if (print)
579 >            System.out.println("threads : " + i +
580 >                               " base iters per thread per run : " +
581                                 LoopHelpers.rightJustify(loopIters[i]));
582          long ntime = runNonAtomic(i,  iters);
583          if (print)
# Line 602 | Line 602 | public class CASLoops {
602              report("Mutex       : ", mtime, ntime, i, iters);
603          Thread.sleep(100L);
604          long stime = runSynched(i, iters);
605 <        if (print)
605 >        if (print)
606              report("Synchronized: ", stime, ntime, i, iters);
607          Thread.sleep(100L);
608      }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines