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.4 by dl, Sun Sep 19 12:55:37 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 103 | Line 103 | public class OfferPollLoops {
103  
104          Thread.sleep(100); // System.gc();
105          if (print)
106 +            System.out.print("ConcurrentLinkedDeque   ");
107 +        oneRun(new ConcurrentLinkedDeque<Integer>(), n, iters);
108 +
109 +        Thread.sleep(100); // System.gc();
110 +        if (print)
111              System.out.print("LinkedBlockingQueue     ");
112          oneRun(new LinkedBlockingQueue<Integer>(), n, iters);
113  
# Line 115 | Line 120 | public class OfferPollLoops {
120          if (print)
121              System.out.print("LinkedBlockingDeque     ");
122          oneRun(new LinkedBlockingDeque<Integer>(), n, iters);
123 <        
123 >
124          Thread.sleep(100); // System.gc();
125          if (print)
126              System.out.print("ArrayBlockingQueue      ");
# Line 133 | Line 138 | public class OfferPollLoops {
138          oneRun(new ArrayBlockingQueue<Integer>(POOL_SIZE, true), n, fairIters);
139  
140      }
141 <    
141 >
142      static abstract class Stage implements Runnable {
143          final int iters;
144          final Queue<Integer> queue;
145          final CyclicBarrier barrier;
146          final Phaser lagPhaser;
147 <        Stage (Queue<Integer> q, CyclicBarrier b, Phaser s,
148 <               int iters) {
144 <            queue = q;
147 >        Stage(Queue<Integer> q, CyclicBarrier b, Phaser s, int iters) {
148 >            queue = q;
149              barrier = b;
150              lagPhaser = s;
151              this.iters = iters;
# Line 171 | Line 175 | public class OfferPollLoops {
175                              break;
176                          if ((i & LAG_MASK) == LAG_MASK)
177                              lagPhaser.arriveAndAwaitAdvance();
178 <                    }                        
178 >                    }
179                  }
180                  addProducerSum(ps);
181                  barrier.await();
182              }
183 <            catch (Exception ie) {
184 <                ie.printStackTrace();
185 <                return;
183 >            catch (Exception ie) {
184 >                ie.printStackTrace();
185 >                return;
186              }
187          }
188      }
189  
190      static class Consumer extends Stage {
191          Consumer(Queue<Integer> q, CyclicBarrier b, Phaser s,
192 <                 int iters) {
192 >                 int iters) {
193              super(q, b, s, iters);
194          }
195  
# Line 209 | Line 213 | public class OfferPollLoops {
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 235 | Line 239 | public class OfferPollLoops {
239  
240  
241   }
238

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines