Path: blob/master/test/hotspot/jtreg/gc/g1/TestGCLogMessages.java
40942 views
/*1* Copyright (c) 2014, 2021, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/2223package gc.g1;2425/*26* @test TestGCLogMessages27* @bug 8035406 8027295 8035398 8019342 8027959 8048179 8027962 8069330 8076463 8150630 8160055 8177059 816619128* @summary Ensure the output for a minor GC with G129* includes the expected necessary messages.30* @requires vm.gc.G131* @library /test/lib32* @modules java.base/jdk.internal.misc33* java.management34* @build sun.hotspot.WhiteBox35* @run driver jdk.test.lib.helpers.ClassFileInstaller sun.hotspot.WhiteBox36* @run main/othervm -Xbootclasspath/a:. -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI37* gc.g1.TestGCLogMessages38*/3940import jdk.test.lib.process.OutputAnalyzer;41import jdk.test.lib.Platform;42import jdk.test.lib.process.ProcessTools;43import sun.hotspot.code.Compiler;4445public class TestGCLogMessages {4647private enum Level {48OFF(""),49INFO("info"),50DEBUG("debug"),51TRACE("trace");5253private String logName;5455Level(String logName) {56this.logName = logName;57}5859public boolean lessThan(Level other) {60return this.compareTo(other) < 0;61}6263public String toString() {64return logName;65}66}6768private class LogMessageWithLevel {69String message;70Level level;7172public LogMessageWithLevel(String message, Level level) {73this.message = message;74this.level = level;75}7677public boolean isAvailable() {78return true;79}80};8182private class LogMessageWithLevelC2OrJVMCIOnly extends LogMessageWithLevel {83public LogMessageWithLevelC2OrJVMCIOnly(String message, Level level) {84super(message, level);85}8687public boolean isAvailable() {88return Compiler.isC2OrJVMCIIncluded();89}90}9192private LogMessageWithLevel allLogMessages[] = new LogMessageWithLevel[] {93new LogMessageWithLevel("Pre Evacuate Collection Set", Level.INFO),94new LogMessageWithLevel("Evacuate Collection Set", Level.INFO),95new LogMessageWithLevel("Post Evacuate Collection Set", Level.INFO),96new LogMessageWithLevel("Other", Level.INFO),9798// Merge Heap Roots99new LogMessageWithLevel("Merge Heap Roots", Level.INFO),100new LogMessageWithLevel("Prepare Merge Heap Roots", Level.DEBUG),101new LogMessageWithLevel("Eager Reclaim", Level.DEBUG),102new LogMessageWithLevel("Remembered Sets", Level.DEBUG),103new LogMessageWithLevel("Merged Sparse", Level.DEBUG),104new LogMessageWithLevel("Merged Fine", Level.DEBUG),105new LogMessageWithLevel("Merged Coarse", Level.DEBUG),106new LogMessageWithLevel("Hot Card Cache", Level.DEBUG),107new LogMessageWithLevel("Log Buffers", Level.DEBUG),108new LogMessageWithLevel("Dirty Cards", Level.DEBUG),109new LogMessageWithLevel("Skipped Cards", Level.DEBUG),110// Scan Heap Roots111new LogMessageWithLevel("Scan Heap Roots", Level.DEBUG),112new LogMessageWithLevel("Scanned Cards", Level.DEBUG),113new LogMessageWithLevel("Scanned Blocks", Level.DEBUG),114new LogMessageWithLevel("Claimed Chunks", Level.DEBUG),115// Code Roots Scan116new LogMessageWithLevel("Code Root Scan", Level.DEBUG),117// Object Copy118new LogMessageWithLevel("Object Copy", Level.DEBUG),119new LogMessageWithLevel("Copied Bytes", Level.DEBUG),120new LogMessageWithLevel("LAB Waste", Level.DEBUG),121new LogMessageWithLevel("LAB Undo Waste", Level.DEBUG),122// Ext Root Scan123new LogMessageWithLevel("Thread Roots", Level.TRACE),124new LogMessageWithLevel("CLDG Roots", Level.TRACE),125new LogMessageWithLevel("CM RefProcessor Roots", Level.TRACE),126new LogMessageWithLevel("JNI Global Roots", Level.TRACE),127new LogMessageWithLevel("VM Global Roots", Level.TRACE),128// Redirty Cards129new LogMessageWithLevel("Redirty Logged Cards", Level.DEBUG),130new LogMessageWithLevel("Redirtied Cards", Level.DEBUG),131// Misc Top-level132new LogMessageWithLevel("Purge Code Roots", Level.DEBUG),133new LogMessageWithLevel("Expand Heap After Collection", Level.DEBUG),134new LogMessageWithLevel("Region Register", Level.DEBUG),135new LogMessageWithLevel("Prepare Heap Roots", Level.DEBUG),136new LogMessageWithLevel("Concatenate Dirty Card Logs", Level.DEBUG),137// Free CSet138new LogMessageWithLevel("Free Collection Set", Level.DEBUG),139new LogMessageWithLevel("Serial Free Collection Set", Level.TRACE),140new LogMessageWithLevel("Young Free Collection Set", Level.TRACE),141new LogMessageWithLevel("Non-Young Free Collection Set", Level.TRACE),142// Rebuild Free List143new LogMessageWithLevel("Rebuild Free List", Level.DEBUG),144new LogMessageWithLevel("Serial Rebuild Free List", Level.TRACE),145new LogMessageWithLevel("Parallel Rebuild Free List", Level.TRACE),146147// Merge PSS148new LogMessageWithLevel("Merge Per-Thread State", Level.DEBUG),149// TLAB handling150new LogMessageWithLevel("Prepare TLABs", Level.DEBUG),151new LogMessageWithLevel("Resize TLABs", Level.DEBUG),152// Reference Processing153new LogMessageWithLevel("Reference Processing", Level.DEBUG),154// VM internal reference processing155new LogMessageWithLevel("Weak Processing", Level.DEBUG),156new LogMessageWithLevel("JNI Weak", Level.DEBUG),157new LogMessageWithLevel("StringTable Weak", Level.DEBUG),158new LogMessageWithLevel("ResolvedMethodTable Weak", Level.DEBUG),159new LogMessageWithLevel("VM Weak", Level.DEBUG),160161new LogMessageWithLevelC2OrJVMCIOnly("Update Derived Pointers", Level.DEBUG),162new LogMessageWithLevel("Start New Collection Set", Level.DEBUG),163};164165void checkMessagesAtLevel(OutputAnalyzer output, LogMessageWithLevel messages[], Level level) throws Exception {166for (LogMessageWithLevel l : messages) {167if (level.lessThan(l.level) || !l.isAvailable()) {168output.shouldNotContain(l.message);169} else {170output.shouldMatch("\\[" + l.level + ".*" + l.message);171}172}173}174175public static void main(String[] args) throws Exception {176new TestGCLogMessages().testNormalLogs();177new TestGCLogMessages().testConcurrentRefinementLogs();178if (Platform.isDebugBuild()) {179new TestGCLogMessages().testWithEvacuationFailureLogs();180}181new TestGCLogMessages().testWithConcurrentStart();182new TestGCLogMessages().testExpandHeap();183}184185private void testNormalLogs() throws Exception {186187ProcessBuilder pb = ProcessTools.createJavaProcessBuilder("-XX:+UseG1GC",188"-Xmx10M",189GCTest.class.getName());190191OutputAnalyzer output = new OutputAnalyzer(pb.start());192checkMessagesAtLevel(output, allLogMessages, Level.OFF);193output.shouldHaveExitValue(0);194195pb = ProcessTools.createJavaProcessBuilder("-XX:+UseG1GC",196"-Xmx10M",197"-Xlog:gc+phases=debug",198GCTest.class.getName());199200output = new OutputAnalyzer(pb.start());201checkMessagesAtLevel(output, allLogMessages, Level.DEBUG);202203pb = ProcessTools.createJavaProcessBuilder("-XX:+UseG1GC",204"-Xmx10M",205"-Xlog:gc+phases=trace",206GCTest.class.getName());207208output = new OutputAnalyzer(pb.start());209checkMessagesAtLevel(output, allLogMessages, Level.TRACE);210output.shouldHaveExitValue(0);211}212213LogMessageWithLevel concRefineMessages[] = new LogMessageWithLevel[] {214new LogMessageWithLevel("Mutator refinement: ", Level.DEBUG),215new LogMessageWithLevel("Concurrent refinement: ", Level.DEBUG),216new LogMessageWithLevel("Total refinement: ", Level.DEBUG),217// "Concurrent refinement rate" optionally printed if any.218// "Generate dirty cards rate" optionally printed if any.219};220221private void testConcurrentRefinementLogs() throws Exception {222ProcessBuilder pb = ProcessTools.createJavaProcessBuilder("-XX:+UseG1GC",223"-Xmx10M",224"-Xlog:gc+refine+stats=debug",225GCTest.class.getName());226OutputAnalyzer output = new OutputAnalyzer(pb.start());227checkMessagesAtLevel(output, concRefineMessages, Level.DEBUG);228}229230LogMessageWithLevel exhFailureMessages[] = new LogMessageWithLevel[] {231new LogMessageWithLevel("Recalculate Used Memory", Level.DEBUG),232new LogMessageWithLevel("Restore Preserved Marks", Level.DEBUG),233new LogMessageWithLevel("Remove Self Forwards", Level.DEBUG),234};235236private void testWithEvacuationFailureLogs() throws Exception {237ProcessBuilder pb = ProcessTools.createJavaProcessBuilder("-XX:+UseG1GC",238"-Xmx32M",239"-Xmn16M",240"-XX:+G1EvacuationFailureALot",241"-XX:G1EvacuationFailureALotCount=100",242"-XX:G1EvacuationFailureALotInterval=1",243"-Xlog:gc+phases=debug",244GCTestWithEvacuationFailure.class.getName());245246OutputAnalyzer output = new OutputAnalyzer(pb.start());247checkMessagesAtLevel(output, exhFailureMessages, Level.DEBUG);248output.shouldHaveExitValue(0);249250pb = ProcessTools.createJavaProcessBuilder("-XX:+UseG1GC",251"-Xmx32M",252"-Xmn16M",253"-Xms32M",254"-Xlog:gc+phases=trace",255GCTestWithEvacuationFailure.class.getName());256257output = new OutputAnalyzer(pb.start());258checkMessagesAtLevel(output, exhFailureMessages, Level.TRACE);259output.shouldHaveExitValue(0);260}261262private void testWithConcurrentStart() throws Exception {263ProcessBuilder pb = ProcessTools.createJavaProcessBuilder("-XX:+UseG1GC",264"-Xmx10M",265"-Xbootclasspath/a:.",266"-Xlog:gc*=debug",267"-XX:+UnlockDiagnosticVMOptions",268"-XX:+WhiteBoxAPI",269GCTestWithConcurrentStart.class.getName());270271OutputAnalyzer output = new OutputAnalyzer(pb.start());272output.shouldContain("Clear Claimed Marks");273output.shouldHaveExitValue(0);274}275276private void testExpandHeap() throws Exception {277ProcessBuilder pb = ProcessTools.createJavaProcessBuilder("-XX:+UseG1GC",278"-Xmx10M",279"-Xbootclasspath/a:.",280"-Xlog:gc+ergo+heap=debug",281"-XX:+UnlockDiagnosticVMOptions",282"-XX:+WhiteBoxAPI",283GCTest.class.getName());284285OutputAnalyzer output = new OutputAnalyzer(pb.start());286output.shouldContain("Expand the heap. requested expansion amount: ");287output.shouldContain("B expansion amount: ");288output.shouldHaveExitValue(0);289}290291292static class GCTest {293private static byte[] garbage;294public static void main(String [] args) {295System.out.println("Creating garbage");296// create 128MB of garbage. This should result in at least one GC297for (int i = 0; i < 1024; i++) {298garbage = new byte[128 * 1024];299}300System.out.println("Done");301}302}303304static class GCTestWithEvacuationFailure {305private static byte[] garbage;306private static byte[] largeObject;307private static Object[] holder = new Object[200]; // Must be larger than G1EvacuationFailureALotCount308309public static void main(String [] args) {310largeObject = new byte[16*1024*1024];311System.out.println("Creating garbage");312// Create 16 MB of garbage. This should result in at least one GC,313// (Heap size is 32M, we use 17MB for the large object above)314// which is larger than G1EvacuationFailureALotInterval.315for (int i = 0; i < 16 * 1024; i++) {316holder[i % holder.length] = new byte[1024];317}318System.out.println("Done");319}320}321322static class GCTestWithConcurrentStart {323public static void main(String [] args) {324sun.hotspot.WhiteBox WB = sun.hotspot.WhiteBox.getWhiteBox();325WB.g1StartConcMarkCycle();326}327}328329}330331332333