Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/hotspot/jtreg/gc/arguments/TestObjectTenuringFlags.java
40942 views
1
/*
2
* Copyright (c) 2014, 2020, 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 TestObjectTenuringFlags
28
* @bug 6521376
29
* @requires vm.gc.Parallel
30
* @summary Tests argument processing for NeverTenure, AlwaysTenure,
31
* and MaxTenuringThreshold
32
* @library /test/lib
33
* @library /
34
* @modules java.base/jdk.internal.misc
35
* java.management
36
* @run driver gc.arguments.TestObjectTenuringFlags
37
*/
38
39
import jdk.test.lib.process.OutputAnalyzer;
40
import jdk.test.lib.process.ProcessTools;
41
42
import java.util.*;
43
44
public class TestObjectTenuringFlags {
45
public static void main(String args[]) throws Exception {
46
// default case
47
runTenuringFlagsConsistencyTest(
48
new String[]{},
49
false /* shouldFail */,
50
new ExpectedTenuringFlags(false /* alwaysTenure */, false /* neverTenure */, 7, 15));
51
52
// valid cases
53
runTenuringFlagsConsistencyTest(
54
new String[]{"-XX:+NeverTenure"},
55
false /* shouldFail */,
56
new ExpectedTenuringFlags(false /* alwaysTenure */, true /* neverTenure */, 7, 16));
57
58
runTenuringFlagsConsistencyTest(
59
new String[]{"-XX:+AlwaysTenure"},
60
false /* shouldFail */,
61
new ExpectedTenuringFlags(true /* alwaysTenure */, false /* neverTenure */, 0, 0));
62
63
runTenuringFlagsConsistencyTest(
64
new String[]{"-XX:MaxTenuringThreshold=0"},
65
false /* shouldFail */,
66
new ExpectedTenuringFlags(true /* alwaysTenure */, false /* neverTenure */, 0, 0));
67
68
runTenuringFlagsConsistencyTest(
69
new String[]{"-XX:MaxTenuringThreshold=5"},
70
false /* shouldFail */,
71
new ExpectedTenuringFlags(false /* alwaysTenure */, false /* neverTenure */, 5, 5));
72
73
runTenuringFlagsConsistencyTest(
74
new String[]{"-XX:MaxTenuringThreshold=10"},
75
false /* shouldFail */,
76
new ExpectedTenuringFlags(false /* alwaysTenure */, false /* neverTenure */, 7, 10));
77
78
runTenuringFlagsConsistencyTest(
79
new String[]{"-XX:MaxTenuringThreshold=15"},
80
false /* shouldFail */,
81
new ExpectedTenuringFlags(false /* alwaysTenure */, false /* neverTenure */, 7, 15));
82
83
runTenuringFlagsConsistencyTest(
84
new String[]{"-XX:MaxTenuringThreshold=16"},
85
false /* shouldFail */,
86
new ExpectedTenuringFlags(false /* alwaysTenure */, false /* neverTenure */, 7, 16));
87
88
runTenuringFlagsConsistencyTest(
89
new String[]{"-XX:InitialTenuringThreshold=0"},
90
false /* shouldFail */,
91
new ExpectedTenuringFlags(false /* alwaysTenure */, false /* neverTenure */, 0, 15));
92
93
runTenuringFlagsConsistencyTest(
94
new String[]{"-XX:InitialTenuringThreshold=5"},
95
false /* shouldFail */,
96
new ExpectedTenuringFlags(false /* alwaysTenure */, false /* neverTenure */, 5, 15));
97
98
runTenuringFlagsConsistencyTest(
99
new String[]{"-XX:InitialTenuringThreshold=10"},
100
false /* shouldFail */,
101
new ExpectedTenuringFlags(false /* alwaysTenure */, false /* neverTenure */, 10, 15));
102
103
runTenuringFlagsConsistencyTest(
104
new String[]{"-XX:InitialTenuringThreshold=15"},
105
false /* shouldFail */,
106
new ExpectedTenuringFlags(false /* alwaysTenure */, false /* neverTenure */, 15, 15));
107
108
// "Last option wins" cases
109
runTenuringFlagsConsistencyTest(
110
new String[]{"-XX:+AlwaysTenure", "-XX:+NeverTenure"},
111
false /* shouldFail */,
112
new ExpectedTenuringFlags(false /* alwaysTenure */, true /* neverTenure */, 7, 16));
113
114
runTenuringFlagsConsistencyTest(
115
new String[]{"-XX:+NeverTenure", "-XX:+AlwaysTenure"},
116
false /* shouldFail */,
117
new ExpectedTenuringFlags(true /* alwaysTenure */, false /* neverTenure */, 0, 0));
118
119
runTenuringFlagsConsistencyTest(
120
new String[]{"-XX:MaxTenuringThreshold=16", "-XX:+AlwaysTenure"},
121
false /* shouldFail */,
122
new ExpectedTenuringFlags(true /* alwaysTenure */, false /* neverTenure */, 0, 0));
123
124
runTenuringFlagsConsistencyTest(
125
new String[]{"-XX:+AlwaysTenure", "-XX:MaxTenuringThreshold=16"},
126
false /* shouldFail */,
127
new ExpectedTenuringFlags(false /* alwaysTenure */, false /* neverTenure */, 7, 16));
128
129
runTenuringFlagsConsistencyTest(
130
new String[]{"-XX:MaxTenuringThreshold=0", "-XX:+NeverTenure"},
131
false /* shouldFail */,
132
new ExpectedTenuringFlags(false /* alwaysTenure */, true /* neverTenure */, 7, 16));
133
134
runTenuringFlagsConsistencyTest(
135
new String[]{"-XX:+NeverTenure", "-XX:MaxTenuringThreshold=0"},
136
false /* shouldFail */,
137
new ExpectedTenuringFlags(true /* alwaysTenure */, false /* neverTenure */, 0, 0));
138
139
// Illegal cases
140
runTenuringFlagsConsistencyTest(
141
new String[]{"-XX:MaxTenuringThreshold=17"},
142
true /* shouldFail */,
143
new ExpectedTenuringFlags());
144
145
runTenuringFlagsConsistencyTest(
146
new String[]{"-XX:InitialTenuringThreshold=16"},
147
true /* shouldFail */,
148
new ExpectedTenuringFlags());
149
150
runTenuringFlagsConsistencyTest(
151
new String[]{"-XX:InitialTenuringThreshold=17"},
152
true /* shouldFail */,
153
new ExpectedTenuringFlags());
154
}
155
156
private static void runTenuringFlagsConsistencyTest(String[] tenuringFlags,
157
boolean shouldFail,
158
ExpectedTenuringFlags expectedFlags) throws Exception {
159
List<String> vmOpts = new ArrayList<>();
160
if (tenuringFlags.length > 0) {
161
Collections.addAll(vmOpts, tenuringFlags);
162
}
163
Collections.addAll(vmOpts, "-XX:+UseParallelGC", "-XX:+PrintFlagsFinal", "-version");
164
165
ProcessBuilder pb = GCArguments.createJavaProcessBuilder(vmOpts);
166
OutputAnalyzer output = new OutputAnalyzer(pb.start());
167
168
if (shouldFail) {
169
output.shouldHaveExitValue(1);
170
} else {
171
output.shouldHaveExitValue(0);
172
String stdout = output.getStdout();
173
checkTenuringFlagsConsistency(stdout, expectedFlags);
174
}
175
}
176
177
private static void checkTenuringFlagsConsistency(String output, ExpectedTenuringFlags expectedFlags) {
178
if (expectedFlags.alwaysTenure != FlagsValue.getFlagBoolValue("AlwaysTenure", output)) {
179
throw new RuntimeException(
180
"Actual flag AlwaysTenure " + FlagsValue.getFlagBoolValue("AlwaysTenure", output) +
181
" is not equal to expected flag AlwaysTenure " + expectedFlags.alwaysTenure);
182
}
183
184
if (expectedFlags.neverTenure != FlagsValue.getFlagBoolValue("NeverTenure", output)) {
185
throw new RuntimeException(
186
"Actual flag NeverTenure " + FlagsValue.getFlagBoolValue("NeverTenure", output) +
187
" is not equal to expected flag NeverTenure " + expectedFlags.neverTenure);
188
}
189
190
if (expectedFlags.initialTenuringThreshold != FlagsValue.getFlagLongValue("InitialTenuringThreshold", output)) {
191
throw new RuntimeException(
192
"Actual flag InitialTenuringThreshold " + FlagsValue.getFlagLongValue("InitialTenuringThreshold", output) +
193
" is not equal to expected flag InitialTenuringThreshold " + expectedFlags.initialTenuringThreshold);
194
}
195
196
if (expectedFlags.maxTenuringThreshold != FlagsValue.getFlagLongValue("MaxTenuringThreshold", output)) {
197
throw new RuntimeException(
198
"Actual flag MaxTenuringThreshold " + FlagsValue.getFlagLongValue("MaxTenuringThreshold", output) +
199
" is not equal to expected flag MaxTenuringThreshold " + expectedFlags.maxTenuringThreshold);
200
}
201
}
202
}
203
204
class ExpectedTenuringFlags {
205
public boolean alwaysTenure;
206
public boolean neverTenure;
207
public long initialTenuringThreshold;
208
public long maxTenuringThreshold;
209
210
public ExpectedTenuringFlags(boolean alwaysTenure,
211
boolean neverTenure,
212
long initialTenuringThreshold,
213
long maxTenuringThreshold) {
214
this.alwaysTenure = alwaysTenure;
215
this.neverTenure = neverTenure;
216
this.initialTenuringThreshold = initialTenuringThreshold;
217
this.maxTenuringThreshold = maxTenuringThreshold;
218
}
219
public ExpectedTenuringFlags() {}
220
}
221
222