hotspot/test/gc/metaspace/TestMetaspaceCMSCancel.java
author jmasa
Fri, 10 Jun 2016 09:22:09 -0700
changeset 39270 9b12d5739295
child 40631 ed82623d7831
permissions -rw-r--r--
8026752: Cancel MetaspaceGC request for a CMS concurrent collection after GC Reviewed-by: sjohanss, sangheki
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
39270
9b12d5739295 8026752: Cancel MetaspaceGC request for a CMS concurrent collection after GC
jmasa
parents:
diff changeset
     1
/*
9b12d5739295 8026752: Cancel MetaspaceGC request for a CMS concurrent collection after GC
jmasa
parents:
diff changeset
     2
 * Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
9b12d5739295 8026752: Cancel MetaspaceGC request for a CMS concurrent collection after GC
jmasa
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
9b12d5739295 8026752: Cancel MetaspaceGC request for a CMS concurrent collection after GC
jmasa
parents:
diff changeset
     4
 *
9b12d5739295 8026752: Cancel MetaspaceGC request for a CMS concurrent collection after GC
jmasa
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
9b12d5739295 8026752: Cancel MetaspaceGC request for a CMS concurrent collection after GC
jmasa
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
9b12d5739295 8026752: Cancel MetaspaceGC request for a CMS concurrent collection after GC
jmasa
parents:
diff changeset
     7
 * published by the Free Software Foundation.
9b12d5739295 8026752: Cancel MetaspaceGC request for a CMS concurrent collection after GC
jmasa
parents:
diff changeset
     8
 *
9b12d5739295 8026752: Cancel MetaspaceGC request for a CMS concurrent collection after GC
jmasa
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
9b12d5739295 8026752: Cancel MetaspaceGC request for a CMS concurrent collection after GC
jmasa
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
9b12d5739295 8026752: Cancel MetaspaceGC request for a CMS concurrent collection after GC
jmasa
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
9b12d5739295 8026752: Cancel MetaspaceGC request for a CMS concurrent collection after GC
jmasa
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
9b12d5739295 8026752: Cancel MetaspaceGC request for a CMS concurrent collection after GC
jmasa
parents:
diff changeset
    13
 * accompanied this code).
9b12d5739295 8026752: Cancel MetaspaceGC request for a CMS concurrent collection after GC
jmasa
parents:
diff changeset
    14
 *
9b12d5739295 8026752: Cancel MetaspaceGC request for a CMS concurrent collection after GC
jmasa
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
9b12d5739295 8026752: Cancel MetaspaceGC request for a CMS concurrent collection after GC
jmasa
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
9b12d5739295 8026752: Cancel MetaspaceGC request for a CMS concurrent collection after GC
jmasa
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
9b12d5739295 8026752: Cancel MetaspaceGC request for a CMS concurrent collection after GC
jmasa
parents:
diff changeset
    18
 *
9b12d5739295 8026752: Cancel MetaspaceGC request for a CMS concurrent collection after GC
jmasa
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
9b12d5739295 8026752: Cancel MetaspaceGC request for a CMS concurrent collection after GC
jmasa
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
9b12d5739295 8026752: Cancel MetaspaceGC request for a CMS concurrent collection after GC
jmasa
parents:
diff changeset
    21
 * questions.
9b12d5739295 8026752: Cancel MetaspaceGC request for a CMS concurrent collection after GC
jmasa
parents:
diff changeset
    22
 */
9b12d5739295 8026752: Cancel MetaspaceGC request for a CMS concurrent collection after GC
jmasa
parents:
diff changeset
    23
import jdk.test.lib.process.ProcessTools;
9b12d5739295 8026752: Cancel MetaspaceGC request for a CMS concurrent collection after GC
jmasa
parents:
diff changeset
    24
import jdk.test.lib.process.OutputAnalyzer;
9b12d5739295 8026752: Cancel MetaspaceGC request for a CMS concurrent collection after GC
jmasa
parents:
diff changeset
    25
import jdk.test.lib.Asserts;
9b12d5739295 8026752: Cancel MetaspaceGC request for a CMS concurrent collection after GC
jmasa
parents:
diff changeset
    26
