Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/hotspot/jtreg/compiler/compilercontrol/parser/HugeDirectiveUtil.java
41154 views
1
/*
2
* Copyright (c) 2015, 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 compiler.compilercontrol.parser;
25
26
import compiler.compilercontrol.share.JSONFile;
27
import compiler.compilercontrol.share.method.MethodDescriptor;
28
import compiler.compilercontrol.share.scenario.DirectiveWriter;
29
import compiler.compilercontrol.share.scenario.Scenario;
30
import jdk.test.lib.process.OutputAnalyzer;
31
import jdk.test.lib.process.ProcessTools;
32
import jdk.test.lib.Utils;
33
34
import java.util.EnumSet;
35
import java.util.List;
36
import java.util.Random;
37
import java.util.stream.Collectors;
38
39
import static compiler.compilercontrol.share.IntrinsicCommand.VALID_INTRINSIC_SAMPLES;
40
41
/**
42
* Creates a huge directive file
43
*/
44
public final class HugeDirectiveUtil {
45
protected static final String EXPECTED_ERROR_STRING = "Parsing of compiler "
46
+ "directives failed";
47
48
private HugeDirectiveUtil() { }
49
50
/**
51
* Creates huge file with specified amount of directives
52
*
53
* @param descriptors a list of descriptors to be randomly used
54
* in match and inline blocks
55
* @param fileName a directives file name to be created
56
* @param amount an amount of match objects
57
*/
58
public static void createHugeFile(List<MethodDescriptor> descriptors,
59
String fileName, int amount) {
60
try (DirectiveWriter file = new DirectiveWriter(fileName)) {
61
file.write(JSONFile.Element.ARRAY);
62
for (int i = 0; i < amount; i++) {
63
createMatchObject(descriptors, file, 1);
64
}
65
file.end();
66
}
67
}
68
69
/**
70
* Creates match object in the given file with specified size
71
*
72
* @param descriptors a list of method descriptors to be used
73
* @param file a directive file to write at
74
* @param objectSize a size of the match object
75
*/
76
public static void createMatchObject(List<MethodDescriptor> descriptors,
77
DirectiveWriter file, int objectSize) {
78
// get random amount of methods for the match
79
List<String> methods = getRandomDescriptors(descriptors);
80
file.match(methods.toArray(new String[methods.size()]));
81
Random random = Utils.getRandomInstance();
82
for (int i = 0; i < objectSize; i++) {
83
// emit compiler block
84
file.emitCompiler(Utils.getRandomElement(
85
Scenario.Compiler.values()));
86
// add option inside the compiler block
87
DirectiveWriter.Option option = Utils.getRandomElement(DirectiveWriter.Option.values());
88
file.option(option,
89
option != DirectiveWriter.Option.INTRINSIC
90
? random.nextBoolean()
91
: "\"" + Utils.getRandomElement(VALID_INTRINSIC_SAMPLES) + "\"");
92
file.end(); // ends compiler block
93
94
// add standalone option, enable can't be used standalone
95
EnumSet<DirectiveWriter.Option> options = EnumSet.complementOf(
96
EnumSet.of(DirectiveWriter.Option.ENABLE));
97
file.option(Utils.getRandomElement(options), random.nextBoolean());
98
}
99
// add inline block with random inlinees
100
methods = getRandomDescriptors(descriptors).stream()
101
.map(s -> (random.nextBoolean() ? "+" : "-") + s)
102
.collect(Collectors.toList());
103
file.inline(methods);
104
105
// end match block
106
file.end();
107
}
108
109
private static List<String> getRandomDescriptors(
110
List<MethodDescriptor> descriptors) {
111
Random random = Utils.getRandomInstance();
112
int amount = 1 + random.nextInt(descriptors.size() - 1);
113
int skipAmount = random.nextInt(descriptors.size() - amount);
114
return descriptors.stream()
115
.skip(skipAmount)
116
.limit(amount)
117
.map(MethodDescriptor::getString)
118
.collect(Collectors.toList());
119
}
120
121
protected static OutputAnalyzer execute(String fileName) {
122
OutputAnalyzer output;
123
try {
124
output = ProcessTools.executeTestJvm(
125
"-XX:+UnlockDiagnosticVMOptions",
126
"-XX:CompilerDirectivesLimit=1000",
127
"-XX:CompilerDirectivesFile=" + fileName,
128
"-version");
129
} catch (Throwable thr) {
130
throw new Error("Execution failed with: " + thr, thr);
131
}
132
return output;
133
}
134
}
135
136