test/gc/class_unloading/TestCMSClassUnloadingEnabledHWM.java

Mon, 06 Nov 2017 16:51:47 +0800

author
aoqi
date
Mon, 06 Nov 2017 16:51:47 +0800
changeset 7997
6cbff0651f1a
parent 7238
85f4c4ecc963
permissions
-rw-r--r--

[Code Reorganization] remove trailing whitespace to pass jcheck test

stefank@6996 1 /*
stefank@6996 2 * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
stefank@6996 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
stefank@6996 4 *
stefank@6996 5 * This code is free software; you can redistribute it and/or modify it
stefank@6996 6 * under the terms of the GNU General Public License version 2 only, as
stefank@6996 7 * published by the Free Software Foundation.
stefank@6996 8 *
stefank@6996 9 * This code is distributed in the hope that it will be useful, but WITHOUT
stefank@6996 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
stefank@6996 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
stefank@6996 12 * version 2 for more details (a copy is included in the LICENSE file that
stefank@6996 13 * accompanied this code).
stefank@6996 14 *
stefank@6996 15 * You should have received a copy of the GNU General Public License version
stefank@6996 16 * 2 along with this work; if not, write to the Free Software Foundation,
stefank@6996 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
stefank@6996 18 *
stefank@6996 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
stefank@6996 20 * or visit www.oracle.com if you need additional information or have any
stefank@6996 21 * questions.
stefank@6996 22 */
stefank@6996 23
stefank@6996 24 /*
stefank@6996 25 * @test
stefank@6996 26 * @key gc
stefank@6996 27 * @bug 8049831
stefank@6996 28 * @library /testlibrary /testlibrary/whitebox
stefank@7238 29 * @build TestCMSClassUnloadingEnabledHWM
stefank@6996 30 * @run main ClassFileInstaller sun.hotspot.WhiteBox
stefank@6996 31 * @run driver TestCMSClassUnloadingEnabledHWM
stefank@6996 32 * @summary Test that -XX:-CMSClassUnloadingEnabled will trigger a Full GC when more than MetaspaceSize metadata is allocated.
stefank@6996 33 */
stefank@6996 34
stefank@6996 35 import com.oracle.java.testlibrary.OutputAnalyzer;
stefank@6996 36 import com.oracle.java.testlibrary.ProcessTools;
stefank@7238 37 import java.lang.management.GarbageCollectorMXBean;
stefank@7238 38 import java.lang.management.ManagementFactory;
stefank@6996 39 import java.util.ArrayList;
stefank@6996 40 import java.util.Arrays;
stefank@7238 41 import sun.hotspot.WhiteBox;
stefank@6996 42
stefank@6996 43 public class TestCMSClassUnloadingEnabledHWM {
stefank@6996 44 private static long MetaspaceSize = 32 * 1024 * 1024;
stefank@6996 45 private static long YoungGenSize = 32 * 1024 * 1024;
stefank@6996 46
stefank@6996 47 private static OutputAnalyzer run(boolean enableUnloading) throws Exception {
stefank@6996 48 ProcessBuilder pb = ProcessTools.createJavaProcessBuilder(
stefank@6996 49 "-Xbootclasspath/a:.",
stefank@7044 50 "-XX:+UnlockDiagnosticVMOptions",
stefank@6996 51 "-XX:+WhiteBoxAPI",
stefank@7238 52 "-Xmx128m",
stefank@7238 53 "-XX:CMSMaxAbortablePrecleanTime=1",
stefank@7238 54 "-XX:CMSWaitDuration=50",
stefank@6996 55 "-XX:MetaspaceSize=" + MetaspaceSize,
stefank@6996 56 "-Xmn" + YoungGenSize,
stefank@6996 57 "-XX:+UseConcMarkSweepGC",
stefank@6996 58 "-XX:" + (enableUnloading ? "+" : "-") + "CMSClassUnloadingEnabled",
stefank@6996 59 "-XX:+PrintHeapAtGC",
stefank@6996 60 "-XX:+PrintGCDetails",
stefank@7238 61 "-XX:+PrintGCTimeStamps",
stefank@7238 62 TestCMSClassUnloadingEnabledHWM.AllocateBeyondMetaspaceSize.class.getName(),
stefank@7238 63 "" + MetaspaceSize);
stefank@6996 64 return new OutputAnalyzer(pb.start());
stefank@6996 65 }
stefank@6996 66
stefank@6996 67 public static OutputAnalyzer runWithCMSClassUnloading() throws Exception {
stefank@6996 68 return run(true);
stefank@6996 69 }
stefank@6996 70
stefank@6996 71 public static OutputAnalyzer runWithoutCMSClassUnloading() throws Exception {
stefank@6996 72 return run(false);
stefank@6996 73 }
stefank@6996 74
stefank@6996 75 public static void testWithoutCMSClassUnloading() throws Exception {
stefank@6996 76 // -XX:-CMSClassUnloadingEnabled is used, so we expect a full GC instead of a concurrent cycle.
stefank@6996 77 OutputAnalyzer out = runWithoutCMSClassUnloading();
stefank@6996 78
stefank@6996 79 out.shouldMatch(".*Full GC.*");
stefank@6996 80 out.shouldNotMatch(".*CMS Initial Mark.*");
stefank@6996 81 }
stefank@6996 82
stefank@6996 83 public static void testWithCMSClassUnloading() throws Exception {
stefank@6996 84 // -XX:+CMSClassUnloadingEnabled is used, so we expect a concurrent cycle instead of a full GC.
stefank@6996 85 OutputAnalyzer out = runWithCMSClassUnloading();
stefank@6996 86
stefank@6996 87 out.shouldMatch(".*CMS Initial Mark.*");
stefank@6996 88 out.shouldNotMatch(".*Full GC.*");
stefank@6996 89 }
stefank@6996 90
stefank@6996 91 public static void main(String args[]) throws Exception {
stefank@6996 92 testWithCMSClassUnloading();
stefank@6996 93 testWithoutCMSClassUnloading();
stefank@6996 94 }
stefank@7238 95
stefank@7238 96 public static class AllocateBeyondMetaspaceSize {
stefank@7238 97 public static void main(String [] args) throws Exception {
stefank@7238 98 if (args.length != 1) {
stefank@7238 99 throw new IllegalArgumentException("Usage: <MetaspaceSize>");
stefank@7238 100 }
stefank@7238 101
stefank@7238 102 WhiteBox wb = WhiteBox.getWhiteBox();
stefank@7238 103
stefank@7238 104 // Allocate past the MetaspaceSize limit.
stefank@7238 105 long metaspaceSize = Long.parseLong(args[0]);
stefank@7238 106 long allocationBeyondMetaspaceSize = metaspaceSize * 2;
stefank@7238 107 long metaspace = wb.allocateMetaspace(null, allocationBeyondMetaspaceSize);
stefank@7238 108
stefank@7238 109 // Wait for at least one GC to occur. The caller will parse the log files produced.
stefank@7238 110 GarbageCollectorMXBean cmsGCBean = getCMSGCBean();
stefank@7238 111 while (cmsGCBean.getCollectionCount() == 0) {
stefank@7238 112 Thread.sleep(100);
stefank@7238 113 }
stefank@7238 114
stefank@7238 115 wb.freeMetaspace(null, metaspace, metaspace);
stefank@7238 116 }
stefank@7238 117
stefank@7238 118 private static GarbageCollectorMXBean getCMSGCBean() {
stefank@7238 119 for (GarbageCollectorMXBean gcBean : ManagementFactory.getGarbageCollectorMXBeans()) {
stefank@7238 120 if (gcBean.getObjectName().toString().equals("java.lang:type=GarbageCollector,name=ConcurrentMarkSweep")) {
stefank@7238 121 return gcBean;
stefank@7238 122 }
stefank@7238 123 }
stefank@7238 124 return null;
stefank@7238 125 }
stefank@7238 126 }
stefank@6996 127 }
stefank@6996 128

mercurial