Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/openjdk-multiarch-jdk8u
Path: blob/aarch64-shenandoah-jdk8u272-b10/hotspot/test/gc/class_unloading/TestCMSClassUnloadingEnabledHWM.java
32283 views
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
*/
23
24
/*
25
* @test
26
* @key gc
27
* @bug 8049831
28
* @library /testlibrary /testlibrary/whitebox
29
* @build TestCMSClassUnloadingEnabledHWM
30
* @run main ClassFileInstaller sun.hotspot.WhiteBox
31
* @run driver TestCMSClassUnloadingEnabledHWM
32
* @summary Test that -XX:-CMSClassUnloadingEnabled will trigger a Full GC when more than MetaspaceSize metadata is allocated.
33
*/
34
35
import com.oracle.java.testlibrary.OutputAnalyzer;
36
import com.oracle.java.testlibrary.ProcessTools;
37
import java.lang.management.GarbageCollectorMXBean;
38
import java.lang.management.ManagementFactory;
39
import java.util.ArrayList;
40
import java.util.Arrays;
41
import sun.hotspot.WhiteBox;
42
43
public class TestCMSClassUnloadingEnabledHWM {
44
private static long MetaspaceSize = 32 * 1024 * 1024;
45
private static long YoungGenSize = 32 * 1024 * 1024;
46
47
private static OutputAnalyzer run(boolean enableUnloading) throws Exception {
48
ProcessBuilder pb = ProcessTools.createJavaProcessBuilder(
49
"-Xbootclasspath/a:.",
50
"-XX:+UnlockDiagnosticVMOptions",
51
"-XX:+WhiteBoxAPI",
52
"-Xmx128m",
53
"-XX:CMSMaxAbortablePrecleanTime=1",
54
"-XX:CMSWaitDuration=50",
55
"-XX:MetaspaceSize=" + MetaspaceSize,
56
"-Xmn" + YoungGenSize,
57
"-XX:+UseConcMarkSweepGC",
58
"-XX:" + (enableUnloading ? "+" : "-") + "CMSClassUnloadingEnabled",
59
"-XX:+PrintHeapAtGC",
60
"-XX:+PrintGCDetails",
61
"-XX:+PrintGCTimeStamps",
62
TestCMSClassUnloadingEnabledHWM.AllocateBeyondMetaspaceSize.class.getName(),
63
"" + MetaspaceSize);
64
return new OutputAnalyzer(pb.start());
65
}
66
67
public static OutputAnalyzer runWithCMSClassUnloading() throws Exception {
68
return run(true);
69
}
70
71
public static OutputAnalyzer runWithoutCMSClassUnloading() throws Exception {
72
return run(false);
73
}
74
75
public static void testWithoutCMSClassUnloading() throws Exception {
76
// -XX:-CMSClassUnloadingEnabled is used, so we expect a full GC instead of a concurrent cycle.
77
OutputAnalyzer out = runWithoutCMSClassUnloading();
78
79
out.shouldMatch(".*Full GC.*");
80
out.shouldNotMatch(".*CMS Initial Mark.*");
81
}
82
83
public static void testWithCMSClassUnloading() throws Exception {
84
// -XX:+CMSClassUnloadingEnabled is used, so we expect a concurrent cycle instead of a full GC.
85
OutputAnalyzer out = runWithCMSClassUnloading();
86
87
out.shouldMatch(".*CMS Initial Mark.*");
88
out.shouldNotMatch(".*Full GC.*");
89
}
90
91
public static void main(String args[]) throws Exception {
92
testWithCMSClassUnloading();
93
testWithoutCMSClassUnloading();
94
}
95
96
public static class AllocateBeyondMetaspaceSize {
97
public static void main(String [] args) throws Exception {
98
if (args.length != 1) {
99
throw new IllegalArgumentException("Usage: <MetaspaceSize>");
100
}
101
102
WhiteBox wb = WhiteBox.getWhiteBox();
103
104
// Allocate past the MetaspaceSize limit.
105
long metaspaceSize = Long.parseLong(args[0]);
106
long allocationBeyondMetaspaceSize = metaspaceSize * 2;
107
long metaspace = wb.allocateMetaspace(null, allocationBeyondMetaspaceSize);
108
109
// Wait for at least one GC to occur. The caller will parse the log files produced.
110
GarbageCollectorMXBean cmsGCBean = getCMSGCBean();
111
while (cmsGCBean.getCollectionCount() == 0) {
112
Thread.sleep(100);
113
}
114
115
wb.freeMetaspace(null, metaspace, metaspace);
116
}
117
118
private static GarbageCollectorMXBean getCMSGCBean() {
119
for (GarbageCollectorMXBean gcBean : ManagementFactory.getGarbageCollectorMXBeans()) {
120
if (gcBean.getObjectName().toString().equals("java.lang:type=GarbageCollector,name=ConcurrentMarkSweep")) {
121
return gcBean;
122
}
123
}
124
return null;
125
}
126
}
127
}
128
129
130