Path: blob/master/test/hotspot/jtreg/gc/logging/TestDeprecatedPrintFlags.java
40942 views
/*1* Copyright (c) 2016, 2020, 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.logging;2425/*26* @test TestDeprecatedPrintFlags27* @bug 814518028* @summary Verify PrintGC, PrintGCDetails and -Xloggc29* @library /test/lib30* @modules java.base/jdk.internal.misc31* java.management32* @run driver gc.logging.TestDeprecatedPrintFlags33*/3435import jdk.test.lib.process.OutputAnalyzer;36import jdk.test.lib.process.ProcessTools;37import java.nio.file.Files;38import java.nio.file.Paths;39import java.util.stream.Collectors;4041public class TestDeprecatedPrintFlags {4243public static void testPrintGC() throws Exception {44ProcessBuilder pb = ProcessTools.createJavaProcessBuilder("-XX:+PrintGC", DoGC.class.getName());45OutputAnalyzer output = new OutputAnalyzer(pb.start());46output.shouldContain("-XX:+PrintGC is deprecated. Will use -Xlog:gc instead.");47output.shouldNotContain("PrintGCDetails");48output.stdoutShouldMatch("\\[info.*\\]\\[gc *\\]");49output.stdoutShouldNotMatch("\\[info.*\\]\\[gc\\,");50output.shouldHaveExitValue(0);51}5253public static void testPrintGCDetails() throws Exception {54ProcessBuilder pb = ProcessTools.createJavaProcessBuilder("-XX:+PrintGCDetails", DoGC.class.getName());55OutputAnalyzer output = new OutputAnalyzer(pb.start());56output.shouldContain("-XX:+PrintGCDetails is deprecated. Will use -Xlog:gc* instead.");57output.shouldNotContain("PrintGC is deprecated");58output.stdoutShouldMatch("\\[info.*\\]\\[gc *\\]");59output.stdoutShouldMatch("\\[info.*\\]\\[gc\\,");60output.shouldHaveExitValue(0);61}6263public static void testXloggc() throws Exception {64String fileName = "gc-test.log";65ProcessBuilder pb = ProcessTools.createJavaProcessBuilder("-Xloggc:" + fileName, DoGC.class.getName());66OutputAnalyzer output = new OutputAnalyzer(pb.start());67output.shouldContain("-Xloggc is deprecated. Will use -Xlog:gc:gc-test.log instead.");68output.shouldNotContain("PrintGCDetails");69output.shouldNotContain("PrintGC");70output.stdoutShouldNotMatch("\\[info.*\\]\\[gc *\\]");71output.stdoutShouldNotMatch("\\[info.*\\]\\[gc\\,");72output.shouldHaveExitValue(0);73String lines = Files.lines(Paths.get(fileName)).collect(Collectors.joining());74System.out.println("lines: " + lines);75OutputAnalyzer outputLog = new OutputAnalyzer(lines, "");76outputLog.stdoutShouldMatch("\\[info.*\\]\\[gc *\\]");77outputLog.stdoutShouldNotMatch("\\[info.*\\]\\[gc\\,");78}7980public static void testXloggcWithPrintGCDetails() throws Exception {81String fileName = "gc-test.log";82ProcessBuilder pb = ProcessTools.createJavaProcessBuilder("-XX:+PrintGCDetails", "-Xloggc:" + fileName, DoGC.class.getName());83OutputAnalyzer output = new OutputAnalyzer(pb.start());84output.shouldContain("-XX:+PrintGCDetails is deprecated. Will use -Xlog:gc* instead.");85output.shouldContain("-Xloggc is deprecated. Will use -Xlog:gc:gc-test.log instead.");86output.shouldNotContain("PrintGC is deprecated");87output.stdoutShouldNotMatch("\\[info.*\\]\\[gc *\\]");88output.stdoutShouldNotMatch("\\[info.*\\]\\[gc\\,");89output.shouldHaveExitValue(0);90String lines = Files.lines(Paths.get(fileName)).collect(Collectors.joining());91OutputAnalyzer outputLog = new OutputAnalyzer(lines, "");92outputLog.stdoutShouldMatch("\\[info.*\\]\\[gc *\\]");93outputLog.stdoutShouldMatch("\\[info.*\\]\\[gc\\,");94}9596public static void main(String[] args) throws Exception {97testPrintGC();98testPrintGCDetails();99testXloggc();100testXloggcWithPrintGCDetails();101}102}103104class DoGC {105public static void main(String[] args) {106System.gc();107}108}109110111