test/hotspot/jtreg/gc/arguments/TestMaxMinHeapFreeRatioFlags.java
author sjohanss
Tue, 14 Nov 2017 11:33:23 +0100
changeset 47885 5caa1d5f74c1
parent 47216 71c04702a3d5
child 50525 767cdb97f103
permissions -rw-r--r--
8186571: Implementation: JEP 307: Parallel Full GC for G1 Summary: Improve G1 worst-case latencies by making the full GC parallel. Reviewed-by: tschatzl, sangheki, ehelin
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
32625
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
     1
/*
47885
5caa1d5f74c1 8186571: Implementation: JEP 307: Parallel Full GC for G1
sjohanss
parents: 47216
diff changeset
     2
 * Copyright (c) 2016, 2017, Oracle and/or its affiliates. All rights reserved.
41705
332239c052cc 8165687: Fix license and copyright headers in jd9 under hotspot/test
stsmirno
parents: 41092
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
332239c052cc 8165687: Fix license and copyright headers in jd9 under hotspot/test
stsmirno
parents: 41092
diff changeset
     4
 *
332239c052cc 8165687: Fix license and copyright headers in jd9 under hotspot/test
stsmirno
parents: 41092
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
332239c052cc 8165687: Fix license and copyright headers in jd9 under hotspot/test
stsmirno
parents: 41092
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
332239c052cc 8165687: Fix license and copyright headers in jd9 under hotspot/test
stsmirno
parents: 41092
diff changeset
     7
 * published by the Free Software Foundation.
332239c052cc 8165687: Fix license and copyright headers in jd9 under hotspot/test
stsmirno
parents: 41092
diff changeset
     8
 *
332239c052cc 8165687: Fix license and copyright headers in jd9 under hotspot/test
stsmirno
parents: 41092
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
332239c052cc 8165687: Fix license and copyright headers in jd9 under hotspot/test
stsmirno
parents: 41092
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
332239c052cc 8165687: Fix license and copyright headers in jd9 under hotspot/test
stsmirno
parents: 41092
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
332239c052cc 8165687: Fix license and copyright headers in jd9 under hotspot/test
stsmirno
parents: 41092
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
332239c052cc 8165687: Fix license and copyright headers in jd9 under hotspot/test
stsmirno
parents: 41092
diff changeset
    13
 * accompanied this code).
332239c052cc 8165687: Fix license and copyright headers in jd9 under hotspot/test
stsmirno
parents: 41092
diff changeset
    14
 *
332239c052cc 8165687: Fix license and copyright headers in jd9 under hotspot/test
stsmirno
parents: 41092
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
332239c052cc 8165687: Fix license and copyright headers in jd9 under hotspot/test
stsmirno
parents: 41092
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
332239c052cc 8165687: Fix license and copyright headers in jd9 under hotspot/test
stsmirno
parents: 41092
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
332239c052cc 8165687: Fix license and copyright headers in jd9 under hotspot/test
stsmirno
parents: 41092
diff changeset
    18
 *
332239c052cc 8165687: Fix license and copyright headers in jd9 under hotspot/test
stsmirno
parents: 41092
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
332239c052cc 8165687: Fix license and copyright headers in jd9 under hotspot/test
stsmirno
parents: 41092
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
332239c052cc 8165687: Fix license and copyright headers in jd9 under hotspot/test
stsmirno
parents: 41092
diff changeset
    21
 * questions.
332239c052cc 8165687: Fix license and copyright headers in jd9 under hotspot/test
stsmirno
parents: 41092
diff changeset
    22
 */
32625
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
    23
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
    24
/*
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
    25
 * @test TestMaxMinHeapFreeRatioFlags
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
    26
 * @key gc
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
    27
 * @summary Verify that heap size changes according to max and min heap free ratios.
40631
ed82623d7831 8157957: ClassNotFoundException: jdk.test.lib.JDKToolFinder
ctornqvi
parents: 40244
diff changeset
    28
 * @library /test/lib
36851
03e2f4d0a421 8153737: Unsupported Module
chegar
parents: 32625
diff changeset
    29
 * @modules java.base/jdk.internal.misc
32625
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
    30
 *          java.management
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
    31
 * @run driver/timeout=240 TestMaxMinHeapFreeRatioFlags
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
    32
 */
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
    33
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
    34
