hotspot/test/gc/TestSmallHeap.java
author brutisso
Wed, 17 Dec 2014 09:47:14 +0100
changeset 28205 6977216c35f2
child 28210 279085467d0a
permissions -rw-r--r--
8067438: Add test to verify minimal heap size Reviewed-by: dfazunen, ehelin
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
28205
6977216c35f2 8067438: Add test to verify minimal heap size
brutisso
parents:
diff changeset
     1
/*
6977216c35f2 8067438: Add test to verify minimal heap size
brutisso
parents:
diff changeset
     2
 * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
6977216c35f2 8067438: Add test to verify minimal heap size
brutisso
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6977216c35f2 8067438: Add test to verify minimal heap size
brutisso
parents:
diff changeset
     4
 *
6977216c35f2 8067438: Add test to verify minimal heap size
brutisso
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
6977216c35f2 8067438: Add test to verify minimal heap size
brutisso
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
6977216c35f2 8067438: Add test to verify minimal heap size
brutisso
parents:
diff changeset
     7
 * published by the Free Software Foundation.
6977216c35f2 8067438: Add test to verify minimal heap size
brutisso
parents:
diff changeset
     8
 *
6977216c35f2 8067438: Add test to verify minimal heap size
brutisso
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
6977216c35f2 8067438: Add test to verify minimal heap size
brutisso
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
6977216c35f2 8067438: Add test to verify minimal heap size
brutisso
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
6977216c35f2 8067438: Add test to verify minimal heap size
brutisso
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
6977216c35f2 8067438: Add test to verify minimal heap size
brutisso
parents:
diff changeset
    13
 * accompanied this code).
6977216c35f2 8067438: Add test to verify minimal heap size
brutisso
parents:
diff changeset
    14
 *
6977216c35f2 8067438: Add test to verify minimal heap size
brutisso
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
6977216c35f2 8067438: Add test to verify minimal heap size
brutisso
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
6977216c35f2 8067438: Add test to verify minimal heap size
brutisso
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
6977216c35f2 8067438: Add test to verify minimal heap size
brutisso
parents:
diff changeset
    18
 *
6977216c35f2 8067438: Add test to verify minimal heap size
brutisso
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
6977216c35f2 8067438: Add test to verify minimal heap size
brutisso
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
6977216c35f2 8067438: Add test to verify minimal heap size
brutisso
parents:
diff changeset
    21
 * questions.
6977216c35f2 8067438: Add test to verify minimal heap size
brutisso
parents:
diff changeset
    22
 */
6977216c35f2 8067438: Add test to verify minimal heap size
brutisso
parents:
diff changeset
    23
6977216c35f2 8067438: Add test to verify minimal heap size
brutisso
parents:
diff changeset
    24
/**
6977216c35f2 8067438: Add test to verify minimal heap size
brutisso
parents:
diff changeset
    25
 * @test TestSmallHeap
6977216c35f2 8067438: Add test to verify minimal heap size
brutisso
parents:
diff changeset
    26
 * @bug 8067438
6977216c35f2 8067438: Add test to verify minimal heap size
brutisso
parents:
diff changeset
    27
 * @requires vm.gc=="null"
6977216c35f2 8067438: Add test to verify minimal heap size
brutisso
parents:
diff changeset
    28
 * @summary Verify that starting the VM with a small heap works
6977216c35f2 8067438: Add test to verify minimal heap size
brutisso
parents:
diff changeset
    29
 * @run main/othervm -Xmx4m -XX:+UseParallelGC TestSmallHeap
6977216c35f2 8067438: Add test to verify minimal heap size
brutisso
parents:
diff changeset
    30
 * @run main/othervm -Xmx4m -XX:+UseSerialGC TestSmallHeap
6977216c35f2 8067438: Add test to verify minimal heap size
brutisso
parents:
diff changeset
    31
 * @run main/othervm -Xmx4m -XX:+UseG1GC TestSmallHeap
6977216c35f2 8067438: Add test to verify minimal heap size
brutisso
parents:
diff changeset
    32
 * @run main/othervm -Xmx4m -XX:+UseConcMarkSweepGC -XX:CMSMarkStackSizeMax=1032 TestSmallHeap
6977216c35f2 8067438: Add test to verify minimal heap size
brutisso
parents:
diff changeset
    33
 *
6977216c35f2 8067438: Add test to verify minimal heap size
brutisso
parents:
diff changeset
    34
 * Note: It would be nice to verify the minimal supported heap size here,
6977216c35f2 8067438: Add test to verify minimal heap size
brutisso
parents:
diff changeset
    35
 * but that turns out to be quite tricky since we align the heap size based
6977216c35f2 8067438: Add test to verify minimal heap size
brutisso
parents:
diff changeset
    36
 * on the card table size. And the card table size is aligned based on the
6977216c35f2 8067438: Add test to verify minimal heap size
brutisso
parents:
diff changeset
    37
 * minimal pages size provided by the os. This means that on most platforms,
6977216c35f2 8067438: Add test to verify minimal heap size
brutisso
parents:
diff changeset
    38
 * where the minimal page size is 4k, we get a minimal heap size of 2m but
6977216c35f2 8067438: Add test to verify minimal heap size
brutisso
parents:
diff changeset
    39
 * on Solaris/Sparc we have a page size of 8k and get a minimal heap size
6977216c35f2 8067438: Add test to verify minimal heap size
brutisso
parents:
diff changeset
    40
 * of 8m.
6977216c35f2 8067438: Add test to verify minimal heap size
brutisso
parents:
diff changeset
    41
 * There is also no check in the VM for verifying that the maximum heap size
6977216c35f2 8067438: Add test to verify minimal heap size
brutisso
parents:
diff changeset
    42
 * is larger than the supported minimal heap size. This means that specifying
6977216c35f2 8067438: Add test to verify minimal heap size
brutisso
parents:
diff changeset
    43
 * -Xmx1m on the command line is fine but will give a heap of 2m (or 4m).
6977216c35f2 8067438: Add test to verify minimal heap size
brutisso
parents:
diff changeset
    44
 * To work around these rather strange behaviors this test uses 4m for all
6977216c35f2 8067438: Add test to verify minimal heap size
brutisso
parents:
diff changeset
    45
 * platforms.
6977216c35f2 8067438: Add test to verify minimal heap size
brutisso
parents:
diff changeset
    46
 */
6977216c35f2 8067438: Add test to verify minimal heap size
brutisso
parents:
diff changeset
    47
6977216c35f2 8067438: Add test to verify minimal heap size
brutisso
parents:
diff changeset
    48
import sun.management.ManagementFactoryHelper;
6977216c35f2 8067438: Add test to verify minimal heap size
brutisso
parents:
diff changeset
    49
import static com.oracle.java.testlibrary.Asserts.*;
6977216c35f2 8067438: Add test to verify minimal heap size
brutisso
parents:
diff changeset
    50
6977216c35f2 8067438: Add test to verify minimal heap size
brutisso
parents:
diff changeset
    51
public class TestSmallHeap {
6977216c35f2 8067438: Add test to verify minimal heap size
brutisso
parents:
diff changeset
    52
6977216c35f2 8067438: Add test to verify minimal heap size
brutisso
parents:
diff changeset
    53
    public static void main(String[] args) {
6977216c35f2 8067438: Add test to verify minimal heap size
brutisso
parents:
diff changeset
    54
        String maxHeap = ManagementFactoryHelper.getDiagnosticMXBean().getVMOption("MaxHeapSize").getValue();
6977216c35f2 8067438: Add test to verify minimal heap size
brutisso
parents:
diff changeset
    55
        String expectedMaxHeap = "4194304";
6977216c35f2 8067438: Add test to verify minimal heap size
brutisso
parents:
diff changeset
    56
        assertEQ(maxHeap, expectedMaxHeap);
6977216c35f2 8067438: Add test to verify minimal heap size
brutisso
parents:
diff changeset
    57
    }
6977216c35f2 8067438: Add test to verify minimal heap size
brutisso
parents:
diff changeset
    58
}