Path: blob/master/test/hotspot/jtreg/gc/shenandoah/options/TestArgumentRanges.java
41153 views
/*1* Copyright (c) 2016, 2018, Red Hat, Inc. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 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 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*22*/2324/*25* @test TestArgumentRanges26* @summary Test that Shenandoah arguments are checked for ranges where applicable27* @requires vm.gc.Shenandoah28* @library /test/lib29* @modules java.base/jdk.internal.misc30* java.management31* @run driver TestArgumentRanges32*/3334import jdk.test.lib.process.ProcessTools;35import jdk.test.lib.process.OutputAnalyzer;3637public class TestArgumentRanges {38public static void main(String[] args) throws Exception {39testRange("ShenandoahGarbageThreshold", 0, 100);40testRange("ShenandoahMinFreeThreshold", 0, 100);41testRange("ShenandoahAllocationThreshold", 0, 100);42testHeuristics();43}4445private static void testHeuristics() throws Exception {4647{48ProcessBuilder pb = ProcessTools.createJavaProcessBuilder(49"-Xmx128m",50"-XX:+UnlockDiagnosticVMOptions",51"-XX:+UnlockExperimentalVMOptions",52"-XX:+UseShenandoahGC",53"-XX:ShenandoahGCHeuristics=aggressive",54"-version");55OutputAnalyzer output = new OutputAnalyzer(pb.start());56output.shouldHaveExitValue(0);57}58{59ProcessBuilder pb = ProcessTools.createJavaProcessBuilder(60"-Xmx128m",61"-XX:+UnlockDiagnosticVMOptions",62"-XX:+UnlockExperimentalVMOptions",63"-XX:+UseShenandoahGC",64"-XX:ShenandoahGCHeuristics=static",65"-version");66OutputAnalyzer output = new OutputAnalyzer(pb.start());67output.shouldHaveExitValue(0);68}69{70ProcessBuilder pb = ProcessTools.createJavaProcessBuilder(71"-Xmx128m",72"-XX:+UnlockDiagnosticVMOptions",73"-XX:+UnlockExperimentalVMOptions",74"-XX:+UseShenandoahGC",75"-XX:ShenandoahGCHeuristics=fluff",76"-version");77OutputAnalyzer output = new OutputAnalyzer(pb.start());78output.shouldMatch("Unknown -XX:ShenandoahGCHeuristics option");79output.shouldHaveExitValue(1);80}81}8283private static void testRange(String option, int min, int max) throws Exception {84{85ProcessBuilder pb = ProcessTools.createJavaProcessBuilder(86"-Xmx128m",87"-XX:+UnlockDiagnosticVMOptions",88"-XX:+UnlockExperimentalVMOptions",89"-XX:+UseShenandoahGC",90"-XX:" + option + "=" + (max + 1),91"-version");92OutputAnalyzer output = new OutputAnalyzer(pb.start());93output.shouldHaveExitValue(1);94}95{96ProcessBuilder pb = ProcessTools.createJavaProcessBuilder(97"-Xmx128m",98"-XX:+UnlockDiagnosticVMOptions",99"-XX:+UnlockExperimentalVMOptions",100"-XX:+UseShenandoahGC",101"-XX:" + option + "=" + max,102"-version");103OutputAnalyzer output = new OutputAnalyzer(pb.start());104output.shouldHaveExitValue(0);105}106{107ProcessBuilder pb = ProcessTools.createJavaProcessBuilder(108"-Xmx128m",109"-XX:+UnlockDiagnosticVMOptions",110"-XX:+UnlockExperimentalVMOptions",111"-XX:+UseShenandoahGC",112"-XX:" + option + "=" + (min - 1),113"-version");114OutputAnalyzer output = new OutputAnalyzer(pb.start());115output.shouldHaveExitValue(1);116}117{118ProcessBuilder pb = ProcessTools.createJavaProcessBuilder(119"-Xmx128m",120"-XX:+UnlockDiagnosticVMOptions",121"-XX:+UnlockExperimentalVMOptions",122"-XX:+UseShenandoahGC",123"-XX:" + option + "=" + min,124"-version");125OutputAnalyzer output = new OutputAnalyzer(pb.start());126output.shouldHaveExitValue(0);127}128}129}130131132