hotspot/test/gc/metaspace/TestCapacityUntilGCWrapAround.java
author sjohanss
Thu, 24 Mar 2016 10:49:08 +0100
changeset 37244 9b8f2dc281ad
parent 33730 30e064828045
child 36851 03e2f4d0a421
permissions -rw-r--r--
8151460: Metaspace counters can have inconsistent values Reviewed-by: jmasa, pliden
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
26938
e0b35f8104a7 8049599: MetaspaceGC::_capacity_until_GC can overflow
ehelin
parents:
diff changeset
     1
/*
29678
dd2f3932c21e 8075586: Add @modules as needed to the open hotspot tests
ykantser
parents: 28190
diff changeset
     2
 * Copyright (c) 2014, 2015, Oracle and/or its affiliates. All rights reserved.
26938
e0b35f8104a7 8049599: MetaspaceGC::_capacity_until_GC can overflow
ehelin
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
e0b35f8104a7 8049599: MetaspaceGC::_capacity_until_GC can overflow
ehelin
parents:
diff changeset
     4
 *
e0b35f8104a7 8049599: MetaspaceGC::_capacity_until_GC can overflow
ehelin
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
e0b35f8104a7 8049599: MetaspaceGC::_capacity_until_GC can overflow
ehelin
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
e0b35f8104a7 8049599: MetaspaceGC::_capacity_until_GC can overflow
ehelin
parents:
diff changeset
     7
 * published by the Free Software Foundation.
e0b35f8104a7 8049599: MetaspaceGC::_capacity_until_GC can overflow
ehelin
parents:
diff changeset
     8
 *
e0b35f8104a7 8049599: MetaspaceGC::_capacity_until_GC can overflow
ehelin
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
e0b35f8104a7 8049599: MetaspaceGC::_capacity_until_GC can overflow
ehelin
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
e0b35f8104a7 8049599: MetaspaceGC::_capacity_until_GC can overflow
ehelin
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
e0b35f8104a7 8049599: MetaspaceGC::_capacity_until_GC can overflow
ehelin
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
e0b35f8104a7 8049599: MetaspaceGC::_capacity_until_GC can overflow
ehelin
parents:
diff changeset
    13
 * accompanied this code).
e0b35f8104a7 8049599: MetaspaceGC::_capacity_until_GC can overflow
ehelin
parents:
diff changeset
    14
 *
e0b35f8104a7 8049599: MetaspaceGC::_capacity_until_GC can overflow
ehelin
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
e0b35f8104a7 8049599: MetaspaceGC::_capacity_until_GC can overflow
ehelin
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
e0b35f8104a7 8049599: MetaspaceGC::_capacity_until_GC can overflow
ehelin
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
e0b35f8104a7 8049599: MetaspaceGC::_capacity_until_GC can overflow
ehelin
parents:
diff changeset
    18
 *
e0b35f8104a7 8049599: MetaspaceGC::_capacity_until_GC can overflow
ehelin
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
e0b35f8104a7 8049599: MetaspaceGC::_capacity_until_GC can overflow
ehelin
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
e0b35f8104a7 8049599: MetaspaceGC::_capacity_until_GC can overflow
ehelin
parents:
diff changeset
    21
 * questions.
e0b35f8104a7 8049599: MetaspaceGC::_capacity_until_GC can overflow
ehelin
parents:
diff changeset
    22
 */
e0b35f8104a7 8049599: MetaspaceGC::_capacity_until_GC can overflow
ehelin
parents:
diff changeset
    23
e0b35f8104a7 8049599: MetaspaceGC::_capacity_until_GC can overflow
ehelin
parents:
diff changeset
    24
/*
e0b35f8104a7 8049599: MetaspaceGC::_capacity_until_GC can overflow
ehelin
parents:
diff changeset
    25
 * @test
e0b35f8104a7 8049599: MetaspaceGC::_capacity_until_GC can overflow
ehelin
parents:
diff changeset
    26
 * @key gc
e0b35f8104a7 8049599: MetaspaceGC::_capacity_until_GC can overflow
ehelin
parents:
diff changeset
    27
 * @bug 8049831
33730
30e064828045 8140189: [TESTBUG] Get rid of "@library /../../test/lib" in jtreg tests
cjplummer
parents: 30604
diff changeset
    28
 * @library /testlibrary /test/lib
29678
dd2f3932c21e 8075586: Add @modules as needed to the open hotspot tests
ykantser
parents: 28190
diff changeset
    29
 * @modules java.base/sun.misc
dd2f3932c21e 8075586: Add @modules as needed to the open hotspot tests
ykantser
parents: 28190
diff changeset
    30
 *          java.management
26938
e0b35f8104a7 8049599: MetaspaceGC::_capacity_until_GC can overflow
ehelin
parents:
diff changeset
    31
 * @build TestCapacityUntilGCWrapAround
e0b35f8104a7 8049599: MetaspaceGC::_capacity_until_GC can overflow
ehelin
parents:
diff changeset
    32
 * @run main ClassFileInstaller sun.hotspot.WhiteBox
e0b35f8104a7 8049599: MetaspaceGC::_capacity_until_GC can overflow
ehelin
parents:
diff changeset
    33
 *                              sun.hotspot.WhiteBox$WhiteBoxPermission
e0b35f8104a7 8049599: MetaspaceGC::_capacity_until_GC can overflow
ehelin
parents:
diff changeset
    34
 * @run main/othervm -Xbootclasspath/a:. -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI TestCapacityUntilGCWrapAround
e0b35f8104a7 8049599: MetaspaceGC::_capacity_until_GC can overflow
ehelin
parents:
diff changeset
    35
 */
