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 TestArgumentRanges 26 * @summary Test that Shenandoah arguments are checked for ranges where applicable 27 * @key gc 28 * @library /testlibrary 29 * 30 * @run driver TestArgumentRanges 31 */ 32 33 import com.oracle.java.testlibrary.*; 34 35 public class TestArgumentRanges { 36 public static void main(String[] args) throws Exception { 37 testRange("ShenandoahGarbageThreshold", 0, 100); 38 testRange("ShenandoahMinFreeThreshold", 0, 100); 39 testRange("ShenandoahAllocationThreshold", 0, 100); 40 testHeuristics(); 41 } 42 43 private static void testHeuristics() throws Exception { 44 45 { 46 ProcessBuilder pb = ProcessTools.createJavaProcessBuilder( 47 "-Xmx128m", 48 "-XX:+UnlockDiagnosticVMOptions", 49 "-XX:+UnlockExperimentalVMOptions", 50 "-XX:+UseShenandoahGC", 51 "-XX:ShenandoahGCHeuristics=aggressive", 52 "-version"); 53 OutputAnalyzer output = new OutputAnalyzer(pb.start()); 54 output.shouldHaveExitValue(0); 55 } 56 { 57 ProcessBuilder pb = ProcessTools.createJavaProcessBuilder( 58 "-Xmx128m", 59 "-XX:+UnlockDiagnosticVMOptions", 60 "-XX:+UnlockExperimentalVMOptions", 61 "-XX:+UseShenandoahGC", 62 "-XX:ShenandoahGCHeuristics=static", 63 "-version"); 64 OutputAnalyzer output = new OutputAnalyzer(pb.start()); 65 output.shouldHaveExitValue(0); 66 } 67 { 68 ProcessBuilder pb = ProcessTools.createJavaProcessBuilder( 69 "-Xmx128m", 70 "-XX:+UnlockDiagnosticVMOptions", 71 "-XX:+UnlockExperimentalVMOptions", 72 "-XX:+UseShenandoahGC", 73 "-XX:ShenandoahGCHeuristics=fluff", 74 "-version"); 75 OutputAnalyzer output = new OutputAnalyzer(pb.start()); 76 output.shouldMatch("Unknown -XX:ShenandoahGCHeuristics option"); 77 output.shouldHaveExitValue(1); 78 } 79 } 80 81 private static void testRange(String option, int min, int max) throws Exception { 82 { 83 ProcessBuilder pb = ProcessTools.createJavaProcessBuilder( 84 "-Xmx128m", 85 "-XX:+UnlockDiagnosticVMOptions", 86 "-XX:+UnlockExperimentalVMOptions", 87 "-XX:+UseShenandoahGC", 88 "-XX:" + option + "=" + (max + 1), 89 "-version"); 90 OutputAnalyzer output = new OutputAnalyzer(pb.start()); 91 output.shouldHaveExitValue(1); 92 } 93 { 94 ProcessBuilder pb = ProcessTools.createJavaProcessBuilder( 95 "-Xmx128m", 96 "-XX:+UnlockDiagnosticVMOptions", 97 "-XX:+UnlockExperimentalVMOptions", 98 "-XX:+UseShenandoahGC", 99 "-XX:" + option + "=" + max, 100 "-version"); 101 OutputAnalyzer output = new OutputAnalyzer(pb.start()); 102 output.shouldHaveExitValue(0); 103 } 104 { 105 ProcessBuilder pb = ProcessTools.createJavaProcessBuilder( 106 "-Xmx128m", 107 "-XX:+UnlockDiagnosticVMOptions", 108 "-XX:+UnlockExperimentalVMOptions", 109 "-XX:+UseShenandoahGC", 110 "-XX:" + option + "=" + (min - 1), 111 "-version"); 112 OutputAnalyzer output = new OutputAnalyzer(pb.start()); 113 output.shouldHaveExitValue(1); 114 } 115 { 116 ProcessBuilder pb = ProcessTools.createJavaProcessBuilder( 117 "-Xmx128m", 118 "-XX:+UnlockDiagnosticVMOptions", 119 "-XX:+UnlockExperimentalVMOptions", 120 "-XX:+UseShenandoahGC", 121 "-XX:" + option + "=" + min, 122 "-version"); 123 OutputAnalyzer output = new OutputAnalyzer(pb.start()); 124 output.shouldHaveExitValue(0); 125 } 126 } 127 }