< prev index next >

test/hotspot/jtreg/gc/stress/systemgc/TestSystemGC.java

Print this page
rev 47694 : imported patch 8190703-testsystemgc-timeout

@@ -88,23 +88,26 @@
 
 class SystemGCTask extends Exitable implements Runnable {
     private long delayMS;
 
     SystemGCTask(long delayMS) {
+System.err.println("SystemGCTask with delay " + delayMS);
         this.delayMS = delayMS;
     }
 
     @Override
     public void run() {
         while (!shouldExit()) {
             System.gc();
-            ThreadUtils.sleep(delayMS);
+            ThreadUtils.sleep(delayMS * 10);
         }
     }
 }
 
 public class TestSystemGC {
+    private static long endTime;
+
     private static final int numGroups = 7;
     private static final int numGCsPerGroup = 4;
 
     private static Map<String, String> longLivedMap = new TreeMap<>();
 

@@ -132,10 +135,13 @@
         ThreadUtils.sleep(1000);
 
         for (int i = 0; i < numGroups; i++) {
             for (int j = 0; j < numGCsPerGroup; j++) {
                 System.gc();
+               if (System.currentTimeMillis() >= endTime) {
+                   return;
+               }
                 ThreadUtils.sleep(getDelayMS(i));
             }
         }
     }
 

@@ -157,11 +163,12 @@
             task.exit();
         }
     }
 
     private static void runAllPhases() {
-        for (int i = 0; i < 4; i++) {
+        int i = 0;
+        while (i < 4 && System.currentTimeMillis() < endTime) {
             SystemGCTask gcTask =
                 (i % 2 == 1) ? createSystemGCTask(numGroups / 3) : null;
             ShortLivedAllocationTask shortTask =
                 (i == 1 || i == 3) ?  new ShortLivedAllocationTask() : null;
             LongLivedAllocationTask longTask =

@@ -176,17 +183,20 @@
             exitTask(gcTask);
             exitTask(shortTask);
             exitTask(longTask);
 
             ThreadUtils.sleep(1000);
+            i++;
         }
     }
 
     public static void main(String[] args) {
+        if (args.length > 0) {
+            int timeout = Integer.parseInt(args[0]) * 1000;
+            System.out.println("Running with timeout of " + timeout + "ms");
+            endTime = System.currentTimeMillis() + timeout;
+        }
         // First allocate the long lived objects and then run all phases.
         populateLongLived();
         runAllPhases();
-        if (args.length > 0 && args[0].equals("long")) {
-            runAllPhases();
-        }
     }
 }
< prev index next >