test/hotspot/jtreg/gc/arguments/TestNewRatioFlag.java
author rkennke
Mon, 10 Dec 2018 15:47:44 +0100
changeset 52925 9c18c9d839d3
parent 50525 767cdb97f103
child 53523 4c5184c56dc2
permissions -rw-r--r--
8214259: Implementation: JEP 189: Shenandoah: A Low-Pause-Time Garbage Collector (Experimental) Reviewed-by: kvn, roland, shade, coleenp, lmesnik, pliden, jgeorge, ihse, erikj Contributed-by: Christine Flood <chf@redhat.com>, Aleksey Shipilev <shade@redhat.com>, Roland Westrelin <rwestrel@redhat.com>, Zhenygu Gu <zgu@redhat.com>, Andrew Haley <aph@redhat.com>, Andrew Dinn <adinn@redhat.com>, Mario Torre <mtorre@redhat.com>, Roman Kennke <rkennke@redhat.com>
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
/*
52925
9c18c9d839d3 8214259: Implementation: JEP 189: Shenandoah: A Low-Pause-Time Garbage Collector (Experimental)
rkennke
parents: 50525
diff changeset
     2
 * Copyright (c) 2015, 2018, 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
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 TestNewRatioFlag
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
 * @bug 8025166
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
    28
 * @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
    29
 * @requires vm.gc != "Z" & vm.gc != "Shenandoah"
40631
ed82623d7831 8157957: ClassNotFoundException: jdk.test.lib.JDKToolFinder
ctornqvi
parents: 36851
diff changeset
    30
 * @library /test/lib
36851
03e2f4d0a421 8153737: Unsupported Module
chegar
parents: 33730
diff changeset
    31
 * @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
    32
 *          java.management
40631
ed82623d7831 8157957: ClassNotFoundException: jdk.test.lib.JDKToolFinder
ctornqvi
parents: 36851
diff changeset
    33
 * @build sun.hotspot.WhiteBox
48791
6e079ff6c83c 8186635: ClassFileInstaller should be run as a driver
iignatyev
parents: 47216
diff changeset
    34
 * @run driver ClassFileInstaller sun.hotspot.WhiteBox
32625
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
    35
 * @run driver TestNewRatioFlag
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
    36
 */
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
    37
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
    38
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
    39
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
    40
import java.util.LinkedList;
40631
ed82623d7831 8157957: ClassNotFoundException: jdk.test.lib.JDKToolFinder
ctornqvi
parents: 36851
diff changeset
    41
import jdk.test.lib.process.ProcessTools;
ed82623d7831 8157957: ClassNotFoundException: jdk.test.lib.JDKToolFinder
ctornqvi
parents: 36851
diff changeset
    42
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
    43
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
    44
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
    45
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
    46
public class TestNewRatioFlag {
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
    47
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 M = 1024 * 1024;
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 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
    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 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
    52
        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
    53
                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
    54
        );
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
        testNewRatio(4, options);
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
    57
        testNewRatio(6, options);
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
    58
        testNewRatio(10, options);
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
    59
        testNewRatio(15, options);
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
    60
        testNewRatio(20, options);
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
    61
    }
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
    62
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
    63
    /**
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
    64
     * 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
    65
     *
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
    66
     * @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
    67
     * @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
    68
     */
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
    69
    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
    70
        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
    71
        Collections.addAll(vmOptions,
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
    72
                "-Xbootclasspath/a:.",
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
    73
                "-XX:+UnlockDiagnosticVMOptions",
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
    74
                "-XX:+WhiteBoxAPI",
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
    75
                "-XX:GCLockerEdenExpansionPercent=0",
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
    76
                "-Xmx" + HEAP_SIZE,
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
    77
                "-Xms" + HEAP_SIZE,
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
    78
                "-XX:NewRatio=" + ratio,
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
    79
                "-XX:-UseLargePages",
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
    80
                NewRatioVerifier.class.getName(),
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
    81
                Integer.toString(ratio)
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
    82
        );
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
    83
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
    84
        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
    85
        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
    86
        analyzer.shouldHaveExitValue(0);
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
    87
        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
    88
    }
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
    89
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
    90
    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
    91
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
    92
        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
    93
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
    94
        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
    95
            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
    96
                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
    97
            }
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
    98
            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
    99
            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
   100
                case DefNew:
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
   101
                case ParNew:
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
   102
                    verifyDefNewNewRatio(expectedRatio);
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
   103
                    break;
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
   104
                case PSNew:
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
   105
                    verifyPSNewRatio(expectedRatio);
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
   106
                    break;
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
   107
                case G1:
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
   108
                    verifyG1NewRatio(expectedRatio);
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
   109
                    break;
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
   110
                default:
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
   111
                    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
   112
            }
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
   113
        }
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
         * 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
   117
         *
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
   118
         * 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
   119
         * 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
   120
         */
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
   121
        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
   122
            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
   123
            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
   124
            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
   125
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
   126
            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
   127
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
   128
            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
   129
                    wb.getHeapSpaceAlignment());
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
            if (expectedNewSize != newSize) {
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
   132
                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
   133
                        + ", 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
   134
            }
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
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
         * 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
   139
         * 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
   140
         * 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
   141
         */
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
   142
        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
   143
            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
   144
            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
   145
            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
   146
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
   147
            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
   148
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
   149
            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
   150
                    wb.getHeapSpaceAlignment());
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
   151
            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
   152
                    wb.psVirtualSpaceAlignment());
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
   153
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
   154
            if (expectedNewSize != newSize) {
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
   155
                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
   156
                        + ", 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
   157
            }
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
   158
        }
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
         * 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
   162
         * 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
   163
         * 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
   164
         * 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
   165
         */
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
   166
        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
   167
            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
   168
            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
   169
            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
   170
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
   171
            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
   172
            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
   173
            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
   174
            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
   175
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
   176
            if (youngListLength != expectedYoungListLength) {
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
   177
                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
   178
                        + ", 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
   179
            }
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
   180
        }
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
}