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

Comparing jsr166/src/test/loops/MultipleProducersSingleConsumerLoops.java (file contents):
Revision 1.4 by dl, Fri Oct 23 19:57:06 2009 UTC vs.
Revision 1.5 by jsr166, Thu Oct 29 23:09:07 2009 UTC

# Line 34 | Line 34 | public class MultipleProducersSingleCons
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      static final int LAG = (1 << 12);
47      static final int LAG_MASK = LAG - 1;
# Line 49 | Line 49 | public class MultipleProducersSingleCons
49      public static void main(String[] args) throws Exception {
50          int maxn = 12; // NCPUS * 3 / 2;
51  
52 <        if (args.length > 0)
52 >        if (args.length > 0)
53              maxn = Integer.parseInt(args[0]);
54  
55          warmup();
# Line 61 | Line 61 | public class MultipleProducersSingleCons
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 MultipleProducersSingleCons
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 MultipleProducersSingleCons
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 MultipleProducersSingleCons
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 MultipleProducersSingleCons
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 149 | Line 149 | public class MultipleProducersSingleCons
149  
150  
151      }
152 <    
152 >
153      static abstract class Stage implements Runnable {
154          final int iters;
155          final BlockingQueue<Integer> queue;
# Line 158 | Line 158 | public class MultipleProducersSingleCons
158          final int lag;
159          Stage (BlockingQueue<Integer> q, CyclicBarrier b, Phaser s,
160                 int iters, int lag) {
161 <            queue = q;
161 >            queue = q;
162              barrier = b;
163              lagPhaser = s;
164              this.iters = iters;
# Line 192 | Line 192 | public class MultipleProducersSingleCons
192                  addProducerSum(ps);
193                  barrier.await();
194              }
195 <            catch (Exception ie) {
196 <                ie.printStackTrace();
197 <                return;
195 >            catch (Exception ie) {
196 >                ie.printStackTrace();
197 >                return;
198              }
199          }
200      }
201  
202      static class Consumer extends Stage {
203          Consumer(BlockingQueue<Integer> q, CyclicBarrier b, Phaser s,
204 <                 int iters, int lag) {
204 >                 int iters, int lag) {
205              super(q, b, s, iters, lag);
206          }
207  
# Line 222 | Line 222 | public class MultipleProducersSingleCons
222                  addConsumerSum(cs);
223                  barrier.await();
224              }
225 <            catch (Exception ie) {
226 <                ie.printStackTrace();
227 <                return;
225 >            catch (Exception ie) {
226 >                ie.printStackTrace();
227 >                return;
228              }
229          }
230  
# Line 247 | Line 247 | public class MultipleProducersSingleCons
247          if (print)
248              System.out.println("\t: " + LoopHelpers.rightJustify(time / (iters * (n + 1))) + " ns per transfer");
249      }
250 <    
250 >
251      static final class LTQasSQ<T> extends LinkedTransferQueue<T> {
252          LTQasSQ() { super(); }
253          public void put(T x) {
254 <            try { super.transfer(x);
254 >            try { super.transfer(x);
255              } catch (InterruptedException ex) { throw new Error(); }
256          }
257      }
# Line 263 | Line 263 | public class MultipleProducersSingleCons
263              if ((++calls & 1) == 0)
264                  super.put(x);
265              else {
266 <                try { super.transfer(x);
267 <                } catch (InterruptedException ex) {
268 <                    throw new Error();
266 >                try { super.transfer(x);
267 >                } catch (InterruptedException ex) {
268 >                    throw new Error();
269                  }
270              }
271          }
272      }
273   }
274

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines