8148940: java/lang/ref/FinalizeOverride.java can time out due to frequent safepointing
authorzmajo
Mon, 29 Feb 2016 07:58:45 +0100
changeset 36415 a172186ba1ca
parent 36414 c0e3caef7d78
child 36417 f4bdcbd7ebc1
8148940: java/lang/ref/FinalizeOverride.java can time out due to frequent safepointing Summary: Reduce the freqency of triggering GCs by sleeping between GCs. Reviewed-by: thartmann, shade
jdk/test/java/lang/ref/FinalizeOverride.java
--- a/jdk/test/java/lang/ref/FinalizeOverride.java	Tue Feb 23 22:10:02 2016 +0300
+++ b/jdk/test/java/lang/ref/FinalizeOverride.java	Mon Feb 29 07:58:45 2016 +0100
@@ -29,7 +29,7 @@
 import java.util.concurrent.atomic.AtomicInteger;
 
 /* @test
- * @bug 8027351
+ * @bug 8027351 8148940
  * @summary Basic test of the finalize method
  */
 
@@ -63,6 +63,19 @@
         while (finalizedCount.get() != (count+1)) {
             System.gc();
             System.runFinalization();
+            // Running System.gc() and System.runFinalization() in a
+            // tight loop can trigger frequent safepointing that slows
+            // down the VM and, as a result, the test. (With the
+            // HotSpot VM, the effect of frequent safepointing is
+            // especially noticeable if the test is run with the
+            // -Xcomp flag.)  Sleeping for a second after every
+            // garbage collection and finalization cycle gives the VM
+            // time to make progress.
+            try {
+                Thread.sleep(1000);
+            } catch (InterruptedException e) {
+                System.out.println("Main thread interrupted, continuing execution.");
+            }
         }
 
         if (privateFinalizeInvoked) {