test/hotspot/jtreg/gc/arguments/TestNewSizeFlags.java
author iignatyev
Wed, 17 Jan 2018 21:44:44 -0800
changeset 48791 6e079ff6c83c
parent 47216 71c04702a3d5
child 50525 767cdb97f103
permissions -rw-r--r--
8186635: ClassFileInstaller should be run as a driver Reviewed-by: 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
/*
40106
6be13673b3c1 8161604: TestNewSizeFlags fails with RuntimeException: max new size != MaxNewSize value
mchernov
parents: 36851
diff changeset
     2
 * Copyright (c) 2015, 2016, Oracle and/or its affiliates. All rights reserved.
32625
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
     4
 *
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
     7
 * published by the Free Software Foundation.
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
     8
 *
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
    13
 * accompanied this code).
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
    14
 *
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
    18
 *
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
    21
 * questions.
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
    22
 */
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
    23
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
    24
/*
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
    25
 * @test TestNewSizeFlags
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 young gen size conforms values specified by NewSize, MaxNewSize and Xmn options
40631
ed82623d7831 8157957: ClassNotFoundException: jdk.test.lib.JDKToolFinder
ctornqvi
parents: 40106
diff changeset
    29
 * @library /test/lib
36851
03e2f4d0a421 8153737: Unsupported Module
chegar
parents: 33730
diff changeset
    30
 * @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
    31
 *          java.management
40631
ed82623d7831 8157957: ClassNotFoundException: jdk.test.lib.JDKToolFinder
ctornqvi
parents: 40106
diff changeset
    32
 * @build sun.hotspot.WhiteBox
48791
6e079ff6c83c 8186635: ClassFileInstaller should be run as a driver
iignatyev
parents: 47216
diff changeset
    33
 * @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
    34
 * @run driver/timeout=240  TestNewSizeFlags
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
    35
 */
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
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
    38
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
    39
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
    40
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
    41
import java.util.LinkedList;
40631
ed82623d7831 8157957: ClassNotFoundException: jdk.test.lib.JDKToolFinder
ctornqvi
parents: 40106
diff changeset
    42
import jdk.test.lib.process.OutputAnalyzer;
ed82623d7831 8157957: ClassNotFoundException: jdk.test.lib.JDKToolFinder
ctornqvi
parents: 40106
diff changeset
    43
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
    44
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
    45
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
    46
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
    47
public class TestNewSizeFlags {
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
    48
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
    49
    public 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
    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("(-Xm[nsx][^ ]+)|"
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
    54
                                + "(-XX:(Max)?((New)|"
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
    55
                                + "(Heap))((Size)|"
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
    56
                                + "(Ratio))=[^ ]+)"))
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
    57
        );
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
    58
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
    59
        // 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
    60
        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
    61
        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
    62
        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
    63
        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
    64
        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
    65
        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
    66
        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
    67
        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
    68
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
    69
        // Test -Xmn
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
    70
        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
    71
        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
    72
        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
    73
    }
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
    74
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
    75
    /**
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
    76
     * 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
    77
     *
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
    78
     * @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
    79
     * @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
    80
     * @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
    81
     * @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
    82
     * @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
    83
     * @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
    84
     */
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
    85
    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
    86
            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
    87
            LinkedList<String> options,
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
    88
            boolean failureExpected) throws Exception {
40106
6be13673b3c1 8161604: TestNewSizeFlags fails with RuntimeException: max new size != MaxNewSize value
mchernov
parents: 36851
diff changeset
    89
        long expectedNewSize = newSize;
6be13673b3c1 8161604: TestNewSizeFlags fails with RuntimeException: max new size != MaxNewSize value
mchernov
parents: 36851
diff changeset
    90
        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
    91
        testVMOptions(newSize, maxNewSize,
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
    92
                heapSize, maxHeapSize,
40106
6be13673b3c1 8161604: TestNewSizeFlags fails with RuntimeException: max new size != MaxNewSize value
mchernov
parents: 36851
diff changeset
    93
                expectedNewSize, expectedMaxNewSize,
32625
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
    94
                options, failureExpected);
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
    95
    }
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
    96
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
    97
    /**
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
    98
     * 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
    99
     *
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
   100
     * @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
   101
     * @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
   102
     * @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
   103
     * @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
   104
     * @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
   105
     */
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
   106
    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
   107
            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
   108
            LinkedList<String> options,
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
   109
            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
   110
        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
   111
        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
   112
        testVMOptions(-1, -1,
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
   113
                heapSize, maxHeapSize,
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
   114
                mnValue, mnValue,
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
   115
                newOptions, failureExpected);
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
   116
    }
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
   117
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
   118
    /**
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
   119
     * 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
   120
     *
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
   121
     * @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
   122
     * @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
   123
     * @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
   124
     * @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
   125
     * @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
   126
     * @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
   127
     * @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
   128
     * @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
   129
     */
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
   130
    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
   131
            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
   132
            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
   133
            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
   134
        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
   135
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
   136
        if (failureExpected) {
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
   137
            analyzer.shouldHaveExitValue(1);
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
   138
            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
   139
                    + "(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
   140
        } else {
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
   141
            analyzer.shouldHaveExitValue(0);
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
   142
        }
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
   143
    }
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
   144
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
   145
    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
   146
            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
   147
            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
   148
            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
   149
        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
   150
        Collections.addAll(vmOptions,
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
   151
                "-Xbootclasspath/a:.",
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
   152
                "-XX:+UnlockDiagnosticVMOptions",
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
   153
                "-XX:+WhiteBoxAPI",
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
   154
                (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
   155
                (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
   156
                "-Xmx" + maxHeapSize,
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
   157
                "-Xms" + heapSize,
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
   158
                "-XX:GCLockerEdenExpansionPercent=0",
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
   159
                "-XX:-UseLargePages",
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
   160
                NewSizeVerifier.class.getName(),
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
   161
                Long.toString(expectedNewSize),
40106
6be13673b3c1 8161604: TestNewSizeFlags fails with RuntimeException: max new size != MaxNewSize value
mchernov
parents: 36851
diff changeset
   162
                Long.toString(expectedMaxNewSize),
6be13673b3c1 8161604: TestNewSizeFlags fails with RuntimeException: max new size != MaxNewSize value
mchernov
parents: 36851
diff changeset
   163
                Long.toString(heapSize),
6be13673b3c1 8161604: TestNewSizeFlags fails with RuntimeException: max new size != MaxNewSize value
mchernov
parents: 36851
diff changeset
   164
                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
   165
        );
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
   166
        vmOptions.removeIf(String::isEmpty);
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
   167
        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
   168
        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
   169
        return analyzer;
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
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
   172
    /**
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
   173
     * 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
   174
     * 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
   175
     * expected max size.
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
   176
     * 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
   177
     * 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
   178
     * 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
   179
     */
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
   180
    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
   181
40106
6be13673b3c1 8161604: TestNewSizeFlags fails with RuntimeException: max new size != MaxNewSize value
mchernov
parents: 36851
diff changeset
   182
        private static final WhiteBox WB = WhiteBox.getWhiteBox();
6be13673b3c1 8161604: TestNewSizeFlags fails with RuntimeException: max new size != MaxNewSize value
mchernov
parents: 36851
diff changeset
   183
        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
   184
        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
   185
        private static final long HEAP_ALIGNMENT = WB.getHeapAlignment();
6be13673b3c1 8161604: TestNewSizeFlags fails with RuntimeException: max new size != MaxNewSize value
mchernov
parents: 36851
diff changeset
   186
        private static final long PS_VIRTUAL_SPACE_ALIGNMENT =
6be13673b3c1 8161604: TestNewSizeFlags fails with RuntimeException: max new size != MaxNewSize value
mchernov
parents: 36851
diff changeset
   187
                (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
   188
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
   189
        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
   190
        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
   191
        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
   192
        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
   193
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
   194
        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
   195
            if (args.length != 4) {
6be13673b3c1 8161604: TestNewSizeFlags fails with RuntimeException: max new size != MaxNewSize value
mchernov
parents: 36851
diff changeset
   196
                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
   197
            }
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
   198
            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
   199
            final long maxNewSize = Long.valueOf(args[1]);
40106
6be13673b3c1 8161604: TestNewSizeFlags fails with RuntimeException: max new size != MaxNewSize value
mchernov
parents: 36851
diff changeset
   200
            final long initialHeapSize = Long.valueOf(args[2]);
6be13673b3c1 8161604: TestNewSizeFlags fails with RuntimeException: max new size != MaxNewSize value
mchernov
parents: 36851
diff changeset
   201
            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
   202
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
   203
            // verify initial size
40106
6be13673b3c1 8161604: TestNewSizeFlags fails with RuntimeException: max new size != MaxNewSize value
mchernov
parents: 36851
diff changeset
   204
            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
   205
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
   206
            // 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
   207
            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
   208
            allocator.allocateMemoryAndVerifyNoOOME();
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
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
   211
        /**
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
   212
         * 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
   213
         */
40106
6be13673b3c1 8161604: TestNewSizeFlags fails with RuntimeException: max new size != MaxNewSize value
mchernov
parents: 36851
diff changeset
   214
        public static Void verifyNewSize(long newSize, long maxNewSize,
6be13673b3c1 8161604: TestNewSizeFlags fails with RuntimeException: max new size != MaxNewSize value
mchernov
parents: 36851
diff changeset
   215
                long initialHeapSize, long maxHeapSize) {
6be13673b3c1 8161604: TestNewSizeFlags fails with RuntimeException: max new size != MaxNewSize value
mchernov
parents: 36851
diff changeset
   216
            long alignedNewSize = alignGenSize(newSize);
6be13673b3c1 8161604: TestNewSizeFlags fails with RuntimeException: max new size != MaxNewSize value
mchernov
parents: 36851
diff changeset
   217
            long alignedMaxNewSize = alignGenSize(maxNewSize);
6be13673b3c1 8161604: TestNewSizeFlags fails with RuntimeException: max new size != MaxNewSize value
mchernov
parents: 36851
diff changeset
   218
            long alignedXms = alignHeapSize(initialHeapSize);
6be13673b3c1 8161604: TestNewSizeFlags fails with RuntimeException: max new size != MaxNewSize value
mchernov
parents: 36851
diff changeset
   219
            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
   220
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
   221
            MemoryUsage youngGenUsage = getYoungGenUsage();
40106
6be13673b3c1 8161604: TestNewSizeFlags fails with RuntimeException: max new size != MaxNewSize value
mchernov
parents: 36851
diff changeset
   222
            long initSize = youngGenUsage.getInit();
6be13673b3c1 8161604: TestNewSizeFlags fails with RuntimeException: max new size != MaxNewSize value
mchernov
parents: 36851
diff changeset
   223
            long commitedSize = youngGenUsage.getCommitted();
6be13673b3c1 8161604: TestNewSizeFlags fails with RuntimeException: max new size != MaxNewSize value
mchernov
parents: 36851
diff changeset
   224
            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
   225
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
   226
            if (newSize != -1) {
40106
6be13673b3c1 8161604: TestNewSizeFlags fails with RuntimeException: max new size != MaxNewSize value
mchernov
parents: 36851
diff changeset
   227
                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
   228
                    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
   229
                            + initSize + " < " + alignedNewSize);
32625
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
   230
                }
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
   231
40106
6be13673b3c1 8161604: TestNewSizeFlags fails with RuntimeException: max new size != MaxNewSize value
mchernov
parents: 36851
diff changeset
   232
                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
   233
                    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
   234
                            + commitedSize + " < " + alignedNewSize);
32625
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
   235
                }
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
   236
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
   237
                // 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
   238
                if (YOUNG_GC_TYPE != GCTypes.YoungGCType.G1
6be13673b3c1 8161604: TestNewSizeFlags fails with RuntimeException: max new size != MaxNewSize value
mchernov
parents: 36851
diff changeset
   239
                        && maxSize < alignedNewSize) {
32625
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
   240
                    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
   241
                            + maxSize + " < " + alignedNewSize);
32625
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
   242
                }
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
   243
            }
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
   244
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
   245
            if (maxNewSize != -1) {
40106
6be13673b3c1 8161604: TestNewSizeFlags fails with RuntimeException: max new size != MaxNewSize value
mchernov
parents: 36851
diff changeset
   246
                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
   247
                    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
   248
                            + initSize + " > " + alignedMaxNewSize);
