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 * @test TestGCLogMessages
26 * @bug 8035406 8027295 8035398 8019342 8027959 8048179 8027962 8069330 8076463 8150630 8160055 8177059
27 * @summary Ensure the output for a minor GC with G1
28 * includes the expected necessary messages.
29 * @key gc
30 * @requires vm.gc.G1
31 * @library /test/lib
32 * @modules java.base/jdk.internal.misc
33 * java.management
34 * @build sun.hotspot.WhiteBox
35 * @run main ClassFileInstaller sun.hotspot.WhiteBox
36 * @run main TestGCLogMessages
37 */
38
39 import jdk.test.lib.process.OutputAnalyzer;
40 import jdk.test.lib.process.ProcessTools;
41 import jdk.test.lib.Platform;
42
43 public class TestGCLogMessages {
44
45 private enum Level {
46 OFF(""),
135 new LogMessageWithLevel("Resize TLABs", Level.DEBUG),
136
137 new LogMessageWithLevelC2OrJVMCIOnly("DerivedPointerTable Update", Level.DEBUG),
138 new LogMessageWithLevel("Start New Collection Set", Level.DEBUG),
139 };
140
141 void checkMessagesAtLevel(OutputAnalyzer output, LogMessageWithLevel messages[], Level level) throws Exception {
142 for (LogMessageWithLevel l : messages) {
143 if (level.lessThan(l.level) || !l.isAvailable()) {
144 output.shouldNotContain(l.message);
145 } else {
146 output.shouldMatch("\\[" + l.level + ".*" + l.message);
147 }
148 }
149 }
150
151 public static void main(String[] args) throws Exception {
152 new TestGCLogMessages().testNormalLogs();
153 new TestGCLogMessages().testWithToSpaceExhaustionLogs();
154 new TestGCLogMessages().testWithInitialMark();
155 }
156
157 private void testNormalLogs() throws Exception {
158
159 ProcessBuilder pb = ProcessTools.createJavaProcessBuilder("-XX:+UseG1GC",
160 "-Xmx10M",
161 GCTest.class.getName());
162
163 OutputAnalyzer output = new OutputAnalyzer(pb.start());
164 checkMessagesAtLevel(output, allLogMessages, Level.OFF);
165 output.shouldHaveExitValue(0);
166
167 pb = ProcessTools.createJavaProcessBuilder("-XX:+UseG1GC",
168 "-XX:+UseStringDeduplication",
169 "-Xmx10M",
170 "-Xlog:gc+phases=debug",
171 GCTest.class.getName());
172
173 output = new OutputAnalyzer(pb.start());
174 checkMessagesAtLevel(output, allLogMessages, Level.DEBUG);
209 GCTestWithToSpaceExhaustion.class.getName());
210
211 output = new OutputAnalyzer(pb.start());
212 checkMessagesAtLevel(output, exhFailureMessages, Level.TRACE);
213 output.shouldHaveExitValue(0);
214 }
215
216 private void testWithInitialMark() throws Exception {
217 ProcessBuilder pb = ProcessTools.createJavaProcessBuilder("-XX:+UseG1GC",
218 "-Xmx10M",
219 "-Xbootclasspath/a:.",
220 "-Xlog:gc*=debug",
221 "-XX:+UnlockDiagnosticVMOptions",
222 "-XX:+WhiteBoxAPI",
223 GCTestWithInitialMark.class.getName());
224
225 OutputAnalyzer output = new OutputAnalyzer(pb.start());
226 output.shouldContain("Clear Claimed Marks");
227 output.shouldHaveExitValue(0);
228 }
229
230 static class GCTest {
231 private static byte[] garbage;
232 public static void main(String [] args) {
233 System.out.println("Creating garbage");
234 // create 128MB of garbage. This should result in at least one GC
235 for (int i = 0; i < 1024; i++) {
236 garbage = new byte[128 * 1024];
237 }
238 System.out.println("Done");
239 }
240 }
241
242 static class GCTestWithToSpaceExhaustion {
243 private static byte[] garbage;
244 private static byte[] largeObject;
245 public static void main(String [] args) {
246 largeObject = new byte[16*1024*1024];
247 System.out.println("Creating garbage");
248 // create 128MB of garbage. This should result in at least one GC,
|
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 * @test TestGCLogMessages
26 * @bug 8035406 8027295 8035398 8019342 8027959 8048179 8027962 8069330 8076463 8150630 8160055 8177059 8166191
27 * @summary Ensure the output for a minor GC with G1
28 * includes the expected necessary messages.
29 * @key gc
30 * @requires vm.gc.G1
31 * @library /test/lib
32 * @modules java.base/jdk.internal.misc
33 * java.management
34 * @build sun.hotspot.WhiteBox
35 * @run main ClassFileInstaller sun.hotspot.WhiteBox
36 * @run main TestGCLogMessages
37 */
38
39 import jdk.test.lib.process.OutputAnalyzer;
40 import jdk.test.lib.process.ProcessTools;
41 import jdk.test.lib.Platform;
42
43 public class TestGCLogMessages {
44
45 private enum Level {
46 OFF(""),
135 new LogMessageWithLevel("Resize TLABs", Level.DEBUG),
136
137 new LogMessageWithLevelC2OrJVMCIOnly("DerivedPointerTable Update", Level.DEBUG),
138 new LogMessageWithLevel("Start New Collection Set", Level.DEBUG),
139 };
140
141 void checkMessagesAtLevel(OutputAnalyzer output, LogMessageWithLevel messages[], Level level) throws Exception {
142 for (LogMessageWithLevel l : messages) {
143 if (level.lessThan(l.level) || !l.isAvailable()) {
144 output.shouldNotContain(l.message);
145 } else {
146 output.shouldMatch("\\[" + l.level + ".*" + l.message);
147 }
148 }
149 }
150
151 public static void main(String[] args) throws Exception {
152 new TestGCLogMessages().testNormalLogs();
153 new TestGCLogMessages().testWithToSpaceExhaustionLogs();
154 new TestGCLogMessages().testWithInitialMark();
155 new TestGCLogMessages().testExpandHeap();
156 }
157
158 private void testNormalLogs() throws Exception {
159
160 ProcessBuilder pb = ProcessTools.createJavaProcessBuilder("-XX:+UseG1GC",
161 "-Xmx10M",
162 GCTest.class.getName());
163
164 OutputAnalyzer output = new OutputAnalyzer(pb.start());
165 checkMessagesAtLevel(output, allLogMessages, Level.OFF);
166 output.shouldHaveExitValue(0);
167
168 pb = ProcessTools.createJavaProcessBuilder("-XX:+UseG1GC",
169 "-XX:+UseStringDeduplication",
170 "-Xmx10M",
171 "-Xlog:gc+phases=debug",
172 GCTest.class.getName());
173
174 output = new OutputAnalyzer(pb.start());
175 checkMessagesAtLevel(output, allLogMessages, Level.DEBUG);
210 GCTestWithToSpaceExhaustion.class.getName());
211
212 output = new OutputAnalyzer(pb.start());
213 checkMessagesAtLevel(output, exhFailureMessages, Level.TRACE);
214 output.shouldHaveExitValue(0);
215 }
216
217 private void testWithInitialMark() throws Exception {
218 ProcessBuilder pb = ProcessTools.createJavaProcessBuilder("-XX:+UseG1GC",
219 "-Xmx10M",
220 "-Xbootclasspath/a:.",
221 "-Xlog:gc*=debug",
222 "-XX:+UnlockDiagnosticVMOptions",
223 "-XX:+WhiteBoxAPI",
224 GCTestWithInitialMark.class.getName());
225
226 OutputAnalyzer output = new OutputAnalyzer(pb.start());
227 output.shouldContain("Clear Claimed Marks");
228 output.shouldHaveExitValue(0);
229 }
230
231 private void testExpandHeap() throws Exception {
232 ProcessBuilder pb = ProcessTools.createJavaProcessBuilder("-XX:+UseG1GC",
233 "-Xmx10M",
234 "-Xbootclasspath/a:.",
235 "-Xlog:gc+ergo+heap=debug",
236 "-XX:+UnlockDiagnosticVMOptions",
237 "-XX:+WhiteBoxAPI",
238 GCTest.class.getName());
239
240 OutputAnalyzer output = new OutputAnalyzer(pb.start());
241 output.shouldContain("Expand the heap. requested expansion amount: ");
242 output.shouldContain("B expansion amount: ");
243 output.shouldHaveExitValue(0);
244 }
245
246
247 static class GCTest {
248 private static byte[] garbage;
249 public static void main(String [] args) {
250 System.out.println("Creating garbage");
251 // create 128MB of garbage. This should result in at least one GC
252 for (int i = 0; i < 1024; i++) {
253 garbage = new byte[128 * 1024];
254 }
255 System.out.println("Done");
256 }
257 }
258
259 static class GCTestWithToSpaceExhaustion {
260 private static byte[] garbage;
261 private static byte[] largeObject;
262 public static void main(String [] args) {
263 largeObject = new byte[16*1024*1024];
264 System.out.println("Creating garbage");
265 // create 128MB of garbage. This should result in at least one GC,
|