Path: blob/master/test/hotspot/jtreg/gc/arguments/TestDynMinHeapFreeRatio.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;2425/**26* @test TestDynMinHeapFreeRatio27* @bug 802839128* @summary Verify that MinHeapFreeRatio flag is manageable29* @library /test/lib30* @modules java.base/jdk.internal.misc31* @modules java.management32* @run main gc.arguments.TestDynMinHeapFreeRatio33* @run main/othervm -XX:MinHeapFreeRatio=0 -XX:MaxHeapFreeRatio=100 gc.arguments.TestDynMinHeapFreeRatio34* @run main/othervm -XX:MinHeapFreeRatio=10 -XX:MaxHeapFreeRatio=50 -XX:-UseAdaptiveSizePolicy gc.arguments.TestDynMinHeapFreeRatio35* @run main/othervm -XX:MinHeapFreeRatio=10 -XX:MaxHeapFreeRatio=50 gc.arguments.TestDynMinHeapFreeRatio36* @run main/othervm -XX:MinHeapFreeRatio=51 -XX:MaxHeapFreeRatio=52 gc.arguments.TestDynMinHeapFreeRatio37* @run main/othervm -XX:MinHeapFreeRatio=75 -XX:MaxHeapFreeRatio=100 gc.arguments.TestDynMinHeapFreeRatio38*/39import static jdk.test.lib.Asserts.assertEQ;40import static jdk.test.lib.Asserts.assertFalse;41import static jdk.test.lib.Asserts.assertTrue;42import jdk.test.lib.management.DynamicVMOption;4344public class TestDynMinHeapFreeRatio {4546public static void main(String args[]) throws Exception {4748// high boundary value49int maxValue = DynamicVMOption.getInt("MaxHeapFreeRatio");50System.out.println("MaxHeapFreeRatio= " + maxValue);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(maxValue + 1),60"-1024", "-1", "101", "1997"61};6263String goodValues[] = {64Integer.toString(maxValue),65Integer.toString(maxValue - 1),66Integer.toString(maxValue / 2),67"0", "1"68};6970// option under test71DynamicVMOption option = new DynamicVMOption("MinHeapFreeRatio");7273assertTrue(option.isWriteable(), "Option " + option.name74+ " is expected to be writable");7576for (String v : badValues) {77assertFalse(option.isValidValue(v),78"'" + v + "' is expected to be illegal for flag " + option.name);79}8081for (String v : goodValues) {82option.setValue(v);83String newValue = option.getValue();84assertEQ(v, newValue);85}86}87}888990