1 /* 2 * Copyright (c) 2016, 2019, 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 package gc.logging; 25 26 /* 27 * @test TestDeprecatedPrintFlags 28 * @bug 8145180 29 * @summary Verify PrintGC, PrintGCDetails and -Xloggc 30 * @key gc 31 * @library /test/lib 32 * @modules java.base/jdk.internal.misc 33 * java.management 34 * @run main gc.logging.TestDeprecatedPrintFlags 35 */ 36 37 import jdk.test.lib.process.OutputAnalyzer; 38 import jdk.test.lib.process.ProcessTools; 39 import java.nio.file.Files; 40 import java.nio.file.Paths; 41 import java.util.stream.Collectors; 42 43 public class TestDeprecatedPrintFlags { 44 testPrintGC()45 public static void testPrintGC() throws Exception { 46 ProcessBuilder pb = ProcessTools.createJavaProcessBuilder("-XX:+PrintGC", DoGC.class.getName()); 47 OutputAnalyzer output = new OutputAnalyzer(pb.start()); 48 output.shouldContain("-XX:+PrintGC is deprecated. Will use -Xlog:gc instead."); 49 output.shouldNotContain("PrintGCDetails"); 50 output.stdoutShouldMatch("\\[info.*\\]\\[gc *\\]"); 51 output.stdoutShouldNotMatch("\\[info.*\\]\\[gc\\,"); 52 output.shouldHaveExitValue(0); 53 } 54 testPrintGCDetails()55 public static void testPrintGCDetails() throws Exception { 56 ProcessBuilder pb = ProcessTools.createJavaProcessBuilder("-XX:+PrintGCDetails", DoGC.class.getName()); 57 OutputAnalyzer output = new OutputAnalyzer(pb.start()); 58 output.shouldContain("-XX:+PrintGCDetails is deprecated. Will use -Xlog:gc* instead."); 59 output.shouldNotContain("PrintGC is deprecated"); 60 output.stdoutShouldMatch("\\[info.*\\]\\[gc *\\]"); 61 output.stdoutShouldMatch("\\[info.*\\]\\[gc\\,"); 62 output.shouldHaveExitValue(0); 63 } 64 testXloggc()65 public static void testXloggc() throws Exception { 66 String fileName = "gc-test.log"; 67 ProcessBuilder pb = ProcessTools.createJavaProcessBuilder("-Xloggc:" + fileName, DoGC.class.getName()); 68 OutputAnalyzer output = new OutputAnalyzer(pb.start()); 69 output.shouldContain("-Xloggc is deprecated. Will use -Xlog:gc:gc-test.log instead."); 70 output.shouldNotContain("PrintGCDetails"); 71 output.shouldNotContain("PrintGC"); 72 output.stdoutShouldNotMatch("\\[info.*\\]\\[gc *\\]"); 73 output.stdoutShouldNotMatch("\\[info.*\\]\\[gc\\,"); 74 output.shouldHaveExitValue(0); 75 String lines = Files.lines(Paths.get(fileName)).collect(Collectors.joining()); 76 System.out.println("lines: " + lines); 77 OutputAnalyzer outputLog = new OutputAnalyzer(lines, ""); 78 outputLog.stdoutShouldMatch("\\[info.*\\]\\[gc *\\]"); 79 outputLog.stdoutShouldNotMatch("\\[info.*\\]\\[gc\\,"); 80 } 81 testXloggcWithPrintGCDetails()82 public static void testXloggcWithPrintGCDetails() throws Exception { 83 String fileName = "gc-test.log"; 84 ProcessBuilder pb = ProcessTools.createJavaProcessBuilder("-XX:+PrintGCDetails", "-Xloggc:" + fileName, DoGC.class.getName()); 85 OutputAnalyzer output = new OutputAnalyzer(pb.start()); 86 output.shouldContain("-XX:+PrintGCDetails is deprecated. Will use -Xlog:gc* instead."); 87 output.shouldContain("-Xloggc is deprecated. Will use -Xlog:gc:gc-test.log instead."); 88 output.shouldNotContain("PrintGC is deprecated"); 89 output.stdoutShouldNotMatch("\\[info.*\\]\\[gc *\\]"); 90 output.stdoutShouldNotMatch("\\[info.*\\]\\[gc\\,"); 91 output.shouldHaveExitValue(0); 92 String lines = Files.lines(Paths.get(fileName)).collect(Collectors.joining()); 93 OutputAnalyzer outputLog = new OutputAnalyzer(lines, ""); 94 outputLog.stdoutShouldMatch("\\[info.*\\]\\[gc *\\]"); 95 outputLog.stdoutShouldMatch("\\[info.*\\]\\[gc\\,"); 96 } 97 main(String[] args)98 public static void main(String[] args) throws Exception { 99 testPrintGC(); 100 testPrintGCDetails(); 101 testXloggc(); 102 testXloggcWithPrintGCDetails(); 103 } 104 } 105 106 class DoGC { main(String[] args)107 public static void main(String[] args) { 108 System.gc(); 109 } 110 } 111