6be13673b3c1 8161604: TestNewSizeFlags fails with RuntimeException: max new size != MaxNewSize value
mchernov
parents: 36851
diff changeset
   249
                }
6be13673b3c1 8161604: TestNewSizeFlags fails with RuntimeException: max new size != MaxNewSize value
mchernov
parents: 36851
diff changeset
   250
6be13673b3c1 8161604: TestNewSizeFlags fails with RuntimeException: max new size != MaxNewSize value
mchernov
parents: 36851
diff changeset
   251
                if (commitedSize > alignedMaxNewSize) {
6be13673b3c1 8161604: TestNewSizeFlags fails with RuntimeException: max new size != MaxNewSize value
mchernov
parents: 36851
diff changeset
   252
                    throw new RuntimeException("actual new size > MaxNewSize value: "
6be13673b3c1 8161604: TestNewSizeFlags fails with RuntimeException: max new size != MaxNewSize value
mchernov
parents: 36851
diff changeset
   253
                            + commitedSize + " > " + alignedMaxNewSize);
32625
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
   254
                }
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
   255
40106
6be13673b3c1 8161604: TestNewSizeFlags fails with RuntimeException: max new size != MaxNewSize value
mchernov
parents: 36851
diff changeset
   256
                if (alignedXms != alignedXmx) {
6be13673b3c1 8161604: TestNewSizeFlags fails with RuntimeException: max new size != MaxNewSize value
mchernov
parents: 36851
diff changeset
   257
                    if (YOUNG_GC_TYPE != GCTypes.YoungGCType.G1
6be13673b3c1 8161604: TestNewSizeFlags fails with RuntimeException: max new size != MaxNewSize value
mchernov
parents: 36851
diff changeset
   258
                            && maxSize != alignedMaxNewSize) {
6be13673b3c1 8161604: TestNewSizeFlags fails with RuntimeException: max new size != MaxNewSize value
mchernov
parents: 36851
diff changeset
   259
                        throw new RuntimeException("max new size != MaxNewSize value: "
6be13673b3c1 8161604: TestNewSizeFlags fails with RuntimeException: max new size != MaxNewSize value
mchernov
parents: 36851
diff changeset
   260
                                + maxSize + " != " + alignedMaxNewSize);
6be13673b3c1 8161604: TestNewSizeFlags fails with RuntimeException: max new size != MaxNewSize value
mchernov
parents: 36851
diff changeset
   261
                    }
6be13673b3c1 8161604: TestNewSizeFlags fails with RuntimeException: max new size != MaxNewSize value
mchernov
parents: 36851
diff changeset
   262
                } else {
6be13673b3c1 8161604: TestNewSizeFlags fails with RuntimeException: max new size != MaxNewSize value
mchernov
parents: 36851
diff changeset
   263
                    if (YOUNG_GC_TYPE != GCTypes.YoungGCType.G1
6be13673b3c1 8161604: TestNewSizeFlags fails with RuntimeException: max new size != MaxNewSize value
mchernov
parents: 36851
diff changeset
   264
                            && maxSize != alignedNewSize) {
6be13673b3c1 8161604: TestNewSizeFlags fails with RuntimeException: max new size != MaxNewSize value
mchernov
parents: 36851
diff changeset
   265
                        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
   266
                                + maxSize + " != " + alignedNewSize + " HeapSize == " + alignedXms);
6be13673b3c1 8161604: TestNewSizeFlags fails with RuntimeException: max new size != MaxNewSize value
mchernov
parents: 36851
diff changeset
   267
                    }
