1 /*
   2  * Copyright (c) 2016, 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 TestRegionSizeArgs
  26  * @summary Test that Shenandoah region size args are checked
  27  * @key gc
  28  * @library /testlibrary
  29  *
  30  * @run driver TestRegionSizeArgs
  31  */
  32 
  33 import com.oracle.java.testlibrary.*;
  34 
  35 public class TestRegionSizeArgs {
  36     public static void main(String[] args) throws Exception {
  37         testInvalidRegionSizes();
  38         testMinRegionSize();
  39         testMaxRegionSize();
  40     }
  41 
  42     private static void testInvalidRegionSizes() throws Exception {
  43 
  44         {
  45             ProcessBuilder pb = ProcessTools.createJavaProcessBuilder("-XX:+UnlockExperimentalVMOptions",
  46                     "-XX:+UseShenandoahGC",
  47                     "-Xms4m",
  48                     "-Xmx1g",
  49                     "-version");
  50             OutputAnalyzer output = new OutputAnalyzer(pb.start());
  51             output.shouldHaveExitValue(0);
  52         }
  53 
  54         {
  55             ProcessBuilder pb = ProcessTools.createJavaProcessBuilder("-XX:+UnlockExperimentalVMOptions",
  56                     "-XX:+UseShenandoahGC",
  57                     "-Xms8m",
  58                     "-Xmx1g",
  59                     "-version");
  60             OutputAnalyzer output = new OutputAnalyzer(pb.start());
  61             output.shouldHaveExitValue(0);
  62         }
  63 
  64         {
  65             ProcessBuilder pb = ProcessTools.createJavaProcessBuilder("-XX:+UnlockExperimentalVMOptions",
  66                     "-XX:+UseShenandoahGC",
  67                     "-Xms100m",
  68                     "-Xmx1g",
  69                     "-XX:ShenandoahRegionSize=200m",
  70                     "-version");
  71             OutputAnalyzer output = new OutputAnalyzer(pb.start());
  72             output.shouldMatch("Invalid -XX:ShenandoahRegionSize option");
  73             output.shouldHaveExitValue(1);
  74         }
  75 
  76         {
  77             ProcessBuilder pb = ProcessTools.createJavaProcessBuilder("-XX:+UnlockExperimentalVMOptions",
  78                     "-XX:+UseShenandoahGC",
  79                     "-Xms100m",
  80                     "-Xmx1g",
  81                     "-XX:ShenandoahRegionSize=9m",
  82                     "-version");
  83             OutputAnalyzer output = new OutputAnalyzer(pb.start());
  84             output.shouldHaveExitValue(0);
  85         }
  86 
  87         {
  88             ProcessBuilder pb = ProcessTools.createJavaProcessBuilder("-XX:+UnlockExperimentalVMOptions",
  89                     "-XX:+UseShenandoahGC",
  90                     "-Xms100m",
  91                     "-Xmx1g",
  92                     "-XX:ShenandoahRegionSize=255K",
  93                     "-version");
  94             OutputAnalyzer output = new OutputAnalyzer(pb.start());
  95             output.shouldMatch("Invalid -XX:ShenandoahRegionSize option");
  96             output.shouldHaveExitValue(1);
  97         }
  98 
  99         {
 100             ProcessBuilder pb = ProcessTools.createJavaProcessBuilder("-XX:+UnlockExperimentalVMOptions",
 101                     "-XX:+UseShenandoahGC",
 102                     "-Xms100m",
 103                     "-Xmx1g",
 104                     "-XX:ShenandoahRegionSize=260K",
 105                     "-version");
 106             OutputAnalyzer output = new OutputAnalyzer(pb.start());
 107             output.shouldHaveExitValue(0);
 108         }
 109 
 110         {
 111             ProcessBuilder pb = ProcessTools.createJavaProcessBuilder("-XX:+UnlockExperimentalVMOptions",
 112                     "-XX:+UseShenandoahGC",
 113                     "-Xms1g",
 114                     "-Xmx1g",
 115                     "-XX:ShenandoahRegionSize=32M",
 116                     "-version");
 117             OutputAnalyzer output = new OutputAnalyzer(pb.start());
 118             output.shouldHaveExitValue(0);
 119         }
 120 
 121         {
 122             ProcessBuilder pb = ProcessTools.createJavaProcessBuilder("-XX:+UnlockExperimentalVMOptions",
 123                     "-XX:+UseShenandoahGC",
 124                     "-Xms1g",
 125                     "-Xmx1g",
 126                     "-XX:ShenandoahRegionSize=64M",
 127                     "-version");
 128             OutputAnalyzer output = new OutputAnalyzer(pb.start());
 129             output.shouldMatch("Invalid -XX:ShenandoahRegionSize option");
 130             output.shouldHaveExitValue(1);
 131         }
 132 
 133         {
 134             ProcessBuilder pb = ProcessTools.createJavaProcessBuilder("-XX:+UnlockExperimentalVMOptions",
 135                     "-XX:+UseShenandoahGC",
 136                     "-Xms1g",
 137                     "-Xmx1g",
 138                     "-XX:ShenandoahRegionSize=256K",
 139                     "-version");
 140             OutputAnalyzer output = new OutputAnalyzer(pb.start());
 141             output.shouldHaveExitValue(0);
 142         }
 143 
 144         {
 145             ProcessBuilder pb = ProcessTools.createJavaProcessBuilder("-XX:+UnlockExperimentalVMOptions",
 146                     "-XX:+UseShenandoahGC",
 147                     "-Xms1g",
 148                     "-Xmx1g",
 149                     "-XX:ShenandoahRegionSize=128K",
 150                     "-version");
 151             OutputAnalyzer output = new OutputAnalyzer(pb.start());
 152             output.shouldMatch("Invalid -XX:ShenandoahRegionSize option");
 153             output.shouldHaveExitValue(1);
 154         }
 155     }
 156 
 157     private static void testMinRegionSize() throws Exception {
 158 
 159         {
 160             ProcessBuilder pb = ProcessTools.createJavaProcessBuilder("-XX:+UnlockExperimentalVMOptions",
 161                     "-XX:+UseShenandoahGC",
 162                     "-Xms100m",
 163                     "-Xmx1g",
 164                     "-XX:ShenandoahMinRegionSize=255K",
 165                     "-version");
 166             OutputAnalyzer output = new OutputAnalyzer(pb.start());
 167             output.shouldMatch("Invalid -XX:ShenandoahMinRegionSize option");
 168             output.shouldHaveExitValue(1);
 169         }
 170 
 171         {
 172             ProcessBuilder pb = ProcessTools.createJavaProcessBuilder("-XX:+UnlockExperimentalVMOptions",
 173                     "-XX:+UseShenandoahGC",
 174                     "-Xms100m",
 175                     "-Xmx1g",
 176                     "-XX:ShenandoahMinRegionSize=1M",
 177                     "-XX:ShenandoahMaxRegionSize=260K",
 178                     "-version");
 179             OutputAnalyzer output = new OutputAnalyzer(pb.start());
 180             output.shouldMatch("Invalid -XX:ShenandoahMinRegionSize or -XX:ShenandoahMaxRegionSize");
 181             output.shouldHaveExitValue(1);
 182         }
 183         {
 184             ProcessBuilder pb = ProcessTools.createJavaProcessBuilder("-XX:+UnlockExperimentalVMOptions",
 185                     "-XX:+UseShenandoahGC",
 186                     "-Xms100m",
 187                     "-Xmx1g",
 188                     "-XX:ShenandoahMinRegionSize=200m",
 189                     "-version");
 190             OutputAnalyzer output = new OutputAnalyzer(pb.start());
 191             output.shouldMatch("Invalid -XX:ShenandoahMinRegionSize option");
 192             output.shouldHaveExitValue(1);
 193         }
 194 
 195         {
 196             ProcessBuilder pb = ProcessTools.createJavaProcessBuilder("-XX:+UnlockExperimentalVMOptions",
 197                     "-XX:+UseShenandoahGC",
 198                     "-Xms100m",
 199                     "-Xmx1g",
 200                     "-XX:ShenandoahMinRegionSize=9m",
 201                     "-version");
 202             OutputAnalyzer output = new OutputAnalyzer(pb.start());
 203             output.shouldHaveExitValue(0);
 204         }
 205 
 206     }
 207 
 208     private static void testMaxRegionSize() throws Exception {
 209 
 210         {
 211             ProcessBuilder pb = ProcessTools.createJavaProcessBuilder("-XX:+UnlockExperimentalVMOptions",
 212                     "-XX:+UseShenandoahGC",
 213                     "-Xms100m",
 214                     "-Xmx1g",
 215                     "-XX:ShenandoahMaxRegionSize=255K",
 216                     "-version");
 217             OutputAnalyzer output = new OutputAnalyzer(pb.start());
 218             output.shouldMatch("Invalid -XX:ShenandoahMaxRegionSize option");
 219             output.shouldHaveExitValue(1);
 220         }
 221 
 222         {
 223             ProcessBuilder pb = ProcessTools.createJavaProcessBuilder("-XX:+UnlockExperimentalVMOptions",
 224                     "-XX:+UseShenandoahGC",
 225                     "-Xms100m",
 226                     "-Xmx1g",
 227                     "-XX:ShenandoahMinRegionSize=1M",
 228                     "-XX:ShenandoahMaxRegionSize=260K",
 229                     "-version");
 230             OutputAnalyzer output = new OutputAnalyzer(pb.start());
 231             output.shouldMatch("Invalid -XX:ShenandoahMinRegionSize or -XX:ShenandoahMaxRegionSize");
 232             output.shouldHaveExitValue(1);
 233         }
 234     }
 235 }