Path: blob/aarch64-shenandoah-jdk8u272-b10/hotspot/test/gc/logging/TestGCId.java
32284 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");4748testGCId("UseShenandoahGC", "PrintGC");49testGCId("UseShenandoahGC", "PrintGCDetails");50}5152private static void verifyContainsGCIDs(OutputAnalyzer output) {53output.shouldMatch("^#0: \\[");54output.shouldMatch("^#1: \\[");55output.shouldHaveExitValue(0);56}5758private static void verifyContainsNoGCIDs(OutputAnalyzer output) {59output.shouldNotMatch("^#[0-9]+: \\[");60output.shouldHaveExitValue(0);61}6263private static void testGCId(String gcFlag, String logFlag) throws Exception {64// GCID logging enabled65ProcessBuilder pb_enabled =66ProcessTools.createJavaProcessBuilder("-XX:+UnlockExperimentalVMOptions", "-XX:+" + gcFlag, "-XX:+" + logFlag, "-Xmx10M", "-XX:+PrintGCID", GCTest.class.getName());67verifyContainsGCIDs(new OutputAnalyzer(pb_enabled.start()));6869// GCID logging disabled70ProcessBuilder pb_disabled =71ProcessTools.createJavaProcessBuilder("-XX:+UnlockExperimentalVMOptions", "-XX:+" + gcFlag, "-XX:+" + logFlag, "-Xmx10M", "-XX:-PrintGCID", GCTest.class.getName());72verifyContainsNoGCIDs(new OutputAnalyzer(pb_disabled.start()));7374// GCID logging default75ProcessBuilder pb_default =76ProcessTools.createJavaProcessBuilder("-XX:+UnlockExperimentalVMOptions", "-XX:+" + gcFlag, "-XX:+" + logFlag, "-Xmx10M", GCTest.class.getName());77verifyContainsNoGCIDs(new OutputAnalyzer(pb_default.start()));78}7980static class GCTest {81private static byte[] garbage;82public static void main(String [] args) {83System.out.println("Creating garbage");84// create 128MB of garbage. This should result in at least one GC85for (int i = 0; i < 1024; i++) {86garbage = new byte[128 * 1024];87}88// do a system gc to get one more gc89System.gc();90System.out.println("Done");91}92}93}949596