test/hotspot/jtreg/gc/TestDisableExplicitGC.java
author prr
Thu, 26 Jul 2018 10:00:40 -0700
changeset 51251 0a7a0a6dfa22
parent 47216 71c04702a3d5
child 53523 4c5184c56dc2
permissions -rw-r--r--
Merge
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
29682
5e1737bfb1bb 8026047: [TESTBUG] add regression test for DisableExplicitGC flag
iignatyev
parents:
diff changeset
     1
/*
38083
2ffb46735fec 8154843: GC tests should be correctly marked with @module
mchernov
parents: 35061
diff changeset
     2
 * Copyright (c) 2015, 2016, Oracle and/or its affiliates. All rights reserved.
29682
5e1737bfb1bb 8026047: [TESTBUG] add regression test for DisableExplicitGC flag
iignatyev
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5e1737bfb1bb 8026047: [TESTBUG] add regression test for DisableExplicitGC flag
iignatyev
parents:
diff changeset
     4
 *
5e1737bfb1bb 8026047: [TESTBUG] add regression test for DisableExplicitGC flag
iignatyev
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
5e1737bfb1bb 8026047: [TESTBUG] add regression test for DisableExplicitGC flag
iignatyev
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5e1737bfb1bb 8026047: [TESTBUG] add regression test for DisableExplicitGC flag
iignatyev
parents:
diff changeset
     7
 * published by the Free Software Foundation.
5e1737bfb1bb 8026047: [TESTBUG] add regression test for DisableExplicitGC flag
iignatyev
parents:
diff changeset
     8
 *
5e1737bfb1bb 8026047: [TESTBUG] add regression test for DisableExplicitGC flag
iignatyev
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
5e1737bfb1bb 8026047: [TESTBUG] add regression test for DisableExplicitGC flag
iignatyev
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
5e1737bfb1bb 8026047: [TESTBUG] add regression test for DisableExplicitGC flag
iignatyev
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
5e1737bfb1bb 8026047: [TESTBUG] add regression test for DisableExplicitGC flag
iignatyev
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
5e1737bfb1bb 8026047: [TESTBUG] add regression test for DisableExplicitGC flag
iignatyev
parents:
diff changeset
    13
 * accompanied this code).
5e1737bfb1bb 8026047: [TESTBUG] add regression test for DisableExplicitGC flag
iignatyev
parents:
diff changeset
    14
 *
5e1737bfb1bb 8026047: [TESTBUG] add regression test for DisableExplicitGC flag
iignatyev
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
5e1737bfb1bb 8026047: [TESTBUG] add regression test for DisableExplicitGC flag
iignatyev
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
5e1737bfb1bb 8026047: [TESTBUG] add regression test for DisableExplicitGC flag
iignatyev
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
5e1737bfb1bb 8026047: [TESTBUG] add regression test for DisableExplicitGC flag
iignatyev
parents:
diff changeset
    18
 *
5e1737bfb1bb 8026047: [TESTBUG] add regression test for DisableExplicitGC flag
iignatyev
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
5e1737bfb1bb 8026047: [TESTBUG] add regression test for DisableExplicitGC flag
iignatyev
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
5e1737bfb1bb 8026047: [TESTBUG] add regression test for DisableExplicitGC flag
iignatyev
parents:
diff changeset
    21
 * questions.
5e1737bfb1bb 8026047: [TESTBUG] add regression test for DisableExplicitGC flag
iignatyev
parents:
diff changeset
    22
 */
5e1737bfb1bb 8026047: [TESTBUG] add regression test for DisableExplicitGC flag
iignatyev
parents:
diff changeset
    23
5e1737bfb1bb 8026047: [TESTBUG] add regression test for DisableExplicitGC flag
iignatyev
parents:
diff changeset
    24
/*
5e1737bfb1bb 8026047: [TESTBUG] add regression test for DisableExplicitGC flag
iignatyev
parents:
diff changeset
    25
 * @test TestDisableExplicitGC
5e1737bfb1bb 8026047: [TESTBUG] add regression test for DisableExplicitGC flag
iignatyev
parents:
diff changeset
    26
 * @requires vm.opt.DisableExplicitGC == null
5e1737bfb1bb 8026047: [TESTBUG] add regression test for DisableExplicitGC flag
iignatyev
parents:
diff changeset
    27
 * @summary Verify GC behavior with DisableExplicitGC flag.
40631
ed82623d7831 8157957: ClassNotFoundException: jdk.test.lib.JDKToolFinder
ctornqvi
parents: 38152
diff changeset
    28
 * @library /test/lib
38152
80e5da81fb2c 8154258: [TESTBUG] Various serviceability tests fail compilation
dsamersoff
parents: 38083
diff changeset
    29
 * @modules java.base/jdk.internal.misc
38083
2ffb46735fec 8154843: GC tests should be correctly marked with @module
mchernov
parents: 35061
diff changeset
    30
 * @modules jdk.management/com.sun.management.internal
35061
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 30604
diff changeset
    31
 * @run main/othervm                             -Xlog:gc=debug TestDisableExplicitGC
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 30604
diff changeset
    32
 * @run main/othervm/fail -XX:+DisableExplicitGC -Xlog:gc=debug TestDisableExplicitGC
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 30604
diff changeset
    33
 * @run main/othervm      -XX:-DisableExplicitGC -Xlog:gc=debug TestDisableExplicitGC
29682
5e1737bfb1bb 8026047: [TESTBUG] add regression test for DisableExplicitGC flag
iignatyev
parents:
diff changeset
    34
 */
