Path: blob/aarch64-shenandoah-jdk8u272-b10/hotspot/test/gc/g1/TestGCLogMessages.java
32284 views
/*1* Copyright (c) 2014, 2015, 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*/2223/*24* @test TestGCLogMessages25* @bug 8035406 8027295 8035398 8019342 8027959 8048179 802796226* @summary Ensure that the PrintGCDetails output for a minor GC with G127* includes the expected necessary messages.28* @key gc29* @library /testlibrary30*/3132import com.oracle.java.testlibrary.ProcessTools;33import com.oracle.java.testlibrary.OutputAnalyzer;3435public class TestGCLogMessages {3637private enum Level {38OFF, FINER, FINEST;39public boolean lessOrEqualTo(Level other) {40return this.compareTo(other) < 0;41}42}4344private class LogMessageWithLevel {45String message;46Level level;4748public LogMessageWithLevel(String message, Level level) {49this.message = message;50this.level = level;51}52};5354private LogMessageWithLevel allLogMessages[] = new LogMessageWithLevel[] {55// Ext Root Scan56new LogMessageWithLevel("Thread Roots (ms)", Level.FINEST),57new LogMessageWithLevel("StringTable Roots (ms)", Level.FINEST),58new LogMessageWithLevel("Universe Roots (ms)", Level.FINEST),59new LogMessageWithLevel("JNI Handles Roots (ms)", Level.FINEST),60new LogMessageWithLevel("ObjectSynchronizer Roots (ms)", Level.FINEST),61new LogMessageWithLevel("FlatProfiler Roots", Level.FINEST),62new LogMessageWithLevel("Management Roots", Level.FINEST),63new LogMessageWithLevel("SystemDictionary Roots", Level.FINEST),64new LogMessageWithLevel("CLDG Roots", Level.FINEST),65new LogMessageWithLevel("JVMTI Roots", Level.FINEST),66new LogMessageWithLevel("CodeCache Roots", Level.FINEST),67new LogMessageWithLevel("SATB Filtering", Level.FINEST),68new LogMessageWithLevel("CM RefProcessor Roots", Level.FINEST),69new LogMessageWithLevel("Wait For Strong CLD", Level.FINEST),70new LogMessageWithLevel("Weak CLD Roots", Level.FINEST),71// Redirty Cards72new LogMessageWithLevel("Redirty Cards", Level.FINER),73new LogMessageWithLevel("Parallel Redirty", Level.FINEST),74new LogMessageWithLevel("Redirtied Cards", Level.FINEST),75// Misc Top-level76new LogMessageWithLevel("Code Root Purge", Level.FINER),77new LogMessageWithLevel("String Dedup Fixup", Level.FINER),78// Free CSet79new LogMessageWithLevel("Young Free CSet", Level.FINEST),80new LogMessageWithLevel("Non-Young Free CSet", Level.FINEST),81// Humongous Eager Reclaim82new LogMessageWithLevel("Humongous Reclaim", Level.FINER),83new LogMessageWithLevel("Humongous Register", Level.FINER),84};8586void checkMessagesAtLevel(OutputAnalyzer output, LogMessageWithLevel messages[], Level level) throws Exception {87for (LogMessageWithLevel l : messages) {88if (level.lessOrEqualTo(l.level)) {89output.shouldNotContain(l.message);90} else {91output.shouldContain(l.message);92}93}94}9596public static void main(String[] args) throws Exception {97new TestGCLogMessages().testNormalLogs();98new TestGCLogMessages().testWithToSpaceExhaustionLogs();99}100101private void testNormalLogs() throws Exception {102103ProcessBuilder pb = ProcessTools.createJavaProcessBuilder("-XX:+UseG1GC",104"-Xmx10M",105GCTest.class.getName());106107OutputAnalyzer output = new OutputAnalyzer(pb.start());108checkMessagesAtLevel(output, allLogMessages, Level.OFF);109output.shouldHaveExitValue(0);110111pb = ProcessTools.createJavaProcessBuilder("-XX:+UseG1GC",112"-XX:+UseStringDeduplication",113"-Xmx10M",114"-XX:+PrintGCDetails",115GCTest.class.getName());116117output = new OutputAnalyzer(pb.start());118checkMessagesAtLevel(output, allLogMessages, Level.FINER);119120pb = ProcessTools.createJavaProcessBuilder("-XX:+UseG1GC",121"-XX:+UseStringDeduplication",122"-Xmx10M",123"-XX:+PrintGCDetails",124"-XX:+UnlockExperimentalVMOptions",125"-XX:G1LogLevel=finest",126GCTest.class.getName());127128output = new OutputAnalyzer(pb.start());129checkMessagesAtLevel(output, allLogMessages, Level.FINEST);130output.shouldHaveExitValue(0);131}132133LogMessageWithLevel exhFailureMessages[] = new LogMessageWithLevel[] {134new LogMessageWithLevel("Evacuation Failure", Level.FINER),135new LogMessageWithLevel("Recalculate Used", Level.FINEST),136new LogMessageWithLevel("Remove Self Forwards", Level.FINEST),137new LogMessageWithLevel("Restore RemSet", Level.FINEST),138};139140private void testWithToSpaceExhaustionLogs() throws Exception {141ProcessBuilder pb = ProcessTools.createJavaProcessBuilder("-XX:+UseG1GC",142"-Xmx32M",143"-Xmn16M",144"-XX:+PrintGCDetails",145GCTestWithToSpaceExhaustion.class.getName());146147OutputAnalyzer output = new OutputAnalyzer(pb.start());148checkMessagesAtLevel(output, exhFailureMessages, Level.FINER);149output.shouldHaveExitValue(0);150151pb = ProcessTools.createJavaProcessBuilder("-XX:+UseG1GC",152"-Xmx32M",153"-Xmn16M",154"-XX:+PrintGCDetails",155"-XX:+UnlockExperimentalVMOptions",156"-XX:G1LogLevel=finest",157GCTestWithToSpaceExhaustion.class.getName());158159output = new OutputAnalyzer(pb.start());160checkMessagesAtLevel(output, exhFailureMessages, Level.FINEST);161output.shouldHaveExitValue(0);162}163164static class GCTest {165private static byte[] garbage;166public static void main(String [] args) {167System.out.println("Creating garbage");168// create 128MB of garbage. This should result in at least one GC169for (int i = 0; i < 1024; i++) {170garbage = new byte[128 * 1024];171}172System.out.println("Done");173}174}175176static class GCTestWithToSpaceExhaustion {177private static byte[] garbage;178private static byte[] largeObject;179public static void main(String [] args) {180largeObject = new byte[16*1024*1024];181System.out.println("Creating garbage");182// create 128MB of garbage. This should result in at least one GC,183// some of them with to-space exhaustion.184for (int i = 0; i < 1024; i++) {185garbage = new byte[128 * 1024];186}187System.out.println("Done");188}189}190}191192193194