1 /* 2 * Copyright (c) 2016, 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 TestAgeOutput 26 * @bug 8164936 27 * @summary Check that G1 prints an age table even for the first garbage collection 28 * @key gc 29 * @requires vm.gc.G1 30 * @modules java.base/jdk.internal.misc 31 * @library /test/lib 32 * @build sun.hotspot.WhiteBox 33 * @run main ClassFileInstaller sun.hotspot.WhiteBox 34 * @run driver TestAgeOutput 35 */ 36 37 import sun.hotspot.WhiteBox; 38 39 import java.util.regex.Matcher; 40 import java.util.regex.Pattern; 41 42 import jdk.test.lib.Platform; 43 import jdk.test.lib.process.OutputAnalyzer; 44 import jdk.test.lib.process.ProcessTools; 45 46 import static jdk.test.lib.Asserts.*; 47 48 public class TestAgeOutput { 49 50 public static void checkPattern(String pattern, String what) throws Exception { 51 Pattern r = Pattern.compile(pattern); 52 Matcher m = r.matcher(what); 53 54 if (!m.find()) { 55 throw new RuntimeException("Could not find pattern " + pattern + " in output"); 56 } 57 } 58 59 public static void runTest() throws Exception { 60 final String[] arguments = { 61 "-Xbootclasspath/a:.", 62 "-XX:+UnlockExperimentalVMOptions", 63 "-XX:+UnlockDiagnosticVMOptions", 64 "-XX:+WhiteBoxAPI", 65 "-XX:+UseG1GC", 66 "-Xmx10M", 67 "-Xlog:gc+age=trace", 68 GCTest.class.getName() 69 }; 70 71 ProcessBuilder pb = ProcessTools.createJavaProcessBuilder(arguments); 72 OutputAnalyzer output = new OutputAnalyzer(pb.start()); 73 74 output.shouldHaveExitValue(0); 75 76 System.out.println(output.getStdout()); 77 78 String stdout = output.getStdout(); 79 80 checkPattern(".*GC\\(0\\) .*Desired survivor size.*", stdout); 81 checkPattern(".*GC\\(0\\) .*Age table with threshold.*", stdout); 82 checkPattern(".*GC\\(0\\) .*- age 1:.*", stdout); 83 } 84 85 public static void main(String[] args) throws Exception { 86 runTest(); 87 } 88 89 static class GCTest { 90 private static final WhiteBox WB = WhiteBox.getWhiteBox(); 91 92 public static Object holder; 93 94 public static void main(String [] args) { 95 holder = new byte[100]; 96 WB.youngGC(); 97 System.out.println(holder); 98 } 99 } 100 } 101