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 /testlibrary
  29  *
  30  * @run driver TestExplicitGC
  31  */
  32 
  33 import com.oracle.java.testlibrary.*;
  34 
  35 public class TestExplicitGC {
  36 
  37     enum Mode {
  38         PRODUCT,
  39         DIAGNOSTIC,
  40         EXPERIMENTAL,
  41     }
  42 
  43     public static void main(String[] args) throws Exception {
  44         if (args.length > 0) {
  45             System.out.println("Calling System.gc()");
  46             System.gc();
  47             return;
  48         }
  49 
  50         String[] full = new String[] {
  51                 "Pause Full"
  52         };
  53 
  54         String[] concurrent = new String[] {
  55                 "Pause Init Mark",
  56                 "Pause Final Mark",
  57         };
  58 
  59         {
  60             ProcessBuilder pb = ProcessTools.createJavaProcessBuilder(
  61                     "-XX:+UnlockExperimentalVMOptions",
  62                     "-XX:+UseShenandoahGC",
  63                     "-verbose:gc",
  64                     TestExplicitGC.class.getName(),
  65                     "test");
  66             OutputAnalyzer output = new OutputAnalyzer(pb.start());
  67             for (String p : full) {
  68                 output.shouldNotContain(p);
  69             }
  70             for (String p : concurrent) {
  71                 output.shouldContain(p);
  72             }
  73         }
  74 
  75         {
  76             ProcessBuilder pb = ProcessTools.createJavaProcessBuilder(
  77                     "-XX:+UnlockExperimentalVMOptions",
  78                     "-XX:+UseShenandoahGC",
  79                     "-verbose:gc",
  80                     "-XX:+DisableExplicitGC",
  81                     TestExplicitGC.class.getName(),
  82                     "test");
  83             OutputAnalyzer output = new OutputAnalyzer(pb.start());
  84             for (String p : full) {
  85                 output.shouldNotContain(p);
  86             }
  87             for (String p : concurrent) {
  88                 output.shouldNotContain(p);
  89             }
  90         }
  91 
  92         {
  93             ProcessBuilder pb = ProcessTools.createJavaProcessBuilder(
  94                     "-XX:+UnlockExperimentalVMOptions",
  95                     "-XX:+UseShenandoahGC",
  96                     "-verbose:gc",
  97                     "-XX:+ExplicitGCInvokesConcurrent",
  98                     TestExplicitGC.class.getName(),
  99                     "test");
 100             OutputAnalyzer output = new OutputAnalyzer(pb.start());
 101             for (String p : full) {
 102                 output.shouldNotContain(p);
 103             }
 104             for (String p : concurrent) {
 105                 output.shouldContain(p);
 106             }
 107         }
 108 
 109         {
 110             ProcessBuilder pb = ProcessTools.createJavaProcessBuilder(
 111                     "-XX:+UnlockExperimentalVMOptions",
 112                     "-XX:+UseShenandoahGC",
 113                     "-verbose:gc",
 114                     "-XX:-ExplicitGCInvokesConcurrent",
 115                     TestExplicitGC.class.getName(),
 116                     "test");
 117             OutputAnalyzer output = new OutputAnalyzer(pb.start());
 118             for (String p : full) {
 119                 output.shouldContain(p);
 120             }
 121             for (String p : concurrent) {
 122                 output.shouldNotContain(p);
 123             }
 124         }
 125     }
 126 }