Path: blob/aarch64-shenandoah-jdk8u272-b10/hotspot/test/gc/shenandoah/options/TestArgumentRanges.java
32285 views
/*1* Copyright (c) 2016, 2018, Red Hat, Inc. All rights reserved.2*3* This code is free software; you can redistribute it and/or modify it4* under the terms of the GNU General Public License version 2 only, as5* published by the Free Software Foundation.6*7* This code is distributed in the hope that it will be useful, but WITHOUT8* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or9* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License10* version 2 for more details (a copy is included in the LICENSE file that11* accompanied this code).12*13* You should have received a copy of the GNU General Public License version14* 2 along with this work; if not, write to the Free Software Foundation,15* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.16*17* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA18* or visit www.oracle.com if you need additional information or have any19* questions.20*21*/2223/*24* @test TestArgumentRanges25* @summary Test that Shenandoah arguments are checked for ranges where applicable26* @key gc27* @library /testlibrary28*29* @run driver TestArgumentRanges30*/3132import com.oracle.java.testlibrary.*;3334public class TestArgumentRanges {35public static void main(String[] args) throws Exception {36testRange("ShenandoahGarbageThreshold", 0, 100);37testRange("ShenandoahMinFreeThreshold", 0, 100);38testRange("ShenandoahAllocationThreshold", 0, 100);39testHeuristics();40}4142private static void testHeuristics() throws Exception {4344{45ProcessBuilder pb = ProcessTools.createJavaProcessBuilder(46"-Xmx128m",47"-XX:+UnlockDiagnosticVMOptions",48"-XX:+UnlockExperimentalVMOptions",49"-XX:+UseShenandoahGC",50"-XX:ShenandoahGCHeuristics=aggressive",51"-version");52OutputAnalyzer output = new OutputAnalyzer(pb.start());53output.shouldHaveExitValue(0);54}55{56ProcessBuilder pb = ProcessTools.createJavaProcessBuilder(57"-Xmx128m",58"-XX:+UnlockDiagnosticVMOptions",59"-XX:+UnlockExperimentalVMOptions",60"-XX:+UseShenandoahGC",61"-XX:ShenandoahGCHeuristics=static",62"-version");63OutputAnalyzer output = new OutputAnalyzer(pb.start());64output.shouldHaveExitValue(0);65}66{67ProcessBuilder pb = ProcessTools.createJavaProcessBuilder(68"-Xmx128m",69"-XX:+UnlockDiagnosticVMOptions",70"-XX:+UnlockExperimentalVMOptions",71"-XX:+UseShenandoahGC",72"-XX:ShenandoahGCHeuristics=fluff",73"-version");74OutputAnalyzer output = new OutputAnalyzer(pb.start());75output.shouldMatch("Unknown -XX:ShenandoahGCHeuristics option");76output.shouldHaveExitValue(1);77}78}7980private static void testRange(String option, int min, int max) throws Exception {81{82ProcessBuilder pb = ProcessTools.createJavaProcessBuilder(83"-Xmx128m",84"-XX:+UnlockDiagnosticVMOptions",85"-XX:+UnlockExperimentalVMOptions",86"-XX:+UseShenandoahGC",87"-XX:" + option + "=" + (max + 1),88"-version");89OutputAnalyzer output = new OutputAnalyzer(pb.start());90output.shouldHaveExitValue(1);91}92{93ProcessBuilder pb = ProcessTools.createJavaProcessBuilder(94"-Xmx128m",95"-XX:+UnlockDiagnosticVMOptions",96"-XX:+UnlockExperimentalVMOptions",97"-XX:+UseShenandoahGC",98"-XX:" + option + "=" + max,99"-version");100OutputAnalyzer output = new OutputAnalyzer(pb.start());101output.shouldHaveExitValue(0);102}103{104ProcessBuilder pb = ProcessTools.createJavaProcessBuilder(105"-Xmx128m",106"-XX:+UnlockDiagnosticVMOptions",107"-XX:+UnlockExperimentalVMOptions",108"-XX:+UseShenandoahGC",109"-XX:" + option + "=" + (min - 1),110"-version");111OutputAnalyzer output = new OutputAnalyzer(pb.start());112output.shouldHaveExitValue(1);113}114{115ProcessBuilder pb = ProcessTools.createJavaProcessBuilder(116"-Xmx128m",117"-XX:+UnlockDiagnosticVMOptions",118"-XX:+UnlockExperimentalVMOptions",119"-XX:+UseShenandoahGC",120"-XX:" + option + "=" + min,121"-version");122OutputAnalyzer output = new OutputAnalyzer(pb.start());123output.shouldHaveExitValue(0);124}125}126}127128129