test/gc/class_unloading/TestG1ClassUnloadingHWM.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 TestG1ClassUnloadingHWM
stefank@6996 30 * @run main ClassFileInstaller sun.hotspot.WhiteBox
stefank@6996 31 * @run driver TestG1ClassUnloadingHWM
stefank@6996 32 * @summary Test that -XX:-ClassUnloadingWithConcurrentMark 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@6996 37 import java.util.ArrayList;
stefank@6996 38 import java.util.Arrays;
stefank@7238 39 import sun.hotspot.WhiteBox;
stefank@6996 40
stefank@6996 41 public class TestG1ClassUnloadingHWM {
stefank@6996 42 private static long MetaspaceSize = 32 * 1024 * 1024;
stefank@6996 43 private static long YoungGenSize = 32 * 1024 * 1024;
stefank@6996 44
stefank@6996 45 private static OutputAnalyzer run(boolean enableUnloading) throws Exception {
stefank@6996 46 ProcessBuilder pb = ProcessTools.createJavaProcessBuilder(
stefank@6996 47 "-Xbootclasspath/a:.",
stefank@7044 48 "-XX:+UnlockDiagnosticVMOptions",
stefank@6996 49 "-XX:+WhiteBoxAPI",
stefank@6996 50 "-XX:MetaspaceSize=" + MetaspaceSize,
stefank@6996 51 "-Xmn" + YoungGenSize,
stefank@6996 52 "-XX:+UseG1GC",
stefank@6996 53 "-XX:" + (enableUnloading ? "+" : "-") + "ClassUnloadingWithConcurrentMark",
stefank@6996 54 "-XX:+PrintHeapAtGC",
stefank@6996 55 "-XX:+PrintGCDetails",
stefank@7238 56 TestG1ClassUnloadingHWM.AllocateBeyondMetaspaceSize.class.getName(),
stefank@6996 57 "" + MetaspaceSize,
stefank@6996 58 "" + YoungGenSize);
stefank@6996 59 return new OutputAnalyzer(pb.start());
stefank@6996 60 }
stefank@6996 61
stefank@6996 62 public static OutputAnalyzer runWithG1ClassUnloading() throws Exception {
stefank@6996 63 return run(true);
stefank@6996 64 }
stefank@6996 65
stefank@6996 66 public static OutputAnalyzer runWithoutG1ClassUnloading() throws Exception {
stefank@6996 67 return run(false);
stefank@6996 68 }
stefank@6996 69
stefank@6996 70 public static void testWithoutG1ClassUnloading() throws Exception {
stefank@6996 71 // -XX:-ClassUnloadingWithConcurrentMark is used, so we expect a full GC instead of a concurrent cycle.
stefank@6996 72 OutputAnalyzer out = runWithoutG1ClassUnloading();
stefank@6996 73
stefank@6996 74 out.shouldMatch(".*Full GC.*");
stefank@6996 75 out.shouldNotMatch(".*initial-mark.*");
stefank@6996 76 }
stefank@6996 77
stefank@6996 78 public static void testWithG1ClassUnloading() throws Exception {
stefank@6996 79 // -XX:+ClassUnloadingWithConcurrentMark is used, so we expect a concurrent cycle instead of a full GC.
stefank@6996 80 OutputAnalyzer out = runWithG1ClassUnloading();
stefank@6996 81
stefank@6996 82 out.shouldMatch(".*initial-mark.*");
stefank@6996 83 out.shouldNotMatch(".*Full GC.*");
stefank@6996 84 }
stefank@6996 85
stefank@6996 86 public static void main(String args[]) throws Exception {
stefank@6996 87 testWithG1ClassUnloading();
stefank@6996 88 testWithoutG1ClassUnloading();
stefank@6996 89 }
stefank@7238 90
stefank@7238 91 public static class AllocateBeyondMetaspaceSize {
stefank@7238 92 public static Object dummy;
stefank@7238 93
stefank@7238 94 public static void main(String [] args) throws Exception {
stefank@7238 95 if (args.length != 2) {
stefank@7238 96 throw new IllegalArgumentException("Usage: <MetaspaceSize> <YoungGenSize>");
stefank@7238 97 }
stefank@7238 98
stefank@7238 99 WhiteBox wb = WhiteBox.getWhiteBox();
stefank@7238 100
stefank@7238 101 // Allocate past the MetaspaceSize limit
stefank@7238 102 long metaspaceSize = Long.parseLong(args[0]);
stefank@7238 103 long allocationBeyondMetaspaceSize = metaspaceSize * 2;
stefank@7238 104 long metaspace = wb.allocateMetaspace(null, allocationBeyondMetaspaceSize);
stefank@7238 105
stefank@7238 106 long youngGenSize = Long.parseLong(args[1]);
stefank@7238 107 triggerYoungGCs(youngGenSize);
stefank@7238 108
stefank@7238 109 wb.freeMetaspace(null, metaspace, metaspace);
stefank@7238 110 }
stefank@7238 111
stefank@7238 112 public static void triggerYoungGCs(long youngGenSize) {
stefank@7238 113 long approxAllocSize = 32 * 1024;
stefank@7238 114 long numAllocations = 2 * youngGenSize / approxAllocSize;
stefank@7238 115
stefank@7238 116 for (long i = 0; i < numAllocations; i++) {
stefank@7238 117 dummy = new byte[(int)approxAllocSize];
stefank@7238 118 }
stefank@7238 119 }
stefank@7238 120 }
stefank@6996 121 }
stefank@6996 122

mercurial