hotspot/test/gc/arguments/TestMaxMinHeapFreeRatioFlags.java
author dsamersoff
Sun, 01 May 2016 12:47:00 +0300
changeset 38152 80e5da81fb2c
parent 37477 0ca0b7388bb6
child 40244 b3055c216762
permissions -rw-r--r--
8154258: [TESTBUG] Various serviceability tests fail compilation Summary: Replace sun.misc.Unsafe with jdk.internal.misc.Unsafe Reviewed-by: chegar, kvn
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
/*
37166
8a5f1594e692 8146436: Add -XX:-ShrinkHeapInSteps option (previously -XX:+UseAggressiveHeapShrink)
cjplummer
parents: 32625
diff changeset
     2
* Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
32625
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
     3
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
     4
*
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
     5
* This code is free software; you can redistribute it and/or modify it
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
     6
* under the terms of the GNU General Public License version 2 only, as
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
     7
* published by the Free Software Foundation.
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
     8
*
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
     9
* This code is distributed in the hope that it will be useful, but WITHOUT
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
    10
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
    11
* FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
    12
* version 2 for more details (a copy is included in the LICENSE file that
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
    13
* accompanied this code).
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
    14
*
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
    15
* You should have received a copy of the GNU General Public License version
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
    16
* 2 along with this work; if not, write to the Free Software Foundation,
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
    17
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
    18
*
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
    19
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
    20
* or visit www.oracle.com if you need additional information or have any
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
    21
* questions.
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
    22
*/
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.
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
    28
 * @library /testlibrary
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
 * @build TestMaxMinHeapFreeRatioFlags
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
    32
 * @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
    33
 */
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
    34
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.LinkedList;
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.Arrays;
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
    37
import java.util.Collections;
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
    38
import jdk.test.lib.OutputAnalyzer;
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.ProcessTools;
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
    40
import jdk.test.lib.Utils;
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
    41
import jdk.test.lib.HeapRegionUsageTool;
38152
80e5da81fb2c 8154258: [TESTBUG] Various serviceability tests fail compilation
dsamersoff
parents: 37477
diff changeset
    42
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
    43
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
    44
public class TestMaxMinHeapFreeRatioFlags {
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
    45
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 M = 1024 * 1024;
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_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
    48
    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
    49
    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
    50
    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
    51
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
    52
    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
    53
        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
    54
                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
    55
        );
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
    56
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
    57
        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
    58
        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
    59
        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
    60
        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
    61
        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
    62
        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
    63
37166
8a5f1594e692 8146436: Add -XX:-ShrinkHeapInSteps option (previously -XX:+UseAggressiveHeapShrink)
cjplummer
parents: 32625
diff changeset
    64
        positiveTest(10, false, 90, false, true, options);
8a5f1594e692 8146436: Add -XX:-ShrinkHeapInSteps option (previously -XX:+UseAggressiveHeapShrink)
cjplummer
parents: 32625
diff changeset
    65
        positiveTest(10, true, 80, false, true, options);
8a5f1594e692 8146436: Add -XX:-ShrinkHeapInSteps option (previously -XX:+UseAggressiveHeapShrink)
cjplummer
parents: 32625
diff changeset
    66
        positiveTest(20, false, 70, true, true, options);
8a5f1594e692 8146436: Add -XX:-ShrinkHeapInSteps option (previously -XX:+UseAggressiveHeapShrink)
cjplummer
parents: 32625
diff changeset
    67
        positiveTest(25, true, 65, true, true, options);
