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 *
29 * @library /test/lib
30 * @run driver TestPeriodicGC
31 */
32
33 import java.util.*;
34
35 import jdk.test.lib.Asserts;
36 import jdk.test.lib.process.ProcessTools;
37 import jdk.test.lib.process.OutputAnalyzer;
38
39 public class TestPeriodicGC {
40
41 public static void testWith(String msg, boolean periodic, String... args) throws Exception {
42 String[] cmds = Arrays.copyOf(args, args.length + 2);
43 cmds[args.length] = TestPeriodicGC.class.getName();
44 cmds[args.length + 1] = "test";
45 ProcessBuilder pb = ProcessTools.createLimitedTestJavaProcessBuilder(cmds);
46
47 OutputAnalyzer output = new OutputAnalyzer(pb.start());
48 output.shouldHaveExitValue(0);
49 if (periodic && !output.getOutput().contains("Trigger: Time since last GC")) {
50 throw new AssertionError(msg + ": Should have periodic GC in logs");
51 }
52 if (!periodic && output.getOutput().contains("Trigger: Time since last GC")) {
53 throw new AssertionError(msg + ": Should not have periodic GC in logs");
54 }
55 }
56
57 public static void main(String[] args) throws Exception {
58 if (args.length > 0 && args[0].equals("test")) {
59 Thread.sleep(5000); // stay idle
60 return;
61 }
62
63 String[] enabled = new String[] {
64 "adaptive",
65 "compact",
66 "static",
67 };
68
69 for (String h : enabled) {
70 testWith("Zero interval with " + h,
71 false,
72 "-Xlog:gc",
73 "-XX:+UnlockDiagnosticVMOptions",
74 "-XX:+UnlockExperimentalVMOptions",
75 "-XX:+UseShenandoahGC",
76 "-XX:ShenandoahGCHeuristics=" + h,
140
141 testWith("Zero interval with passive",
142 false,
143 "-Xlog:gc",
144 "-XX:+UnlockDiagnosticVMOptions",
145 "-XX:+UnlockExperimentalVMOptions",
146 "-XX:+UseShenandoahGC",
147 "-XX:ShenandoahGCMode=passive",
148 "-XX:ShenandoahGuaranteedGCInterval=0"
149 );
150
151 testWith("Short interval with passive",
152 false,
153 "-Xlog:gc",
154 "-XX:+UnlockDiagnosticVMOptions",
155 "-XX:+UnlockExperimentalVMOptions",
156 "-XX:+UseShenandoahGC",
157 "-XX:ShenandoahGCMode=passive",
158 "-XX:ShenandoahGuaranteedGCInterval=1000"
159 );
160 }
161
162 }
|
1 /*
2 * Copyright (c) 2017, 2020, Red Hat, Inc. All rights reserved.
3 * Copyright Amazon.com Inc. or its affiliates. All Rights Reserved.
4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 *
6 * This code is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License version 2 only, as
8 * published by the Free Software Foundation.
9 *
10 * This code is distributed in the hope that it will be useful, but WITHOUT
11 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
13 * version 2 for more details (a copy is included in the LICENSE file that
14 * accompanied this code).
15 *
16 * You should have received a copy of the GNU General Public License version
17 * 2 along with this work; if not, write to the Free Software Foundation,
18 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
19 *
20 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
21 * or visit www.oracle.com if you need additional information or have any
22 * questions.
23 *
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.createLimitedTestJavaProcessBuilder(cmds);
47
48 OutputAnalyzer output = new OutputAnalyzer(pb.start());
49 output.shouldHaveExitValue(0);
50 if (periodic && !output.getOutput().contains("Trigger (GLOBAL): Time since last GC")) {
51 throw new AssertionError(msg + ": Should have periodic GC in logs");
52 }
53 if (!periodic && output.getOutput().contains("Trigger (GLOBAL): Time since last GC")) {
54 throw new AssertionError(msg + ": Should not have periodic GC in logs");
55 }
56 }
57
58 public static void testGenerational(boolean periodic, String... args) throws Exception {
59 String[] cmds = Arrays.copyOf(args, args.length + 2);
60 cmds[args.length] = TestPeriodicGC.class.getName();
61 cmds[args.length + 1] = "test";
62 ProcessBuilder pb = ProcessTools.createLimitedTestJavaProcessBuilder(cmds);
63
64 OutputAnalyzer output = new OutputAnalyzer(pb.start());
65 output.shouldHaveExitValue(0);
66 if (periodic) {
67 if (!output.getOutput().contains("Trigger (YOUNG): Time since last GC")) {
68 throw new AssertionError("Generational mode: Should have periodic young GC in logs");
69 }
70 if (!output.getOutput().contains("Trigger (OLD): Time since last GC")) {
71 throw new AssertionError("Generational mode: Should have periodic old GC in logs");
72 }
73 } else {
74 if (output.getOutput().contains("Trigger (YOUNG): Time since last GC")) {
75 throw new AssertionError("Generational mode: Should not have periodic young GC in logs");
76 }
77 if (output.getOutput().contains("Trigger (OLD): Time since last GC")) {
78 throw new AssertionError("Generational mode: Should not have periodic old GC in logs");
79 }
80 }
81 }
82
83 public static void main(String[] args) throws Exception {
84 if (args.length > 0 && args[0].equals("test")) {
85 Thread.sleep(5000); // stay idle
86 return;
87 }
88
89 String[] enabled = new String[] {
90 "adaptive",
91 "compact",
92 "static",
93 };
94
95 for (String h : enabled) {
96 testWith("Zero interval with " + h,
97 false,
98 "-Xlog:gc",
99 "-XX:+UnlockDiagnosticVMOptions",
100 "-XX:+UnlockExperimentalVMOptions",
101 "-XX:+UseShenandoahGC",
102 "-XX:ShenandoahGCHeuristics=" + h,
166
167 testWith("Zero interval with passive",
168 false,
169 "-Xlog:gc",
170 "-XX:+UnlockDiagnosticVMOptions",
171 "-XX:+UnlockExperimentalVMOptions",
172 "-XX:+UseShenandoahGC",
173 "-XX:ShenandoahGCMode=passive",
174 "-XX:ShenandoahGuaranteedGCInterval=0"
175 );
176
177 testWith("Short interval with passive",
178 false,
179 "-Xlog:gc",
180 "-XX:+UnlockDiagnosticVMOptions",
181 "-XX:+UnlockExperimentalVMOptions",
182 "-XX:+UseShenandoahGC",
183 "-XX:ShenandoahGCMode=passive",
184 "-XX:ShenandoahGuaranteedGCInterval=1000"
185 );
186
187 testGenerational(true,
188 "-Xlog:gc",
189 "-XX:+UnlockDiagnosticVMOptions",
190 "-XX:+UnlockExperimentalVMOptions",
191 "-XX:+UseShenandoahGC",
192 "-XX:ShenandoahGCMode=generational",
193 "-XX:ShenandoahGuaranteedYoungGCInterval=1000",
194 "-XX:ShenandoahGuaranteedOldGCInterval=1500"
195 );
196
197 testGenerational(false,
198 "-Xlog:gc",
199 "-XX:+UnlockDiagnosticVMOptions",
200 "-XX:+UnlockExperimentalVMOptions",
201 "-XX:+UseShenandoahGC",
202 "-XX:ShenandoahGCMode=generational",
203 "-XX:ShenandoahGuaranteedYoungGCInterval=0",
204 "-XX:ShenandoahGuaranteedOldGCInterval=0"
205 );
206 }
207
208 }
|