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 TestExplicitGCNoConcurrent
  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 TestExplicitGCNoConcurrent
  32  */
  33 
  34 import jdk.test.lib.process.ProcessTools;
  35 import jdk.test.lib.process.OutputAnalyzer;
  36 
  37 public class TestExplicitGCNoConcurrent {
  38 
  39     public static void main(String[] args) throws Exception {
  40         if (args.length > 0) {
  41             System.out.println("Calling System.gc()");
  42             System.gc();
  43             return;
  44         }
  45 
  46         String[] concurrent = new String[] {
  47             "Pause Init Mark",
  48             "Pause Final Mark",
  49             "Pause Init Update Refs",
  50             "Pause Final Update Refs",
  51             "Pause Init Traversal",
  52             "Pause Final Traversal",
  53         };
  54 
  55         String[] opts = new String[] {
  56             "",
  57             "-XX:-ExplicitGCInvokesConcurrent",
  58             "-XX:+ExplicitGCInvokesConcurrent"
  59         };
  60 
  61         for (String opt : opts) {
  62             ProcessBuilder pb = ProcessTools.createJavaProcessBuilder(
  63                                     "-XX:+UnlockExperimentalVMOptions",
  64                                     "-XX:+UseShenandoahGC",
  65                                     "-Xlog:gc",
  66                                     "-XX:+UnlockDiagnosticVMOptions",
  67                                     opt,
  68                                     "-XX:ShenandoahGCHeuristics=passive",
  69                                     TestExplicitGCNoConcurrent.class.getName(),
  70                                     "test");
  71             OutputAnalyzer output = new OutputAnalyzer(pb.start());
  72             for (String p : concurrent) {
  73                 output.shouldNotContain(p);
  74             }
  75         }
  76     }
  77 }