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