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

Comparing jsr166/src/test/loops/ConcurrentDequeLoops.java (file contents):
Revision 1.1 by dl, Mon May 2 19:19:38 2005 UTC vs.
Revision 1.10 by jsr166, Thu Dec 18 18:13:06 2014 UTC

# Line 1 | Line 1
1   /*
2 * @test %I% %E%
3 * @bug 4486658
4 * @compile -source 1.5 ConcurrentDequeLoops.java
5 * @run main/timeout=230 ConcurrentDequeLoops
6 * @summary Checks that a set of threads can repeatedly get and modify items
7 */
8 /*
2   * Written by Doug Lea with assistance from members of JCP JSR-166
3 < * Expert Group and released to the public domain. Use, modify, and
4 < * redistribute this code in any way without acknowledgement.
3 > * Expert Group and released to the public domain, as explained at
4 > * http://creativecommons.org/publicdomain/zero/1.0/
5   */
6  
7   import java.util.*;
# Line 29 | Line 22 | public class ConcurrentDequeLoops {
22          if (args.length > 0) {
23              try {
24                  klass = Class.forName(args[0]);
25 <            } catch(ClassNotFoundException e) {
25 >            } catch (ClassNotFoundException e) {
26                  throw new RuntimeException("Class " + args[0] + " not found.");
27              }
28          }
29 <        else
29 >        else
30              throw new Error();
31  
32 <        if (args.length > 1)
32 >        if (args.length > 1)
33              maxStages = Integer.parseInt(args[1]);
34  
35          System.out.print("Class: " + klass.getName());
# Line 50 | Line 43 | public class ConcurrentDequeLoops {
43          Thread.sleep(100);
44          print = true;
45  
46 <        int k = 1;
54 <        for (int i = 1; i <= maxStages;) {
46 >        for (int k = 1, i = 1; i <= maxStages;) {
47              oneRun(klass, i, items);
48              if (i == k) {
49                  k = i << 1;
50                  i = i + (i >>> 1);
51 <            }
52 <            else
51 >            }
52 >            else
53                  i = k;
54          }
55          pool.shutdown();
56 <   }
56 >    }
57  
58      static class Stage implements Callable<Integer> {
59          final Deque<Integer> queue;
60          final CyclicBarrier barrier;
61          final LoopHelpers.SimpleRandom rng = new LoopHelpers.SimpleRandom();
62          int items;
63 <        Stage (Deque<Integer> q, CyclicBarrier b, int items) {
64 <            queue = q;
63 >        Stage(Deque<Integer> q, CyclicBarrier b, int items) {
64 >            queue = q;
65              barrier = b;
66              this.items = items;
67          }
# Line 79 | Line 71 | public class ConcurrentDequeLoops {
71              // transform it, and put back in.
72              try {
73                  barrier.await();
74 <                int l = (int)System.nanoTime();
74 >                int l = (int) System.nanoTime();
75                  int takes = 0;
76                  for (;;) {
77                      Integer item;
# Line 107 | Line 99 | public class ConcurrentDequeLoops {
99                          else
100                              queue.addLast(res);
101                      }
102 <                    else { // spinwait
102 >                    else { // spinwait
103                          for (int k = 1 + (l & 15); k != 0; --k)
104                              l = LoopHelpers.compute1(LoopHelpers.compute2(l));
105                          if ((l & 3) == 3) {
# Line 117 | Line 109 | public class ConcurrentDequeLoops {
109                  }
110                  return new Integer(l);
111              }
112 <            catch (Exception ie) {
112 >            catch (Exception ie) {
113                  ie.printStackTrace();
114                  throw new Error("Call loop failed");
115              }
# Line 125 | Line 117 | public class ConcurrentDequeLoops {
117      }
118  
119      static void oneRun(Class klass, int n, int items) throws Exception {
120 <        Deque<Integer> q = (Deque<Integer>)klass.newInstance();
120 >        Deque<Integer> q = (Deque<Integer>) klass.newInstance();
121          LoopHelpers.BarrierTimer timer = new LoopHelpers.BarrierTimer();
122          CyclicBarrier barrier = new CyclicBarrier(n + 1, timer);
123          totalItems = new AtomicInteger(n * items);
124          ArrayList<Future<Integer>> results = new ArrayList<Future<Integer>>(n);
125 <        for (int i = 0; i < n; ++i)
125 >        for (int i = 0; i < n; ++i)
126              results.add(pool.submit(new Stage(q, barrier, items)));
127  
128          if (print)
# Line 148 | Line 140 | public class ConcurrentDequeLoops {
140              System.out.println(LoopHelpers.rightJustify(time / (items * n)) + " ns per item");
141          if (total == 0) // avoid overoptimization
142              System.out.println("useless result: " + total);
143 <        
143 >
144      }
145   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines