test/hotspot/jtreg/gc/arguments/TestNewRatioFlag.java
author lkorinth
Wed, 13 Nov 2019 11:37:29 +0100
changeset 59053 ba6c248cae19
parent 55610 47fdb5b0fa41
permissions -rw-r--r--
8232365: Implementation for JEP 363: Remove the Concurrent Mark Sweep (CMS) Garbage Collector Reviewed-by: kbarrett, tschatzl, erikj, coleenp, dholmes
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
/*
53523
4c5184c56dc2 8214799: Add package declaration to each JTREG test case in the gc folder
lkorinth
parents: 52925
diff changeset
     2
 * Copyright (c) 2015, 2019, Oracle and/or its affiliates. All rights reserved.
41705
332239c052cc 8165687: Fix license and copyright headers in jd9 under hotspot/test
stsmirno
parents: 40631
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: 40631
diff changeset
     4
 *
332239c052cc 8165687: Fix license and copyright headers in jd9 under hotspot/test
stsmirno
parents: 40631
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: 40631
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: 40631
diff changeset
     7
 * published by the Free Software Foundation.
332239c052cc 8165687: Fix license and copyright headers in jd9 under hotspot/test
stsmirno
parents: 40631
diff changeset
     8
 *
332239c052cc 8165687: Fix license and copyright headers in jd9 under hotspot/test
stsmirno
parents: 40631
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: 40631
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: 40631
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: 40631
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: 40631
diff changeset
    13
 * accompanied this code).
332239c052cc 8165687: Fix license and copyright headers in jd9 under hotspot/test
stsmirno
parents: 40631
diff changeset
    14
 *
332239c052cc 8165687: Fix license and copyright headers in jd9 under hotspot/test
stsmirno
parents: 40631
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: 40631
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: 40631
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: 40631
diff changeset
    18
 *
332239c052cc 8165687: Fix license and copyright headers in jd9 under hotspot/test
stsmirno
parents: 40631
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: 40631
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: 40631
diff changeset
    21
 * questions.
332239c052cc 8165687: Fix license and copyright headers in jd9 under hotspot/test
stsmirno
parents: 40631
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
53523
4c5184c56dc2 8214799: Add package declaration to each JTREG test case in the gc folder
lkorinth
parents: 52925
diff changeset
    24
package gc.arguments;
4c5184c56dc2 8214799: Add package declaration to each JTREG test case in the gc folder
lkorinth
parents: 52925
diff changeset
    25
32625
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
    26
/*
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
    27
 * @test TestNewRatioFlag
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
    28
 * @key gc
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
    29
 * @bug 8025166
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
    30
 * @summary Verify that heap devided among generations according to NewRatio
52925
9c18c9d839d3 8214259: Implementation: JEP 189: Shenandoah: A Low-Pause-Time Garbage Collector (Experimental)
rkennke
parents: 50525
diff changeset
    31
 * @requires vm.gc != "Z" & vm.gc != "Shenandoah"
40631
ed82623d7831 8157957: ClassNotFoundException: jdk.test.lib.JDKToolFinder
ctornqvi
parents: 36851
diff changeset
    32
 * @library /test/lib
53523
4c5184c56dc2 8214799: Add package declaration to each JTREG test case in the gc folder
lkorinth
parents: 52925
diff changeset
    33
 * @library /
36851
03e2f4d0a421 8153737: Unsupported Module
chegar
parents: 33730
diff changeset
    34
 * @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
    35
 *          java.management
40631
ed82623d7831 8157957: ClassNotFoundException: jdk.test.lib.JDKToolFinder
ctornqvi
parents: 36851
diff changeset
    36
 * @build sun.hotspot.WhiteBox
48791
6e079ff6c83c 8186635: ClassFileInstaller should be run as a driver
iignatyev
parents: 47216
diff changeset
    37
 * @run driver ClassFileInstaller sun.hotspot.WhiteBox
53523
4c5184c56dc2 8214799: Add package declaration to each JTREG test case in the gc folder
lkorinth
parents: 52925
diff changeset
    38
 * @run driver gc.arguments.TestNewRatioFlag
32625
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
    39
 */
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
    40
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
    41
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
    42
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
    43
import java.util.LinkedList;
40631
ed82623d7831 8157957: ClassNotFoundException: jdk.test.lib.JDKToolFinder
ctornqvi
parents: 36851
diff changeset
    44
import jdk.test.lib.process.ProcessTools;
ed82623d7831 8157957: ClassNotFoundException: jdk.test.lib.JDKToolFinder
ctornqvi
parents: 36851
diff changeset
    45
import jdk.test.lib.process.OutputAnalyzer;
32625
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
    46
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
    47
import sun.hotspot.WhiteBox;
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
    48
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
    49
