< prev index next >

test/gc/shenandoah/TestPeriodicGC.java

Print this page
rev 10697 : [backport] Prepare tests for making UseShenandoahGC experimental
rev 10772 : [backport] Update copyrights
rev 10782 : [backport] Shenandoah should @require Shenandoah, @key gc, and have good @test
rev 10786 : [backport] Reformat Shenandoah tests
   1 /*
   2  * Copyright (c) 2017 Red Hat, Inc. and/or its affiliates.
   3  *
   4  * This code is free software; you can redistribute it and/or modify it
   5  * under the terms of the GNU General Public License version 2 only, as
   6  * published by the Free Software Foundation.
   7  *
   8  * This code is distributed in the hope that it will be useful, but WITHOUT
   9  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  10  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  11  * version 2 for more details (a copy is included in the LICENSE file that
  12  * accompanied this code).
  13  *
  14  * You should have received a copy of the GNU General Public License version
  15  * 2 along with this work; if not, write to the Free Software Foundation,
  16  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  17  *
  18  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  19  * or visit www.oracle.com if you need additional information or have any
  20  * questions.
  21  *
  22  */
  23 
  24 /*
  25  * @test TestPeriodicGC
  26  * @summary Test that periodic GC is working
  27  * @key gc
  28  * @library /testlibrary

  29  * @run driver TestPeriodicGC
  30  */
  31 
  32 import java.util.*;
  33 
  34 import com.oracle.java.testlibrary.*;
  35 
  36 public class TestPeriodicGC {
  37 
  38     public static void testWith(String msg, boolean periodic, String... args) throws Exception {
  39         String[] cmds = Arrays.copyOf(args, args.length + 2);
  40         cmds[args.length] = TestPeriodicGC.class.getName();
  41         cmds[args.length + 1] = "test";
  42         ProcessBuilder pb = ProcessTools.createJavaProcessBuilder(cmds);
  43 
  44         OutputAnalyzer output = new OutputAnalyzer(pb.start());
  45         output.shouldHaveExitValue(0);
  46         if (periodic && !output.getOutput().contains("Trigger: Time since last GC")) {
  47             throw new AssertionError(msg + ": Should have periodic GC in logs");
  48         }


  55         if (args.length > 0 && args[0].equals("test")) {
  56            Thread.sleep(5000); // stay idle
  57            return;
  58         }
  59 
  60         String[] enabled = new String[] {
  61            "adaptive",
  62            "compact",
  63            "static"
  64         };
  65 
  66         String[] disabled = new String[] {
  67            "aggressive",
  68            "passive",
  69         };
  70 
  71         for (String h : enabled) {
  72             testWith("Short period with " + h,
  73                 true,
  74                 "-verbose:gc",
  75                 "-XX:+UseShenandoahGC",
  76                 "-XX:+UnlockDiagnosticVMOptions",
  77                 "-XX:+UnlockExperimentalVMOptions",

  78                 "-XX:ShenandoahGCHeuristics=" + h,
  79                 "-XX:ShenandoahGuaranteedGCInterval=1000"
  80             );
  81 
  82             testWith("Long period with " + h,
  83                 false,
  84                 "-verbose:gc",
  85                 "-XX:+UseShenandoahGC",
  86                 "-XX:+UnlockDiagnosticVMOptions",
  87                 "-XX:+UnlockExperimentalVMOptions",

  88                 "-XX:ShenandoahGCHeuristics=" + h,
  89                 "-XX:ShenandoahGuaranteedGCInterval=100000" // deliberately too long
  90             );
  91         }
  92 
  93         for (String h : disabled) {
  94             testWith("Short period with " + h,
  95                 false,
  96                 "-verbose:gc",
  97                 "-XX:+UseShenandoahGC",
  98                 "-XX:+UnlockDiagnosticVMOptions",
  99                 "-XX:+UnlockExperimentalVMOptions",

 100                 "-XX:ShenandoahGCHeuristics=" + h,
 101                 "-XX:ShenandoahGuaranteedGCInterval=1000"
 102             );
 103         }
 104     }
 105 
 106 }
   1 /*
   2  * Copyright (c) 2017, 2018, Red Hat, Inc. All rights reserved.
   3  *
   4  * This code is free software; you can redistribute it and/or modify it
   5  * under the terms of the GNU General Public License version 2 only, as
   6  * published by the Free Software Foundation.
   7  *
   8  * This code is distributed in the hope that it will be useful, but WITHOUT
   9  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  10  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  11  * version 2 for more details (a copy is included in the LICENSE file that
  12  * accompanied this code).
  13  *
  14  * You should have received a copy of the GNU General Public License version
  15  * 2 along with this work; if not, write to the Free Software Foundation,
  16  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  17  *
  18  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  19  * or visit www.oracle.com if you need additional information or have any
  20  * questions.
  21  *
  22  */
  23 
  24 /*
  25  * @test TestPeriodicGC
  26  * @summary Test that periodic GC is working
  27  * @key gc
  28  * @library /testlibrary
  29  *
  30  * @run driver TestPeriodicGC
  31  */
  32 
  33 import java.util.*;
  34 
  35 import com.oracle.java.testlibrary.*;
  36 
  37 public class TestPeriodicGC {
  38 
  39     public static void testWith(String msg, boolean periodic, String... args) throws Exception {
  40         String[] cmds = Arrays.copyOf(args, args.length + 2);
  41         cmds[args.length] = TestPeriodicGC.class.getName();
  42         cmds[args.length + 1] = "test";
  43         ProcessBuilder pb = ProcessTools.createJavaProcessBuilder(cmds);
  44 
  45         OutputAnalyzer output = new OutputAnalyzer(pb.start());
  46         output.shouldHaveExitValue(0);
  47         if (periodic && !output.getOutput().contains("Trigger: Time since last GC")) {
  48             throw new AssertionError(msg + ": Should have periodic GC in logs");
  49         }


  56         if (args.length > 0 && args[0].equals("test")) {
  57             Thread.sleep(5000); // stay idle
  58             return;
  59         }
  60 
  61         String[] enabled = new String[] {
  62                 "adaptive",
  63                 "compact",
  64                 "static"
  65         };
  66 
  67         String[] disabled = new String[] {
  68                 "aggressive",
  69                 "passive",
  70         };
  71 
  72         for (String h : enabled) {
  73             testWith("Short period with " + h,
  74                     true,
  75                     "-verbose:gc",

  76                     "-XX:+UnlockDiagnosticVMOptions",
  77                     "-XX:+UnlockExperimentalVMOptions",
  78                     "-XX:+UseShenandoahGC",
  79                     "-XX:ShenandoahGCHeuristics=" + h,
  80                     "-XX:ShenandoahGuaranteedGCInterval=1000"
  81             );
  82 
  83             testWith("Long period with " + h,
  84                     false,
  85                     "-verbose:gc",

  86                     "-XX:+UnlockDiagnosticVMOptions",
  87                     "-XX:+UnlockExperimentalVMOptions",
  88                     "-XX:+UseShenandoahGC",
  89                     "-XX:ShenandoahGCHeuristics=" + h,
  90                     "-XX:ShenandoahGuaranteedGCInterval=100000" // deliberately too long
  91             );
  92         }
  93 
  94         for (String h : disabled) {
  95             testWith("Short period with " + h,
  96                     false,
  97                     "-verbose:gc",

  98                     "-XX:+UnlockDiagnosticVMOptions",
  99                     "-XX:+UnlockExperimentalVMOptions",
 100                     "-XX:+UseShenandoahGC",
 101                     "-XX:ShenandoahGCHeuristics=" + h,
 102                     "-XX:ShenandoahGuaranteedGCInterval=1000"
 103             );
 104         }
 105     }
 106 
 107 }
< prev index next >