import sun.hotspot.WhiteBox;
9b12d5739295 8026752: Cancel MetaspaceGC request for a CMS concurrent collection after GC
jmasa
parents:
diff changeset
    27
9b12d5739295 8026752: Cancel MetaspaceGC request for a CMS concurrent collection after GC
jmasa
parents:
diff changeset
    28
/* @test TestMetaspaceCMSCancel
9b12d5739295 8026752: Cancel MetaspaceGC request for a CMS concurrent collection after GC
jmasa
parents:
diff changeset
    29
 * @bug 8026752
9b12d5739295 8026752: Cancel MetaspaceGC request for a CMS concurrent collection after GC
jmasa
parents:
diff changeset
    30
 * @summary Tests cancel of CMS concurrent cycle for Metaspace after a full GC
9b12d5739295 8026752: Cancel MetaspaceGC request for a CMS concurrent collection after GC
jmasa
parents:
diff changeset
    31
 * @library /testlibrary /test/lib /test/lib/share/classes
9b12d5739295 8026752: Cancel MetaspaceGC request for a CMS concurrent collection after GC
jmasa
parents:
diff changeset
    32
 * @modules java.base/jdk.internal.misc
9b12d5739295 8026752: Cancel MetaspaceGC request for a CMS concurrent collection after GC
jmasa
parents:
diff changeset
    33
 * @build TestMetaspaceCMSCancel
9b12d5739295 8026752: Cancel MetaspaceGC request for a CMS concurrent collection after GC
jmasa
parents:
diff changeset
    34
 * @run main ClassFileInstaller sun.hotspot.WhiteBox
9b12d5739295 8026752: Cancel MetaspaceGC request for a CMS concurrent collection after GC
jmasa
parents:
diff changeset
    35
 * @run main/othervm TestMetaspaceCMSCancel
9b12d5739295 8026752: Cancel MetaspaceGC request for a CMS concurrent collection after GC
jmasa
parents:
diff changeset
    36
 */
9b12d5739295 8026752: Cancel MetaspaceGC request for a CMS concurrent collection after GC
jmasa
parents:
diff changeset
    37
9b12d5739295 8026752: Cancel MetaspaceGC request for a CMS concurrent collection after GC
jmasa
parents:
diff changeset
    38
9b12d5739295 8026752: Cancel MetaspaceGC request for a CMS concurrent collection after GC
jmasa
parents:
diff changeset
    39