e0b35f8104a7 8049599: MetaspaceGC::_capacity_until_GC can overflow
ehelin
parents:
diff changeset
    36
e0b35f8104a7 8049599: MetaspaceGC::_capacity_until_GC can overflow
ehelin
parents:
diff changeset
    37
import sun.hotspot.WhiteBox;
e0b35f8104a7 8049599: MetaspaceGC::_capacity_until_GC can overflow
ehelin
parents:
diff changeset
    38
30604
b8d532cb6420 8067013: Rename the com.oracle.java.testlibary package
ykantser
parents: 29678
diff changeset
    39
import jdk.test.lib.Asserts;
b8d532cb6420 8067013: Rename the com.oracle.java.testlibary package
ykantser
parents: 29678
diff changeset
    40
import jdk.test.lib.Platform;
26938
e0b35f8104a7 8049599: MetaspaceGC::_capacity_until_GC can overflow
ehelin
parents:
diff changeset
    41
e0b35f8104a7 8049599: MetaspaceGC::_capacity_until_GC can overflow
ehelin
parents:
diff changeset
    42
public class TestCapacityUntilGCWrapAround {
e0b35f8104a7 8049599: MetaspaceGC::_capacity_until_GC can overflow
ehelin
parents:
diff changeset
    43
    private static long MB = 1024 * 1024;
e0b35f8104a7 8049599: MetaspaceGC::_capacity_until_GC can overflow
ehelin
parents:
diff changeset
    44
    private static long GB = 1024 * MB;
e0b35f8104a7 8049599: MetaspaceGC::_capacity_until_GC can overflow
ehelin
parents:
diff changeset
    45
    private static long MAX_UINT = 4 * GB - 1; // On 32-bit platforms
e0b35f8104a7 8049599: MetaspaceGC::_capacity_until_GC can overflow
ehelin
parents:
diff changeset
    46
e0b35f8104a7 8049599: MetaspaceGC::_capacity_until_GC can overflow
ehelin
parents:
diff changeset
    47
    public static void main(String[] args) {
e0b35f8104a7 8049599: MetaspaceGC::_capacity_until_GC can overflow
ehelin
parents:
diff changeset
    48
        if (Platform.is32bit()) {
e0b35f8104a7 8049599: MetaspaceGC::_capacity_until_GC can overflow
ehelin
parents:
diff changeset
    49
            WhiteBox wb = WhiteBox.getWhiteBox();
e0b35f8104a7 8049599: MetaspaceGC::_capacity_until_GC can overflow
ehelin
parents:
diff changeset
    50
e0b35f8104a7 8049599: MetaspaceGC::_capacity_until_GC can overflow
ehelin
parents:
diff changeset
    51
            long before = wb.metaspaceCapacityUntilGC();
e0b35f8104a7 8049599: MetaspaceGC::_capacity_until_GC can overflow
ehelin
parents:
diff changeset
    52
            // Now force possible overflow of capacity_until_GC.
e0b35f8104a7 8049599: MetaspaceGC::_capacity_until_GC can overflow
ehelin
parents:
diff changeset
    53
            long after = wb.incMetaspaceCapacityUntilGC(MAX_UINT);
e0b35f8104a7 8049599: MetaspaceGC::_capacity_until_GC can overflow
ehelin
parents:
diff changeset
    54
e0b35f8104a7 8049599: MetaspaceGC::_capacity_until_GC can overflow
ehelin
parents:
diff changeset
    55
            Asserts.assertGTE(after, before,
e0b35f8104a7 8049599: MetaspaceGC::_capacity_until_GC can overflow
ehelin
parents:
diff changeset
    56
                              "Increasing with MAX_UINT should not cause wrap around: " + after + " < " + before);
e0b35f8104a7 8049599: MetaspaceGC::_capacity_until_GC can overflow
ehelin
parents:
diff changeset
    57
            Asserts.assertLTE(after, MAX_UINT,
e0b35f8104a7 8049599: MetaspaceGC::_capacity_until_GC can overflow
ehelin
parents:
diff changeset
    58
                              "Increasing with MAX_UINT should not cause value larger than MAX_UINT:" + after);
e0b35f8104a7 8049599: MetaspaceGC::_capacity_until_GC can overflow
ehelin
parents:
diff changeset
    59
        }
e0b35f8104a7 8049599: MetaspaceGC::_capacity_until_GC can overflow
ehelin
parents:
diff changeset
    60
    }
e0b35f8104a7 8049599: MetaspaceGC::_capacity_until_GC can overflow
ehelin
parents:
diff changeset
    61
}