Mon, 06 Nov 2017 16:51:47 +0800
[Code Reorganization] remove trailing whitespace to pass jcheck test
1 /*
2 * Copyright (c) 2014, 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 */
24 /*
25 * @test
26 * @key gc
27 * @bug 8049831
28 * @library /testlibrary /testlibrary/whitebox
29 * @build TestG1ClassUnloadingHWM
30 * @run main ClassFileInstaller sun.hotspot.WhiteBox
31 * @run driver TestG1ClassUnloadingHWM
32 * @summary Test that -XX:-ClassUnloadingWithConcurrentMark will trigger a Full GC when more than MetaspaceSize metadata is allocated.
33 */
35 import com.oracle.java.testlibrary.OutputAnalyzer;
36 import com.oracle.java.testlibrary.ProcessTools;
37 import java.util.ArrayList;
38 import java.util.Arrays;
39 import sun.hotspot.WhiteBox;
41 public class TestG1ClassUnloadingHWM {
42 private static long MetaspaceSize = 32 * 1024 * 1024;
43 private static long YoungGenSize = 32 * 1024 * 1024;
45 private static OutputAnalyzer run(boolean enableUnloading) throws Exception {
46 ProcessBuilder pb = ProcessTools.createJavaProcessBuilder(
47 "-Xbootclasspath/a:.",
48 "-XX:+UnlockDiagnosticVMOptions",
49 "-XX:+WhiteBoxAPI",
50 "-XX:MetaspaceSize=" + MetaspaceSize,
51 "-Xmn" + YoungGenSize,
52 "-XX:+UseG1GC",
53 "-XX:" + (enableUnloading ? "+" : "-") + "ClassUnloadingWithConcurrentMark",
54 "-XX:+PrintHeapAtGC",
55 "-XX:+PrintGCDetails",
56 TestG1ClassUnloadingHWM.AllocateBeyondMetaspaceSize.class.getName(),
57 "" + MetaspaceSize,
58 "" + YoungGenSize);
59 return new OutputAnalyzer(pb.start());
60 }
62 public static OutputAnalyzer runWithG1ClassUnloading() throws Exception {
63 return run(true);
64 }
66 public static OutputAnalyzer runWithoutG1ClassUnloading() throws Exception {
67 return run(false);
68 }
70 public static void testWithoutG1ClassUnloading() throws Exception {
71 // -XX:-ClassUnloadingWithConcurrentMark is used, so we expect a full GC instead of a concurrent cycle.
72 OutputAnalyzer out = runWithoutG1ClassUnloading();
74 out.shouldMatch(".*Full GC.*");
75 out.shouldNotMatch(".*initial-mark.*");
76 }
78 public static void testWithG1ClassUnloading() throws Exception {
79 // -XX:+ClassUnloadingWithConcurrentMark is used, so we expect a concurrent cycle instead of a full GC.
80 OutputAnalyzer out = runWithG1ClassUnloading();
82 out.shouldMatch(".*initial-mark.*");
83 out.shouldNotMatch(".*Full GC.*");
84 }
86 public static void main(String args[]) throws Exception {
87 testWithG1ClassUnloading();
88 testWithoutG1ClassUnloading();
89 }
91 public static class AllocateBeyondMetaspaceSize {
92 public static Object dummy;
94 public static void main(String [] args) throws Exception {
95 if (args.length != 2) {
96 throw new IllegalArgumentException("Usage: <MetaspaceSize> <YoungGenSize>");
97 }
99 WhiteBox wb = WhiteBox.getWhiteBox();
101 // Allocate past the MetaspaceSize limit
102 long metaspaceSize = Long.parseLong(args[0]);
103 long allocationBeyondMetaspaceSize = metaspaceSize * 2;
104 long metaspace = wb.allocateMetaspace(null, allocationBeyondMetaspaceSize);
106 long youngGenSize = Long.parseLong(args[1]);
107 triggerYoungGCs(youngGenSize);
109 wb.freeMetaspace(null, metaspace, metaspace);
110 }
112 public static void triggerYoungGCs(long youngGenSize) {
113 long approxAllocSize = 32 * 1024;
114 long numAllocations = 2 * youngGenSize / approxAllocSize;
116 for (long i = 0; i < numAllocations; i++) {
117 dummy = new byte[(int)approxAllocSize];
118 }
119 }
120 }
121 }