public class TestMetaspaceCMSCancel {
9b12d5739295 8026752: Cancel MetaspaceGC request for a CMS concurrent collection after GC
jmasa
parents:
diff changeset
    40
9b12d5739295 8026752: Cancel MetaspaceGC request for a CMS concurrent collection after GC
jmasa
parents:
diff changeset
    41
    public static void main(String[] args) throws Exception {
9b12d5739295 8026752: Cancel MetaspaceGC request for a CMS concurrent collection after GC
jmasa
parents:
diff changeset
    42
        // Set a small MetaspaceSize so that a CMS concurrent collection will be
9b12d5739295 8026752: Cancel MetaspaceGC request for a CMS concurrent collection after GC
jmasa
parents:
diff changeset
    43
        // scheduled.  Set CMSWaitDuration to 5s so that the concurrent collection
9b12d5739295 8026752: Cancel MetaspaceGC request for a CMS concurrent collection after GC
jmasa
parents:
diff changeset
    44
        // start may be delayed.  It does not guarantee 5s before the start of the
9b12d5739295 8026752: Cancel MetaspaceGC request for a CMS concurrent collection after GC
jmasa
parents:
diff changeset
    45
        // concurrent collection but does increase the probability that it will
9b12d5739295 8026752: Cancel MetaspaceGC request for a CMS concurrent collection after GC
jmasa
parents:
diff changeset
    46
        // be started later.  System.gc() is used to invoke a full collection.  Set
9b12d5739295 8026752: Cancel MetaspaceGC request for a CMS concurrent collection after GC
jmasa
parents:
diff changeset
    47
        // ExplicitGCInvokesConcurrent to off so it is a STW collection.
9b12d5739295 8026752: Cancel MetaspaceGC request for a CMS concurrent collection after GC
jmasa
parents:
diff changeset
    48
        ProcessBuilder pb = ProcessTools.createJavaProcessBuilder("-Xbootclasspath/a:.",
9b12d5739295 8026752: Cancel MetaspaceGC request for a CMS concurrent collection after GC
jmasa
parents:
diff changeset
    49
                                                                  "-XX:+UnlockDiagnosticVMOptions",
9b12d5739295 8026752: Cancel MetaspaceGC request for a CMS concurrent collection after GC
jmasa
parents:
diff changeset
    50
                                                                  "-XX:+WhiteBoxAPI",
9b12d5739295 8026752: Cancel MetaspaceGC request for a CMS concurrent collection after GC
jmasa
parents:
diff changeset
    51
                                                                  "-XX:+UseConcMarkSweepGC",
9b12d5739295 8026752: Cancel MetaspaceGC request for a CMS concurrent collection after GC
jmasa
parents:
diff changeset
    52
                                                                  "-XX:MetaspaceSize=2m",
9b12d5739295 8026752: Cancel MetaspaceGC request for a CMS concurrent collection after GC
jmasa
parents:
diff changeset
    53
                                                                  "-XX:CMSWaitDuration=5000",
9b12d5739295 8026752: Cancel MetaspaceGC request for a CMS concurrent collection after GC
jmasa
parents:
diff changeset
    54
                                                                  "-XX:-ExplicitGCInvokesConcurrent",
9b12d5739295 8026752: Cancel MetaspaceGC request for a CMS concurrent collection after GC
jmasa
parents:
diff changeset
    55
                                                                  "-Xlog:gc*=debug",
9b12d5739295 8026752: Cancel MetaspaceGC request for a CMS concurrent collection after GC
jmasa
parents:
diff changeset
    56
                                                                  MetaspaceGCTest.class.getName());
9b12d5739295 8026752: Cancel MetaspaceGC request for a CMS concurrent collection after GC
jmasa
parents:
diff changeset
    57
9b12d5739295 8026752: Cancel MetaspaceGC request for a CMS concurrent collection after GC
jmasa
parents:
diff changeset
    58
        OutputAnalyzer output = new OutputAnalyzer(pb.start());
9b12d5739295 8026752: Cancel MetaspaceGC request for a CMS concurrent collection after GC
jmasa
parents:
diff changeset
    59
        output.shouldNotContain("Concurrent Reset");
9b12d5739295 8026752: Cancel MetaspaceGC request for a CMS concurrent collection after GC
jmasa
parents:
diff changeset
    60
        output.shouldHaveExitValue(0);
9b12d5739295 8026752: Cancel MetaspaceGC request for a CMS concurrent collection after GC
jmasa
parents:
diff changeset
    61
    }
9b12d5739295 8026752: Cancel MetaspaceGC request for a CMS concurrent collection after GC
jmasa
parents:
diff changeset
    62
9b12d5739295 8026752: Cancel MetaspaceGC request for a CMS concurrent collection after GC
jmasa
parents:
diff changeset
    63
    static class MetaspaceGCTest {
9b12d5739295 8026752: Cancel MetaspaceGC request for a CMS concurrent collection after GC
jmasa
parents:
diff changeset
    64
        public static void main(String [] args) {
9b12d5739295 8026752: Cancel MetaspaceGC request for a CMS concurrent collection after GC
jmasa
parents:
diff changeset
    65
            WhiteBox wb = WhiteBox.getWhiteBox();
9b12d5739295 8026752: Cancel MetaspaceGC request for a CMS concurrent collection after GC
jmasa
parents:
diff changeset
    66
            System.gc();
9b12d5739295 8026752: Cancel MetaspaceGC request for a CMS concurrent collection after GC
jmasa
parents:
diff changeset
    67
            Asserts.assertFalse(wb.metaspaceShouldConcurrentCollect());
9b12d5739295 8026752: Cancel MetaspaceGC request for a CMS concurrent collection after GC
jmasa
parents:
diff changeset
    68
        }
9b12d5739295 8026752: Cancel MetaspaceGC request for a CMS concurrent collection after GC
jmasa
parents:
diff changeset
    69
    }
9b12d5739295 8026752: Cancel MetaspaceGC request for a CMS concurrent collection after GC
jmasa
parents:
diff changeset
    70
}