Path: blob/master/test/hotspot/jtreg/gc/arguments/TestHeapFreeRatio.java
40948 views
/*1* Copyright (c) 2013, 2020, Oracle and/or its affiliates. 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*/2223package gc.arguments;2425/*26* @test TestHeapFreeRatio27* @bug 802566128* @summary Test parsing of -Xminf and -Xmaxf29* @library /test/lib30* @library /31* @modules java.base/jdk.internal.misc32* java.management33* @run driver gc.arguments.TestHeapFreeRatio34*/3536import jdk.test.lib.process.OutputAnalyzer;37import jdk.test.lib.process.ProcessTools;3839public class TestHeapFreeRatio {4041enum Validation {42VALID,43MIN_INVALID,44MAX_INVALID,45OUT_OF_RANGE,46COMBINATION_INVALID47}4849private static void testMinMaxFreeRatio(String min, String max, Validation type) throws Exception {50ProcessBuilder pb = GCArguments.createJavaProcessBuilder(51"-Xminf" + min,52"-Xmaxf" + max,53"-version");54OutputAnalyzer output = new OutputAnalyzer(pb.start());5556switch (type) {57case VALID:58output.shouldNotContain("Error");59output.shouldHaveExitValue(0);60break;61case MIN_INVALID:62output.shouldContain("Bad min heap free percentage size: -Xminf" + min);63output.shouldContain("Error");64output.shouldHaveExitValue(1);65break;66case MAX_INVALID:67output.shouldContain("Bad max heap free percentage size: -Xmaxf" + max);68output.shouldContain("Error");69output.shouldHaveExitValue(1);70break;71case OUT_OF_RANGE:72output.shouldContain("outside the allowed range");73output.shouldContain("Error");74output.shouldHaveExitValue(1);75break;76case COMBINATION_INVALID:77output.shouldContain("must be less than or equal to MaxHeapFreeRatio");78output.shouldContain("Error");79output.shouldHaveExitValue(1);80break;81default:82throw new IllegalStateException("Must specify expected validation type");83}8485System.out.println(output.getOutput());86}8788public static void main(String args[]) throws Exception {89testMinMaxFreeRatio( "0.1", "0.5", Validation.VALID);90testMinMaxFreeRatio( ".1", ".5", Validation.VALID);91testMinMaxFreeRatio( "0.5", "0.5", Validation.VALID);9293testMinMaxFreeRatio("=0.1", "0.5", Validation.MIN_INVALID);94testMinMaxFreeRatio("0.1f", "0.5", Validation.MIN_INVALID);95testMinMaxFreeRatio(96"INVALID", "0.5", Validation.MIN_INVALID);9798testMinMaxFreeRatio( "0.1", "0.5f", Validation.MAX_INVALID);99testMinMaxFreeRatio( "0.1", "=0.5", Validation.MAX_INVALID);100testMinMaxFreeRatio(101"0.1", "INVALID", Validation.MAX_INVALID);102103testMinMaxFreeRatio("-0.1", "0.5", Validation.OUT_OF_RANGE);104testMinMaxFreeRatio( "1.1", "0.5", Validation.OUT_OF_RANGE);105testMinMaxFreeRatio(106"2147483647", "0.5", Validation.OUT_OF_RANGE);107testMinMaxFreeRatio( "0.1", "-0.5", Validation.OUT_OF_RANGE);108testMinMaxFreeRatio( "0.1", "1.5", Validation.OUT_OF_RANGE);109testMinMaxFreeRatio(110"0.1", "2147483647", Validation.OUT_OF_RANGE);111112testMinMaxFreeRatio( "0.5", "0.1", Validation.COMBINATION_INVALID);113testMinMaxFreeRatio( ".5", ".10", Validation.COMBINATION_INVALID);114testMinMaxFreeRatio("0.12","0.100", Validation.COMBINATION_INVALID);115}116}117118119