Path: blob/master/test/hotspot/jtreg/gc/arguments/TestDynMaxHeapFreeRatio.java
40942 views
/*1* Copyright (c) 2014, 2019, 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;2425import static jdk.test.lib.Asserts.assertEQ;26import static jdk.test.lib.Asserts.assertFalse;27import static jdk.test.lib.Asserts.assertTrue;28import jdk.test.lib.management.DynamicVMOption;2930/**31* @test TestDynMaxHeapFreeRatio32* @bug 802839133* @summary Verify that MaxHeapFreeRatio flag is manageable34* @library /test/lib35* @modules java.base/jdk.internal.misc36* @modules java.management37* @run main gc.arguments.TestDynMaxHeapFreeRatio38* @run main/othervm -XX:MinHeapFreeRatio=0 -XX:MaxHeapFreeRatio=100 gc.arguments.TestDynMaxHeapFreeRatio39* @run main/othervm -XX:MinHeapFreeRatio=10 -XX:MaxHeapFreeRatio=50 -XX:-UseAdaptiveSizePolicy gc.arguments.TestDynMaxHeapFreeRatio40* @run main/othervm -XX:MinHeapFreeRatio=10 -XX:MaxHeapFreeRatio=50 gc.arguments.TestDynMaxHeapFreeRatio41* @run main/othervm -XX:MinHeapFreeRatio=51 -XX:MaxHeapFreeRatio=52 gc.arguments.TestDynMaxHeapFreeRatio42* @run main/othervm -XX:MinHeapFreeRatio=75 -XX:MaxHeapFreeRatio=100 gc.arguments.TestDynMaxHeapFreeRatio43*/44public class TestDynMaxHeapFreeRatio {4546public static void main(String args[]) throws Exception {4748// low boundary value49int minValue = DynamicVMOption.getInt("MinHeapFreeRatio");50System.out.println("MinHeapFreeRatio= " + minValue);5152String badValues[] = {53null,54"",55"not a number",56"8.5", "-0.01",57Integer.toString(Integer.MIN_VALUE),58Integer.toString(Integer.MAX_VALUE),59Integer.toString(minValue - 1),60"-1024", "-1", "101", "1997"61};6263String goodValues[] = {64Integer.toString(minValue),65Integer.toString(minValue + 1),66Integer.toString((minValue + 100) / 2),67"99", "100"68};6970DynamicVMOption option = new DynamicVMOption("MaxHeapFreeRatio");7172assertTrue(option.isWriteable(), "Option " + option.name73+ " is expected to be writable");7475for (String v : badValues) {76assertFalse(option.isValidValue(v),77"'" + v + "' is expected to be illegal for flag " + option.name);78}79for (String v : goodValues) {80option.setValue(v);81String newValue = option.getValue();82assertEQ(v, newValue);83}84}85}868788