17 |
|
static final int POOL_MASK = POOL_SIZE-1; |
18 |
|
static final Integer[] intPool = new Integer[POOL_SIZE]; |
19 |
|
static { |
20 |
< |
for (int i = 0; i < POOL_SIZE; ++i) |
20 |
> |
for (int i = 0; i < POOL_SIZE; ++i) |
21 |
|
intPool[i] = Integer.valueOf(i); |
22 |
|
} |
23 |
|
|
24 |
< |
// max lag between a producer and consumer to avoid |
24 |
> |
// max lag between a producer and consumer to avoid |
25 |
|
// this becoming a GC test rather than queue test. |
26 |
|
// Used only per-pair to lessen impact on queue sync |
27 |
|
static final int LAG_MASK = (1 << 12) - 1; |
47 |
|
int maxPairs = NCPUS * 3 / 2; |
48 |
|
int iters = 1000000; |
49 |
|
|
50 |
< |
if (args.length > 0) |
50 |
> |
if (args.length > 0) |
51 |
|
maxPairs = Integer.parseInt(args[0]); |
52 |
|
|
53 |
|
print = true; |
59 |
|
if (i == k) { |
60 |
|
k = i << 1; |
61 |
|
i = i + (i >>> 1); |
62 |
< |
} |
63 |
< |
else |
62 |
> |
} |
63 |
> |
else |
64 |
|
i = k; |
65 |
|
} |
66 |
|
pool.shutdown(); |
108 |
|
oneRun(new ArrayBlockingQueue<Integer>(POOL_SIZE, true), n, iters/16); |
109 |
|
|
110 |
|
} |
111 |
< |
|
111 |
> |
|
112 |
|
static abstract class Stage implements Runnable { |
113 |
|
final int iters; |
114 |
|
final BlockingQueue<Integer> queue; |
115 |
|
final CyclicBarrier barrier; |
116 |
|
final Phaser lagPhaser; |
117 |
|
Stage (BlockingQueue<Integer> q, CyclicBarrier b, Phaser s, int iters) { |
118 |
< |
queue = q; |
118 |
> |
queue = q; |
119 |
|
barrier = b; |
120 |
|
lagPhaser = s; |
121 |
|
this.iters = iters; |
151 |
|
addProducerSum(s); |
152 |
|
barrier.await(); |
153 |
|
} |
154 |
< |
catch (Exception ie) { |
155 |
< |
ie.printStackTrace(); |
156 |
< |
return; |
154 |
> |
catch (Exception ie) { |
155 |
> |
ie.printStackTrace(); |
156 |
> |
return; |
157 |
|
} |
158 |
|
} |
159 |
|
} |
160 |
|
|
161 |
|
static class Consumer extends Stage { |
162 |
< |
Consumer(BlockingQueue<Integer> q, CyclicBarrier b, Phaser s, int iters) { |
162 |
> |
Consumer(BlockingQueue<Integer> q, CyclicBarrier b, Phaser s, int iters) { |
163 |
|
super(q, b, s, iters); |
164 |
|
} |
165 |
|
|
171 |
|
int i = 0; |
172 |
|
long timeout = 1000; |
173 |
|
while (i < iters) { |
174 |
< |
Integer e = queue.poll(timeout, |
174 |
> |
Integer e = queue.poll(timeout, |
175 |
|
TimeUnit.NANOSECONDS); |
176 |
|
if (e != null) { |
177 |
|
l = LoopHelpers.compute4(e.intValue()); |
188 |
|
addConsumerSum(s); |
189 |
|
barrier.await(); |
190 |
|
} |
191 |
< |
catch (Exception ie) { |
192 |
< |
ie.printStackTrace(); |
193 |
< |
return; |
191 |
> |
catch (Exception ie) { |
192 |
> |
ie.printStackTrace(); |
193 |
> |
return; |
194 |
|
} |
195 |
|
} |
196 |
|
|
216 |
|
static final class LTQasSQ<T> extends LinkedTransferQueue<T> { |
217 |
|
LTQasSQ() { super(); } |
218 |
|
public void put(T x) { |
219 |
< |
try { super.transfer(x); |
219 |
> |
try { super.transfer(x); |
220 |
|
} catch (InterruptedException ex) { throw new Error(); } |
221 |
|
} |
222 |
|
|
223 |
|
public boolean offer(T x, long timeout, TimeUnit unit) { |
224 |
< |
return super.offer(x, timeout, unit); |
224 |
> |
return super.offer(x, timeout, unit); |
225 |
|
} |
226 |
|
|
227 |
|
} |