< prev index next >

test/hotspot/jtreg/gc/g1/TestGCLogMessages.java

Print this page
rev 60060 : [mq]: 8210462-lkorinth-review


 170         new LogMessageWithLevel("VM Weak", Level.DEBUG),
 171 
 172         new LogMessageWithLevelC2OrJVMCIOnly("DerivedPointerTable Update", Level.DEBUG),
 173         new LogMessageWithLevel("Start New Collection Set", Level.DEBUG),
 174     };
 175 
 176     void checkMessagesAtLevel(OutputAnalyzer output, LogMessageWithLevel messages[], Level level) throws Exception {
 177         for (LogMessageWithLevel l : messages) {
 178             if (level.lessThan(l.level) || !l.isAvailable()) {
 179                 output.shouldNotContain(l.message);
 180             } else {
 181                 output.shouldMatch("\\[" + l.level + ".*" + l.message);
 182             }
 183         }
 184     }
 185 
 186     public static void main(String[] args) throws Exception {
 187         new TestGCLogMessages().testNormalLogs();
 188         new TestGCLogMessages().testConcurrentRefinementLogs();
 189         new TestGCLogMessages().testWithToSpaceExhaustionLogs();
 190         new TestGCLogMessages().testWithInitialMark();
 191         new TestGCLogMessages().testExpandHeap();
 192     }
 193 
 194     private void testNormalLogs() throws Exception {
 195 
 196         ProcessBuilder pb = ProcessTools.createJavaProcessBuilder("-XX:+UseG1GC",
 197                                                                   "-Xmx10M",
 198                                                                   GCTest.class.getName());
 199 
 200         OutputAnalyzer output = new OutputAnalyzer(pb.start());
 201         checkMessagesAtLevel(output, allLogMessages, Level.OFF);
 202         output.shouldHaveExitValue(0);
 203 
 204         pb = ProcessTools.createJavaProcessBuilder("-XX:+UseG1GC",
 205                                                    "-XX:+UseStringDeduplication",
 206                                                    "-Xmx10M",
 207                                                    "-Xlog:gc+phases=debug",
 208                                                    GCTest.class.getName());
 209 
 210         output = new OutputAnalyzer(pb.start());


 249                                                                   "-Xmx32M",
 250                                                                   "-Xmn16M",
 251                                                                   "-Xlog:gc+phases=debug",
 252                                                                   GCTestWithToSpaceExhaustion.class.getName());
 253 
 254         OutputAnalyzer output = new OutputAnalyzer(pb.start());
 255         checkMessagesAtLevel(output, exhFailureMessages, Level.DEBUG);
 256         output.shouldHaveExitValue(0);
 257 
 258         pb = ProcessTools.createJavaProcessBuilder("-XX:+UseG1GC",
 259                                                    "-Xmx32M",
 260                                                    "-Xmn16M",
 261                                                    "-Xlog:gc+phases=trace",
 262                                                    GCTestWithToSpaceExhaustion.class.getName());
 263 
 264         output = new OutputAnalyzer(pb.start());
 265         checkMessagesAtLevel(output, exhFailureMessages, Level.TRACE);
 266         output.shouldHaveExitValue(0);
 267     }
 268 
 269     private void testWithInitialMark() throws Exception {
 270         ProcessBuilder pb = ProcessTools.createJavaProcessBuilder("-XX:+UseG1GC",
 271                                                                   "-Xmx10M",
 272                                                                   "-Xbootclasspath/a:.",
 273                                                                   "-Xlog:gc*=debug",
 274                                                                   "-XX:+UnlockDiagnosticVMOptions",
 275                                                                   "-XX:+WhiteBoxAPI",
 276                                                                   GCTestWithInitialMark.class.getName());
 277 
 278         OutputAnalyzer output = new OutputAnalyzer(pb.start());
 279         output.shouldContain("Clear Claimed Marks");
 280         output.shouldHaveExitValue(0);
 281     }
 282 
 283     private void testExpandHeap() throws Exception {
 284         ProcessBuilder pb = ProcessTools.createJavaProcessBuilder("-XX:+UseG1GC",
 285                                                                   "-Xmx10M",
 286                                                                   "-Xbootclasspath/a:.",
 287                                                                   "-Xlog:gc+ergo+heap=debug",
 288                                                                   "-XX:+UnlockDiagnosticVMOptions",
 289                                                                   "-XX:+WhiteBoxAPI",
 290                                                                   GCTest.class.getName());
 291 
 292         OutputAnalyzer output = new OutputAnalyzer(pb.start());
 293         output.shouldContain("Expand the heap. requested expansion amount: ");
 294         output.shouldContain("B expansion amount: ");
 295         output.shouldHaveExitValue(0);
 296     }


 306             }
 307             System.out.println("Done");
 308         }
 309     }
 310 
 311     static class GCTestWithToSpaceExhaustion {
 312         private static byte[] garbage;
 313         private static byte[] largeObject;
 314         public static void main(String [] args) {
 315             largeObject = new byte[16*1024*1024];
 316             System.out.println("Creating garbage");
 317             // create 128MB of garbage. This should result in at least one GC,
 318             // some of them with to-space exhaustion.
 319             for (int i = 0; i < 1024; i++) {
 320                 garbage = new byte[128 * 1024];
 321             }
 322             System.out.println("Done");
 323         }
 324     }
 325 
 326     static class GCTestWithInitialMark {
 327         public static void main(String [] args) {
 328             sun.hotspot.WhiteBox WB = sun.hotspot.WhiteBox.getWhiteBox();
 329             WB.g1StartConcMarkCycle();
 330         }
 331     }
 332 
 333 }
 334 


 170         new LogMessageWithLevel("VM Weak", Level.DEBUG),
 171 
 172         new LogMessageWithLevelC2OrJVMCIOnly("DerivedPointerTable Update", Level.DEBUG),
 173         new LogMessageWithLevel("Start New Collection Set", Level.DEBUG),
 174     };
 175 
 176     void checkMessagesAtLevel(OutputAnalyzer output, LogMessageWithLevel messages[], Level level) throws Exception {
 177         for (LogMessageWithLevel l : messages) {
 178             if (level.lessThan(l.level) || !l.isAvailable()) {
 179                 output.shouldNotContain(l.message);
 180             } else {
 181                 output.shouldMatch("\\[" + l.level + ".*" + l.message);
 182             }
 183         }
 184     }
 185 
 186     public static void main(String[] args) throws Exception {
 187         new TestGCLogMessages().testNormalLogs();
 188         new TestGCLogMessages().testConcurrentRefinementLogs();
 189         new TestGCLogMessages().testWithToSpaceExhaustionLogs();
 190         new TestGCLogMessages().testWithConcurrentStart();
 191         new TestGCLogMessages().testExpandHeap();
 192     }
 193 
 194     private void testNormalLogs() throws Exception {
 195 
 196         ProcessBuilder pb = ProcessTools.createJavaProcessBuilder("-XX:+UseG1GC",
 197                                                                   "-Xmx10M",
 198                                                                   GCTest.class.getName());
 199 
 200         OutputAnalyzer output = new OutputAnalyzer(pb.start());
 201         checkMessagesAtLevel(output, allLogMessages, Level.OFF);
 202         output.shouldHaveExitValue(0);
 203 
 204         pb = ProcessTools.createJavaProcessBuilder("-XX:+UseG1GC",
 205                                                    "-XX:+UseStringDeduplication",
 206                                                    "-Xmx10M",
 207                                                    "-Xlog:gc+phases=debug",
 208                                                    GCTest.class.getName());
 209 
 210         output = new OutputAnalyzer(pb.start());


 249                                                                   "-Xmx32M",
 250                                                                   "-Xmn16M",
 251                                                                   "-Xlog:gc+phases=debug",
 252                                                                   GCTestWithToSpaceExhaustion.class.getName());
 253 
 254         OutputAnalyzer output = new OutputAnalyzer(pb.start());
 255         checkMessagesAtLevel(output, exhFailureMessages, Level.DEBUG);
 256         output.shouldHaveExitValue(0);
 257 
 258         pb = ProcessTools.createJavaProcessBuilder("-XX:+UseG1GC",
 259                                                    "-Xmx32M",
 260                                                    "-Xmn16M",
 261                                                    "-Xlog:gc+phases=trace",
 262                                                    GCTestWithToSpaceExhaustion.class.getName());
 263 
 264         output = new OutputAnalyzer(pb.start());
 265         checkMessagesAtLevel(output, exhFailureMessages, Level.TRACE);
 266         output.shouldHaveExitValue(0);
 267     }
 268 
 269     private void testWithConcurrentStart() throws Exception {
 270         ProcessBuilder pb = ProcessTools.createJavaProcessBuilder("-XX:+UseG1GC",
 271                                                                   "-Xmx10M",
 272                                                                   "-Xbootclasspath/a:.",
 273                                                                   "-Xlog:gc*=debug",
 274                                                                   "-XX:+UnlockDiagnosticVMOptions",
 275                                                                   "-XX:+WhiteBoxAPI",
 276                                                                   GCTestWithConcurrentStart.class.getName());
 277 
 278         OutputAnalyzer output = new OutputAnalyzer(pb.start());
 279         output.shouldContain("Clear Claimed Marks");
 280         output.shouldHaveExitValue(0);
 281     }
 282 
 283     private void testExpandHeap() throws Exception {
 284         ProcessBuilder pb = ProcessTools.createJavaProcessBuilder("-XX:+UseG1GC",
 285                                                                   "-Xmx10M",
 286                                                                   "-Xbootclasspath/a:.",
 287                                                                   "-Xlog:gc+ergo+heap=debug",
 288                                                                   "-XX:+UnlockDiagnosticVMOptions",
 289                                                                   "-XX:+WhiteBoxAPI",
 290                                                                   GCTest.class.getName());
 291 
 292         OutputAnalyzer output = new OutputAnalyzer(pb.start());
 293         output.shouldContain("Expand the heap. requested expansion amount: ");
 294         output.shouldContain("B expansion amount: ");
 295         output.shouldHaveExitValue(0);
 296     }


 306             }
 307             System.out.println("Done");
 308         }
 309     }
 310 
 311     static class GCTestWithToSpaceExhaustion {
 312         private static byte[] garbage;
 313         private static byte[] largeObject;
 314         public static void main(String [] args) {
 315             largeObject = new byte[16*1024*1024];
 316             System.out.println("Creating garbage");
 317             // create 128MB of garbage. This should result in at least one GC,
 318             // some of them with to-space exhaustion.
 319             for (int i = 0; i < 1024; i++) {
 320                 garbage = new byte[128 * 1024];
 321             }
 322             System.out.println("Done");
 323         }
 324     }
 325 
 326     static class GCTestWithConcurrentStart {
 327         public static void main(String [] args) {
 328             sun.hotspot.WhiteBox WB = sun.hotspot.WhiteBox.getWhiteBox();
 329             WB.g1StartConcMarkCycle();
 330         }
 331     }
 332 
 333 }
 334 
< prev index next >