equal
deleted
inserted
replaced
33 /* |
33 /* |
34 * @test |
34 * @test |
35 * @bug 6785442 |
35 * @bug 6785442 |
36 * @summary Benchmark that tries to GC-tenure head, followed by |
36 * @summary Benchmark that tries to GC-tenure head, followed by |
37 * many add/remove operations. |
37 * many add/remove operations. |
38 * @run main GCRetention 12345 |
38 * @run main GCRetention just-testing |
39 */ |
39 */ |
40 |
40 |
41 import static java.util.concurrent.TimeUnit.SECONDS; |
41 import static java.util.concurrent.TimeUnit.SECONDS; |
42 |
42 |
43 import java.lang.ref.WeakReference; |
43 import java.lang.ref.WeakReference; |
58 import java.util.List; |
58 import java.util.List; |
59 import java.util.Queue; |
59 import java.util.Queue; |
60 import java.util.Map; |
60 import java.util.Map; |
61 |
61 |
62 public class GCRetention { |
62 public class GCRetention { |
63 // Suitable for benchmarking. Overridden by args[0] for testing. |
63 boolean benchmarkMode; |
64 int count = 1024 * 1024; |
64 int count; |
65 |
65 |
66 /** No guarantees, but effective in practice. */ |
66 /** No guarantees, but effective in practice. */ |
67 static void forceFullGc() { |
67 static void forceFullGc() { |
68 CountDownLatch finalizeDone = new CountDownLatch(1); |
68 CountDownLatch finalizeDone = new CountDownLatch(1); |
69 WeakReference<?> ref = new WeakReference<Object>(new Object() { |
69 WeakReference<?> ref = new WeakReference<Object>(new Object() { |
122 for (String name : classNames) |
122 for (String name : classNames) |
123 System.out.printf(format, name, results.get(name)); |
123 System.out.printf(format, name, results.get(name)); |
124 } |
124 } |
125 |
125 |
126 void test(String[] args) { |
126 void test(String[] args) { |
127 if (args.length > 0) |
127 benchmarkMode = ! (args.length > 0 && args[0].equals("just-testing")); |
128 count = Integer.valueOf(args[0]); |
128 count = benchmarkMode ? 1024 * 1024 : 30; |
|
129 |
129 // Warmup |
130 // Warmup |
130 for (Queue<Boolean> queue : queues()) |
131 for (Queue<Boolean> queue : queues()) |
131 test(queue); |
132 test(queue); |
132 results.clear(); |
133 results.clear(); |
133 for (Queue<Boolean> queue : queues()) |
134 for (Queue<Boolean> queue : queues()) |
138 |
139 |
139 void test(Queue<Boolean> q) { |
140 void test(Queue<Boolean> q) { |
140 long t0 = System.nanoTime(); |
141 long t0 = System.nanoTime(); |
141 for (int i = 0; i < count; i++) |
142 for (int i = 0; i < count; i++) |
142 check(q.add(Boolean.TRUE)); |
143 check(q.add(Boolean.TRUE)); |
143 forceFullGc(); |
144 if (benchmarkMode) forceFullGc(); |
144 // forceFullGc(); |
145 // forceFullGc(); |
145 Boolean x; |
146 Boolean x; |
146 while ((x = q.poll()) != null) |
147 while ((x = q.poll()) != null) |
147 equal(x, Boolean.TRUE); |
148 equal(x, Boolean.TRUE); |
148 check(q.isEmpty()); |
149 check(q.isEmpty()); |