test/hotspot/jtreg/gc/arguments/TestNewSizeFlags.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.
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
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 TestNewSizeFlags
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 young gen size conforms values specified by NewSize, MaxNewSize and Xmn options
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: 40106
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: 40106
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/timeout=240  gc.arguments.TestNewSizeFlags
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.io.IOException;
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
    42
import java.lang.management.MemoryUsage;
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.Arrays;
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
    44
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
    45
import java.util.LinkedList;
40631
ed82623d7831 8157957: ClassNotFoundException: jdk.test.lib.JDKToolFinder
ctornqvi
parents: 40106
diff changeset
    46
import jdk.test.lib.process.OutputAnalyzer;
ed82623d7831 8157957: ClassNotFoundException: jdk.test.lib.JDKToolFinder
ctornqvi
parents: 40106
diff changeset
    47
import jdk.test.lib.process.ProcessTools;
32625
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
    48
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
    49
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
    50
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
    51
public class TestNewSizeFlags {
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
    52
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
    53
    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
    54
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
    55
    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
    56
        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
    57
                Arrays.asList(Utils.getFilteredTestJavaOpts("(-Xm[nsx][^ ]+)|"
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
    58
                                + "(-XX:(Max)?((New)|"
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
    59
                                + "(Heap))((Size)|"
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
    60
                                + "(Ratio))=[^ ]+)"))
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
        // Test NewSize and MaxNewSize
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
    64
        testNewSizeFlags(20 * M, 10 * M, 30 * M, 40 * M, options, false);
40106
6be13673b3c1 8161604: TestNewSizeFlags fails with RuntimeException: max new size != MaxNewSize value
mchernov
parents: 36851
diff changeset
    65
        testNewSizeFlags(10 * M, 20 * M, 30 * M, 80 * M, options, false);
32625
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
    66
        testNewSizeFlags(-1, 20 * M, 30 * M, 40 * M, options, false);
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
    67
        testNewSizeFlags(10 * M, -1, 30 * M, 40 * M, options, false);
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
    68
        testNewSizeFlags(20 * M, 20 * M, 30 * M, 40 * M, options, false);
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
    69
        testNewSizeFlags(20 * M, 30 * M, 40 * M, 50 * M, options, false);
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
    70
        testNewSizeFlags(30 * M, 100 * M, 150 * M, 200 * M, options, false);
40106
6be13673b3c1 8161604: TestNewSizeFlags fails with RuntimeException: max new size != MaxNewSize value
mchernov
parents: 36851
diff changeset
    71
        testNewSizeFlags(20 * M, 30 * M, 128 * M, 128 * M, options, false);
32625
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
    72
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
    73
        // Test -Xmn
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
    74
        testXmnFlags(0, 30 * M, 40 * M, options, true);
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
    75
        testXmnFlags(20 * M, 30 * M, 40 * M, options, false);
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
    76
        testXmnFlags(50 * M, 70 * M, 100 * M, options, false);
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
    77
    }
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
    78
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
    79
    /**
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
    80
     * Verify that NewSize and MaxNewSize flags affect young gen size.
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
    81
     *
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
    82
     * @param newSize value of NewSize option, omitted if negative
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
    83
     * @param maxNewSize value of MaxNewSize option, omitted if negative
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
    84
     * @param heapSize value of HeapSize option
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
    85
     * @param maxHeapSize value of MaxHeapSize option
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
    86
     * @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
    87
     * @param failureExpected true if JVM should fail with passed heap size options
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
    public static void testNewSizeFlags(long newSize, long maxNewSize,
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
    90
            long heapSize, long maxHeapSize,
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
    91
            LinkedList<String> options,
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
    92
            boolean failureExpected) throws Exception {
40106
6be13673b3c1 8161604: TestNewSizeFlags fails with RuntimeException: max new size != MaxNewSize value
mchernov
parents: 36851
diff changeset
    93
        long expectedNewSize = newSize;
6be13673b3c1 8161604: TestNewSizeFlags fails with RuntimeException: max new size != MaxNewSize value
mchernov
parents: 36851
diff changeset
    94
        long expectedMaxNewSize = (maxNewSize >= 0 ? Math.max(maxNewSize, newSize) : maxNewSize);
32625
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
    95
        testVMOptions(newSize, maxNewSize,
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
    96
                heapSize, maxHeapSize,
40106
6be13673b3c1 8161604: TestNewSizeFlags fails with RuntimeException: max new size != MaxNewSize value
mchernov
parents: 36851
diff changeset
    97
                expectedNewSize, expectedMaxNewSize,
32625
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
    98
                options, failureExpected);
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
    /**
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
   102
     * Verify that -Xmn flag affect young gen size.
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
   103
     *
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
   104
     * @param mnValue value of -Xmn option
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
   105
     * @param heapSize value of HeapSize option
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
   106
     * @param maxHeapSize value of MaxHeapSize option
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
   107
     * @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
   108
     * @param failureExpected true if JVM should fail with passed heap size options
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
   109
     */
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
   110
    public static void testXmnFlags(long mnValue,
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
   111
            long heapSize, long maxHeapSize,
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
   112
            LinkedList<String> options,
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
   113
            boolean failureExpected) throws Exception {
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
   114
        LinkedList<String> newOptions = new LinkedList<>(options);
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
   115
        newOptions.add("-Xmn" + mnValue);
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
   116
        testVMOptions(-1, -1,
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
   117
                heapSize, maxHeapSize,
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
   118
                mnValue, mnValue,
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
   119
                newOptions, failureExpected);
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
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
     * Verify that NewSize and MaxNewSize flags affect young gen size.
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
   124
     *
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
   125
     * @param newSize value of NewSize option, omitted if negative
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
   126
     * @param maxNewSize value of MaxNewSize option, omitted if negative
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
   127
     * @param heapSize value of HeapSize option
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
   128
     * @param maxHeapSize value of MaxHeapSize option
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
   129
     * @param expectedNewSize expected initial young gen size
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
   130
     * @param expectedMaxNewSize expected max young gen size
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
   131
     * @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
   132
     * @param failureExpected true if JVM should fail with passed heap size options
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
   133
     */
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
   134
    public static void testVMOptions(long newSize, long maxNewSize,
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
   135
            long heapSize, long maxHeapSize,
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
   136
            long expectedNewSize, long expectedMaxNewSize,
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
   137
            LinkedList<String> options, boolean failureExpected) throws Exception {
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
   138
        OutputAnalyzer analyzer = startVM(options, newSize, maxNewSize, heapSize, maxHeapSize, expectedNewSize, expectedMaxNewSize);
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
        if (failureExpected) {
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
   141
            analyzer.shouldHaveExitValue(1);
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
   142
            analyzer.shouldMatch("(Error occurred during initialization of VM)|"
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
   143
                    + "(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
   144
        } else {
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
   145
            analyzer.shouldHaveExitValue(0);
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
    }
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
    private static OutputAnalyzer startVM(LinkedList<String> options,
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
   150
            long newSize, long maxNewSize,
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
   151
            long heapSize, long maxHeapSize,
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
   152
            long expectedNewSize, long expectedMaxNewSize) throws Exception, IOException {
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
   153
        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
   154
        Collections.addAll(vmOptions,
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
   155
                "-Xbootclasspath/a:.",
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
   156
                "-XX:+UnlockDiagnosticVMOptions",
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
   157
                "-XX:+WhiteBoxAPI",
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
   158
                (newSize >= 0 ? "-XX:NewSize=" + newSize : ""),
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
   159
                (maxNewSize >= 0 ? "-XX:MaxNewSize=" + maxNewSize : ""),
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
   160
                "-Xmx" + maxHeapSize,
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
   161
                "-Xms" + heapSize,
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
   162
                "-XX:GCLockerEdenExpansionPercent=0",
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
   163
                "-XX:-UseLargePages",
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
   164
                NewSizeVerifier.class.getName(),
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
   165
                Long.toString(expectedNewSize),
40106
6be13673b3c1 8161604: TestNewSizeFlags fails with RuntimeException: max new size != MaxNewSize value
mchernov
parents: 36851
diff changeset
   166
                Long.toString(expectedMaxNewSize),
6be13673b3c1 8161604: TestNewSizeFlags fails with RuntimeException: max new size != MaxNewSize value
mchernov
parents: 36851
diff changeset
   167
                Long.toString(heapSize),
6be13673b3c1 8161604: TestNewSizeFlags fails with RuntimeException: max new size != MaxNewSize value
mchernov
parents: 36851
diff changeset
   168
                Long.toString(maxHeapSize)
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
        vmOptions.removeIf(String::isEmpty);
55610
47fdb5b0fa41 8217170: gc/arguments/TestUseCompressedOopsErgo.java timed out
kbarrett
parents: 53523
diff changeset
   171
        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
   172
        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
   173
        return analyzer;
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
   174
    }
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
    /**
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
   177
     * NewSizeVerifier checks that initial young gen size is equal to expected
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
   178
     * regardful to alignment and that young gen size will not be greater than
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
   179
     * expected max size.
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
   180
     * In order to verify that young gen size will not be greater then expected
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
   181
     * max size, NewSizeVerifier do some object allocation to force garbage
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
   182
     * collection and heap expansion.
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
    public static class NewSizeVerifier {
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
   185
40106
6be13673b3c1 8161604: TestNewSizeFlags fails with RuntimeException: max new size != MaxNewSize value
mchernov
parents: 36851
diff changeset
   186
        private static final WhiteBox WB = WhiteBox.getWhiteBox();
6be13673b3c1 8161604: TestNewSizeFlags fails with RuntimeException: max new size != MaxNewSize value
mchernov
parents: 36851
diff changeset
   187
        private static final GCTypes.YoungGCType YOUNG_GC_TYPE = GCTypes.YoungGCType.getYoungGCType();
6be13673b3c1 8161604: TestNewSizeFlags fails with RuntimeException: max new size != MaxNewSize value
mchernov
parents: 36851
diff changeset
   188
        private static final long HEAP_SPACE_ALIGNMENT = WB.getHeapSpaceAlignment();
6be13673b3c1 8161604: TestNewSizeFlags fails with RuntimeException: max new size != MaxNewSize value
mchernov
parents: 36851
diff changeset
   189
        private static final long HEAP_ALIGNMENT = WB.getHeapAlignment();
6be13673b3c1 8161604: TestNewSizeFlags fails with RuntimeException: max new size != MaxNewSize value
mchernov
parents: 36851
diff changeset
   190
        private static final long PS_VIRTUAL_SPACE_ALIGNMENT =
6be13673b3c1 8161604: TestNewSizeFlags fails with RuntimeException: max new size != MaxNewSize value
mchernov
parents: 36851
diff changeset
   191
                (YOUNG_GC_TYPE == GCTypes.YoungGCType.PSNew) ? WB.psVirtualSpaceAlignment() : 0;
32625
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
   192
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
   193
        public static final int ARRAY_LENGTH = 100;
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
   194
        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
   195
        public static final int MAX_ITERATIONS = 10;
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
   196
        public static byte garbage[][] = 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
   197
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
   198
        public static void main(String args[]) throws Exception {
40106
6be13673b3c1 8161604: TestNewSizeFlags fails with RuntimeException: max new size != MaxNewSize value
mchernov
parents: 36851
diff changeset
   199
            if (args.length != 4) {
6be13673b3c1 8161604: TestNewSizeFlags fails with RuntimeException: max new size != MaxNewSize value
mchernov
parents: 36851
diff changeset
   200
                throw new IllegalArgumentException("Expected 4 args: <expectedNewSize> <expectedMaxNewSize> <initialHeapSize> <maxHeapSize>");
32625
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
   201
            }
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
   202
            final long newSize = Long.valueOf(args[0]);
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
   203
            final long maxNewSize = Long.valueOf(args[1]);
40106
6be13673b3c1 8161604: TestNewSizeFlags fails with RuntimeException: max new size != MaxNewSize value
mchernov
parents: 36851
diff changeset
   204
            final long initialHeapSize = Long.valueOf(args[2]);
6be13673b3c1 8161604: TestNewSizeFlags fails with RuntimeException: max new size != MaxNewSize value
mchernov
parents: 36851
diff changeset
   205
            final long maxHeapSize = Long.valueOf(args[3]);
32625
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
            // verify initial size
40106
6be13673b3c1 8161604: TestNewSizeFlags fails with RuntimeException: max new size != MaxNewSize value
mchernov
parents: 36851
diff changeset
   208
            verifyNewSize(newSize, maxNewSize, initialHeapSize, maxHeapSize);
32625
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
   209
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
   210
            // force GC and verify that size is still correct
40106
6be13673b3c1 8161604: TestNewSizeFlags fails with RuntimeException: max new size != MaxNewSize value
mchernov
parents: 36851
diff changeset
   211
            AllocationHelper allocator = new AllocationHelper(MAX_ITERATIONS, ARRAY_LENGTH, CHUNK_SIZE, () -> (verifyNewSize(newSize, maxNewSize, initialHeapSize, maxHeapSize)));
32625
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
   212
            allocator.allocateMemoryAndVerifyNoOOME();
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
   213
        }
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
   214
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
   215
        /**
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
   216
         * Verify that actual young gen size conforms NewSize and MaxNewSize values.
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
   217
         */
40106
6be13673b3c1 8161604: TestNewSizeFlags fails with RuntimeException: max new size != MaxNewSize value
mchernov
parents: 36851
diff changeset
   218
        public static Void verifyNewSize(long newSize, long maxNewSize,
6be13673b3c1 8161604: TestNewSizeFlags fails with RuntimeException: max new size != MaxNewSize value
mchernov
parents: 36851
diff changeset
   219
                long initialHeapSize, long maxHeapSize) {
6be13673b3c1 8161604: TestNewSizeFlags fails with RuntimeException: max new size != MaxNewSize value
mchernov
parents: 36851
diff changeset
   220
            long alignedNewSize = alignGenSize(newSize);
6be13673b3c1 8161604: TestNewSizeFlags fails with RuntimeException: max new size != MaxNewSize value
mchernov
parents: 36851
diff changeset
   221
            long alignedMaxNewSize = alignGenSize(maxNewSize);
6be13673b3c1 8161604: TestNewSizeFlags fails with RuntimeException: max new size != MaxNewSize value
mchernov
parents: 36851
diff changeset
   222
            long alignedXms = alignHeapSize(initialHeapSize);
6be13673b3c1 8161604: TestNewSizeFlags fails with RuntimeException: max new size != MaxNewSize value
mchernov
parents: 36851
diff changeset
   223
            long alignedXmx = alignHeapSize(maxHeapSize);
32625
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
            MemoryUsage youngGenUsage = getYoungGenUsage();
40106
6be13673b3c1 8161604: TestNewSizeFlags fails with RuntimeException: max new size != MaxNewSize value
mchernov
parents: 36851
diff changeset
   226
            long initSize = youngGenUsage.getInit();
6be13673b3c1 8161604: TestNewSizeFlags fails with RuntimeException: max new size != MaxNewSize value
mchernov
parents: 36851
diff changeset
   227
            long commitedSize = youngGenUsage.getCommitted();
6be13673b3c1 8161604: TestNewSizeFlags fails with RuntimeException: max new size != MaxNewSize value
mchernov
parents: 36851
diff changeset
   228
            long maxSize = youngGenUsage.getMax();
32625
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
   229
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
   230
            if (newSize != -1) {
40106
6be13673b3c1 8161604: TestNewSizeFlags fails with RuntimeException: max new size != MaxNewSize value
mchernov
parents: 36851
diff changeset
   231
                if (initSize < alignedNewSize) {
32625
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
   232
                    throw new RuntimeException("initial new size < NewSize value: "
40106
6be13673b3c1 8161604: TestNewSizeFlags fails with RuntimeException: max new size != MaxNewSize value
mchernov
parents: 36851
diff changeset
   233
                            + initSize + " < " + alignedNewSize);
32625
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
40106
6be13673b3c1 8161604: TestNewSizeFlags fails with RuntimeException: max new size != MaxNewSize value
mchernov
parents: 36851
diff changeset
   236
                if (commitedSize < alignedNewSize) {
32625
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
   237
                    throw new RuntimeException("actual new size < NewSize value: "
40106
6be13673b3c1 8161604: TestNewSizeFlags fails with RuntimeException: max new size != MaxNewSize value
mchernov
parents: 36851
diff changeset
   238
                            + commitedSize + " < " + alignedNewSize);
32625
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
   239
                }
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
   240
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
   241
                // for G1 max new size == committed new size
40106
6be13673b3c1 8161604: TestNewSizeFlags fails with RuntimeException: max new size != MaxNewSize value
mchernov
parents: 36851
diff changeset
   242
                if (YOUNG_GC_TYPE != GCTypes.YoungGCType.G1
6be13673b3c1 8161604: TestNewSizeFlags fails with RuntimeException: max new size != MaxNewSize value
mchernov
parents: 36851
diff changeset
   243
                        && maxSize < alignedNewSize) {
32625
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
   244
                    throw new RuntimeException("max new size < NewSize value: "
40106
6be13673b3c1 8161604: TestNewSizeFlags fails with RuntimeException: max new size != MaxNewSize value
mchernov
parents: 36851
diff changeset
   245
                            + maxSize + " < " + alignedNewSize);
32625
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
   246
                }
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
   247
            }
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
   248
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
   249
            if (maxNewSize != -1) {
40106
6be13673b3c1 8161604: TestNewSizeFlags fails with RuntimeException: max new size != MaxNewSize value
mchernov
parents: 36851
diff changeset
   250
                if (initSize > alignedMaxNewSize) {
32625
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
   251
                    throw new RuntimeException("initial new size > MaxNewSize value: "
40106
6be13673b3c1 8161604: TestNewSizeFlags fails with RuntimeException: max new size != MaxNewSize value
mchernov
parents: 36851
diff changeset
   252
                            + initSize + " > " + alignedMaxNewSize);
6be13673b3c1 8161604: TestNewSizeFlags fails with RuntimeException: max new size != MaxNewSize value
mchernov
parents: 36851
diff changeset
   253
                }
6be13673b3c1 8161604: TestNewSizeFlags fails with RuntimeException: max new size != MaxNewSize value
mchernov
parents: 36851
diff changeset
   254
6be13673b3c1 8161604: TestNewSizeFlags fails with RuntimeException: max new size != MaxNewSize value
mchernov
parents: 36851
diff changeset
   255
                if (commitedSize > alignedMaxNewSize) {
6be13673b3c1 8161604: TestNewSizeFlags fails with RuntimeException: max new size != MaxNewSize value
mchernov
parents: 36851
diff changeset
   256
                    throw new RuntimeException("actual new size > MaxNewSize value: "
6be13673b3c1 8161604: TestNewSizeFlags fails with RuntimeException: max new size != MaxNewSize value
mchernov
parents: 36851
diff changeset
   257
                            + commitedSize + " > " + alignedMaxNewSize);
32625
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
40106
6be13673b3c1 8161604: TestNewSizeFlags fails with RuntimeException: max new size != MaxNewSize value
mchernov
parents: 36851
diff changeset
   260
                if (alignedXms != alignedXmx) {
6be13673b3c1 8161604: TestNewSizeFlags fails with RuntimeException: max new size != MaxNewSize value
mchernov
parents: 36851
diff changeset
   261
                    if (YOUNG_GC_TYPE != GCTypes.YoungGCType.G1
6be13673b3c1 8161604: TestNewSizeFlags fails with RuntimeException: max new size != MaxNewSize value
mchernov
parents: 36851
diff changeset
   262
                            && maxSize != alignedMaxNewSize) {
6be13673b3c1 8161604: TestNewSizeFlags fails with RuntimeException: max new size != MaxNewSize value
mchernov
parents: 36851
diff changeset
   263
                        throw new RuntimeException("max new size != MaxNewSize value: "
6be13673b3c1 8161604: TestNewSizeFlags fails with RuntimeException: max new size != MaxNewSize value
mchernov
parents: 36851
diff changeset
   264
                                + maxSize + " != " + alignedMaxNewSize);
6be13673b3c1 8161604: TestNewSizeFlags fails with RuntimeException: max new size != MaxNewSize value
mchernov
parents: 36851
diff changeset
   265
                    }
6be13673b3c1 8161604: TestNewSizeFlags fails with RuntimeException: max new size != MaxNewSize value
mchernov
parents: 36851
diff changeset
   266
                } else {
6be13673b3c1 8161604: TestNewSizeFlags fails with RuntimeException: max new size != MaxNewSize value
mchernov
parents: 36851
diff changeset
   267
                    if (YOUNG_GC_TYPE != GCTypes.YoungGCType.G1
6be13673b3c1 8161604: TestNewSizeFlags fails with RuntimeException: max new size != MaxNewSize value
mchernov
parents: 36851
diff changeset
   268
                            && maxSize != alignedNewSize) {
6be13673b3c1 8161604: TestNewSizeFlags fails with RuntimeException: max new size != MaxNewSize value
mchernov
parents: 36851
diff changeset
   269
                        throw new RuntimeException("max new size != NewSize for case InitialHeapSize == MaxHeapSize value: "
6be13673b3c1 8161604: TestNewSizeFlags fails with RuntimeException: max new size != MaxNewSize value
mchernov
parents: 36851
diff changeset
   270
                                + maxSize + " != " + alignedNewSize + " HeapSize == " + alignedXms);
6be13673b3c1 8161604: TestNewSizeFlags fails with RuntimeException: max new size != MaxNewSize value
mchernov
parents: 36851
diff changeset
   271
                    }
32625
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
   272
                }
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
   273
            }
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
   274
            return null;
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
   275
        }
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
   276
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
   277
        /**
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
   278
         *  Get young gen memory usage.
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
         *  For G1 it is EdenUsage + SurvivorUsage,
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
   281
         *  for other GCs it is EdenUsage + 2 * SurvivorUsage.
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
   282
         *  For G1 max value is just LONG_MAX.
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
   283
         *  For all GCs used value is 0.
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
   284
         */
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
   285
        private static MemoryUsage getYoungGenUsage() {
40106
6be13673b3c1 8161604: TestNewSizeFlags fails with RuntimeException: max new size != MaxNewSize value
mchernov
parents: 36851
diff changeset
   286
            MemoryUsage edenUsage = HeapRegionUsageTool.getEdenUsage();
6be13673b3c1 8161604: TestNewSizeFlags fails with RuntimeException: max new size != MaxNewSize value
mchernov
parents: 36851
diff changeset
   287
            MemoryUsage survivorUsage = HeapRegionUsageTool.getSurvivorUsage();
6be13673b3c1 8161604: TestNewSizeFlags fails with RuntimeException: max new size != MaxNewSize value
mchernov
parents: 36851
diff changeset
   288
            long edenUsageInit = edenUsage.getInit();
6be13673b3c1 8161604: TestNewSizeFlags fails with RuntimeException: max new size != MaxNewSize value
mchernov
parents: 36851
diff changeset
   289
            long edenUsageCommited = edenUsage.getCommitted();
6be13673b3c1 8161604: TestNewSizeFlags fails with RuntimeException: max new size != MaxNewSize value
mchernov
parents: 36851
diff changeset
   290
            long survivorUsageInit = survivorUsage.getInit();
6be13673b3c1 8161604: TestNewSizeFlags fails with RuntimeException: max new size != MaxNewSize value
mchernov
parents: 36851
diff changeset
   291
            long survivorUsageCommited = survivorUsage.getCommitted();
6be13673b3c1 8161604: TestNewSizeFlags fails with RuntimeException: max new size != MaxNewSize value
mchernov
parents: 36851
diff changeset
   292
6be13673b3c1 8161604: TestNewSizeFlags fails with RuntimeException: max new size != MaxNewSize value
mchernov
parents: 36851
diff changeset
   293
            if (YOUNG_GC_TYPE == GCTypes.YoungGCType.G1) {
6be13673b3c1 8161604: TestNewSizeFlags fails with RuntimeException: max new size != MaxNewSize value
mchernov
parents: 36851
diff changeset
   294
                return new MemoryUsage(edenUsageInit + survivorUsageInit, 0,
6be13673b3c1 8161604: TestNewSizeFlags fails with RuntimeException: max new size != MaxNewSize value
mchernov
parents: 36851
diff changeset
   295
                        edenUsageCommited + survivorUsageCommited, Long.MAX_VALUE);
32625
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
   296
            } else {
40106
6be13673b3c1 8161604: TestNewSizeFlags fails with RuntimeException: max new size != MaxNewSize value
mchernov
parents: 36851
diff changeset
   297
                return new MemoryUsage(edenUsageInit + survivorUsageInit * 2, 0,
6be13673b3c1 8161604: TestNewSizeFlags fails with RuntimeException: max new size != MaxNewSize value
mchernov
parents: 36851
diff changeset
   298
                        edenUsageCommited + survivorUsageCommited * 2,
6be13673b3c1 8161604: TestNewSizeFlags fails with RuntimeException: max new size != MaxNewSize value
mchernov
parents: 36851
diff changeset
   299
                        edenUsage.getMax() + survivorUsage.getMax() * 2);
32625
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
        }
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
   302
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
   303
        /**
40106
6be13673b3c1 8161604: TestNewSizeFlags fails with RuntimeException: max new size != MaxNewSize value
mchernov
parents: 36851
diff changeset
   304
         * Align generation size regardful to used young GC.
32625
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
   305
         */
40106
6be13673b3c1 8161604: TestNewSizeFlags fails with RuntimeException: max new size != MaxNewSize value
mchernov
parents: 36851
diff changeset
   306
        public static long alignGenSize(long value) {
6be13673b3c1 8161604: TestNewSizeFlags fails with RuntimeException: max new size != MaxNewSize value
mchernov
parents: 36851
diff changeset
   307
            switch (YOUNG_GC_TYPE) {
32625
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
   308
                case DefNew:
40106
6be13673b3c1 8161604: TestNewSizeFlags fails with RuntimeException: max new size != MaxNewSize value
mchernov
parents: 36851
diff changeset
   309
                    return HeapRegionUsageTool.alignDown(value, HEAP_SPACE_ALIGNMENT);
32625
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
   310
                case PSNew:
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
   311
                    return HeapRegionUsageTool.alignUp(HeapRegionUsageTool.alignDown(value,
40106
6be13673b3c1 8161604: TestNewSizeFlags fails with RuntimeException: max new size != MaxNewSize value
mchernov
parents: 36851
diff changeset
   312
                            HEAP_SPACE_ALIGNMENT),
6be13673b3c1 8161604: TestNewSizeFlags fails with RuntimeException: max new size != MaxNewSize value
mchernov
parents: 36851
diff changeset
   313
                            PS_VIRTUAL_SPACE_ALIGNMENT);
32625
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
   314
                case G1:
40106
6be13673b3c1 8161604: TestNewSizeFlags fails with RuntimeException: max new size != MaxNewSize value
mchernov
parents: 36851
diff changeset
   315
                    return HeapRegionUsageTool.alignUp(value, WB.g1RegionSize());
32625
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
   316
                default:
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
   317
                    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
   318
            }
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
   319
        }
40106
6be13673b3c1 8161604: TestNewSizeFlags fails with RuntimeException: max new size != MaxNewSize value
mchernov
parents: 36851
diff changeset
   320
6be13673b3c1 8161604: TestNewSizeFlags fails with RuntimeException: max new size != MaxNewSize value
mchernov
parents: 36851
diff changeset
   321
        /**
6be13673b3c1 8161604: TestNewSizeFlags fails with RuntimeException: max new size != MaxNewSize value
mchernov
parents: 36851
diff changeset
   322
         * Align heap size.
6be13673b3c1 8161604: TestNewSizeFlags fails with RuntimeException: max new size != MaxNewSize value
mchernov
parents: 36851
diff changeset
   323
         */
6be13673b3c1 8161604: TestNewSizeFlags fails with RuntimeException: max new size != MaxNewSize value
mchernov
parents: 36851
diff changeset
   324
        public static long alignHeapSize(long value){
6be13673b3c1 8161604: TestNewSizeFlags fails with RuntimeException: max new size != MaxNewSize value
mchernov
parents: 36851
diff changeset
   325
            return HeapRegionUsageTool.alignUp(value,HEAP_ALIGNMENT);
6be13673b3c1 8161604: TestNewSizeFlags fails with RuntimeException: max new size != MaxNewSize value
mchernov
parents: 36851
diff changeset
   326
        }
32625
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
   327
    }
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
   328
}