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

Comparing jsr166/src/test/loops/ProducerConsumerLoops.java (file contents):
Revision 1.3 by dl, Fri Oct 23 19:57:06 2009 UTC vs.
Revision 1.6 by jsr166, Mon Sep 27 19:15:15 2010 UTC

# Line 34 | Line 34 | public class ProducerConsumerLoops {
34      static final int POOL_MASK = POOL_SIZE-1;
35      static final Integer[] intPool = new Integer[POOL_SIZE];
36      static {
37 <        for (int i = 0; i < POOL_SIZE; ++i)
37 >        for (int i = 0; i < POOL_SIZE; ++i)
38              intPool[i] = Integer.valueOf(i);
39      }
40  
41      // Number of puts by producers or takes by consumers
42      static final int ITERS = 1 << 20;
43  
44 <    // max lag between a producer and consumer to avoid
44 >    // max lag between a producer and consumer to avoid
45      // this becoming a GC test rather than queue test.
46      // Used only per-pair to lessen impact on queue sync
47      static final int LAG_MASK = (1 << 12) - 1;
# Line 49 | Line 49 | public class ProducerConsumerLoops {
49      public static void main(String[] args) throws Exception {
50          int maxPairs = NCPUS * 3 / 2;
51  
52 <        if (args.length > 0)
52 >        if (args.length > 0)
53              maxPairs = Integer.parseInt(args[0]);
54  
55          warmup();
# Line 61 | Line 61 | public class ProducerConsumerLoops {
61              if (i == k) {
62                  k = i << 1;
63                  i = i + (i >>> 1);
64 <            }
65 <            else
64 >            }
65 >            else
66                  i = k;
67          }
68          pool.shutdown();
# Line 73 | Line 73 | public class ProducerConsumerLoops {
73          System.out.print("Warmup ");
74          int it = 2000;
75          for (int j = 5; j > 0; --j) {
76 <            oneTest(j, it);
76 >            oneTest(j, it);
77              System.out.print(".");
78              it += 1000;
79          }
80          System.gc();
81          it = 20000;
82          for (int j = 5; j > 0; --j) {
83 <            oneTest(j, it);
83 >            oneTest(j, it);
84              System.out.print(".");
85              it += 10000;
86          }
# Line 110 | Line 110 | public class ProducerConsumerLoops {
110          if (print)
111              System.out.print("LinkedBlockingDeque     ");
112          oneRun(new LinkedBlockingDeque<Integer>(), n, iters);
113 <        
113 >
114          Thread.sleep(100); // System.gc();
115          if (print)
116              System.out.print("ArrayBlockingQueue      ");
# Line 121 | Line 121 | public class ProducerConsumerLoops {
121              System.out.print("SynchronousQueue        ");
122          oneRun(new SynchronousQueue<Integer>(), n, iters);
123  
124 <        
124 >
125          Thread.sleep(100); // System.gc();
126          if (print)
127              System.out.print("SynchronousQueue(fair)  ");
# Line 136 | Line 136 | public class ProducerConsumerLoops {
136          if (print)
137              System.out.print("LinkedTransferQueue(half)");
138          oneRun(new HalfSyncLTQ<Integer>(), n, iters);
139 <        
139 >
140          Thread.sleep(100); // System.gc();
141          if (print)
142              System.out.print("PriorityBlockingQueue   ");
# Line 148 | Line 148 | public class ProducerConsumerLoops {
148          oneRun(new ArrayBlockingQueue<Integer>(POOL_SIZE, true), n, fairIters);
149  
150      }
151 <    
152 <    static abstract class Stage implements Runnable {
151 >
152 >    abstract static class Stage implements Runnable {
153          final int iters;
154          final BlockingQueue<Integer> queue;
155          final CyclicBarrier barrier;
156          final Phaser lagPhaser;
157 <        Stage (BlockingQueue<Integer> q, CyclicBarrier b, Phaser s,
158 <               int iters) {
159 <            queue = q;
157 >        Stage(BlockingQueue<Integer> q, CyclicBarrier b, Phaser s, int iters) {
158 >            queue = q;
159              barrier = b;
160              lagPhaser = s;
161              this.iters = iters;
# Line 186 | Line 185 | public class ProducerConsumerLoops {
185                  addProducerSum(ps);
186                  barrier.await();
187              }
188 <            catch (Exception ie) {
189 <                ie.printStackTrace();
190 <                return;
188 >            catch (Exception ie) {
189 >                ie.printStackTrace();
190 >                return;
191              }
192          }
193      }
194  
195      static class Consumer extends Stage {
196          Consumer(BlockingQueue<Integer> q, CyclicBarrier b, Phaser s,
197 <                 int iters) {
197 >                 int iters) {
198              super(q, b, s, iters);
199          }
200  
# Line 213 | Line 212 | public class ProducerConsumerLoops {
212                  addConsumerSum(cs);
213                  barrier.await();
214              }
215 <            catch (Exception ie) {
216 <                ie.printStackTrace();
217 <                return;
215 >            catch (Exception ie) {
216 >                ie.printStackTrace();
217 >                return;
218              }
219          }
220  
# Line 240 | Line 239 | public class ProducerConsumerLoops {
239      static final class LTQasSQ<T> extends LinkedTransferQueue<T> {
240          LTQasSQ() { super(); }
241          public void put(T x) {
242 <            try { super.transfer(x);
242 >            try { super.transfer(x);
243              } catch (InterruptedException ex) { throw new Error(); }
244          }
245      }
# Line 252 | Line 251 | public class ProducerConsumerLoops {
251              if ((++calls & 1) == 0)
252                  super.put(x);
253              else {
254 <                try { super.transfer(x);
255 <                } catch (InterruptedException ex) {
256 <                    throw new Error();
254 >                try { super.transfer(x);
255 >                } catch (InterruptedException ex) {
256 >                    throw new Error();
257                  }
258              }
259          }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines