1 /*
2 * Copyright (c) 2017, 2018, 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
27 * @summary Test that Shenandoah reacts to explicit GC flags appropriately
28 * @requires vm.gc.Shenandoah
29 * @library /test/lib
30 * @modules java.base/jdk.internal.misc
31 * java.management
32 * @run driver TestExplicitGC
33 */
34
35 import jdk.test.lib.process.ProcessTools;
36 import jdk.test.lib.process.OutputAnalyzer;
37
38 public class TestExplicitGC {
39
40 enum Mode {
41 PRODUCT,
42 DIAGNOSTIC,
43 EXPERIMENTAL,
44 }
45
46 public static void main(String[] args) throws Exception {
47 if (args.length > 0) {
48 System.out.println("Calling System.gc()");
49 System.gc();
50 return;
51 }
52
53 String[] full = new String[] {
54 "Pause Full"
55 };
56
57 String[] concNormal = new String[] {
58 "Pause Init Mark",
59 "Pause Final Mark",
60 };
61
62 {
63 OutputAnalyzer output = ProcessTools.executeLimitedTestJava(
64 "-Xmx128m",
65 "-XX:+UnlockExperimentalVMOptions",
66 "-XX:+UseShenandoahGC",
67 "-Xlog:gc",
68 TestExplicitGC.class.getName(),
69 "test");
70 for (String p : full) {
71 output.shouldNotContain(p);
72 }
73 for (String p : concNormal) {
74 output.shouldContain(p);
75 }
76 }
77
78 {
79 OutputAnalyzer output = ProcessTools.executeLimitedTestJava(
80 "-Xmx128m",
81 "-XX:+UnlockExperimentalVMOptions",
82 "-XX:+UseShenandoahGC",
83 "-Xlog:gc",
84 "-XX:+DisableExplicitGC",
85 TestExplicitGC.class.getName(),
86 "test");
87 for (String p : full) {
88 output.shouldNotContain(p);
89 }
90 for (String p : concNormal) {
91 output.shouldNotContain(p);
92 }
93 }
94
95 {
96 OutputAnalyzer output = ProcessTools.executeLimitedTestJava(
97 "-Xmx128m",
98 "-XX:+UnlockExperimentalVMOptions",
99 "-XX:+UseShenandoahGC",
100 "-Xlog:gc",
101 "-XX:+ExplicitGCInvokesConcurrent",
102 TestExplicitGC.class.getName(),
103 "test");
104 for (String p : full) {
105 output.shouldNotContain(p);
106 }
107 for (String p : concNormal) {
108 output.shouldContain(p);
109 }
110 }
111
112 {
113 OutputAnalyzer output = ProcessTools.executeLimitedTestJava(
114 "-Xmx128m",
115 "-XX:+UnlockExperimentalVMOptions",
116 "-XX:+UseShenandoahGC",
117 "-Xlog:gc",
118 "-XX:-ExplicitGCInvokesConcurrent",
119 TestExplicitGC.class.getName(),
120 "test");
121 for (String p : full) {
122 output.shouldContain(p);
123 }
124 for (String p : concNormal) {
125 output.shouldNotContain(p);
126 }
127 }
128
129 {
130 OutputAnalyzer output = ProcessTools.executeLimitedTestJava(
131 "-Xmx128m",
132 "-XX:+UnlockExperimentalVMOptions",
133 "-XX:+UseShenandoahGC",
134 "-Xlog:gc",
135 "-XX:+ExplicitGCInvokesConcurrent",
136 "-XX:ShenandoahGCMode=iu",
137 TestExplicitGC.class.getName(),
138 "test");
139 for (String p : full) {
140 output.shouldNotContain(p);
141 }
142 for (String p : concNormal) {
143 output.shouldContain(p);
144 }
145 }
146 }
147 }