import java.util.LinkedList;
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
    35
import java.util.Arrays;
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
    36
import java.util.Collections;
40631
ed82623d7831 8157957: ClassNotFoundException: jdk.test.lib.JDKToolFinder
ctornqvi
parents: 40244
diff changeset
    37
import jdk.test.lib.process.OutputAnalyzer;
ed82623d7831 8157957: ClassNotFoundException: jdk.test.lib.JDKToolFinder
ctornqvi
parents: 40244
diff changeset
    38
import jdk.test.lib.process.ProcessTools;
32625
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
    39
import jdk.test.lib.Utils;
38152
80e5da81fb2c 8154258: [TESTBUG] Various serviceability tests fail compilation
dsamersoff
parents: 37477
diff changeset
    40
import jdk.internal.misc.Unsafe;
32625
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
    41
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
    42
public class TestMaxMinHeapFreeRatioFlags {
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
    43
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
    44
    public static final long M = 1024 * 1024;
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
    45
    public static final long MAX_HEAP_SIZE = 200 * M;
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
    46
    public static final long HEAP_SIZE = 10 * M;
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
    47
    public static final long MAX_NEW_SIZE = 20 * M;
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
    48
    public static final long NEW_SIZE = 5 * M;
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
    49
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
    50
    public static void main(String args[]) throws Exception {
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
    51
        LinkedList<String> options = new LinkedList<>(
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
    52
                Arrays.asList(Utils.getFilteredTestJavaOpts("-XX:[^ ]*HeapFreeRatio","-XX:\\+ExplicitGCInvokesConcurrent"))
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
    53
        );
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
    54
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
    55
        negativeTest(20, false, 10, true, options);
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
    56
        negativeTest(100, true, 0, false, options);
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
    57
        negativeTest(101, false, 50, false, options);
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
    58
        negativeTest(49, true, 102, true, options);
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
    59
        negativeTest(-1, false, 50, false, options);
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
    60
        negativeTest(50, true, -1, true, options);
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
    61
37166
8a5f1594e692 8146436: Add -XX:-ShrinkHeapInSteps option (previously -XX:+UseAggressiveHeapShrink)
cjplummer
parents: 32625
diff changeset
    62
        positiveTest(10, false, 90, false, true, options);
8a5f1594e692 8146436: Add -XX:-ShrinkHeapInSteps option (previously -XX:+UseAggressiveHeapShrink)
cjplummer
parents: 32625
diff changeset
    63
        positiveTest(10, true, 80, false, true, options);
8a5f1594e692 8146436: Add -XX:-ShrinkHeapInSteps option (previously -XX:+UseAggressiveHeapShrink)
cjplummer
parents: 32625
diff changeset
    64
        positiveTest(20, false, 70, true, true, options);
8a5f1594e692 8146436: Add -XX:-ShrinkHeapInSteps option (previously -XX:+UseAggressiveHeapShrink)
cjplummer
parents: 32625
diff changeset
    65
        positiveTest(25, true, 65, true, true, options);
8a5f1594e692 8146436: Add -XX:-ShrinkHeapInSteps option (previously -XX:+UseAggressiveHeapShrink)
cjplummer
parents: 32625
diff changeset
    66
        positiveTest(40, false, 50, false, true, options);
32625
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
    67
    }
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
    68
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
    69
    /**
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
    70
     * Verify that heap size will be changed to conform
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
    71
     * min and max heap free ratios.
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
    72
     *
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
    73
     * @param minRatio value of MinHeapFreeRatio option
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
    74
     * @param useXminf used Xminf option instead of MinHeapFreeRatio
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
    75
     * @param maxRatio value of MaxHeapFreeRatio option
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
    76
     * @param useXmaxf used Xmaxf option instead of MaxHeapFreeRatio
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
    77
     * @param options additional options for JVM
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
    78
     */
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
    79
    public static void positiveTest(int minRatio, boolean useXminf,
37166
8a5f1594e692 8146436: Add -XX:-ShrinkHeapInSteps option (previously -XX:+UseAggressiveHeapShrink)
cjplummer
parents: 32625
diff changeset
    80
            int maxRatio, boolean useXmaxf, boolean shrinkHeapInSteps,
32625
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
    81
            LinkedList<String> options) throws Exception {
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
    82
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
    83
        LinkedList<String> vmOptions = new LinkedList<>(options);
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
    84
        Collections.addAll(vmOptions,
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
    85
                (useXminf ? "-Xminf" + minRatio / 100.0 : "-XX:MinHeapFreeRatio=" + minRatio),
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
    86
                (useXmaxf ? "-Xmaxf" + maxRatio / 100.0 : "-XX:MaxHeapFreeRatio=" + maxRatio),
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
    87
                "-Xmx" + MAX_HEAP_SIZE,
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
    88
                "-Xms" + HEAP_SIZE,
40244
b3055c216762 8136930: Simplify use of module-system options by custom launchers
hseigel
parents: 38152
diff changeset
    89
                "--add-exports=java.base/jdk.internal.misc=ALL-UNNAMED",
32625
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
    90
                "-XX:NewSize=" + NEW_SIZE,
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
    91
                "-XX:MaxNewSize=" + MAX_NEW_SIZE,
37166
8a5f1594e692 8146436: Add -XX:-ShrinkHeapInSteps option (previously -XX:+UseAggressiveHeapShrink)
cjplummer
parents: 32625
diff changeset
    92
                "-XX:" + (shrinkHeapInSteps ? '+' : '-') + "ShrinkHeapInSteps",
32625
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
    93
                RatioVerifier.class.getName(),
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
    94
                Integer.toString(minRatio),
37166
8a5f1594e692 8146436: Add -XX:-ShrinkHeapInSteps option (previously -XX:+UseAggressiveHeapShrink)
cjplummer
parents: 32625
diff changeset
    95
                Integer.toString(maxRatio),
8a5f1594e692 8146436: Add -XX:-ShrinkHeapInSteps option (previously -XX:+UseAggressiveHeapShrink)
cjplummer
parents: 32625
diff changeset
    96
                Boolean.toString(shrinkHeapInSteps)
32625
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
    97
        );
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
    98
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
    99
        ProcessBuilder procBuilder = ProcessTools.createJavaProcessBuilder(vmOptions.toArray(new String[vmOptions.size()]));
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
   100
        OutputAnalyzer analyzer = new OutputAnalyzer(procBuilder.start());
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
   101
        analyzer.shouldHaveExitValue(0);
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
   102
    }
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
   103
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
   104
    /**
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
   105
     * Verify that VM will fail to start with specified ratios.
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
   106
     *
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
   107
     * @param minRatio value of MinHeapFreeRatio option
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
   108
     * @param useXminf used Xminf option instead of MinHeapFreeRatio
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
   109
     * @param maxRatio value of MaxHeapFreeRatio option
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
   110
     * @param useXmaxf used Xmaxf option instead of MaxHeapFreeRatio
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
   111
     * @param options additional options for JVM
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
   112
     */
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
   113
    public static void negativeTest(int minRatio, boolean useXminf,
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
   114
            int maxRatio, boolean useXmaxf,
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
   115
            LinkedList<String> options) throws Exception {
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
   116
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
   117
        LinkedList<String> vmOptions = new LinkedList<>(options);
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
   118
        Collections.addAll(vmOptions,
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
   119
                (useXminf ? "-Xminf" + minRatio / 100.0 : "-XX:MinHeapFreeRatio=" + minRatio),
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
   120
                (useXmaxf ? "-Xmaxf" + maxRatio / 100.0 : "-XX:MaxHeapFreeRatio=" + maxRatio),
40244
b3055c216762 8136930: Simplify use of module-system options by custom launchers
hseigel
parents: 38152
diff changeset
   121
                "--add-exports=java.base/jdk.internal.misc=ALL-UNNAMED",
32625
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
   122
                "-version"
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
   123
        );
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
   124
        ProcessBuilder procBuilder = ProcessTools.createJavaProcessBuilder(vmOptions.toArray(new String[vmOptions.size()]));
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
   125
        OutputAnalyzer analyzer = new OutputAnalyzer(procBuilder.start());
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
   126
        analyzer.shouldHaveExitValue(1);
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
   127
        analyzer.shouldContain("Error: Could not create the Java Virtual Machine.");
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
   128
    }
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
   129
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
   130
    /**
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
   131
     * RatioVerifier will be executed in the tested VM.
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
   132
     * It will check that real heap usage after collection lies between MinHeapFreeRatio and MaxHeapFreeRatio.
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
   133
     */
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
   134
    public static class RatioVerifier {
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
   135
41092
c388d897472d 8165889: Remove jdk.test.lib.unsafe.UnsafeHelper
gtriantafill
parents: 40855
diff changeset
   136
        private static final Unsafe unsafe = Unsafe.getUnsafe();
32625
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
   137
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
   138
        // Size of byte array that will be allocated
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
   139
        public static final int CHUNK_SIZE = 1024;
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
   140
        // Length of byte array, that will be added to "garbage" list.
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
   141
        public static final int ARRAY_LENGTH = CHUNK_SIZE - Unsafe.ARRAY_BYTE_BASE_OFFSET;
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
   142
        // Amount of tries to force heap shrinking/expansion using GC
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
   143
        public static final int GC_TRIES = 10;
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
   144
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
   145
        // Value that will be added/substracted from expected min/max heap free ratio
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
   146
        // during memory allocation to make sure that specified limit will be exceeded.
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
   147
        public static final double OVERLOAD = 0.05;
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
   148
        // Acceptable heap free ratio limit exceedance: verification will fail if
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
   149
        // actual ratio is lower than expected min heap free ratio - VARIANCE or
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
   150
        // higher than expected max heap free ratio + VARIANCE.
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
   151
        public static final double VARIANCE = 0.025;
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
   152
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
   153
        public static LinkedList<Object> garbage = new LinkedList<>();
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
   154
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
   155
        public static void main(String args[]) throws Exception {
37166
8a5f1594e692 8146436: Add -XX:-ShrinkHeapInSteps option (previously -XX:+UseAggressiveHeapShrink)
cjplummer
parents: 32625
diff changeset
   156
            if (args.length != 3) {
8a5f1594e692 8146436: Add -XX:-ShrinkHeapInSteps option (previously -XX:+UseAggressiveHeapShrink)
cjplummer
parents: 32625
diff changeset
   157
                throw new IllegalArgumentException("Expected 3 args: <minRatio> <maxRatio> <shrinkHeapInSteps>");
32625
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
   158
            }
47885
5caa1d5f74c1 8186571: Implementation: JEP 307: Parallel Full GC for G1
sjohanss
parents: 47216
diff changeset
   159
            if (GCTypes.OldGCType.getOldGCType() == GCTypes.OldGCType.PSOld ||
5caa1d5f74c1 8186571: Implementation: JEP 307: Parallel Full GC for G1
sjohanss
parents: 47216
diff changeset
   160
                GCTypes.OldGCType.getOldGCType() == GCTypes.OldGCType.G1) {
5caa1d5f74c1 8186571: Implementation: JEP 307: Parallel Full GC for G1
sjohanss
parents: 47216
diff changeset
   161
                System.out.println("Test is not applicable to parallel full GCs");
32625
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
   162
                return;
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
   163
            }
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
   164
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
   165
            double minRatio = Integer.valueOf(args[0]) / 100.0;
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
   166
            double maxRatio = Integer.valueOf(args[1]) / 100.0;
37166
8a5f1594e692 8146436: Add -XX:-ShrinkHeapInSteps option (previously -XX:+UseAggressiveHeapShrink)
cjplummer
parents: 32625
diff changeset
   167
            boolean shrinkHeapInSteps = Boolean.valueOf(args[2]);
32625
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
   168
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
   169
            long maxHeapSize = getMax();
37166
8a5f1594e692 8146436: Add -XX:-ShrinkHeapInSteps option (previously -XX:+UseAggressiveHeapShrink)
cjplummer
parents: 32625
diff changeset
   170
            int gcTries = (shrinkHeapInSteps ? GC_TRIES : 1);
32625
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
   171
37412
d5f8d53af5ec 8153277: [TESTBUG] gc/arguments/TestMaxMinHeapFreeRatioFlags is too sensitive for stray allocations in verifyRatio
shade
parents: 37166
diff changeset
   172
            // Initial checks. This also links up everything in these helper methods,
d5f8d53af5ec 8153277: [TESTBUG] gc/arguments/TestMaxMinHeapFreeRatioFlags is too sensitive for stray allocations in verifyRatio
shade
parents: 37166
diff changeset
   173
            // in case it brings more garbage.
d5f8d53af5ec 8153277: [TESTBUG] gc/arguments/TestMaxMinHeapFreeRatioFlags is too sensitive for stray allocations in verifyRatio
shade
parents: 37166
diff changeset
   174
            forceGC(gcTries);
d5f8d53af5ec 8153277: [TESTBUG] gc/arguments/TestMaxMinHeapFreeRatioFlags is too sensitive for stray allocations in verifyRatio
shade
parents: 37166
diff changeset
   175
            verifyRatio(minRatio, maxRatio);
d5f8d53af5ec 8153277: [TESTBUG] gc/arguments/TestMaxMinHeapFreeRatioFlags is too sensitive for stray allocations in verifyRatio
shade
parents: 37166
diff changeset
   176
32625
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
   177
            // commit 0.5 of total heap size to have enough space
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
   178
            // to both shink and expand
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
   179
            while (getCommitted() < maxHeapSize / 2) {
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
   180
                garbage.add(new byte[ARRAY_LENGTH]);
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
   181
            }
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
   182
37166
8a5f1594e692 8146436: Add -XX:-ShrinkHeapInSteps option (previously -XX:+UseAggressiveHeapShrink)
cjplummer
parents: 32625
diff changeset
   183
            forceGC(gcTries);
32625
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
   184
            // Verify that current heap free ratio lies between specified limits
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
   185
            verifyRatio(minRatio, maxRatio);
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
   186
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
   187
            // Estimate how much memory we have to allocate to force expansion
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
   188
            long memoryToFill = (long) (getCommitted() * (1 - minRatio + OVERLOAD))
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
   189
                    - getUsed();
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
   190
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
   191
            long previouslyCommitted = getCommitted();
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
   192
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
   193
            while (memoryToFill > 0) {
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
   194
                garbage.add(new byte[CHUNK_SIZE]);
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
   195
                memoryToFill -= CHUNK_SIZE;
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
   196
            }
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
   197
37166
8a5f1594e692 8146436: Add -XX:-ShrinkHeapInSteps option (previously -XX:+UseAggressiveHeapShrink)
cjplummer
parents: 32625
diff changeset
   198
            forceGC(gcTries);
32625
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
   199
            // Verify that after memory allocation heap free ratio is still conforming specified limits
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
   200
            verifyRatio(minRatio, maxRatio);
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
   201
            // Verify that heap was actually expanded
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
   202
            if (previouslyCommitted >= getCommitted()) {
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
   203
                throw new RuntimeException("Heap was not expanded.");
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
   204
            }
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
   205
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
   206
            // Estimate how much memory we have to free to force shrinking
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
   207
            long memoryToFree = getUsed()
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
   208
                    - (long) (getCommitted() * (1 - maxRatio - OVERLOAD));
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
   209
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
   210
            previouslyCommitted = getCommitted();
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
   211
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
   212
            while (memoryToFree > 0 && garbage.size() > 0) {
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
   213
                garbage.remove(garbage.size() - 1);
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
   214
                memoryToFree -= CHUNK_SIZE;
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
   215
            }
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
   216
37166
8a5f1594e692 8146436: Add -XX:-ShrinkHeapInSteps option (previously -XX:+UseAggressiveHeapShrink)
cjplummer
parents: 32625
diff changeset
   217
            forceGC(gcTries);
32625
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
   218
            // Verify that heap free ratio is still conforming specified limits
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
   219
            verifyRatio(minRatio, maxRatio);
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
   220
            // Verify that heap was actually shrinked
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
   221
            if (previouslyCommitted <= getCommitted()) {
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
   222
                throw new RuntimeException("Heap was not shrinked.");
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
   223
            }
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
   224
        }
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
   225
37166
8a5f1594e692 8146436: Add -XX:-ShrinkHeapInSteps option (previously -XX:+UseAggressiveHeapShrink)
cjplummer
parents: 32625
diff changeset
   226
        public static void forceGC(int gcTries) {
8a5f1594e692 8146436: Add -XX:-ShrinkHeapInSteps option (previously -XX:+UseAggressiveHeapShrink)
cjplummer
parents: 32625
diff changeset
   227
            for (int i = 0; i < gcTries; i++) {
32625
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
   228
                System.gc();
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
   229
                try {
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
   230
                    Thread.sleep(10);
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
   231
                } catch (InterruptedException ie) {
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
   232
                }
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
   233
            }
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
   234
        }
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
   235
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
   236
        /**
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
   237
         * Verify that heap free ratio is conforming specified limits.
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
   238
         * Actual heap free ratio may be very close to one of specified limits,
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
   239
         * but exceed for more then VARIANCE.
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
   240
         * Verification will also pass if actual ratio is not conforming limits,
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
   241
         * but it is not possible to shrink/expand heap.
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
   242
         */
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
   243
        public static void verifyRatio(double minRatio, double maxRatio) {
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
   244
            double ratio = getHeapFreeRatio();
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
   245
            System.out.println(minRatio + " " + ratio + " " + maxRatio);
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
   246
            if (minRatio - ratio > VARIANCE
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
   247
                    && getCommitted() < getMax()) {
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
   248
                throw new RuntimeException("Current heap free ratio is lower than "
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
   249
                        + "MinHeapFreeRatio (" + ratio + " vs " + minRatio + ").");
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
   250
            }
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
   251
            if (ratio - maxRatio > VARIANCE
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
   252
                    && getUsed() > getInit()) {
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
   253
                throw new RuntimeException("Current heap free ratio is higher than "
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
   254
                        + "MaxHeapFreeRatio (" + ratio + " vs " + maxRatio + ").");
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
   255
            }
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
   256
        }
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
   257
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
   258
        /*
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
   259
         * Obtain information about heap size.
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
   260
         *
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
   261
         * For G1 information summed up for all type of regions,
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
   262
         * because tested options affect overall heap sizing.
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
   263
         *
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
   264
         * For all other GCs return information only for old gen.
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
   265
         */
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
   266
        public static long getMax() {
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
   267
            return HeapRegionUsageTool.getOldUsage().getMax();
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
   268
        }
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
   269
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
   270
        public static long getInit() {
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
   271
            if (GCTypes.OldGCType.getOldGCType() == GCTypes.OldGCType.G1) {
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
   272
                return HeapRegionUsageTool.getEdenUsage().getInit()
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
   273
                        + HeapRegionUsageTool.getSurvivorUsage().getInit()
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
   274
                        + HeapRegionUsageTool.getOldUsage().getInit();
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
   275
            } else {
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
   276
                return HeapRegionUsageTool.getOldUsage().getInit();
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
   277
            }
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
   278
        }
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
   279
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
   280
        public static long getUsed() {
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
   281
            if (GCTypes.OldGCType.getOldGCType() == GCTypes.OldGCType.G1) {
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
   282
                return HeapRegionUsageTool.getEdenUsage().getUsed()
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
   283
                        + HeapRegionUsageTool.getSurvivorUsage().getUsed()
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
   284
                        + HeapRegionUsageTool.getOldUsage().getUsed();
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
   285
            } else {
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
   286
                return HeapRegionUsageTool.getOldUsage().getUsed();
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
   287
            }
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
   288
        }
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
   289
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
   290
        public static long getCommitted() {
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
   291
            if (GCTypes.OldGCType.getOldGCType() == GCTypes.OldGCType.G1) {
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
   292
                return HeapRegionUsageTool.getEdenUsage().getCommitted()
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
   293
                        + HeapRegionUsageTool.getSurvivorUsage().getCommitted()
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
   294
                        + HeapRegionUsageTool.getOldUsage().getCommitted();
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
   295
            } else {
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
   296
                return HeapRegionUsageTool.getOldUsage().getCommitted();
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
   297
            }
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
   298
        }
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
   299
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
   300
        public static long getFree() {
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
   301
            return getCommitted() - getUsed();
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
   302
        }
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
   303
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
   304
        public static double getHeapFreeRatio() {
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
   305
            return getFree() / (double) getCommitted();
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
   306
        }
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
   307
    }
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
   308
}