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