1 /*
   2  * Copyright (c) 2017, 2018, Red Hat, Inc. All rights reserved.
   3  *
   4  * This code is free software; you can redistribute it and/or modify it
   5  * under the terms of the GNU General Public License version 2 only, as
   6  * published by the Free Software Foundation.
   7  *
   8  * This code is distributed in the hope that it will be useful, but WITHOUT
   9  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  10  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  11  * version 2 for more details (a copy is included in the LICENSE file that
  12  * accompanied this code).
  13  *
  14  * You should have received a copy of the GNU General Public License version
  15  * 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 USA
  19  * or visit www.oracle.com if you need additional information or have any
  20  * questions.
  21  *
  22  */
  23 
  24 /*
  25  * @test TestExplicitGC
  26  * @summary Test that Shenandoah reacts to explicit GC flags appropriately
  27  * @key gc
  28  * @library /test/lib
  29  * @modules java.base/jdk.internal.misc
  30  *          java.management
  31  * @run driver TestExplicitGC
  32  */
  33 
  34 import jdk.test.lib.process.ProcessTools;
  35 import jdk.test.lib.process.OutputAnalyzer;
  36 
  37 public class TestExplicitGC {
  38 
  39     enum Mode {
  40         PRODUCT,
  41         DIAGNOSTIC,
  42         EXPERIMENTAL,
  43     }
  44 
  45     public static void main(String[] args) throws Exception {
  46         if (args.length > 0) {
  47             System.out.println("Calling System.gc()");
  48             System.gc();
  49             return;
  50         }
  51 
  52         String[] full = new String[] {
  53             "Pause Full"
  54         };
  55 
  56         String[] concNormal = new String[] {
  57             "Pause Init Mark",
  58             "Pause Final Mark",
  59         };
  60 
  61         String[] concTraversal = new String[] {
  62             "Pause Init Traversal",
  63             "Pause Final Traversal",
  64         };
  65 
  66         {
  67             ProcessBuilder pb = ProcessTools.createJavaProcessBuilder(
  68                                     "-XX:+UnlockExperimentalVMOptions",
  69                                     "-XX:+UseShenandoahGC",
  70                                     "-Xlog:gc",
  71                                     TestExplicitGC.class.getName(),
  72                                     "test");
  73             OutputAnalyzer output = new OutputAnalyzer(pb.start());
  74             for (String p : full) {
  75                 output.shouldNotContain(p);
  76             }
  77             for (String p : concNormal) {
  78                 output.shouldContain(p);
  79             }
  80             for (String p : concTraversal) {
  81                 output.shouldNotContain(p);
  82             }
  83         }
  84 
  85         {
  86             ProcessBuilder pb = ProcessTools.createJavaProcessBuilder(
  87                                     "-XX:+UnlockExperimentalVMOptions",
  88                                     "-XX:+UseShenandoahGC",
  89                                     "-Xlog:gc",
  90                                     "-XX:+DisableExplicitGC",
  91                                     TestExplicitGC.class.getName(),
  92                                     "test");
  93             OutputAnalyzer output = new OutputAnalyzer(pb.start());
  94             for (String p : full) {
  95                 output.shouldNotContain(p);
  96             }
  97             for (String p : concNormal) {
  98                 output.shouldNotContain(p);
  99             }
 100             for (String p : concTraversal) {
 101                 output.shouldNotContain(p);
 102             }
 103         }
 104 
 105         {
 106             ProcessBuilder pb = ProcessTools.createJavaProcessBuilder(
 107                                     "-XX:+UnlockExperimentalVMOptions",
 108                                     "-XX:+UseShenandoahGC",
 109                                     "-Xlog:gc",
 110                                     "-XX:+ExplicitGCInvokesConcurrent",
 111                                     TestExplicitGC.class.getName(),
 112                                     "test");
 113             OutputAnalyzer output = new OutputAnalyzer(pb.start());
 114             for (String p : full) {
 115                 output.shouldNotContain(p);
 116             }
 117             for (String p : concNormal) {
 118                 output.shouldContain(p);
 119             }
 120             for (String p : concTraversal) {
 121                 output.shouldNotContain(p);
 122             }
 123         }
 124 
 125         {
 126             ProcessBuilder pb = ProcessTools.createJavaProcessBuilder(
 127                                     "-XX:+UnlockExperimentalVMOptions",
 128                                     "-XX:+UseShenandoahGC",
 129                                     "-Xlog:gc",
 130                                     "-XX:+ExplicitGCInvokesConcurrent",
 131                                     "-XX:ShenandoahGCHeuristics=traversal",
 132                                     TestExplicitGC.class.getName(),
 133                                     "test");
 134             OutputAnalyzer output = new OutputAnalyzer(pb.start());
 135             for (String p : full) {
 136                 output.shouldNotContain(p);
 137             }
 138             for (String p : concNormal) {
 139                 output.shouldNotContain(p);
 140             }
 141             for (String p : concTraversal) {
 142                 output.shouldContain(p);
 143             }
 144         }
 145 
 146         {
 147             ProcessBuilder pb = ProcessTools.createJavaProcessBuilder(
 148                                     "-XX:+UnlockExperimentalVMOptions",
 149                                     "-XX:+UseShenandoahGC",
 150                                     "-Xlog:gc",
 151                                     "-XX:-ExplicitGCInvokesConcurrent",
 152                                     TestExplicitGC.class.getName(),
 153                                     "test");
 154             OutputAnalyzer output = new OutputAnalyzer(pb.start());
 155             for (String p : full) {
 156                 output.shouldContain(p);
 157             }
 158             for (String p : concNormal) {
 159                 output.shouldNotContain(p);
 160             }
 161             for (String p : concTraversal) {
 162                 output.shouldNotContain(p);
 163             }
 164         }
 165     }
 166 }