ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/jsr166/jsr166/src/test/jtreg/util/Collection/IteratorMicroBenchmark.java
(Generate patch)

Comparing jsr166/src/test/jtreg/util/Collection/IteratorMicroBenchmark.java (file contents):
Revision 1.43 by jsr166, Thu Apr 5 15:36:06 2018 UTC vs.
Revision 1.44 by jsr166, Wed May 9 17:43:01 2018 UTC

# Line 27 | Line 27
27   * @run main IteratorMicroBenchmark iterations=1 size=8 warmup=0
28   */
29  
30 + import static java.util.concurrent.TimeUnit.MILLISECONDS;
31   import static java.util.stream.Collectors.summingInt;
32   import static java.util.stream.Collectors.toCollection;
33  
34 + import java.lang.ref.ReferenceQueue;
35   import java.lang.ref.WeakReference;
36   import java.util.ArrayDeque;
37   import java.util.ArrayList;
# Line 54 | Line 56 | import java.util.concurrent.LinkedTransf
56   import java.util.concurrent.PriorityBlockingQueue;
57   import java.util.concurrent.CountDownLatch;
58   import java.util.concurrent.ThreadLocalRandom;
57 import java.util.concurrent.TimeUnit;
59   import java.util.concurrent.atomic.LongAdder;
60   import java.util.function.UnaryOperator;
61   import java.util.regex.Pattern;
# Line 109 | Line 110 | public class IteratorMicroBenchmark {
110  
111      /** No guarantees, but effective in practice. */
112      static void forceFullGc() {
113 <        CountDownLatch finalizeDone = new CountDownLatch(1);
114 <        WeakReference<?> ref = new WeakReference<Object>(new Object() {
115 <            @SuppressWarnings("deprecation")
116 <            protected void finalize() { finalizeDone.countDown(); }});
113 >        long timeoutMillis = 1000L;
114 >        CountDownLatch finalized = new CountDownLatch(1);
115 >        ReferenceQueue<Object> queue = new ReferenceQueue<>();
116 >        WeakReference<Object> ref = new WeakReference<>(
117 >            new Object() { protected void finalize() { finalized.countDown(); }},
118 >            queue);
119          try {
120 <            for (int i = 0; i < 10; i++) {
120 >            for (int tries = 3; tries--> 0; ) {
121                  System.gc();
122 <                if (finalizeDone.await(1L, TimeUnit.SECONDS) && ref.get() == null) {
122 >                if (finalized.await(timeoutMillis, MILLISECONDS)
123 >                    && queue.remove(timeoutMillis) != null
124 >                    && ref.get() == null) {
125                      System.runFinalization(); // try to pick up stragglers
126                      return;
127                  }
128 +                timeoutMillis *= 4;
129              }
130          } catch (InterruptedException unexpected) {
131              throw new AssertionError("unexpected InterruptedException");

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines