Path: blob/jdk8u272-b10-aarch32-20201026/hotspot/test/gc/logging/TestGCId.java
48799 views
/*1* Copyright (c) 2014, 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 TestGCId25* @bug 804360726* @summary Ensure that the GCId is logged27* @key gc28* @library /testlibrary29*/3031import com.oracle.java.testlibrary.ProcessTools;32import com.oracle.java.testlibrary.OutputAnalyzer;3334public class TestGCId {35public static void main(String[] args) throws Exception {36testGCId("UseParallelGC", "PrintGC");37testGCId("UseParallelGC", "PrintGCDetails");3839testGCId("UseG1GC", "PrintGC");40testGCId("UseG1GC", "PrintGCDetails");4142testGCId("UseConcMarkSweepGC", "PrintGC");43testGCId("UseConcMarkSweepGC", "PrintGCDetails");4445testGCId("UseSerialGC", "PrintGC");46testGCId("UseSerialGC", "PrintGCDetails");47}4849private static void verifyContainsGCIDs(OutputAnalyzer output) {50output.shouldMatch("^#0: \\[");51output.shouldMatch("^#1: \\[");52output.shouldHaveExitValue(0);53}5455private static void verifyContainsNoGCIDs(OutputAnalyzer output) {56output.shouldNotMatch("^#[0-9]+: \\[");57output.shouldHaveExitValue(0);58}5960private static void testGCId(String gcFlag, String logFlag) throws Exception {61// GCID logging enabled62ProcessBuilder pb_enabled =63ProcessTools.createJavaProcessBuilder("-XX:+" + gcFlag, "-XX:+" + logFlag, "-Xmx10M", "-XX:+PrintGCID", GCTest.class.getName());64verifyContainsGCIDs(new OutputAnalyzer(pb_enabled.start()));6566// GCID logging disabled67ProcessBuilder pb_disabled =68ProcessTools.createJavaProcessBuilder("-XX:+" + gcFlag, "-XX:+" + logFlag, "-Xmx10M", "-XX:-PrintGCID", GCTest.class.getName());69verifyContainsNoGCIDs(new OutputAnalyzer(pb_disabled.start()));7071// GCID logging default72ProcessBuilder pb_default =73ProcessTools.createJavaProcessBuilder("-XX:+" + gcFlag, "-XX:+" + logFlag, "-Xmx10M", GCTest.class.getName());74verifyContainsNoGCIDs(new OutputAnalyzer(pb_default.start()));75}7677static class GCTest {78private static byte[] garbage;79public static void main(String [] args) {80System.out.println("Creating garbage");81// create 128MB of garbage. This should result in at least one GC82for (int i = 0; i < 1024; i++) {83garbage = new byte[128 * 1024];84}85// do a system gc to get one more gc86System.gc();87System.out.println("Done");88}89}90}919293