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 /test/lib 29 * @run driver TestPeriodicGC 30 */ 31 32 import java.util.*; 33 34 import jdk.test.lib.Asserts; 35 import jdk.test.lib.process.ProcessTools; 36 import jdk.test.lib.process.OutputAnalyzer; 37 38 public class TestPeriodicGC { 39 40 public static void testWith(String msg, boolean periodic, String... args) throws Exception { 41 String[] cmds = Arrays.copyOf(args, args.length + 2); 42 cmds[args.length] = TestPeriodicGC.class.getName(); 43 cmds[args.length + 1] = "test"; 44 ProcessBuilder pb = ProcessTools.createJavaProcessBuilder(cmds); 45 46 OutputAnalyzer output = new OutputAnalyzer(pb.start()); 47 output.shouldHaveExitValue(0); 48 if (periodic && !output.getOutput().contains("Trigger: Time since last GC")) { 49 throw new AssertionError(msg + ": Should have periodic GC in logs"); 50 } 51 if (!periodic && output.getOutput().contains("Trigger: Time since last GC")) { 52 throw new AssertionError(msg + ": Should not have periodic GC in logs"); 53 } 54 } 55 56 public static void main(String[] args) throws Exception { 57 if (args.length > 0 && args[0].equals("test")) { 58 Thread.sleep(5000); // stay idle 59 return; 60 } 61 62 String[] enabled = new String[] { 63 "adaptive", 64 "compact", 65 "static", 66 "traversal", 67 }; 68 69 String[] disabled = new String[] { 70 "aggressive", 71 "passive", 72 }; 73 74 for (String h : enabled) { 75 testWith("Short period with " + h, 76 true, 77 "-Xlog:gc", 78 "-XX:+UnlockDiagnosticVMOptions", 79 "-XX:+UnlockExperimentalVMOptions", 80 "-XX:+UseShenandoahGC", 81 "-XX:ShenandoahGCHeuristics=" + h, 82 "-XX:ShenandoahGuaranteedGCInterval=1000" 83 ); 84 85 testWith("Long period with " + h, 86 false, 87 "-Xlog:gc", 88 "-XX:+UnlockDiagnosticVMOptions", 89 "-XX:+UnlockExperimentalVMOptions", 90 "-XX:+UseShenandoahGC", 91 "-XX:ShenandoahGCHeuristics=" + h, 92 "-XX:ShenandoahGuaranteedGCInterval=100000" // deliberately too long 93 ); 94 } 95 96 for (String h : disabled) { 97 testWith("Short period with " + h, 98 false, 99 "-Xlog:gc", 100 "-XX:+UnlockDiagnosticVMOptions", 101 "-XX:+UnlockExperimentalVMOptions", 102 "-XX:+UseShenandoahGC", 103 "-XX:ShenandoahGCHeuristics=" + h, 104 "-XX:ShenandoahGuaranteedGCInterval=1000" 105 ); 106 } 107 } 108 109 }