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