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.4 by jsr166, Thu Oct 29 23:09:08 2009 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 <    
151 >
152      static abstract class Stage implements Runnable {
153          final int iters;
154          final BlockingQueue<Integer> queue;
# Line 156 | Line 156 | public class ProducerConsumerLoops {
156          final Phaser lagPhaser;
157          Stage (BlockingQueue<Integer> q, CyclicBarrier b, Phaser s,
158                 int iters) {
159 <            queue = q;
159 >            queue = q;
160              barrier = b;
161              lagPhaser = s;
162              this.iters = iters;
# Line 186 | Line 186 | public class ProducerConsumerLoops {
186                  addProducerSum(ps);
187                  barrier.await();
188              }
189 <            catch (Exception ie) {
190 <                ie.printStackTrace();
191 <                return;
189 >            catch (Exception ie) {
190 >                ie.printStackTrace();
191 >                return;
192              }
193          }
194      }
195  
196      static class Consumer extends Stage {
197          Consumer(BlockingQueue<Integer> q, CyclicBarrier b, Phaser s,
198 <                 int iters) {
198 >                 int iters) {
199              super(q, b, s, iters);
200          }
201  
# Line 213 | Line 213 | public class ProducerConsumerLoops {
213                  addConsumerSum(cs);
214                  barrier.await();
215              }
216 <            catch (Exception ie) {
217 <                ie.printStackTrace();
218 <                return;
216 >            catch (Exception ie) {
217 >                ie.printStackTrace();
218 >                return;
219              }
220          }
221  
# Line 240 | Line 240 | public class ProducerConsumerLoops {
240      static final class LTQasSQ<T> extends LinkedTransferQueue<T> {
241          LTQasSQ() { super(); }
242          public void put(T x) {
243 <            try { super.transfer(x);
243 >            try { super.transfer(x);
244              } catch (InterruptedException ex) { throw new Error(); }
245          }
246      }
# Line 252 | Line 252 | public class ProducerConsumerLoops {
252              if ((++calls & 1) == 0)
253                  super.put(x);
254              else {
255 <                try { super.transfer(x);
256 <                } catch (InterruptedException ex) {
257 <                    throw new Error();
255 >                try { super.transfer(x);
256 >                } catch (InterruptedException ex) {
257 >                    throw new Error();
258                  }
259              }
260          }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines