# HG changeset patch # User jmasa # Date 1464326962 25200 # Thu May 26 22:29:22 2016 -0700 # Node ID 8f52db06bd2c99930e6204d0947765978dea84e7 # Parent f0c6ff7fcfa9b3ac8887ad192980d6c044a941e9 8026752: Cancel MetaspaceGC request for a CMS concurrent collection after GC Reviewed-by: diff --git a/src/share/vm/gc/cms/concurrentMarkSweepGeneration.cpp b/src/share/vm/gc/cms/concurrentMarkSweepGeneration.cpp --- a/src/share/vm/gc/cms/concurrentMarkSweepGeneration.cpp +++ b/src/share/vm/gc/cms/concurrentMarkSweepGeneration.cpp @@ -708,6 +708,8 @@ for (uint i = 0; i < ParallelGCThreads; i++) { _par_gc_thread_states[i]->promo.reset(); } + // No longer a need to do a concurrent collection for Metaspace. + MetaspaceGC::set_should_concurrent_collect(false); } void ConcurrentMarkSweepGeneration::compute_new_size() { diff --git a/test/gc/metaspace/TestMetaspaceCMSCancel.java b/test/gc/metaspace/TestMetaspaceCMSCancel.java new file mode 100644 --- /dev/null +++ b/test/gc/metaspace/TestMetaspaceCMSCancel.java @@ -0,0 +1,68 @@ +/* + * Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ +import jdk.test.lib.ProcessTools; +import jdk.test.lib.OutputAnalyzer; +import java.util.ArrayList; + +/* @test TestMetaspaceCMSCancel + * @bug 8026752 + * @summary Tests cancel of CMS concurrent cycle for Metaspace after a full GC + * @library /testlibrary + * @modules java.base/jdk.internal.misc + */ +public class TestMetaspaceCMSCancel { + + public static void main(String[] args) throws Exception { + // Set a small MetaspaceSize so that a CMS concurrent collection will be + // scheduled. Set CMSWaitDuration to 5s so that the concurrent collection + // start may be delayed. It does not guarantee 5s before the start of the + // concurrent collection but does increase the probability that it will + // be started later. System.gc() is used to invoke a full collection. Set + // ExplicitGCInvokesConcurrent to off so it is a STW collection. + ProcessBuilder pb = ProcessTools.createJavaProcessBuilder("-XX:+UseConcMarkSweepGC", + "-XX:MetaspaceSize=2m", + "-XX:CMSWaitDuration=5000", + "-XX:-ExplicitGCInvokesConcurrent", + "-Xlog:gc*=debug", + MetaspaceGCTest.class.getName()); + + OutputAnalyzer output = new OutputAnalyzer(pb.start()); + + output.shouldNotContain("Concurrent Reset"); + output.shouldHaveExitValue(0); + } + + static class MetaspaceGCTest { + public static void main(String [] args) { + System.gc(); + while (true) { + try { + Thread.sleep(20000); + return; + } catch (InterruptedException e) { + continue; + } + } + } + } +} # HG changeset patch # User jmasa # Date 1465336570 25200 # Tue Jun 07 14:56:10 2016 -0700 # Node ID 02d9491c73fe33e002fd6653de9d52e3eafb219b # Parent 8f52db06bd2c99930e6204d0947765978dea84e7 [mq]: whitebox diff --git a/src/share/vm/prims/whitebox.cpp b/src/share/vm/prims/whitebox.cpp --- a/src/share/vm/prims/whitebox.cpp +++ b/src/share/vm/prims/whitebox.cpp @@ -1390,6 +1390,11 @@ return (jlong) MetaspaceGC::capacity_until_GC(); WB_END +WB_ENTRY(jboolean, WB_MetaspaceShouldConcurrentCollect(JNIEnv* env, jobject wb)) +tty->print_cr("MetaspaceGC::should_concurrent_collect(): %s", MetaspaceGC::should_concurrent_collect() ? "true" : "false"); + return MetaspaceGC::should_concurrent_collect(); +WB_END + WB_ENTRY(void, WB_AssertMatchingSafepointCalls(JNIEnv* env, jobject o, jboolean mutexSafepointValue, jboolean attemptedNoSafepointValue)) Monitor::SafepointCheckRequired sfpt_check_required = mutexSafepointValue ? @@ -1770,6 +1775,7 @@ CC"(Ljava/lang/ClassLoader;JJ)V", (void*)&WB_FreeMetaspace }, {CC"incMetaspaceCapacityUntilGC", CC"(J)J", (void*)&WB_IncMetaspaceCapacityUntilGC }, {CC"metaspaceCapacityUntilGC", CC"()J", (void*)&WB_MetaspaceCapacityUntilGC }, + {CC"metaspaceShouldConcurrentCollect", CC"()Z", (void*)&WB_MetaspaceShouldConcurrentCollect }, {CC"getCPUFeatures", CC"()Ljava/lang/String;", (void*)&WB_GetCPUFeatures }, {CC"getNMethod0", CC"(Ljava/lang/reflect/Executable;Z)[Ljava/lang/Object;", (void*)&WB_GetNMethod }, diff --git a/test/gc/metaspace/TestMetaspaceCMSCancel.java b/test/gc/metaspace/TestMetaspaceCMSCancel.java --- a/test/gc/metaspace/TestMetaspaceCMSCancel.java +++ b/test/gc/metaspace/TestMetaspaceCMSCancel.java @@ -20,16 +20,22 @@ * or visit www.oracle.com if you need additional information or have any * questions. */ -import jdk.test.lib.ProcessTools; -import jdk.test.lib.OutputAnalyzer; -import java.util.ArrayList; +import jdk.test.lib.process.ProcessTools; +import jdk.test.lib.process.OutputAnalyzer; +import jdk.test.lib.Asserts; +import sun.hotspot.WhiteBox; /* @test TestMetaspaceCMSCancel * @bug 8026752 * @summary Tests cancel of CMS concurrent cycle for Metaspace after a full GC - * @library /testlibrary + * @library /testlibrary /test/lib /test/lib/share/classes * @modules java.base/jdk.internal.misc + * @build TestMetaspaceCMSCancel + * @run main ClassFileInstaller sun.hotspot.WhiteBox + * @run main/othervm TestMetaspaceCMSCancel */ + + public class TestMetaspaceCMSCancel { public static void main(String[] args) throws Exception { @@ -39,7 +45,10 @@ // concurrent collection but does increase the probability that it will // be started later. System.gc() is used to invoke a full collection. Set // ExplicitGCInvokesConcurrent to off so it is a STW collection. - ProcessBuilder pb = ProcessTools.createJavaProcessBuilder("-XX:+UseConcMarkSweepGC", + ProcessBuilder pb = ProcessTools.createJavaProcessBuilder("-Xbootclasspath/a:.", + "-XX:+UnlockDiagnosticVMOptions", + "-XX:+WhiteBoxAPI", + "-XX:+UseConcMarkSweepGC", "-XX:MetaspaceSize=2m", "-XX:CMSWaitDuration=5000", "-XX:-ExplicitGCInvokesConcurrent", @@ -47,22 +56,15 @@ MetaspaceGCTest.class.getName()); OutputAnalyzer output = new OutputAnalyzer(pb.start()); - output.shouldNotContain("Concurrent Reset"); output.shouldHaveExitValue(0); } static class MetaspaceGCTest { public static void main(String [] args) { + WhiteBox wb = WhiteBox.getWhiteBox(); System.gc(); - while (true) { - try { - Thread.sleep(20000); - return; - } catch (InterruptedException e) { - continue; - } - } + Asserts.assertFalse(wb.metaspaceShouldConcurrentCollect()); } } }