32625
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
   268
                }
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
   269
            }
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
   270
            return null;
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
   271
        }
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
         *  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
   275
         *
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
   276
         *  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
   277
         *  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
   278
         *  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
   279
         *  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
   280
         */
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
   281
        private static MemoryUsage getYoungGenUsage() {
40106
6be13673b3c1 8161604: TestNewSizeFlags fails with RuntimeException: max new size != MaxNewSize value
mchernov
parents: 36851
diff changeset
   282
            MemoryUsage edenUsage = HeapRegionUsageTool.getEdenUsage();
6be13673b3c1 8161604: TestNewSizeFlags fails with RuntimeException: max new size != MaxNewSize value
mchernov
parents: 36851
diff changeset
   283
            MemoryUsage survivorUsage = HeapRegionUsageTool.getSurvivorUsage();
6be13673b3c1 8161604: TestNewSizeFlags fails with RuntimeException: max new size != MaxNewSize value
mchernov
parents: 36851
diff changeset
   284
            long edenUsageInit = edenUsage.getInit();
6be13673b3c1 8161604: TestNewSizeFlags fails with RuntimeException: max new size != MaxNewSize value
mchernov
parents: 36851
diff changeset
   285
            long edenUsageCommited = edenUsage.getCommitted();
6be13673b3c1 8161604: TestNewSizeFlags fails with RuntimeException: max new size != MaxNewSize value
mchernov
parents: 36851
diff changeset
   286
            long survivorUsageInit = survivorUsage.getInit();
6be13673b3c1 8161604: TestNewSizeFlags fails with RuntimeException: max new size != MaxNewSize value
mchernov
parents: 36851
diff changeset
   287
            long survivorUsageCommited = survivorUsage.getCommitted();
6be13673b3c1 8161604: TestNewSizeFlags fails with RuntimeException: max new size != MaxNewSize value
mchernov
parents: 36851
diff changeset
   288
6be13673b3c1 8161604: TestNewSizeFlags fails with RuntimeException: max new size != MaxNewSize value
mchernov
parents: 36851
diff changeset
   289
            if (YOUNG_GC_TYPE == GCTypes.YoungGCType.G1) {
6be13673b3c1 8161604: TestNewSizeFlags fails with RuntimeException: max new size != MaxNewSize value
mchernov
parents: 36851
diff changeset
   290
                return new MemoryUsage(edenUsageInit + survivorUsageInit, 0,
6be13673b3c1 8161604: TestNewSizeFlags fails with RuntimeException: max new size != MaxNewSize value
mchernov
parents: 36851
diff changeset
   291
                        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
   292
            } else {
40106
6be13673b3c1 8161604: TestNewSizeFlags fails with RuntimeException: max new size != MaxNewSize value
mchernov
parents: 36851
diff changeset
   293
                return new MemoryUsage(edenUsageInit + survivorUsageInit * 2, 0,
6be13673b3c1 8161604: TestNewSizeFlags fails with RuntimeException: max new size != MaxNewSize value
mchernov
parents: 36851
diff changeset
   294
                        edenUsageCommited + survivorUsageCommited * 2,
6be13673b3c1 8161604: TestNewSizeFlags fails with RuntimeException: max new size != MaxNewSize value
mchernov
parents: 36851
diff changeset
   295
                        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
   296
            }
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
   297
        }
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
   298
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
   299
        /**
40106
6be13673b3c1 8161604: TestNewSizeFlags fails with RuntimeException: max new size != MaxNewSize value
mchernov
parents: 36851
diff changeset
   300
         * 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
   301
         */
40106
6be13673b3c1 8161604: TestNewSizeFlags fails with RuntimeException: max new size != MaxNewSize value
mchernov
parents: 36851
diff changeset
   302
        public static long alignGenSize(long value) {
6be13673b3c1 8161604: TestNewSizeFlags fails with RuntimeException: max new size != MaxNewSize value
mchernov
parents: 36851
diff changeset
   303
            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
   304
                case DefNew:
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
   305
                case ParNew:
40106
6be13673b3c1 8161604: TestNewSizeFlags fails with RuntimeException: max new size != MaxNewSize value
mchernov
parents: 36851
diff changeset
   306
                    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
   307
                case PSNew:
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
   308
                    return HeapRegionUsageTool.alignUp(HeapRegionUsageTool.alignDown(value,
40106
6be13673b3c1 8161604: TestNewSizeFlags fails with RuntimeException: max new size != MaxNewSize value
mchernov
parents: 36851
diff changeset
   309
                            HEAP_SPACE_ALIGNMENT),
6be13673b3c1 8161604: TestNewSizeFlags fails with RuntimeException: max new size != MaxNewSize value
mchernov
parents: 36851
diff changeset
   310
                            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
   311
                case G1:
40106
6be13673b3c1 8161604: TestNewSizeFlags fails with RuntimeException: max new size != MaxNewSize value
mchernov
parents: 36851
diff changeset
   312
                    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
   313
                default:
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
   314
                    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
   315
            }
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
   316
        }
40106
6be13673b3c1 8161604: TestNewSizeFlags fails with RuntimeException: max new size != MaxNewSize value
mchernov
parents: 36851
diff changeset
   317
6be13673b3c1 8161604: TestNewSizeFlags fails with RuntimeException: max new size != MaxNewSize value
mchernov
parents: 36851
diff changeset
   318
        /**
6be13673b3c1 8161604: TestNewSizeFlags fails with RuntimeException: max new size != MaxNewSize value
mchernov
parents: 36851
diff changeset
   319
         * Align heap size.
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
        public static long alignHeapSize(long value){
6be13673b3c1 8161604: TestNewSizeFlags fails with RuntimeException: max new size != MaxNewSize value
mchernov
parents: 36851
diff changeset
   322
            return HeapRegionUsageTool.alignUp(value,HEAP_ALIGNMENT);
6be13673b3c1 8161604: TestNewSizeFlags fails with RuntimeException: max new size != MaxNewSize value
mchernov
parents: 36851
diff changeset
   323
        }
32625
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
   324
    }
054d452e4e06 8081317: [NEWTEST] documented GC ratio tuning and new size options should be covered by regression tests
mchernov
parents:
diff changeset
   325
}