1 |
|
/* |
2 |
– |
* @test %I% %E% |
3 |
– |
* @bug 4486658 |
4 |
– |
* @compile -source 1.5 ConcurrentDequeLoops.java |
5 |
– |
* @run main/timeout=230 ConcurrentDequeLoops |
6 |
– |
* @summary Checks that a set of threads can repeatedly get and modify items |
7 |
– |
*/ |
8 |
– |
/* |
2 |
|
* Written by Doug Lea with assistance from members of JCP JSR-166 |
3 |
< |
* Expert Group and released to the public domain. Use, modify, and |
4 |
< |
* redistribute this code in any way without acknowledgement. |
3 |
> |
* Expert Group and released to the public domain, as explained at |
4 |
> |
* http://creativecommons.org/licenses/publicdomain |
5 |
|
*/ |
6 |
|
|
7 |
|
import java.util.*; |
22 |
|
if (args.length > 0) { |
23 |
|
try { |
24 |
|
klass = Class.forName(args[0]); |
25 |
< |
} catch(ClassNotFoundException e) { |
25 |
> |
} catch (ClassNotFoundException e) { |
26 |
|
throw new RuntimeException("Class " + args[0] + " not found."); |
27 |
|
} |
28 |
|
} |
29 |
< |
else |
29 |
> |
else |
30 |
|
throw new Error(); |
31 |
|
|
32 |
< |
if (args.length > 1) |
32 |
> |
if (args.length > 1) |
33 |
|
maxStages = Integer.parseInt(args[1]); |
34 |
|
|
35 |
|
System.out.print("Class: " + klass.getName()); |
49 |
|
if (i == k) { |
50 |
|
k = i << 1; |
51 |
|
i = i + (i >>> 1); |
52 |
< |
} |
53 |
< |
else |
52 |
> |
} |
53 |
> |
else |
54 |
|
i = k; |
55 |
|
} |
56 |
|
pool.shutdown(); |
62 |
|
final LoopHelpers.SimpleRandom rng = new LoopHelpers.SimpleRandom(); |
63 |
|
int items; |
64 |
|
Stage (Deque<Integer> q, CyclicBarrier b, int items) { |
65 |
< |
queue = q; |
65 |
> |
queue = q; |
66 |
|
barrier = b; |
67 |
|
this.items = items; |
68 |
|
} |
100 |
|
else |
101 |
|
queue.addLast(res); |
102 |
|
} |
103 |
< |
else { // spinwait |
103 |
> |
else { // spinwait |
104 |
|
for (int k = 1 + (l & 15); k != 0; --k) |
105 |
|
l = LoopHelpers.compute1(LoopHelpers.compute2(l)); |
106 |
|
if ((l & 3) == 3) { |
110 |
|
} |
111 |
|
return new Integer(l); |
112 |
|
} |
113 |
< |
catch (Exception ie) { |
113 |
> |
catch (Exception ie) { |
114 |
|
ie.printStackTrace(); |
115 |
|
throw new Error("Call loop failed"); |
116 |
|
} |
123 |
|
CyclicBarrier barrier = new CyclicBarrier(n + 1, timer); |
124 |
|
totalItems = new AtomicInteger(n * items); |
125 |
|
ArrayList<Future<Integer>> results = new ArrayList<Future<Integer>>(n); |
126 |
< |
for (int i = 0; i < n; ++i) |
126 |
> |
for (int i = 0; i < n; ++i) |
127 |
|
results.add(pool.submit(new Stage(q, barrier, items))); |
128 |
|
|
129 |
|
if (print) |
141 |
|
System.out.println(LoopHelpers.rightJustify(time / (items * n)) + " ns per item"); |
142 |
|
if (total == 0) // avoid overoptimization |
143 |
|
System.out.println("useless result: " + total); |
144 |
< |
|
144 |
> |
|
145 |
|
} |
146 |
|
} |