5e1737bfb1bb 8026047: [TESTBUG] add regression test for DisableExplicitGC flag
iignatyev
parents:
diff changeset
    35
import java.lang.management.GarbageCollectorMXBean;
5e1737bfb1bb 8026047: [TESTBUG] add regression test for DisableExplicitGC flag
iignatyev
parents:
diff changeset
    36
import java.util.List;
30604
b8d532cb6420 8067013: Rename the com.oracle.java.testlibary package
ykantser
parents: 29682
diff changeset
    37
import static jdk.test.lib.Asserts.*;
29682
5e1737bfb1bb 8026047: [TESTBUG] add regression test for DisableExplicitGC flag
iignatyev
parents:
diff changeset
    38
5e1737bfb1bb 8026047: [TESTBUG] add regression test for DisableExplicitGC flag
iignatyev
parents:
diff changeset
    39
public class TestDisableExplicitGC {
5e1737bfb1bb 8026047: [TESTBUG] add regression test for DisableExplicitGC flag
iignatyev
parents:
diff changeset
    40
5e1737bfb1bb 8026047: [TESTBUG] add regression test for DisableExplicitGC flag
iignatyev
parents:
diff changeset
    41
    public static void main(String[] args) throws InterruptedException {
5e1737bfb1bb 8026047: [TESTBUG] add regression test for DisableExplicitGC flag
iignatyev
parents:
diff changeset
    42
        List<GarbageCollectorMXBean> list = java.lang.management.ManagementFactory.getGarbageCollectorMXBeans();
5e1737bfb1bb 8026047: [TESTBUG] add regression test for DisableExplicitGC flag
iignatyev
parents:
diff changeset
    43
        long collectionCountBefore = getCollectionCount(list);
5e1737bfb1bb 8026047: [TESTBUG] add regression test for DisableExplicitGC flag
iignatyev
parents:
diff changeset
    44
        System.gc();
5e1737bfb1bb 8026047: [TESTBUG] add regression test for DisableExplicitGC flag
iignatyev
parents:
diff changeset
    45
        long collectionCountAfter = getCollectionCount(list);
5e1737bfb1bb 8026047: [TESTBUG] add regression test for DisableExplicitGC flag
iignatyev
parents:
diff changeset
    46
        assertLT(collectionCountBefore, collectionCountAfter);
5e1737bfb1bb 8026047: [TESTBUG] add regression test for DisableExplicitGC flag
iignatyev
parents:
diff changeset
    47
    }
5e1737bfb1bb 8026047: [TESTBUG] add regression test for DisableExplicitGC flag
iignatyev
parents:
diff changeset
    48
5e1737bfb1bb 8026047: [TESTBUG] add regression test for DisableExplicitGC flag
iignatyev
parents:
diff changeset
    49
    private static long getCollectionCount(List<GarbageCollectorMXBean> list) {
5e1737bfb1bb 8026047: [TESTBUG] add regression test for DisableExplicitGC flag
iignatyev
parents:
diff changeset
    50
        int collectionCount = 0;
5e1737bfb1bb 8026047: [TESTBUG] add regression test for DisableExplicitGC flag
iignatyev
parents:
diff changeset
    51
        for (GarbageCollectorMXBean gcMXBean : list) {
5e1737bfb1bb 8026047: [TESTBUG] add regression test for DisableExplicitGC flag
iignatyev
parents:
diff changeset
    52
            collectionCount += gcMXBean.getCollectionCount();
5e1737bfb1bb 8026047: [TESTBUG] add regression test for DisableExplicitGC flag
iignatyev
parents:
diff changeset
    53
        }
5e1737bfb1bb 8026047: [TESTBUG] add regression test for DisableExplicitGC flag
iignatyev
parents:
diff changeset
    54
        return collectionCount;
5e1737bfb1bb 8026047: [TESTBUG] add regression test for DisableExplicitGC flag
iignatyev
parents:
diff changeset
    55
    }
5e1737bfb1bb 8026047: [TESTBUG] add regression test for DisableExplicitGC flag
iignatyev
parents:
diff changeset
    56
}