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; |
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(); |
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(); |
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 |
|
} |
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 "); |
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; |
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; |
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 |
|
|
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 |
|
|
235 |
|
|
236 |
|
|
237 |
|
} |
238 |
– |
|