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

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

# Line 34 | Line 34 | public class OfferPollLoops {
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 OfferPollLoops {
49      public static void main(String[] args) throws Exception {
50          int maxN = 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 OfferPollLoops {
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 OfferPollLoops {
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 115 | Line 115 | public class OfferPollLoops {
115          if (print)
116              System.out.print("LinkedBlockingDeque     ");
117          oneRun(new LinkedBlockingDeque<Integer>(), n, iters);
118 <        
118 >
119          Thread.sleep(100); // System.gc();
120          if (print)
121              System.out.print("ArrayBlockingQueue      ");
# Line 133 | Line 133 | public class OfferPollLoops {
133          oneRun(new ArrayBlockingQueue<Integer>(POOL_SIZE, true), n, fairIters);
134  
135      }
136 <    
136 >
137      static abstract class Stage implements Runnable {
138          final int iters;
139          final Queue<Integer> queue;
# Line 141 | Line 141 | public class OfferPollLoops {
141          final Phaser lagPhaser;
142          Stage (Queue<Integer> q, CyclicBarrier b, Phaser s,
143                 int iters) {
144 <            queue = q;
144 >            queue = q;
145              barrier = b;
146              lagPhaser = s;
147              this.iters = iters;
# Line 171 | Line 171 | public class OfferPollLoops {
171                              break;
172                          if ((i & LAG_MASK) == LAG_MASK)
173                              lagPhaser.arriveAndAwaitAdvance();
174 <                    }                        
174 >                    }
175                  }
176                  addProducerSum(ps);
177                  barrier.await();
178              }
179 <            catch (Exception ie) {
180 <                ie.printStackTrace();
181 <                return;
179 >            catch (Exception ie) {
180 >                ie.printStackTrace();
181 >                return;
182              }
183          }
184      }
185  
186      static class Consumer extends Stage {
187          Consumer(Queue<Integer> q, CyclicBarrier b, Phaser s,
188 <                 int iters) {
188 >                 int iters) {
189              super(q, b, s, iters);
190          }
191  
# Line 209 | Line 209 | public class OfferPollLoops {
209                  addConsumerSum(cs);
210                  barrier.await();
211              }
212 <            catch (Exception ie) {
213 <                ie.printStackTrace();
214 <                return;
212 >            catch (Exception ie) {
213 >                ie.printStackTrace();
214 >                return;
215              }
216          }
217  
# Line 235 | Line 235 | public class OfferPollLoops {
235  
236  
237   }
238

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines