Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/hotspot/jtreg/gc/arguments/TestParallelGCThreads.java
40942 views
1
/*
2
* Copyright (c) 2014, 2021, 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
package gc.arguments;
25
26
/*
27
* @test TestParallelGCThreads
28
* @bug 8059527 8081382
29
* @summary Tests argument processing for ParallelGCThreads
30
* @library /test/lib
31
* @library /
32
* @modules java.base/jdk.internal.misc
33
* java.management
34
* @build sun.hotspot.WhiteBox
35
* @run driver jdk.test.lib.helpers.ClassFileInstaller sun.hotspot.WhiteBox
36
* @run main/othervm -Xbootclasspath/a:. -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI gc.arguments.TestParallelGCThreads
37
*/
38
39
import java.util.ArrayList;
40
import java.util.List;
41
import jdk.test.lib.Asserts;
42
import jdk.test.lib.process.OutputAnalyzer;
43
import jdk.test.lib.process.ProcessTools;
44
import jtreg.SkippedException;
45
import sun.hotspot.gc.GC;
46
47
public class TestParallelGCThreads {
48
49
public static void main(String args[]) throws Exception {
50
testFlags();
51
testDefaultValue();
52
}
53
54
private static final String flagName = "ParallelGCThreads";
55
56
// uint ParallelGCThreads = 23 {product}
57
private static final String printFlagsFinalPattern = " *uint *" + flagName + " *:?= *(\\d+) *\\{product\\} *";
58
59
public static void testDefaultValue() throws Exception {
60
ProcessBuilder pb = GCArguments.createJavaProcessBuilder(
61
"-XX:+UnlockExperimentalVMOptions", "-XX:+PrintFlagsFinal", "-version");
62
63
OutputAnalyzer output = new OutputAnalyzer(pb.start());
64
String value = output.firstMatch(printFlagsFinalPattern, 1);
65
66
try {
67
Asserts.assertNotNull(value, "Couldn't find uint flag " + flagName);
68
69
Long longValue = new Long(value);
70
71
// Sanity check that we got a non-zero value.
72
Asserts.assertNotEquals(longValue, "0");
73
74
output.shouldHaveExitValue(0);
75
} catch (Exception e) {
76
System.err.println(output.getOutput());
77
throw e;
78
}
79
}
80
81
public static void testFlags() throws Exception {
82
// For each parallel collector (G1, Parallel)
83
List<String> supportedGC = new ArrayList<String>();
84
85
if (GC.G1.isSupported()) {
86
supportedGC.add("G1");
87
}
88
if (GC.Parallel.isSupported()) {
89
supportedGC.add("Parallel");
90
}
91
92
if (supportedGC.isEmpty()) {
93
throw new SkippedException("Skipping test because none of G1/Parallel is supported.");
94
}
95
96
for (String gc : supportedGC) {
97
// Make sure the VM does not allow ParallelGCThreads set to 0
98
ProcessBuilder pb = GCArguments.createJavaProcessBuilder(
99
"-XX:+Use" + gc + "GC",
100
"-XX:ParallelGCThreads=0",
101
"-XX:+PrintFlagsFinal",
102
"-version");
103
OutputAnalyzer output = new OutputAnalyzer(pb.start());
104
output.shouldHaveExitValue(1);
105
106
// Do some basic testing to ensure the flag updates the count
107
for (long i = 1; i <= 3; i++) {
108
long count = getParallelGCThreadCount(
109
"-XX:+Use" + gc + "GC",
110
"-XX:ParallelGCThreads=" + i,
111
"-XX:+PrintFlagsFinal",
112
"-version");
113
Asserts.assertEQ(count, i, "Specifying ParallelGCThreads=" + i + " for " + gc + "GC does not set the thread count properly!");
114
}
115
}
116
117
// 4294967295 == (unsigned int) -1
118
// So setting ParallelGCThreads=4294967295 should give back 4294967295
119
// and setting ParallelGCThreads=4294967296 should give back 0. (SerialGC is ok with ParallelGCThreads=0)
120
for (long i = 4294967295L; i <= 4294967296L; i++) {
121
long count = getParallelGCThreadCount(
122
"-XX:+UseSerialGC",
123
"-XX:ParallelGCThreads=" + i,
124
"-XX:+PrintFlagsFinal",
125
"-version");
126
Asserts.assertEQ(count, i % 4294967296L, "Specifying ParallelGCThreads=" + i + " does not set the thread count properly!");
127
}
128
}
129
130
public static long getParallelGCThreadCount(String... flags) throws Exception {
131
ProcessBuilder pb = GCArguments.createJavaProcessBuilder(flags);
132
OutputAnalyzer output = new OutputAnalyzer(pb.start());
133
output.shouldHaveExitValue(0);
134
String stdout = output.getStdout();
135
return FlagsValue.getFlagLongValue("ParallelGCThreads", stdout);
136
}
137
}
138
139