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 } 50 if (!periodic && output.getOutput().contains("Trigger: Time since last GC")) { 51 throw new AssertionError(msg + ": Should not have periodic GC in logs"); 52 } 53 } 54 55 public static void main(String[] args) throws Exception { 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 for (String h : enabled) { 68 testWith("Short period with " + h, 69 true, 70 "-verbose:gc", 71 "-XX:+UnlockDiagnosticVMOptions", 72 "-XX:+UnlockExperimentalVMOptions", 73 "-XX:+UseShenandoahGC", 74 "-XX:ShenandoahGCHeuristics=" + h, 75 "-XX:ShenandoahGuaranteedGCInterval=1000" 76 ); 77 78 testWith("Long period with " + h, 79 false, 80 "-verbose:gc", 81 "-XX:+UnlockDiagnosticVMOptions", 82 "-XX:+UnlockExperimentalVMOptions", 83 "-XX:+UseShenandoahGC", 84 "-XX:ShenandoahGCHeuristics=" + h, 85 "-XX:ShenandoahGuaranteedGCInterval=100000" // deliberately too long 86 ); 87 } 88 89 testWith("Short period with aggressive", 90 false, 91 "-verbose:gc", 92 "-XX:+UnlockDiagnosticVMOptions", 93 "-XX:+UnlockExperimentalVMOptions", 94 "-XX:+UseShenandoahGC", 95 "-XX:ShenandoahGCHeuristics=aggressive", 96 "-XX:ShenandoahGuaranteedGCInterval=1000" 97 ); 98 testWith("Short period with passive", 99 false, 100 "-verbose:gc", 101 "-XX:+UnlockDiagnosticVMOptions", 102 "-XX:+UnlockExperimentalVMOptions", 103 "-XX:+UseShenandoahGC", 104 "-XX:ShenandoahGCMode=passive", 105 "-XX:ShenandoahGuaranteedGCInterval=1000" 106 ); 107 } 108 109 }