1 /* 2 * Copyright (c) 2017, 2020, Red Hat, Inc. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * This code is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. 8 * 9 * This code is distributed in the hope that it will be useful, but WITHOUT 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 12 * version 2 for more details (a copy is included in the LICENSE file that 13 * accompanied this code). 14 * 15 * You should have received a copy of the GNU General Public License version 16 * 2 along with this work; if not, write to the Free Software Foundation, 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 18 * 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 20 * or visit www.oracle.com if you need additional information or have any 21 * questions. 22 * 23 */ 24 25 /* 26 * @test TestPeriodicGC 27 * @summary Test that periodic GC is working 28 * @key gc 29 * @requires vm.gc.Shenandoah & !vm.graal.enabled 30 * @library /test/lib 31 * @run driver TestPeriodicGC 32 */ 33 34 import java.util.*; 35 36 import jdk.test.lib.Asserts; 37 import jdk.test.lib.process.ProcessTools; 38 import jdk.test.lib.process.OutputAnalyzer; 39 40 public class TestPeriodicGC { 41 42 public static void testWith(String msg, boolean periodic, String... args) throws Exception { 43 String[] cmds = Arrays.copyOf(args, args.length + 2); 44 cmds[args.length] = TestPeriodicGC.class.getName(); 45 cmds[args.length + 1] = "test"; 46 ProcessBuilder pb = ProcessTools.createJavaProcessBuilder(cmds); 47 48 OutputAnalyzer output = new OutputAnalyzer(pb.start()); 49 output.shouldHaveExitValue(0); 50 if (periodic && !output.getOutput().contains("Trigger: Time since last GC")) { 51 throw new AssertionError(msg + ": Should have periodic GC in logs"); 52 } 53 if (!periodic && output.getOutput().contains("Trigger: Time since last GC")) { 54 throw new AssertionError(msg + ": Should not have periodic GC in logs"); 55 } 56 } 57 58 public static void main(String[] args) throws Exception { 59 if (args.length > 0 && args[0].equals("test")) { 60 Thread.sleep(5000); // stay idle 61 return; 62 } 63 64 String[] enabled = new String[] { 65 "adaptive", 66 "compact", 67 "static", 68 }; 69 70 for (String h : enabled) { 71 testWith("Zero interval with " + h, 72 false, 73 "-Xlog:gc", 74 "-XX:+UnlockDiagnosticVMOptions", 75 "-XX:+UnlockExperimentalVMOptions", 76 "-XX:+UseShenandoahGC", 77 "-XX:ShenandoahGCHeuristics=" + h, 78 "-XX:ShenandoahGuaranteedGCInterval=0" 79 ); 80 81 testWith("Short interval with " + h, 82 true, 83 "-Xlog:gc", 84 "-XX:+UnlockDiagnosticVMOptions", 85 "-XX:+UnlockExperimentalVMOptions", 86 "-XX:+UseShenandoahGC", 87 "-XX:ShenandoahGCHeuristics=" + h, 88 "-XX:ShenandoahGuaranteedGCInterval=1000" 89 ); 90 91 testWith("Long interval with " + h, 92 false, 93 "-Xlog:gc", 94 "-XX:+UnlockDiagnosticVMOptions", 95 "-XX:+UnlockExperimentalVMOptions", 96 "-XX:+UseShenandoahGC", 97 "-XX:ShenandoahGCHeuristics=" + h, 98 "-XX:ShenandoahGuaranteedGCInterval=100000" // deliberately too long 99 ); 100 } 101 102 testWith("Short interval with aggressive", 103 false, 104 "-Xlog:gc", 105 "-XX:+UnlockDiagnosticVMOptions", 106 "-XX:+UnlockExperimentalVMOptions", 107 "-XX:+UseShenandoahGC", 108 "-XX:ShenandoahGCHeuristics=aggressive", 109 "-XX:ShenandoahGuaranteedGCInterval=1000" 110 ); 111 112 testWith("Zero interval with passive", 113 false, 114 "-Xlog:gc", 115 "-XX:+UnlockDiagnosticVMOptions", 116 "-XX:+UnlockExperimentalVMOptions", 117 "-XX:+UseShenandoahGC", 118 "-XX:ShenandoahGCMode=passive", 119 "-XX:ShenandoahGuaranteedGCInterval=0" 120 ); 121 122 testWith("Short interval with passive", 123 false, 124 "-Xlog:gc", 125 "-XX:+UnlockDiagnosticVMOptions", 126 "-XX:+UnlockExperimentalVMOptions", 127 "-XX:+UseShenandoahGC", 128 "-XX:ShenandoahGCMode=passive", 129 "-XX:ShenandoahGuaranteedGCInterval=1000" 130 ); 131 } 132 133 }