Path: blob/master/test/hotspot/jtreg/gc/metaspace/TestSizeTransitions.java
40942 views
/*1* Copyright (c) 2019, 2020, Oracle and/or its affiliates. All rights reserved.2* Copyright (c) 2019, Twitter, Inc.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 it6* under the terms of the GNU General Public License version 2 only, as7* published by the Free Software Foundation.8*9* This code is distributed in the hope that it will be useful, but WITHOUT10* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or11* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License12* version 2 for more details (a copy is included in the LICENSE file that13* accompanied this code).14*15* You should have received a copy of the GNU General Public License version16* 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 USA20* or visit www.oracle.com if you need additional information or have any21* questions.22*23*/2425package gc.metaspace;2627import jdk.test.lib.Platform;28import jdk.test.lib.process.ProcessTools;29import jdk.test.lib.process.OutputAnalyzer;30import java.util.ArrayList;31import java.util.List;3233/* @test TestSizeTransitionsSerial34* @requires vm.gc.Serial35* @summary Tests that the metaspace size transition logging is done correctly.36* @library /test/lib37* @run driver gc.metaspace.TestSizeTransitions false -XX:+UseSerialGC38* @run driver gc.metaspace.TestSizeTransitions true -XX:+UseSerialGC39*/4041/* @test TestSizeTransitionsParallel42* @requires vm.gc.Parallel43* @summary Tests that the metaspace size transition logging is done correctly.44* @library /test/lib45* @run driver gc.metaspace.TestSizeTransitions false -XX:+UseParallelGC46* @run driver gc.metaspace.TestSizeTransitions true -XX:+UseParallelGC47*/4849/* @test TestSizeTransitionsG150* @requires vm.gc.G151* @summary Tests that the metaspace size transition logging is done correctly.52* @library /test/lib53* @run driver gc.metaspace.TestSizeTransitions false -XX:+UseG1GC54* @run driver gc.metaspace.TestSizeTransitions true -XX:+UseG1GC55*/5657public class TestSizeTransitions {58public static class Run {59public static void main(String... args) throws Exception {60System.out.println("Run started.");6162// easiest way to generate a metaspace transition is to ask for a full GC63System.gc();6465System.out.println("Run finished.");66}67}6869// matches the log tags70// e.g., [0.043s][info][gc]71private static final String LOG_TAGS_REGEX = "(\\[.*\\])+ ";7273// matches a size transition74// e.g., 177K(4864K)->177K(4864K)75private static final String SIZE_TRANSITION_REGEX = "\\d+K\\(\\d+K\\)->\\d+K\\(\\d+K\\)";7677// matches -coops metaspace size transitions78private static final String NO_COMPRESSED_KLASS_POINTERS_REGEX =79String.format("^%s.* Metaspace: %s$",80LOG_TAGS_REGEX,81SIZE_TRANSITION_REGEX);8283// matches +coops metaspace size transitions84private static final String COMPRESSED_KLASS_POINTERS_REGEX =85String.format("^%s.* Metaspace: %s NonClass: %s Class: %s$",86LOG_TAGS_REGEX,87SIZE_TRANSITION_REGEX,88SIZE_TRANSITION_REGEX,89SIZE_TRANSITION_REGEX);9091public static void main(String... args) throws Exception {92// args: <use-coops> <gc-arg>93if (args.length != 2) {94throw new RuntimeException("wrong number of args: " + args.length);95}9697final boolean hasCompressedKlassPointers = Platform.is64bit();98final boolean useCompressedKlassPointers = Boolean.parseBoolean(args[0]);99final String gcArg = args[1];100101if (!hasCompressedKlassPointers && useCompressedKlassPointers) {102// No need to run this configuration.103System.out.println("Skipping test.");104return;105}106107List<String> jvmArgs = new ArrayList<>();108if (hasCompressedKlassPointers) {109jvmArgs.add(useCompressedKlassPointers ? "-XX:+UseCompressedClassPointers" : "-XX:-UseCompressedClassPointers");110}111jvmArgs.add(gcArg);112jvmArgs.add("-Xmx256m");113jvmArgs.add("-Xlog:gc,gc+metaspace=info");114jvmArgs.add(TestSizeTransitions.Run.class.getName());115116System.out.println("JVM args:");117for (String a : jvmArgs) {118System.out.println(" " + a);119}120121final ProcessBuilder pb = ProcessTools.createJavaProcessBuilder(jvmArgs);122final OutputAnalyzer output = new OutputAnalyzer(pb.start());123System.out.println(output.getStdout());124output.shouldHaveExitValue(0);125126if (useCompressedKlassPointers) {127output.stdoutShouldMatch(COMPRESSED_KLASS_POINTERS_REGEX);128output.stdoutShouldNotMatch(NO_COMPRESSED_KLASS_POINTERS_REGEX);129} else {130output.stdoutShouldMatch(NO_COMPRESSED_KLASS_POINTERS_REGEX);131output.stdoutShouldNotMatch(COMPRESSED_KLASS_POINTERS_REGEX);132}133}134}135136137