Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/hotspot/jtreg/compiler/oracle/CheckCompileCommandOption.java
41152 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
/*
25
* @test CheckCompileCommandOption
26
* @summary Checks parsing of -XX:CompileCommand=option
27
* @bug 8055286 8056964 8059847 8069035
28
* @library /test/lib
29
* @modules java.base/jdk.internal.misc
30
* java.management
31
* @requires vm.flagless
32
* @requires vm.debug == true
33
* @run driver compiler.oracle.CheckCompileCommandOption
34
*/
35
36
package compiler.oracle;
37
38
import jdk.test.lib.process.OutputAnalyzer;
39
import jdk.test.lib.process.ProcessTools;
40
41
import java.io.File;
42
43
public class CheckCompileCommandOption {
44
45
// Currently, two types of trailing options can be used with
46
// -XX:CompileCommand=option
47
//
48
// (1) CompileCommand=option,Klass::method,option
49
// (2) CompileCommand=option,Klass::method,type,option,value
50
//
51
// Type (1) is used to enable a boolean option for a method.
52
//
53
// Type (2) is used to support options with a value. Values can
54
// have the the following types: intx, uintx, bool, ccstr,
55
// ccstrlist, and double.
56
57
private static final String[][] FILE_ARGUMENTS = {
58
{
59
"-XX:CompileCommandFile=" + new File(System.getProperty("test.src", "."), "command1.txt"),
60
"-version"
61
},
62
{
63
"-XX:CompileCommandFile=" + new File(System.getProperty("test.src", "."), "command2.txt"),
64
"-version"
65
}
66
};
67
68
private static final String[][] FILE_EXPECTED_OUTPUT = {
69
{
70
"com/oracle/Test.test1 bool TestOptionBool = true",
71
"com/oracle/Test.test2 bool TestOptionBool = true",
72
"com/oracle/Test.test3 bool TestOptionBool = true",
73
"com/oracle/Test.test4 bool TestOptionBool = true",
74
"com/oracle/Test.test4 bool TestOptionBool2 = true",
75
"com/oracle/Test.test5 bool TestOptionBool = true",
76
"com/oracle/Test.test5 bool TestOptionBool2 = true",
77
"com/oracle/Test.test6(I) bool TestOptionBool = true",
78
"com/oracle/Test.test7(I) bool TestOptionBool = true",
79
"com/oracle/Test.test8(I) bool TestOptionBool = true",
80
"com/oracle/Test.test9(I) bool TestOptionBool = true",
81
"com/oracle/Test.test9(I) bool TestOptionBool2 = true",
82
"com/oracle/Test.test10(I) bool TestOptionBool = true",
83
"com/oracle/Test.test10(I) bool TestOptionBool2 = true"
84
},
85
{
86
"Test.test const char* TestOptionList = '_foo _bar'",
87
"Test.test const char* TestOptionStr = '_foo'",
88
"Test.test bool TestOptionBool = false",
89
"Test.test intx TestOptionInt = -1",
90
"Test.test uintx TestOptionUint = 1",
91
"Test.test bool TestOptionBool2 = true",
92
"Test.test double TestOptionDouble = 1.123000"
93
}
94
};
95
96
private static final String[][] TYPE_1_ARGUMENTS = {
97
{
98
"-XX:CompileCommand=option,com/oracle/Test.test,TestOptionBool",
99
"-XX:CompileCommand=option,com/oracle/Test,test,TestOptionBool2",
100
"-XX:CompileCommand=option,com/oracle/Test.test2,TestOptionBool2,TestOptionBool",
101
"-version"
102
}
103
};
104
105
private static final String[][] TYPE_1_EXPECTED_OUTPUTS = {
106
{
107
"com/oracle/Test.test bool TestOptionBool = true",
108
"com/oracle/Test.test bool TestOptionBool2 = true",
109
"com/oracle/Test.test2 bool TestOptionBool = true",
110
"com/oracle/Test.test2 bool TestOptionBool2 = true",
111
}
112
};
113
114
private static final String[][] TYPE_2_ARGUMENTS = {
115
{
116
"-XX:CompileCommand=option,Test::test,ccstrlist,TestOptionList,_foo,_bar",
117
"-XX:CompileCommand=option,Test::test,ccstr,TestOptionStr,_foo",
118
"-XX:CompileCommand=option,Test::test,bool,TestOptionBool,false",
119
"-XX:CompileCommand=option,Test::test,intx,TestOptionInt,-1",
120
"-XX:CompileCommand=option,Test::test,uintx,TestOptionUint,1",
121
"-XX:CompileCommand=option,Test::test,TestOptionBool2",
122
"-XX:CompileCommand=option,Test::test,double,TestOptionDouble,1.123",
123
"-XX:CompileCommand=option,Test.test2,double,TestOptionDouble,1.123",
124
"-version"
125
}
126
};
127
128
private static final String[][] TYPE_2_EXPECTED_OUTPUTS = {
129
{
130
"Test.test const char* TestOptionList = '_foo _bar'",
131
"Test.test const char* TestOptionStr = '_foo'",
132
"Test.test bool TestOptionBool = false",
133
"Test.test intx TestOptionInt = -1",
134
"Test.test uintx TestOptionUint = 1",
135
"Test.test bool TestOptionBool2 = true",
136
"Test.test double TestOptionDouble = 1.123000",
137
"Test.test2 double TestOptionDouble = 1.123000"
138
}
139
};
140
141
private static final String[][] TYPE_3_ARGUMENTS = {
142
{
143
"-XX:CompileCommand=option,Test::test,bool,TestOptionBool,false,intx,TestOptionInt,-1,uintx,TestOptionUint,1,TestOptionBool2,double,TestOptionDouble,1.123",
144
"-version"
145
}
146
};
147
148
private static final String[][] TYPE_3_EXPECTED_OUTPUTS = {
149
{
150
"Test.test bool TestOptionBool = false",
151
"Test.test intx TestOptionInt = -1",
152
"Test.test uintx TestOptionUint = 1",
153
"Test.test bool TestOptionBool2 = true",
154
"Test.test double TestOptionDouble = 1.123000"
155
}
156
};
157
158
private static final String[][] TYPE_4_ARGUMENTS = {
159
{
160
"-XX:CompileCommand=TestOptionList,Test::test,_foo,_bar",
161
"-XX:CompileCommand=TestOptionStr,Test::test,_foo",
162
"-XX:CompileCommand=TestOptionBool,Test::test,false",
163
"-XX:CompileCommand=TestOptionInt,Test::test,-1",
164
"-XX:CompileCommand=TestOptionUint,Test::test,1",
165
"-XX:CompileCommand=TestOptionBool2,Test::test",
166
"-XX:CompileCommand=TestOptionDouble,Test::test,1.123",
167
"-XX:CompileCommand=TestOptionDouble,Test.test2,1.123",
168
"-version"
169
}
170
};
171
172
private static final String[][] TYPE_4_EXPECTED_OUTPUTS = {
173
{
174
"CompileCommand: TestOptionList Test.test const char* TestOptionList = '_foo _bar'",
175
"CompileCommand: TestOptionStr Test.test const char* TestOptionStr = '_foo'",
176
"CompileCommand: TestOptionBool Test.test bool TestOptionBool = false",
177
"CompileCommand: TestOptionInt Test.test intx TestOptionInt = -1",
178
"CompileCommand: TestOptionUint Test.test uintx TestOptionUint = 1",
179
"CompileCommand: TestOptionBool2 Test.test bool TestOptionBool2 = true",
180
"CompileCommand: TestOptionDouble Test.test double TestOptionDouble = 1.123000",
181
"CompileCommand: TestOptionDouble Test.test2 double TestOptionDouble = 1.123000"
182
}
183
};
184
185
private static final String[][] TYPE_4_INVALID_ARGUMENTS = {
186
{
187
"-XX:CompileCommand=InvalidOption,Test::test,_foo,_bar",
188
"-XX:CompileCommand=TestOptionInt,Test::test,_foo",
189
"-XX:CompileCommand=TestOptionBool,Test::test,1",
190
"-XX:CompileCommand=TestOptionDouble,Test::test,-1",
191
"-XX:CompileCommand=TestOptionUint,Test::test",
192
"-XX:CompileCommand=TestOptionBool2,Test::test,falsee",
193
"-XX:CompileCommand=TestOptionDouble,Test::test,true",
194
"-XX:CompileCommand=TestOptionDouble,Test.test2,1.f",
195
"-version"
196
}
197
};
198
199
private static final String[][] TYPE_4_INVALID_OUTPUTS = {
200
{
201
"Unrecognized option 'InvalidOption'",
202
"Value cannot be read for option 'TestOptionInt' of type 'intx'",
203
"Value cannot be read for option 'TestOptionBool' of type 'bool'",
204
"Value cannot be read for option 'TestOptionDouble' of type 'double'",
205
"Option 'TestOptionUint' is not followed by a value",
206
"Value cannot be read for option 'TestOptionBool2' of type 'bool'",
207
"Value cannot be read for option 'TestOptionDouble' of type 'double'",
208
"Value cannot be read for option 'TestOptionDouble' of type 'double'"
209
}
210
};
211
212
private static final String[][] TYPE_2_INVALID_ARGUMENTS = {
213
{
214
// bool flag name missing
215
"-XX:CompileCommand=option,Test::test,bool",
216
"-version"
217
},
218
{
219
// bool flag value missing
220
"-XX:CompileCommand=option,Test::test,bool,MyBoolOption",
221
"-version"
222
},
223
{
224
// wrong value for bool flag
225
"-XX:CompileCommand=option,Test::test,bool,MyBoolOption,100",
226
"-version"
227
},
228
{
229
// intx flag name missing
230
"-XX:CompileCommand=option,Test::test,bool,MyBoolOption,false,intx",
231
"-version"
232
},
233
{
234
// intx flag value missing
235
"-XX:CompileCommand=option,Test::test,bool,MyBoolOption,false,intx,MyIntOption",
236
"-version"
237
},
238
{
239
// wrong value for intx flag
240
"-XX:CompileCommand=option,Test::test,bool,MyBoolOption,false,intx,MyIntOption,true",
241
"-version"
242
},
243
{
244
// wrong value for flag double flag
245
"-XX:CompileCommand=option,Test::test,double,MyDoubleOption,1",
246
"-version"
247
}
248
};
249
250
private static void verifyValidOption(String[] arguments, String[] expected_outputs) throws Exception {
251
ProcessBuilder pb;
252
OutputAnalyzer out;
253
254
pb = ProcessTools.createJavaProcessBuilder(arguments);
255
out = new OutputAnalyzer(pb.start());
256
257
for (String expected_output : expected_outputs) {
258
out.shouldContain(expected_output);
259
}
260
261
out.shouldNotContain("CompileCommand: An error occurred during parsing");
262
out.shouldHaveExitValue(0);
263
}
264
265
private static void verifyInvalidOption(String[] arguments) throws Exception {
266
ProcessBuilder pb;
267
OutputAnalyzer out;
268
269
pb = ProcessTools.createJavaProcessBuilder(arguments);
270
out = new OutputAnalyzer(pb.start());
271
272
out.shouldContain("CompileCommand: An error occurred during parsing");
273
out.shouldHaveExitValue(0);
274
}
275
276
private static void verifyInvalidOption(String[] arguments, String[] expected_outputs) throws Exception {
277
ProcessBuilder pb;
278
OutputAnalyzer out;
279
280
pb = ProcessTools.createJavaProcessBuilder(arguments);
281
out = new OutputAnalyzer(pb.start());
282
283
for (String expected_output : expected_outputs) {
284
out.shouldContain(expected_output);
285
}
286
287
out.shouldContain("CompileCommand: An error occurred during parsing");
288
out.shouldHaveExitValue(0);
289
290
}
291
292
293
public static void main(String[] args) throws Exception {
294
295
if (TYPE_1_ARGUMENTS.length != TYPE_1_EXPECTED_OUTPUTS.length) {
296
throw new RuntimeException("Test is set up incorrectly: length of arguments and expected outputs for type (1) options does not match.");
297
}
298
299
if (TYPE_2_ARGUMENTS.length != TYPE_2_EXPECTED_OUTPUTS.length) {
300
throw new RuntimeException("Test is set up incorrectly: length of arguments and expected outputs for type (2) options does not match.");
301
}
302
303
if (TYPE_3_ARGUMENTS.length != TYPE_3_EXPECTED_OUTPUTS.length) {
304
throw new RuntimeException("Test is set up incorrectly: length of arguments and expected outputs for type (3) options does not match.");
305
}
306
307
if (TYPE_4_ARGUMENTS.length != TYPE_4_EXPECTED_OUTPUTS.length) {
308
throw new RuntimeException("Test is set up incorrectly: length of arguments and expected outputs for type (4) options does not match.");
309
}
310
311
// Check if type (1) options are parsed correctly
312
for (int i = 0; i < TYPE_1_ARGUMENTS.length; i++) {
313
verifyValidOption(TYPE_1_ARGUMENTS[i], TYPE_1_EXPECTED_OUTPUTS[i]);
314
}
315
316
// Check if type (2) options are parsed correctly
317
for (int i = 0; i < TYPE_2_ARGUMENTS.length; i++) {
318
verifyValidOption(TYPE_2_ARGUMENTS[i], TYPE_2_EXPECTED_OUTPUTS[i]);
319
}
320
321
// Check if type (3) options are parsed correctly
322
for (int i = 0; i < TYPE_3_ARGUMENTS.length; i++) {
323
verifyValidOption(TYPE_3_ARGUMENTS[i], TYPE_3_EXPECTED_OUTPUTS[i]);
324
}
325
326
// Check if type (4) options are parsed correctly
327
for (int i = 0; i < TYPE_4_ARGUMENTS.length; i++) {
328
verifyValidOption(TYPE_4_ARGUMENTS[i], TYPE_4_EXPECTED_OUTPUTS[i]);
329
}
330
331
// Check if error is reported for invalid type (2) options
332
// (flags with type information specified)
333
for (String[] arguments: TYPE_2_INVALID_ARGUMENTS) {
334
verifyInvalidOption(arguments);
335
}
336
337
// Check if error is reported for invalid type (2) options
338
// (flags with type information specified)
339
for (int i = 0; i < TYPE_4_INVALID_ARGUMENTS.length; i++) {
340
verifyInvalidOption(TYPE_4_INVALID_ARGUMENTS[i], TYPE_4_INVALID_OUTPUTS[i]);
341
}
342
343
// Check if commands in command file are parsed correctly
344
for (int i = 0; i < FILE_ARGUMENTS.length; i++) {
345
verifyValidOption(FILE_ARGUMENTS[i], FILE_EXPECTED_OUTPUT[i]);
346
}
347
}
348
}
349
350