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.3 by jsr166, Wed Sep 1 07:47:27 2010 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;
140          final CyclicBarrier barrier;
141          final Phaser lagPhaser;
142 <        Stage (Queue<Integer> q, CyclicBarrier b, Phaser s,
143 <               int iters) {
144 <            queue = q;
142 >        Stage(Queue<Integer> q, CyclicBarrier b, Phaser s, int iters) {
143 >            queue = q;
144              barrier = b;
145              lagPhaser = s;
146              this.iters = iters;
# Line 171 | Line 170 | public class OfferPollLoops {
170                              break;
171                          if ((i & LAG_MASK) == LAG_MASK)
172                              lagPhaser.arriveAndAwaitAdvance();
173 <                    }                        
173 >                    }
174                  }
175                  addProducerSum(ps);
176                  barrier.await();
177              }
178 <            catch (Exception ie) {
179 <                ie.printStackTrace();
180 <                return;
178 >            catch (Exception ie) {
179 >                ie.printStackTrace();
180 >                return;
181              }
182          }
183      }
184  
185      static class Consumer extends Stage {
186          Consumer(Queue<Integer> q, CyclicBarrier b, Phaser s,
187 <                 int iters) {
187 >                 int iters) {
188              super(q, b, s, iters);
189          }
190  
# Line 209 | Line 208 | public class OfferPollLoops {
208                  addConsumerSum(cs);
209                  barrier.await();
210              }
211 <            catch (Exception ie) {
212 <                ie.printStackTrace();
213 <                return;
211 >            catch (Exception ie) {
212 >                ie.printStackTrace();
213 >                return;
214              }
215          }
216  
# Line 235 | Line 234 | public class OfferPollLoops {
234  
235  
236   }
238

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines