1 /* 2 * Copyright (c) 2016, 2018, Red Hat, Inc. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * This code is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. 8 * 9 * This code is distributed in the hope that it will be useful, but WITHOUT 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 12 * version 2 for more details (a copy is included in the LICENSE file that 13 * accompanied this code). 14 * 15 * You should have received a copy of the GNU General Public License version 16 * 2 along with this work; if not, write to the Free Software Foundation, 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 18 * 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 20 * or visit www.oracle.com if you need additional information or have any 21 * questions. 22 * 23 */ 24 25 /* 26 * @test TestArgumentRanges 27 * @summary Test that Shenandoah arguments are checked for ranges where applicable 28 * @requires vm.gc.Shenandoah & !vm.graal.enabled 29 * @library /test/lib 30 * @modules java.base/jdk.internal.misc 31 * java.management 32 * @run driver TestArgumentRanges 33 */ 34 35 import jdk.test.lib.process.ProcessTools; 36 import jdk.test.lib.process.OutputAnalyzer; 37 38 public class TestArgumentRanges { 39 public static void main(String[] args) throws Exception { 40 testRange("ShenandoahGarbageThreshold", 0, 100); 41 testRange("ShenandoahMinFreeThreshold", 0, 100); 42 testRange("ShenandoahAllocationThreshold", 0, 100); 43 testHeuristics(); 44 } 45 46 private static void testHeuristics() throws Exception { 47 48 { 49 ProcessBuilder pb = ProcessTools.createJavaProcessBuilder( 50 "-Xmx128m", 51 "-XX:+UnlockDiagnosticVMOptions", 52 "-XX:+UnlockExperimentalVMOptions", 53 "-XX:+UseShenandoahGC", 54 "-XX:ShenandoahGCHeuristics=aggressive", 55 "-version"); 56 OutputAnalyzer output = new OutputAnalyzer(pb.start()); 57 output.shouldHaveExitValue(0); 58 } 59 { 60 ProcessBuilder pb = ProcessTools.createJavaProcessBuilder( 61 "-Xmx128m", 62 "-XX:+UnlockDiagnosticVMOptions", 63 "-XX:+UnlockExperimentalVMOptions", 64 "-XX:+UseShenandoahGC", 65 "-XX:ShenandoahGCHeuristics=static", 66 "-version"); 67 OutputAnalyzer output = new OutputAnalyzer(pb.start()); 68 output.shouldHaveExitValue(0); 69 } 70 { 71 ProcessBuilder pb = ProcessTools.createJavaProcessBuilder( 72 "-Xmx128m", 73 "-XX:+UnlockDiagnosticVMOptions", 74 "-XX:+UnlockExperimentalVMOptions", 75 "-XX:+UseShenandoahGC", 76 "-XX:ShenandoahGCHeuristics=fluff", 77 "-version"); 78 OutputAnalyzer output = new OutputAnalyzer(pb.start()); 79 output.shouldMatch("Unknown -XX:ShenandoahGCHeuristics option"); 80 output.shouldHaveExitValue(1); 81 } 82 } 83 84 private static void testRange(String option, int min, int max) throws Exception { 85 { 86 ProcessBuilder pb = ProcessTools.createJavaProcessBuilder( 87 "-Xmx128m", 88 "-XX:+UnlockDiagnosticVMOptions", 89 "-XX:+UnlockExperimentalVMOptions", 90 "-XX:+UseShenandoahGC", 91 "-XX:" + option + "=" + (max + 1), 92 "-version"); 93 OutputAnalyzer output = new OutputAnalyzer(pb.start()); 94 output.shouldHaveExitValue(1); 95 } 96 { 97 ProcessBuilder pb = ProcessTools.createJavaProcessBuilder( 98 "-Xmx128m", 99 "-XX:+UnlockDiagnosticVMOptions", 100 "-XX:+UnlockExperimentalVMOptions", 101 "-XX:+UseShenandoahGC", 102 "-XX:" + option + "=" + max, 103 "-version"); 104 OutputAnalyzer output = new OutputAnalyzer(pb.start()); 105 output.shouldHaveExitValue(0); 106 } 107 { 108 ProcessBuilder pb = ProcessTools.createJavaProcessBuilder( 109 "-Xmx128m", 110 "-XX:+UnlockDiagnosticVMOptions", 111 "-XX:+UnlockExperimentalVMOptions", 112 "-XX:+UseShenandoahGC", 113 "-XX:" + option + "=" + (min - 1), 114 "-version"); 115 OutputAnalyzer output = new OutputAnalyzer(pb.start()); 116 output.shouldHaveExitValue(1); 117 } 118 { 119 ProcessBuilder pb = ProcessTools.createJavaProcessBuilder( 120 "-Xmx128m", 121 "-XX:+UnlockDiagnosticVMOptions", 122 "-XX:+UnlockExperimentalVMOptions", 123 "-XX:+UseShenandoahGC", 124 "-XX:" + option + "=" + min, 125 "-version"); 126 OutputAnalyzer output = new OutputAnalyzer(pb.start()); 127 output.shouldHaveExitValue(0); 128 } 129 } 130 }