1 /*
2 * Copyright (c) 2014, Oracle and/or its affiliates. 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 * @test TestGCLogMessages
26 * @bug 8035406 8027295 8035398 8019342 8027959 8048179
27 * @summary Ensure that the PrintGCDetails output for a minor GC with G1
28 * includes the expected necessary messages.
29 * @key gc
30 * @library /testlibrary
31 */
32
33 import com.oracle.java.testlibrary.ProcessTools;
34 import com.oracle.java.testlibrary.OutputAnalyzer;
35
36 public class TestGCLogMessages {
37 public static void main(String[] args) throws Exception {
38 testNormalLogs();
39 testWithToSpaceExhaustionLogs();
40 }
41
42 private static void testNormalLogs() throws Exception {
43
44 ProcessBuilder pb = ProcessTools.createJavaProcessBuilder("-XX:+UseG1GC",
45 "-Xmx10M",
46 GCTest.class.getName());
47
48 OutputAnalyzer output = new OutputAnalyzer(pb.start());
49
50 output.shouldNotContain("[Redirty Cards");
51 output.shouldNotContain("[Parallel Redirty");
52 output.shouldNotContain("[Redirtied Cards");
53 output.shouldNotContain("[Code Root Purge");
54 output.shouldNotContain("[String Dedup Fixup");
55 output.shouldNotContain("[Young Free CSet");
56 output.shouldNotContain("[Non-Young Free CSet");
57 output.shouldNotContain("[Humongous Register");
58 output.shouldNotContain("[Humongous Reclaim");
59 output.shouldHaveExitValue(0);
60
61 pb = ProcessTools.createJavaProcessBuilder("-XX:+UseG1GC",
62 "-XX:+UseStringDeduplication",
63 "-Xmx10M",
64 "-XX:+PrintGCDetails",
65 GCTest.class.getName());
66
67 output = new OutputAnalyzer(pb.start());
68
69 output.shouldContain("[Redirty Cards");
70 output.shouldNotContain("[Parallel Redirty");
71 output.shouldNotContain("[Redirtied Cards");
72 output.shouldContain("[Code Root Purge");
73 output.shouldContain("[String Dedup Fixup");
74 output.shouldNotContain("[Young Free CSet");
75 output.shouldNotContain("[Non-Young Free CSet");
76 output.shouldContain("[Humongous Register");
77 output.shouldNotContain("[Humongous Total");
78 output.shouldNotContain("[Humongous Candidate");
79 output.shouldContain("[Humongous Reclaim");
80 output.shouldNotContain("[Humongous Reclaimed");
81 output.shouldHaveExitValue(0);
82
83 pb = ProcessTools.createJavaProcessBuilder("-XX:+UseG1GC",
84 "-XX:+UseStringDeduplication",
85 "-Xmx10M",
86 "-XX:+PrintGCDetails",
87 "-XX:+UnlockExperimentalVMOptions",
88 "-XX:G1LogLevel=finest",
89 GCTest.class.getName());
90
91 output = new OutputAnalyzer(pb.start());
92
93 output.shouldContain("[Redirty Cards");
94 output.shouldContain("[Parallel Redirty");
95 output.shouldContain("[Redirtied Cards");
96 output.shouldContain("[Code Root Purge");
97 output.shouldContain("[String Dedup Fixup");
98 output.shouldContain("[Young Free CSet");
99 output.shouldContain("[Non-Young Free CSet");
100 output.shouldContain("[Humongous Register");
101 output.shouldContain("[Humongous Total");
102 output.shouldContain("[Humongous Candidate");
103 output.shouldContain("[Humongous Reclaim");
104 output.shouldContain("[Humongous Reclaimed");
105 output.shouldHaveExitValue(0);
106 }
107
108 private static void testWithToSpaceExhaustionLogs() throws Exception {
109 ProcessBuilder pb = ProcessTools.createJavaProcessBuilder("-XX:+UseG1GC",
110 "-Xmx32M",
111 "-Xmn16M",
112 "-XX:+PrintGCDetails",
113 GCTestWithToSpaceExhaustion.class.getName());
114
115 OutputAnalyzer output = new OutputAnalyzer(pb.start());
116 output.shouldContain("[Evacuation Failure");
117 output.shouldNotContain("[Recalculate Used");
118 output.shouldNotContain("[Remove Self Forwards");
119 output.shouldNotContain("[Restore RemSet");
120 output.shouldHaveExitValue(0);
121
122 pb = ProcessTools.createJavaProcessBuilder("-XX:+UseG1GC",
123 "-Xmx32M",
124 "-Xmn16M",
125 "-XX:+PrintGCDetails",
126 "-XX:+UnlockExperimentalVMOptions",
127 "-XX:G1LogLevel=finest",
128 GCTestWithToSpaceExhaustion.class.getName());
129
130 output = new OutputAnalyzer(pb.start());
131 output.shouldContain("[Evacuation Failure");
132 output.shouldContain("[Recalculate Used");
133 output.shouldContain("[Remove Self Forwards");
134 output.shouldContain("[Restore RemSet");
135 output.shouldHaveExitValue(0);
136 }
137
138 static class GCTest {
139 private static byte[] garbage;
140 public static void main(String [] args) {
141 System.out.println("Creating garbage");
142 // create 128MB of garbage. This should result in at least one GC
143 for (int i = 0; i < 1024; i++) {
144 garbage = new byte[128 * 1024];
145 }
146 System.out.println("Done");
147 }
148 }
149
150 static class GCTestWithToSpaceExhaustion {
151 private static byte[] garbage;
152 private static byte[] largeObject;
153 public static void main(String [] args) {
154 largeObject = new byte[16*1024*1024];
155 System.out.println("Creating garbage");
156 // create 128MB of garbage. This should result in at least one GC,
157 // some of them with to-space exhaustion.
158 for (int i = 0; i < 1024; i++) {
159 garbage = new byte[128 * 1024];
160 }
161 System.out.println("Done");
162 }
163 }
164 }
|
1 /*
2 * Copyright (c) 2014, 2015 Oracle and/or its affiliates. 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 * @test TestGCLogMessages
26 * @bug 8035406 8027295 8035398 8019342 8027959 8048179 8027962
27 * @summary Ensure that the PrintGCDetails output for a minor GC with G1
28 * includes the expected necessary messages.
29 * @key gc
30 * @library /testlibrary
31 */
32
33 import com.oracle.java.testlibrary.ProcessTools;
34 import com.oracle.java.testlibrary.OutputAnalyzer;
35
36 public class TestGCLogMessages {
37 private class LogMessageWithLevel {
38 String message;
39 int level;
40
41 public LogMessageWithLevel(String message, int level) {
42 this.message = message;
43 this.level = level;
44 }
45 };
46
47 LogMessageWithLevel messages[] = new LogMessageWithLevel[] {
48 // Ext Root Scan
49 new LogMessageWithLevel("Thread Roots (ms)", 3),
50 new LogMessageWithLevel("StringTable Roots (ms)", 3),
51 new LogMessageWithLevel("Universe Roots (ms)", 3),
52 new LogMessageWithLevel("JNI Handles Roots (ms)", 3),
53 new LogMessageWithLevel("ObjectSynchronizer Roots (ms)", 3),
54 new LogMessageWithLevel("FlatProfiler Roots", 3),
55 new LogMessageWithLevel("Management Roots", 3),
56 new LogMessageWithLevel("SystemDictionary Roots", 3),
57 new LogMessageWithLevel("CLDG Roots", 3),
58 new LogMessageWithLevel("JVMTI Roots", 3),
59 new LogMessageWithLevel("CodeCache Roots", 3),
60 new LogMessageWithLevel("Filter SATB Roots", 3),
61 new LogMessageWithLevel("CM RefProcessor Roots", 3),
62 new LogMessageWithLevel("Wait For Strong CLD", 3),
63 new LogMessageWithLevel("Weak CLD Roots", 3),
64 // Redirty Cards
65 new LogMessageWithLevel("Redirty Cards", 2),
66 new LogMessageWithLevel("Parallel Redirty", 3),
67 new LogMessageWithLevel("Redirtied Cards", 3),
68 // Misc Top-level
69 new LogMessageWithLevel("Code Root Purge", 2),
70 new LogMessageWithLevel("String Dedup Fixup", 2),
71 // Free CSet
72 new LogMessageWithLevel("Young Free CSet", 3),
73 new LogMessageWithLevel("Non-Young Free CSet", 3),
74 // Humongous Eager Reclaim
75 new LogMessageWithLevel("Humongous Reclaim", 2),
76 new LogMessageWithLevel("Humongous Register", 2),
77 };
78
79 void checkMessagesAtLevel(OutputAnalyzer output, LogMessageWithLevel messages[], int level) throws Exception {
80 for (LogMessageWithLevel l : messages) {
81 if (level >= l.level) {
82 output.shouldContain(l.message);
83 } else {
84 output.shouldNotContain(l.message);
85 }
86 }
87 }
88
89 public static void main(String[] args) throws Exception {
90 new TestGCLogMessages().testNormalLogs();
91 new TestGCLogMessages().testWithToSpaceExhaustionLogs();
92 }
93
94 private void testNormalLogs() throws Exception {
95
96 ProcessBuilder pb = ProcessTools.createJavaProcessBuilder("-XX:+UseG1GC",
97 "-Xmx10M",
98 GCTest.class.getName());
99
100 OutputAnalyzer output = new OutputAnalyzer(pb.start());
101 checkMessagesAtLevel(output, messages, 0);
102 output.shouldHaveExitValue(0);
103
104 pb = ProcessTools.createJavaProcessBuilder("-XX:+UseG1GC",
105 "-XX:+UseStringDeduplication",
106 "-Xmx10M",
107 "-XX:+PrintGCDetails",
108 GCTest.class.getName());
109
110 output = new OutputAnalyzer(pb.start());
111 checkMessagesAtLevel(output, messages, 2);
112
113 pb = ProcessTools.createJavaProcessBuilder("-XX:+UseG1GC",
114 "-XX:+UseStringDeduplication",
115 "-Xmx10M",
116 "-XX:+PrintGCDetails",
117 "-XX:+UnlockExperimentalVMOptions",
118 "-XX:G1LogLevel=finest",
119 GCTest.class.getName());
120
121 output = new OutputAnalyzer(pb.start());
122 checkMessagesAtLevel(output, messages, 3);
123 output.shouldHaveExitValue(0);
124 }
125
126 LogMessageWithLevel exhFailureMessages[] = new LogMessageWithLevel[] {
127 new LogMessageWithLevel("Evacuation Failure", 2),
128 new LogMessageWithLevel("Recalculate Used", 3),
129 new LogMessageWithLevel("Remove Self Forwards", 3),
130 new LogMessageWithLevel("Restore RemSet", 3),
131 };
132
133 private void testWithToSpaceExhaustionLogs() throws Exception {
134 ProcessBuilder pb = ProcessTools.createJavaProcessBuilder("-XX:+UseG1GC",
135 "-Xmx32M",
136 "-Xmn16M",
137 "-XX:+PrintGCDetails",
138 GCTestWithToSpaceExhaustion.class.getName());
139
140 OutputAnalyzer output = new OutputAnalyzer(pb.start());
141 checkMessagesAtLevel(output, exhFailureMessages, 2);
142 output.shouldHaveExitValue(0);
143
144 pb = ProcessTools.createJavaProcessBuilder("-XX:+UseG1GC",
145 "-Xmx32M",
146 "-Xmn16M",
147 "-XX:+PrintGCDetails",
148 "-XX:+UnlockExperimentalVMOptions",
149 "-XX:G1LogLevel=finest",
150 GCTestWithToSpaceExhaustion.class.getName());
151
152 output = new OutputAnalyzer(pb.start());
153 checkMessagesAtLevel(output, exhFailureMessages, 3);
154 output.shouldHaveExitValue(0);
155 }
156
157 static class GCTest {
158 private static byte[] garbage;
159 public static void main(String [] args) {
160 System.out.println("Creating garbage");
161 // create 128MB of garbage. This should result in at least one GC
162 for (int i = 0; i < 1024; i++) {
163 garbage = new byte[128 * 1024];
164 }
165 System.out.println("Done");
166 }
167 }
168
169 static class GCTestWithToSpaceExhaustion {
170 private static byte[] garbage;
171 private static byte[] largeObject;
172 public static void main(String [] args) {
173 largeObject = new byte[16*1024*1024];
174 System.out.println("Creating garbage");
175 // create 128MB of garbage. This should result in at least one GC,
176 // some of them with to-space exhaustion.
177 for (int i = 0; i < 1024; i++) {
178 garbage = new byte[128 * 1024];
179 }
180 System.out.println("Done");
181 }
182 }
183 }
184
|