test/hotspot/jtreg/gc/metaspace/TestSizeTransitions.java
changeset 55751 014decdb5086
child 57596 dad0062bb7f3
equal deleted inserted replaced
55750:6f60cfd502c3 55751:014decdb5086
       
     1 /*
       
     2  * Copyright (c) 2019, Oracle and/or its affiliates. All rights reserved.
       
     3  * Copyright (c) 2019, Twitter, Inc.
       
     4  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
       
     5  *
       
     6  * This code is free software; you can redistribute it and/or modify it
       
     7  * under the terms of the GNU General Public License version 2 only, as
       
     8  * published by the Free Software Foundation.
       
     9  *
       
    10  * This code is distributed in the hope that it will be useful, but WITHOUT
       
    11  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
       
    12  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
       
    13  * version 2 for more details (a copy is included in the LICENSE file that
       
    14  * accompanied this code).
       
    15  *
       
    16  * You should have received a copy of the GNU General Public License version
       
    17  * 2 along with this work; if not, write to the Free Software Foundation,
       
    18  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
       
    19  *
       
    20  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
       
    21  * or visit www.oracle.com if you need additional information or have any
       
    22  * questions.
       
    23  *
       
    24  */
       
    25 
       
    26 package gc.metaspace;
       
    27 
       
    28 import jdk.test.lib.process.ProcessTools;
       
    29 import jdk.test.lib.process.OutputAnalyzer;
       
    30 
       
    31 /* @test TestSizeTransitionsSerial
       
    32  * @key gc
       
    33  * @requires vm.gc.Serial
       
    34  * @summary Tests that the metaspace size transition logging is done correctly.
       
    35  * @library /test/lib
       
    36  * @run driver gc.metaspace.TestSizeTransitions false -XX:+UseSerialGC
       
    37  * @run driver gc.metaspace.TestSizeTransitions true  -XX:+UseSerialGC
       
    38  */
       
    39 
       
    40 /* @test TestSizeTransitionsParallel
       
    41  * @key gc
       
    42  * @requires vm.gc.Parallel
       
    43  * @summary Tests that the metaspace size transition logging is done correctly.
       
    44  * @library /test/lib
       
    45  * @run driver gc.metaspace.TestSizeTransitions false -XX:+UseParallelGC
       
    46  * @run driver gc.metaspace.TestSizeTransitions true  -XX:+UseParallelGC
       
    47  */
       
    48 
       
    49 /* @test TestSizeTransitionsG1
       
    50  * @key gc
       
    51  * @requires vm.gc.G1
       
    52  * @summary Tests that the metaspace size transition logging is done correctly.
       
    53  * @library /test/lib
       
    54  * @run driver gc.metaspace.TestSizeTransitions false -XX:+UseG1GC
       
    55  * @run driver gc.metaspace.TestSizeTransitions true  -XX:+UseG1GC
       
    56  */
       
    57 
       
    58 /* @test TestSizeTransitionsCMS
       
    59  * @key gc
       
    60  * @requires vm.gc.ConcMarkSweep
       
    61  * @summary Tests that the metaspace size transition logging is done correctly.
       
    62  * @library /test/lib
       
    63  * @run driver gc.metaspace.TestSizeTransitions false -XX:+UseConcMarkSweepGC
       
    64  * @run driver gc.metaspace.TestSizeTransitions true  -XX:+UseConcMarkSweepGC
       
    65  */
       
    66 
       
    67 public class TestSizeTransitions {
       
    68   public static class Run {
       
    69     public static void main(String... args) throws Exception {
       
    70       System.out.println("Run started.");
       
    71 
       
    72       // easiest way to generate a metaspace transition is to ask for a full GC
       
    73       System.gc();
       
    74 
       
    75       System.out.println("Run finished.");
       
    76     }
       
    77   }
       
    78 
       
    79   // matches the log tags
       
    80   //   e.g., [0.043s][info][gc]
       
    81   private static final String LOG_TAGS_REGEX = "(\\[.*\\])+ ";
       
    82 
       
    83   // matches a size transition
       
    84   //   e.g., 177K(4864K)->177K(4864K)
       
    85   private static final String SIZE_TRANSITION_REGEX = "\\d+K\\(\\d+K\\)->\\d+K\\(\\d+K\\)";
       
    86 
       
    87   // matches -coops metaspace size transitions
       
    88   private static final String NO_COOPS_REGEX =
       
    89     String.format("^%s.* Metaspace: %s$",
       
    90                   LOG_TAGS_REGEX,
       
    91                   SIZE_TRANSITION_REGEX);
       
    92 
       
    93   // matches +coops metaspace size transitions
       
    94   private static final String COOPS_REGEX =
       
    95     String.format("^%s.* Metaspace: %s NonClass: %s Class: %s$",
       
    96                   LOG_TAGS_REGEX,
       
    97                   SIZE_TRANSITION_REGEX,
       
    98                   SIZE_TRANSITION_REGEX,
       
    99                   SIZE_TRANSITION_REGEX);
       
   100 
       
   101   public static void main(String... args) throws Exception {
       
   102     // args: <use-coops> <gc-arg>
       
   103     if (args.length != 2) {
       
   104       throw new RuntimeException("wrong number of args: " + args.length);
       
   105     }
       
   106 
       
   107     final boolean useCoops = Boolean.parseBoolean(args[0]);
       
   108     final String gcArg = args[1];
       
   109     final String[] jvmArgs = {
       
   110       useCoops ? "-XX:+UseCompressedOops" : "-XX:-UseCompressedOops",
       
   111       gcArg,
       
   112       "-Xmx256m",
       
   113       "-Xlog:gc,gc+metaspace=info",
       
   114       TestSizeTransitions.Run.class.getName()
       
   115     };
       
   116 
       
   117     System.out.println("JVM args:");
       
   118     for (String a : jvmArgs) {
       
   119       System.out.println("  " + a);
       
   120     }
       
   121 
       
   122     final ProcessBuilder pb = ProcessTools.createJavaProcessBuilder(jvmArgs);
       
   123     final OutputAnalyzer output = new OutputAnalyzer(pb.start());
       
   124     System.out.println(output.getStdout());
       
   125     output.shouldHaveExitValue(0);
       
   126 
       
   127     if (useCoops) {
       
   128       output.stdoutShouldMatch(COOPS_REGEX);
       
   129       output.stdoutShouldNotMatch(NO_COOPS_REGEX);
       
   130     } else {
       
   131       output.stdoutShouldMatch(NO_COOPS_REGEX);
       
   132       output.stdoutShouldNotMatch(COOPS_REGEX);
       
   133     }
       
   134   }
       
   135 }