1 /*
   2  * Copyright (c) 2016, 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 import jdk.test.lib.process.ProcessTools;
  24 import jdk.test.lib.process.OutputAnalyzer;
  25 import jdk.test.lib.Asserts;
  26 import sun.hotspot.WhiteBox;
  27 
  28 /* @test TestMetaspaceCMSCancel
  29  * @bug 8026752
  30  * @summary Tests cancel of CMS concurrent cycle for Metaspace after a full GC
  31  * @library /testlibrary /test/lib /test/lib/share/classes
  32  * @modules java.base/jdk.internal.misc
  33  * @build TestMetaspaceCMSCancel
  34  * @run main ClassFileInstaller sun.hotspot.WhiteBox
  35  * @run main/othervm TestMetaspaceCMSCancel
  36  */
  37 
  38 
  39 public class TestMetaspaceCMSCancel {
  40 
  41     public static void main(String[] args) throws Exception {
  42         // Set a small MetaspaceSize so that a CMS concurrent collection will be
  43         // scheduled.  Set CMSWaitDuration to 5s so that the concurrent collection
  44         // start may be delayed.  It does not guarantee 5s before the start of the
  45         // concurrent collection but does increase the probability that it will
  46         // be started later.  System.gc() is used to invoke a full collection.  Set
  47         // ExplicitGCInvokesConcurrent to off so it is a STW collection.
  48         ProcessBuilder pb = ProcessTools.createJavaProcessBuilder("-Xbootclasspath/a:.",
  49                                                                   "-XX:+UnlockDiagnosticVMOptions",
  50                                                                   "-XX:+WhiteBoxAPI",
  51                                                                   "-XX:+UseConcMarkSweepGC",
  52                                                                   "-XX:MetaspaceSize=2m",
  53                                                                   "-XX:CMSWaitDuration=5000",
  54                                                                   "-XX:-ExplicitGCInvokesConcurrent",
  55                                                                   "-Xlog:gc*=debug",
  56                                                                   MetaspaceGCTest.class.getName());
  57 
  58         OutputAnalyzer output = new OutputAnalyzer(pb.start());
  59         output.shouldNotContain("Concurrent Reset");
  60         output.shouldHaveExitValue(0);
  61     }
  62 
  63     static class MetaspaceGCTest {
  64         public static void main(String [] args) {
  65             WhiteBox wb = WhiteBox.getWhiteBox();
  66             System.gc();
  67             Asserts.assertFalse(wb.metaspaceShouldConcurrentCollect());
  68         }
  69     }
  70 }