8a5f1594e692 8146436: Add -XX:-ShrinkHeapInSteps option (previously -XX:+UseAggressiveHeapShrink)
cjplummer
parents: 32625
diff changeset
    68
        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
    69
    }
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
    70
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
    71
    /**
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
    72
     * 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
    73
     * 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
    74
     *
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
    75
     * @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
    76
     * @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
    77
     * @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
    78
     * @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
    79
     * @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
    80
     */
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
    81
    public static void positiveTest(int minRatio, boolean useXminf,
37166
8a5f1594e692 8146436: Add -XX:-ShrinkHeapInSteps option (previously -XX:+UseAggressiveHeapShrink)
cjplummer
parents: 32625
diff changeset
    82
            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
    83
            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
    84
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
    85
        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
    86
        Collections.addAll(vmOptions,
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
    87
                (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
    88
                (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
    89
                "-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
    90
                "-Xms" + HEAP_SIZE,
38152
80e5da81fb2c 8154258: [TESTBUG] Various serviceability tests fail compilation
dsamersoff
parents: 37477
diff changeset
    91
                "-XaddExports: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
    92
                "-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
    93
                "-XX:MaxNewSize=" + MAX_NEW_SIZE,
37166
8a5f1594e692 8146436: Add -XX:-ShrinkHeapInSteps option (previously -XX:+UseAggressiveHeapShrink)
cjplummer
parents: 32625
diff changeset
    94
                "-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
    95
                RatioVerifier.class.getName(),
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
    96
                Integer.toString(minRatio),
37166
8a5f1594e692 8146436: Add -XX:-ShrinkHeapInSteps option (previously -XX:+UseAggressiveHeapShrink)
cjplummer
parents: 32625
diff changeset
    97
                Integer.toString(maxRatio),
8a5f1594e692 8146436: Add -XX:-ShrinkHeapInSteps option (previously -XX:+UseAggressiveHeapShrink)
cjplummer
parents: 32625
diff changeset
    98
                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
    99
        );
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
   100
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
   101
        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
   102
        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
   103
        analyzer.shouldHaveExitValue(0);
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
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
     * 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
   108
     *
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
   109
     * @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
   110
     * @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
   111
     * @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
   112
     * @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
   113
     * @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
   114
     */
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
   115
    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
   116
            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
   117
            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
   118
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
   119
        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
   120
        Collections.addAll(vmOptions,
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
   121
                (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
   122
                (useXmaxf ? "-Xmaxf" + maxRatio / 100.0 : "-XX:MaxHeapFreeRatio=" + maxRatio),
38152
80e5da81fb2c 8154258: [TESTBUG] Various serviceability tests fail compilation
dsamersoff
parents: 37477
diff changeset
   123
                "-XaddExports: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
   124
                "-version"
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
   125
        );
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
   126
        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
   127
        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
   128
        analyzer.shouldHaveExitValue(1);
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
   129
        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
   130
    }
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
   131
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
   132
    /**
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
   133
     * 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
   134
     * 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
   135
     */
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
   136
    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
   137
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
   138
        private static final Unsafe unsafe = Utils.getUnsafe();
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
   139
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
   140
        // 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
   141
        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
   142
        // 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
   143
        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
   144
        // 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
   145
        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
   146
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
   147
        // 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
   148
        // 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
   149
        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
   150
        // 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
   151
        // 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
   152
        // 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
   153
        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
   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 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
   156
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
   157
        public static void main(String args[]) throws Exception {
37166
8a5f1594e692 8146436: Add -XX:-ShrinkHeapInSteps option (previously -XX:+UseAggressiveHeapShrink)
cjplummer
parents: 32625
diff changeset
   158
            if (args.length != 3) {
8a5f1594e692 8146436: Add -XX:-ShrinkHeapInSteps option (previously -XX:+UseAggressiveHeapShrink)
cjplummer
parents: 32625
diff changeset
   159
                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
   160
            }
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
   161
            if (GCTypes.OldGCType.getOldGCType() == GCTypes.OldGCType.PSOld) {
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
   162
                System.out.println("Test is not applicable to parallel GC");
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
   163
                return;
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
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
   166
            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
   167
            double maxRatio = Integer.valueOf(args[1]) / 100.0;
37166
8a5f1594e692 8146436: Add -XX:-ShrinkHeapInSteps option (previously -XX:+UseAggressiveHeapShrink)
cjplummer
parents: 32625
diff changeset
   168
            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
   169
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
   170
            long maxHeapSize = getMax();
37166
8a5f1594e692 8146436: Add -XX:-ShrinkHeapInSteps option (previously -XX:+UseAggressiveHeapShrink)
cjplummer
parents: 32625
diff changeset
   171
            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
   172
37412
d5f8d53af5ec 8153277: [TESTBUG] gc/arguments/TestMaxMinHeapFreeRatioFlags is too sensitive for stray allocations in verifyRatio
shade
parents: 37166
diff changeset
   173
            // 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
   174
            // 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
   175
            forceGC(gcTries);
d5f8d53af5ec 8153277: [TESTBUG] gc/arguments/TestMaxMinHeapFreeRatioFlags is too sensitive for stray allocations in verifyRatio
shade
parents: 37166
diff changeset
   176
            verifyRatio(minRatio, maxRatio);
d5f8d53af5ec 8153277: [TESTBUG] gc/arguments/TestMaxMinHeapFreeRatioFlags is too sensitive for stray allocations in verifyRatio
shade
parents: 37166
diff changeset
   177
32625
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
   178
            // 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
   179
            // 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
   180
            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
   181
                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
   182
            }
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
   183
37166
8a5f1594e692 8146436: Add -XX:-ShrinkHeapInSteps option (previously -XX:+UseAggressiveHeapShrink)
cjplummer
parents: 32625
diff changeset
   184
            forceGC(gcTries);
32625
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
   185
            // 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
   186
            verifyRatio(minRatio, maxRatio);
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
   187
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
   188
            // 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
   189
            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
   190
                    - getUsed();
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
   191
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
   192
            long previouslyCommitted = getCommitted();
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
   193
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
   194
            while (memoryToFill > 0) {
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
   195
                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
   196
                memoryToFill -= CHUNK_SIZE;
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
   197
            }
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
   198
37166
8a5f1594e692 8146436: Add -XX:-ShrinkHeapInSteps option (previously -XX:+UseAggressiveHeapShrink)
cjplummer
parents: 32625
diff changeset
   199
            forceGC(gcTries);
32625
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
   200
            // 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
   201
            verifyRatio(minRatio, maxRatio);
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
   202
            // 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
   203
            if (previouslyCommitted >= getCommitted()) {
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
   204
                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
   205
            }
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
   206
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
   207
            // 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
   208
            long memoryToFree = getUsed()
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
   209
                    - (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
   210
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
   211
            previouslyCommitted = getCommitted();
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
   212
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
   213
            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
   214
                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
   215
                memoryToFree -= CHUNK_SIZE;
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
   216
            }
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
   217
37166
8a5f1594e692 8146436: Add -XX:-ShrinkHeapInSteps option (previously -XX:+UseAggressiveHeapShrink)
cjplummer
parents: 32625
diff changeset
   218
            forceGC(gcTries);
32625
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
   219
            // 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
   220
            verifyRatio(minRatio, maxRatio);
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
   221
            // 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
   222
            if (previouslyCommitted <= getCommitted()) {
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
   223
                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
   224
            }
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
   225
        }
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
   226
37166
8a5f1594e692 8146436: Add -XX:-ShrinkHeapInSteps option (previously -XX:+UseAggressiveHeapShrink)
cjplummer
parents: 32625
diff changeset
   227
        public static void forceGC(int gcTries) {
8a5f1594e692 8146436: Add -XX:-ShrinkHeapInSteps option (previously -XX:+UseAggressiveHeapShrink)
cjplummer
parents: 32625
diff changeset
   228
            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
   229
                System.gc();
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
   230
                try {
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
   231
                    Thread.sleep(10);
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
   232
                } catch (InterruptedException ie) {
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
        /**
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
   238
         * 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
   239
         * 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
   240
         * 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
   241
         * 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
   242
         * 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
   243
         */
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
   244
        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
   245
            double ratio = getHeapFreeRatio();
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
   246
            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
   247
            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
   248
                    && getCommitted() < getMax()) {
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
   249
                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
   250
                        + "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
   251
            }
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
   252
            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
   253
                    && getUsed() > getInit()) {
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
   254
                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
   255
                        + "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
   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
        /*
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
   260
         * 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
   261
         *
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
   262
         * 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
   263
         * 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
   264
         *
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
   265
         * 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
   266
         */
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
   267
        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
   268
            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
   269
        }
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
   270
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
   271
        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
   272
            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
   273
                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
   274
                        + HeapRegionUsageTool.getSurvivorUsage().getInit()
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
   275
                        + HeapRegionUsageTool.getOldUsage().getInit();
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
   276
            } else {
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
   277
                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
   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
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
   281
        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
   282
            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
   283
                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
   284
                        + HeapRegionUsageTool.getSurvivorUsage().getUsed()
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
   285
                        + HeapRegionUsageTool.getOldUsage().getUsed();
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
   286
            } else {
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
   287
                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
   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
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
   291
        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
   292
            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
   293
                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
   294
                        + HeapRegionUsageTool.getSurvivorUsage().getCommitted()
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
   295
                        + HeapRegionUsageTool.getOldUsage().getCommitted();
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
   296
            } else {
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
   297
                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
   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
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
   301
        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
   302
            return getCommitted() - getUsed();
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
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
   305
        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
   306
            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
   307
        }
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
   308
    }
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
   309
}