public class TestNewRatioFlag {
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
    50
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
    51
    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
    52
    public static final long HEAP_SIZE = 100 * M;
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
    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
    55
        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
    56
                Arrays.asList(Utils.getFilteredTestJavaOpts("(-XX:[^ ]*NewSize=[^ ]+)|(-Xm[ns][^ ]+)"))
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
    57
        );
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
    58
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
    59
        testNewRatio(4, options);
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
    60
        testNewRatio(6, options);
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
    61
        testNewRatio(10, options);
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
    62
        testNewRatio(15, options);
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
    63
        testNewRatio(20, options);
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
    64
    }
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
    65
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
    66
    /**
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
    67
     * Verify that actual size of young gen conforms specified NewRatio
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
     * @param ratio value of NewRatio option
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
    70
     * @param options additional options for VM
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
    public static void testNewRatio(int ratio, 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
    73
        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
    74
        Collections.addAll(vmOptions,
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
    75
                "-Xbootclasspath/a:.",
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
    76
                "-XX:+UnlockDiagnosticVMOptions",
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
    77
                "-XX:+WhiteBoxAPI",
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
    78
                "-XX:GCLockerEdenExpansionPercent=0",
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
    79
                "-Xmx" + HEAP_SIZE,
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
    80
                "-Xms" + HEAP_SIZE,
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
    81
                "-XX:NewRatio=" + ratio,
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
    82
                "-XX:-UseLargePages",
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
    83
                NewRatioVerifier.class.getName(),
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
    84
                Integer.toString(ratio)
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
    85
        );
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
    86
55610
47fdb5b0fa41 8217170: gc/arguments/TestUseCompressedOopsErgo.java timed out
kbarrett
parents: 53523
diff changeset
    87
        ProcessBuilder procBuilder = GCArguments.createJavaProcessBuilder(vmOptions.toArray(new String[vmOptions.size()]));
32625
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
    88
        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
    89
        analyzer.shouldHaveExitValue(0);
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
    90
        System.out.println(analyzer.getOutput());
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
    91
    }
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
    92
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
    93
    public static class NewRatioVerifier {
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
    94
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
    95
        static WhiteBox wb = WhiteBox.getWhiteBox();
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
    96
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
    97
        public static void main(String args[]) {
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
    98
            if (args.length != 1) {
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
    99
                throw new IllegalArgumentException("Expected 1 arg: <expectedRatio>");
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
            int expectedRatio = Integer.valueOf(args[0]);
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
   102
            switch (GCTypes.YoungGCType.getYoungGCType()) {
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
   103
                case DefNew:
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
   104
                    verifyDefNewNewRatio(expectedRatio);
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
   105
                    break;
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
   106
                case PSNew:
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
   107
                    verifyPSNewRatio(expectedRatio);
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
   108
                    break;
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
   109
                case G1:
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
   110
                    verifyG1NewRatio(expectedRatio);
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
   111
                    break;
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
   112
                default:
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
   113
                    throw new RuntimeException("Unexpected young GC type");
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
        }
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
        /**
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
   118
         * Verify NewSize for DefNew and ParNew collectors.
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
   119
         *
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
   120
         * Compare expected NewSize calculated according to sizing policies used by DefNew
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
   121
         * with NewSize value reported by MemoryPoolMXBeans.
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
   122
         */
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
   123
        public static void verifyDefNewNewRatio(int expectedRatio) {
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
   124
            long initEden = HeapRegionUsageTool.getEdenUsage().getInit();
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
   125
            long initSurv = HeapRegionUsageTool.getSurvivorUsage().getInit();
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
   126
            long initOld = HeapRegionUsageTool.getOldUsage().getInit();
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
   127
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
   128
            long newSize = initEden + 2 * initSurv;
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
            long expectedNewSize = HeapRegionUsageTool.alignDown(initOld / expectedRatio,
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
   131
                    wb.getHeapSpaceAlignment());
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
            if (expectedNewSize != newSize) {
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
   134
                throw new RuntimeException("Expected young gen size is: " + expectedNewSize
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
   135
                        + ", but observed new size is: " + newSize);
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
   136
            }
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
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
         * Verify NewSize for PS collector.
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
   141
         * Expected NewSize calculated according to alignment policies used by PS
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
   142
         * and then compared with actual NewSize obtained from MemoryPoolMXBeans.
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
   143
         */
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
   144
        public static void verifyPSNewRatio(int expectedRatio) {
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
   145
            long initEden = HeapRegionUsageTool.getEdenUsage().getInit();
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
   146
            long initSurv = HeapRegionUsageTool.getSurvivorUsage().getInit();
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
   147
            long initOld = HeapRegionUsageTool.getOldUsage().getInit();
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
   148
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
   149
            long newSize = initEden + 2 * initSurv;
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
   150
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
   151
            long alignedDownNewSize = HeapRegionUsageTool.alignDown(initOld / expectedRatio,
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
   152
                    wb.getHeapSpaceAlignment());
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
   153
            long expectedNewSize = HeapRegionUsageTool.alignUp(alignedDownNewSize,
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
   154
                    wb.psVirtualSpaceAlignment());
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
   155
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
   156
            if (expectedNewSize != newSize) {
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
   157
                throw new RuntimeException("Expected young gen size is: " + expectedNewSize
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
   158
                        + ", but observed new size is: " + newSize);
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
   159
            }
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
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
   162
        /**
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
   163
         * Verify NewSize for G1 GC.
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
   164
         * Amount of young regions calculated according to sizing policies used by G1
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
   165
         * and then compared with actual number of young regions derived from
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
   166
         * values reported by MemoryPoolMXBeans and region size.
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
   167
         */
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
   168
        public static void verifyG1NewRatio(int expectedRatio) {
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
   169
            long initEden = HeapRegionUsageTool.getEdenUsage().getInit();
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
   170
            long initSurv = HeapRegionUsageTool.getSurvivorUsage().getInit();
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
   171
            long maxOld = HeapRegionUsageTool.getOldUsage().getMax();
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
   172
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
   173
            int regionSize = wb.g1RegionSize();
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
   174
            int youngListLength = (int) ((initEden + initSurv) / regionSize);
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
   175
            int maxRegions = (int) (maxOld / regionSize);
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
   176
            int expectedYoungListLength = (int) (maxRegions / (double) (expectedRatio + 1));
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
   177
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
   178
            if (youngListLength != expectedYoungListLength) {
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
   179
                throw new RuntimeException("Expected G1 young list length is: " + expectedYoungListLength
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
   180
                        + ", but observed young list length is: " + youngListLength);
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
        }
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
   183
    }
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
   184
}