8037510: CMM Testing: Min/MaxHeapFreeRatio flags should be manageable through the API

Thu, 20 Mar 2014 16:31:47 +0100

author
jwilhelm
date
Thu, 20 Mar 2014 16:31:47 +0100
changeset 6400
3b4e1b5c13a0
parent 6394
c96e9c8adb81
child 6401
b828d0d08417

8037510: CMM Testing: Min/MaxHeapFreeRatio flags should be manageable through the API
Summary: Added tests for Min/MaxHeapFreeRatio flags
Reviewed-by: jwilhelm, tschatzl
Contributed-by: andrey.x.zakharov@oracle.com

test/TEST.groups file | annotate | diff | comparison | revisions
test/gc/arguments/TestDynMaxHeapFreeRatio.java file | annotate | diff | comparison | revisions
test/gc/arguments/TestDynMinHeapFreeRatio.java file | annotate | diff | comparison | revisions
test/testlibrary/com/oracle/java/testlibrary/DynamicVMOptionChecker.java file | annotate | diff | comparison | revisions
test/testlibrary/com/oracle/java/testlibrary/TestDynamicVMOption.java file | annotate | diff | comparison | revisions
     1.1 --- a/test/TEST.groups	Thu Mar 20 13:29:03 2014 -0700
     1.2 +++ b/test/TEST.groups	Thu Mar 20 16:31:47 2014 +0100
     1.3 @@ -130,6 +130,8 @@
     1.4    gc/g1/TestHumongousAllocInitialMark.java \
     1.5    gc/arguments/TestG1HeapRegionSize.java \
     1.6    gc/metaspace/TestMetaspaceMemoryPool.java \
     1.7 +  gc/arguments/TestDynMinHeapFreeRatio.java \
     1.8 +  gc/arguments/TestDynMaxHeapFreeRatio.java \
     1.9    runtime/InternalApi/ThreadCpuTimesDeadlock.java \
    1.10    serviceability/threads/TestFalseDeadLock.java \
    1.11    compiler/tiered/NonTieredLevelsTest.java \
     2.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     2.2 +++ b/test/gc/arguments/TestDynMaxHeapFreeRatio.java	Thu Mar 20 16:31:47 2014 +0100
     2.3 @@ -0,0 +1,64 @@
     2.4 +/*
     2.5 + * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
     2.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     2.7 + *
     2.8 + * This code is free software; you can redistribute it and/or modify it
     2.9 + * under the terms of the GNU General Public License version 2 only, as
    2.10 + * published by the Free Software Foundation.
    2.11 + *
    2.12 + * This code is distributed in the hope that it will be useful, but WITHOUT
    2.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    2.14 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
    2.15 + * version 2 for more details (a copy is included in the LICENSE file that
    2.16 + * accompanied this code).
    2.17 + *
    2.18 + * You should have received a copy of the GNU General Public License version
    2.19 + * 2 along with this work; if not, write to the Free Software Foundation,
    2.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
    2.21 + *
    2.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
    2.23 + * or visit www.oracle.com if you need additional information or have any
    2.24 + * questions.
    2.25 + */
    2.26 +
    2.27 +/**
    2.28 + * @test TestDynMaxHeapFreeRatio
    2.29 + * @bug 8028391
    2.30 + * @summary Verify that MaxHeapFreeRatio flag is manageable
    2.31 + * @library /testlibrary
    2.32 + * @run main TestDynMaxHeapFreeRatio
    2.33 + * @run main/othervm -XX:MinHeapFreeRatio=0 -XX:MaxHeapFreeRatio=100 TestDynMaxHeapFreeRatio
    2.34 + * @run main/othervm -XX:MinHeapFreeRatio=10 -XX:MaxHeapFreeRatio=50 -XX:-UseAdaptiveSizePolicy TestDynMaxHeapFreeRatio
    2.35 + * @run main/othervm -XX:MinHeapFreeRatio=10 -XX:MaxHeapFreeRatio=50 TestDynMaxHeapFreeRatio
    2.36 + * @run main/othervm -XX:MinHeapFreeRatio=51 -XX:MaxHeapFreeRatio=52 TestDynMaxHeapFreeRatio
    2.37 + * @run main/othervm -XX:MinHeapFreeRatio=75 -XX:MaxHeapFreeRatio=100 TestDynMaxHeapFreeRatio
    2.38 + */
    2.39 +import com.oracle.java.testlibrary.TestDynamicVMOption;
    2.40 +import com.oracle.java.testlibrary.DynamicVMOptionChecker;
    2.41 +
    2.42 +public class TestDynMaxHeapFreeRatio extends TestDynamicVMOption {
    2.43 +
    2.44 +    public static final String MinFreeRatioFlagName = "MinHeapFreeRatio";
    2.45 +    public static final String MaxFreeRatioFlagName = "MaxHeapFreeRatio";
    2.46 +
    2.47 +    public TestDynMaxHeapFreeRatio() {
    2.48 +        super(MaxFreeRatioFlagName);
    2.49 +    }
    2.50 +
    2.51 +    public void test() {
    2.52 +
    2.53 +        int minHeapFreeValue = DynamicVMOptionChecker.getIntValue(MinFreeRatioFlagName);
    2.54 +        System.out.println(MinFreeRatioFlagName + " = " + minHeapFreeValue);
    2.55 +
    2.56 +        testPercentageValues();
    2.57 +
    2.58 +        checkInvalidValue(Integer.toString(minHeapFreeValue - 1));
    2.59 +        checkValidValue(Integer.toString(minHeapFreeValue));
    2.60 +        checkValidValue("100");
    2.61 +    }
    2.62 +
    2.63 +    public static void main(String args[]) throws Exception {
    2.64 +        new TestDynMaxHeapFreeRatio().test();
    2.65 +    }
    2.66 +
    2.67 +}
     3.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     3.2 +++ b/test/gc/arguments/TestDynMinHeapFreeRatio.java	Thu Mar 20 16:31:47 2014 +0100
     3.3 @@ -0,0 +1,62 @@
     3.4 +/*
     3.5 + * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
     3.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     3.7 + *
     3.8 + * This code is free software; you can redistribute it and/or modify it
     3.9 + * under the terms of the GNU General Public License version 2 only, as
    3.10 + * published by the Free Software Foundation.
    3.11 + *
    3.12 + * This code is distributed in the hope that it will be useful, but WITHOUT
    3.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    3.14 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
    3.15 + * version 2 for more details (a copy is included in the LICENSE file that
    3.16 + * accompanied this code).
    3.17 + *
    3.18 + * You should have received a copy of the GNU General Public License version
    3.19 + * 2 along with this work; if not, write to the Free Software Foundation,
    3.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
    3.21 + *
    3.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
    3.23 + * or visit www.oracle.com if you need additional information or have any
    3.24 + * questions.
    3.25 + */
    3.26 +
    3.27 +/**
    3.28 + * @test TestDynMinHeapFreeRatio
    3.29 + * @bug 8028391
    3.30 + * @summary Verify that MinHeapFreeRatio flag is manageable
    3.31 + * @library /testlibrary
    3.32 + * @run main TestDynMinHeapFreeRatio
    3.33 + * @run main/othervm -XX:MinHeapFreeRatio=0 -XX:MaxHeapFreeRatio=100 TestDynMinHeapFreeRatio
    3.34 + * @run main/othervm -XX:MinHeapFreeRatio=10 -XX:MaxHeapFreeRatio=50 -XX:-UseAdaptiveSizePolicy TestDynMinHeapFreeRatio
    3.35 + * @run main/othervm -XX:MinHeapFreeRatio=10 -XX:MaxHeapFreeRatio=50 TestDynMinHeapFreeRatio
    3.36 + * @run main/othervm -XX:MinHeapFreeRatio=51 -XX:MaxHeapFreeRatio=52 TestDynMinHeapFreeRatio
    3.37 + * @run main/othervm -XX:MinHeapFreeRatio=75 -XX:MaxHeapFreeRatio=100 TestDynMinHeapFreeRatio
    3.38 + */
    3.39 +import com.oracle.java.testlibrary.TestDynamicVMOption;
    3.40 +import com.oracle.java.testlibrary.DynamicVMOptionChecker;
    3.41 +
    3.42 +public class TestDynMinHeapFreeRatio extends TestDynamicVMOption {
    3.43 +
    3.44 +    public static final String MinFreeRatioFlagName = "MinHeapFreeRatio";
    3.45 +    public static final String MaxFreeRatioFlagName = "MaxHeapFreeRatio";
    3.46 +
    3.47 +    public TestDynMinHeapFreeRatio() {
    3.48 +        super(MinFreeRatioFlagName);
    3.49 +    }
    3.50 +
    3.51 +    public void test() {
    3.52 +        int maxHeapFreeValue = DynamicVMOptionChecker.getIntValue(MaxFreeRatioFlagName);
    3.53 +        System.out.println(MaxFreeRatioFlagName + " = " + maxHeapFreeValue);
    3.54 +
    3.55 +        testPercentageValues();
    3.56 +
    3.57 +        checkInvalidValue(Integer.toString(maxHeapFreeValue + 1));
    3.58 +        checkValidValue(Integer.toString(maxHeapFreeValue));
    3.59 +        checkValidValue("0");
    3.60 +    }
    3.61 +
    3.62 +    public static void main(String args[]) throws Exception {
    3.63 +        new TestDynMinHeapFreeRatio().test();
    3.64 +    }
    3.65 +}
     4.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     4.2 +++ b/test/testlibrary/com/oracle/java/testlibrary/DynamicVMOptionChecker.java	Thu Mar 20 16:31:47 2014 +0100
     4.3 @@ -0,0 +1,121 @@
     4.4 +/*
     4.5 + * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
     4.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     4.7 + *
     4.8 + * This code is free software; you can redistribute it and/or modify it
     4.9 + * under the terms of the GNU General Public License version 2 only, as
    4.10 + * published by the Free Software Foundation.
    4.11 + *
    4.12 + * This code is distributed in the hope that it will be useful, but WITHOUT
    4.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    4.14 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
    4.15 + * version 2 for more details (a copy is included in the LICENSE file that
    4.16 + * accompanied this code).
    4.17 + *
    4.18 + * You should have received a copy of the GNU General Public License version
    4.19 + * 2 along with this work; if not, write to the Free Software Foundation,
    4.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
    4.21 + *
    4.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
    4.23 + * or visit www.oracle.com if you need additional information or have any
    4.24 + * questions.
    4.25 + */
    4.26 +package com.oracle.java.testlibrary;
    4.27 +
    4.28 +import com.sun.management.HotSpotDiagnosticMXBean;
    4.29 +import com.sun.management.VMOption;
    4.30 +import java.lang.management.ManagementFactory;
    4.31 +
    4.32 +/**
    4.33 + * Simple class to check writeability, invalid and valid values for VMOption
    4.34 + */
    4.35 +public class DynamicVMOptionChecker {
    4.36 +
    4.37 +    /**
    4.38 +     * Reads VM option from PlatformMXBean and parse it to integer value
    4.39 +     *
    4.40 +     * @param name of option
    4.41 +     * @return parsed value
    4.42 +     */
    4.43 +    public static int getIntValue(String name) {
    4.44 +
    4.45 +        VMOption option = ManagementFactory.
    4.46 +                getPlatformMXBean(HotSpotDiagnosticMXBean.class).
    4.47 +                getVMOption(name);
    4.48 +
    4.49 +        return Integer.parseInt(option.getValue());
    4.50 +    }
    4.51 +
    4.52 +    /**
    4.53 +     * Sets VM option value
    4.54 +     *
    4.55 +     * @param name of option
    4.56 +     * @param value to set
    4.57 +     */
    4.58 +    public static void setIntValue(String name, int value) {
    4.59 +        ManagementFactory.getPlatformMXBean(HotSpotDiagnosticMXBean.class).setVMOption(name, Integer.toString(value));
    4.60 +    }
    4.61 +
    4.62 +    /**
    4.63 +     * Checks that VM option is dynamically writable
    4.64 +     *
    4.65 +     * @param name
    4.66 +     * @throws RuntimeException if option if not writable
    4.67 +     * @return always true
    4.68 +     */
    4.69 +    public static boolean checkIsWritable(String name) {
    4.70 +        VMOption option = ManagementFactory.
    4.71 +                getPlatformMXBean(HotSpotDiagnosticMXBean.class).
    4.72 +                getVMOption(name);
    4.73 +
    4.74 +        if (!option.isWriteable()) {
    4.75 +            throw new RuntimeException(name + " is not writable");
    4.76 +        }
    4.77 +
    4.78 +        return true;
    4.79 +    }
    4.80 +
    4.81 +    /**
    4.82 +     * Checks that value cannot be set
    4.83 +     *
    4.84 +     * @param name of flag
    4.85 +     * @param value string representation of value to set
    4.86 +     * @throws RuntimeException on error - when expected exception hasn't been thrown
    4.87 +     */
    4.88 +    public static void checkInvalidValue(String name, String value) {
    4.89 +        // should throw
    4.90 +        try {
    4.91 +            ManagementFactory.
    4.92 +                    getPlatformMXBean(HotSpotDiagnosticMXBean.class).
    4.93 +                    setVMOption(name, value);
    4.94 +
    4.95 +        } catch (IllegalArgumentException e) {
    4.96 +            return;
    4.97 +        }
    4.98 +
    4.99 +        throw new RuntimeException("Expected IllegalArgumentException was not thrown, " + name + "= " + value);
   4.100 +    }
   4.101 +
   4.102 +    /**
   4.103 +     * Checks that value can be set
   4.104 +     *
   4.105 +     * @param name of flag to set
   4.106 +     * @param value string representation of value to set
   4.107 +     * @throws RuntimeException on error - when value in VM is not equal to origin
   4.108 +     */
   4.109 +    public static void checkValidValue(String name, String value) {
   4.110 +        ManagementFactory.
   4.111 +                getPlatformMXBean(HotSpotDiagnosticMXBean.class).
   4.112 +                setVMOption(name, value);
   4.113 +
   4.114 +        VMOption option = ManagementFactory.
   4.115 +                getPlatformMXBean(HotSpotDiagnosticMXBean.class).
   4.116 +                getVMOption(name);
   4.117 +
   4.118 +        if (!option.getValue().equals(value)) {
   4.119 +            throw new RuntimeException("Actual value of " + name + " \"" + option.getValue()
   4.120 +                    + "\" not equal origin \"" + value + "\"");
   4.121 +        }
   4.122 +    }
   4.123 +
   4.124 +}
     5.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     5.2 +++ b/test/testlibrary/com/oracle/java/testlibrary/TestDynamicVMOption.java	Thu Mar 20 16:31:47 2014 +0100
     5.3 @@ -0,0 +1,104 @@
     5.4 +/*
     5.5 + * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
     5.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     5.7 + *
     5.8 + * This code is free software; you can redistribute it and/or modify it
     5.9 + * under the terms of the GNU General Public License version 2 only, as
    5.10 + * published by the Free Software Foundation.
    5.11 + *
    5.12 + * This code is distributed in the hope that it will be useful, but WITHOUT
    5.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    5.14 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
    5.15 + * version 2 for more details (a copy is included in the LICENSE file that
    5.16 + * accompanied this code).
    5.17 + *
    5.18 + * You should have received a copy of the GNU General Public License version
    5.19 + * 2 along with this work; if not, write to the Free Software Foundation,
    5.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
    5.21 + *
    5.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
    5.23 + * or visit www.oracle.com if you need additional information or have any
    5.24 + * questions.
    5.25 + */
    5.26 +package com.oracle.java.testlibrary;
    5.27 +
    5.28 +/**
    5.29 + * Simple class to check writeability, invalid and valid values for concrete VMOption
    5.30 + */
    5.31 +public class TestDynamicVMOption {
    5.32 +
    5.33 +    private final String name;
    5.34 +    private final int value;
    5.35 +
    5.36 +    /**
    5.37 +     * Constructor
    5.38 +     *
    5.39 +     * @param name of VM option to test
    5.40 +     */
    5.41 +    public TestDynamicVMOption(String name) {
    5.42 +        this.name = name;
    5.43 +        this.value = DynamicVMOptionChecker.getIntValue(name);
    5.44 +        System.out.println(this.name + " = " + this.value);
    5.45 +    }
    5.46 +
    5.47 +    /**
    5.48 +     * Checks that this value can accept valid percentage values and cannot accept invalid percentage values
    5.49 +     *
    5.50 +     * @throws RuntimeException
    5.51 +     */
    5.52 +    public void testPercentageValues() {
    5.53 +        checkInvalidValue(Integer.toString(Integer.MIN_VALUE));
    5.54 +        checkInvalidValue(Integer.toString(Integer.MAX_VALUE));
    5.55 +        checkInvalidValue("-10");
    5.56 +        checkInvalidValue("190");
    5.57 +    }
    5.58 +
    5.59 +    /**
    5.60 +     * Reads VM option from PlatformMXBean and parse it to integer value
    5.61 +     *
    5.62 +     * @return value
    5.63 +     */
    5.64 +    public int getIntValue() {
    5.65 +        return DynamicVMOptionChecker.getIntValue(this.name);
    5.66 +    }
    5.67 +
    5.68 +    /**
    5.69 +     * Sets VM option value
    5.70 +     *
    5.71 +     * @param value to set
    5.72 +     */
    5.73 +    public void setIntValue(int value) {
    5.74 +        DynamicVMOptionChecker.setIntValue(this.name, value);
    5.75 +    }
    5.76 +
    5.77 +    /**
    5.78 +     * Checks that this VM option is dynamically writable
    5.79 +     *
    5.80 +     * @throws RuntimeException if option if not writable
    5.81 +     * @return true
    5.82 +     */
    5.83 +    public boolean checkIsWritable() throws RuntimeException {
    5.84 +        return DynamicVMOptionChecker.checkIsWritable(this.name);
    5.85 +    }
    5.86 +
    5.87 +    /**
    5.88 +     * Checks that value for this VM option cannot be set
    5.89 +     *
    5.90 +     * @param value to check
    5.91 +     * @throws RuntimeException on error - when expected exception hasn't been thrown
    5.92 +     */
    5.93 +    public void checkInvalidValue(String value) {
    5.94 +        DynamicVMOptionChecker.checkInvalidValue(this.name, value);
    5.95 +    }
    5.96 +
    5.97 +    /**
    5.98 +     * Checks that value for this VM option can be set
    5.99 +     *
   5.100 +     * @param value to check
   5.101 +     * @throws RuntimeException on error - when value in VM is not equal to origin
   5.102 +     */
   5.103 +    public void checkValidValue(String value) {
   5.104 +        DynamicVMOptionChecker.checkValidValue(this.name, value);
   5.105 +    }
   5.106 +
   5.107 +}

mercurial