22 |
|
static final int POOL_MASK = POOL_SIZE-1; |
23 |
|
static final Integer[] intPool = new Integer[POOL_SIZE]; |
24 |
|
static { |
25 |
< |
for (int i = 0; i < POOL_SIZE; ++i) |
25 |
> |
for (int i = 0; i < POOL_SIZE; ++i) |
26 |
|
intPool[i] = Integer.valueOf(i); |
27 |
|
} |
28 |
|
|
29 |
|
public static void main(String[] args) throws Exception { |
30 |
|
int maxn = 12; |
31 |
|
|
32 |
< |
if (args.length > 0) |
32 |
> |
if (args.length > 0) |
33 |
|
maxn = Integer.parseInt(args[0]); |
34 |
|
|
35 |
|
print = false; |
43 |
|
if (i == k) { |
44 |
|
k = i << 1; |
45 |
|
i = i + (i >>> 1); |
46 |
< |
} |
47 |
< |
else |
46 |
> |
} |
47 |
> |
else |
48 |
|
i = k; |
49 |
|
} |
50 |
< |
|
50 |
> |
|
51 |
|
pool.shutdown(); |
52 |
|
} |
53 |
|
|
56 |
|
System.out.print("Warmup "); |
57 |
|
int it = 2000; |
58 |
|
for (int j = 5; j > 0; --j) { |
59 |
< |
oneTest(j, it); |
59 |
> |
oneTest(j, it); |
60 |
|
System.out.print("."); |
61 |
|
it += 1000; |
62 |
|
} |
63 |
|
System.gc(); |
64 |
|
it = 20000; |
65 |
|
for (int j = 5; j > 0; --j) { |
66 |
< |
oneTest(j, it); |
66 |
> |
oneTest(j, it); |
67 |
|
System.out.print("."); |
68 |
|
it += 10000; |
69 |
|
} |
93 |
|
if (print) |
94 |
|
System.out.print("LinkedBlockingDeque "); |
95 |
|
oneRun(new LinkedBlockingDeque<Integer>(), n, iters); |
96 |
< |
|
96 |
> |
|
97 |
|
Thread.sleep(100); // System.gc(); |
98 |
|
if (print) |
99 |
|
System.out.print("ArrayBlockingQueue "); |
103 |
|
if (print) |
104 |
|
System.out.print("SynchronousQueue "); |
105 |
|
oneRun(new SynchronousQueue<Integer>(), n, iters); |
106 |
< |
|
106 |
> |
|
107 |
|
Thread.sleep(100); // System.gc(); |
108 |
|
if (print) |
109 |
|
System.out.print("SynchronousQueue(fair) "); |
118 |
|
if (print) |
119 |
|
System.out.print("LinkedTransferQueue(half)"); |
120 |
|
oneRun(new HalfSyncLTQ<Integer>(), n, iters); |
121 |
< |
|
121 |
> |
|
122 |
|
Thread.sleep(100); // System.gc(); |
123 |
|
if (print) |
124 |
|
System.out.print("PriorityBlockingQueue "); |
130 |
|
oneRun(new ArrayBlockingQueue<Integer>(POOL_SIZE, true), n, fairIters); |
131 |
|
|
132 |
|
} |
133 |
< |
|
133 |
> |
|
134 |
|
static abstract class Stage implements Runnable { |
135 |
|
final int iters; |
136 |
|
final BlockingQueue<Integer> queue; |
137 |
|
final CyclicBarrier barrier; |
138 |
|
volatile int result; |
139 |
|
Stage (BlockingQueue<Integer> q, CyclicBarrier b, int iters) { |
140 |
< |
queue = q; |
140 |
> |
queue = q; |
141 |
|
barrier = b; |
142 |
|
this.iters = iters; |
143 |
|
} |
160 |
|
barrier.await(); |
161 |
|
result = 432; |
162 |
|
} |
163 |
< |
catch (Exception ie) { |
164 |
< |
ie.printStackTrace(); |
165 |
< |
return; |
163 |
> |
catch (Exception ie) { |
164 |
> |
ie.printStackTrace(); |
165 |
> |
return; |
166 |
|
} |
167 |
|
} |
168 |
|
} |
169 |
|
|
170 |
|
static class Consumer extends Stage { |
171 |
< |
Consumer(BlockingQueue<Integer> q, CyclicBarrier b, int iters) { |
171 |
> |
Consumer(BlockingQueue<Integer> q, CyclicBarrier b, int iters) { |
172 |
|
super(q, b, iters); |
173 |
|
|
174 |
|
} |
186 |
|
result = s; |
187 |
|
if (s == 0) System.out.print(" "); |
188 |
|
} |
189 |
< |
catch (Exception ie) { |
190 |
< |
ie.printStackTrace(); |
191 |
< |
return; |
189 |
> |
catch (Exception ie) { |
190 |
> |
ie.printStackTrace(); |
191 |
> |
return; |
192 |
|
} |
193 |
|
} |
194 |
|
|
211 |
|
static final class LTQasSQ<T> extends LinkedTransferQueue<T> { |
212 |
|
LTQasSQ() { super(); } |
213 |
|
public void put(T x) { |
214 |
< |
try { super.transfer(x); |
214 |
> |
try { super.transfer(x); |
215 |
|
} catch (InterruptedException ex) { throw new Error(); } |
216 |
|
} |
217 |
|
} |
223 |
|
if ((++calls & 1) == 0) |
224 |
|
super.put(x); |
225 |
|
else { |
226 |
< |
try { super.transfer(x); |
227 |
< |
} catch (InterruptedException ex) { |
228 |
< |
throw new Error(); |
226 |
> |
try { super.transfer(x); |
227 |
> |
} catch (InterruptedException ex) { |
228 |
> |
throw new Error(); |
229 |
|
} |
230 |
|
} |
231 |
|
} |