Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/hotspot/jtreg/compiler/compilercontrol/InlineMatcherTest.java
41149 views
1
/*
2
* Copyright (c) 2015, 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 InlineMatcherTest
26
* @bug 8074095
27
* @summary Testing of compiler/InlineMatcher
28
* @modules java.base/jdk.internal.misc
29
* @library /test/lib
30
*
31
* @build sun.hotspot.WhiteBox
32
* @run driver jdk.test.lib.helpers.ClassFileInstaller sun.hotspot.WhiteBox
33
* @run main/othervm -Xbootclasspath/a:. -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI
34
* compiler.compilercontrol.InlineMatcherTest
35
*/
36
37
package compiler.compilercontrol;
38
39
import sun.hotspot.WhiteBox;
40
41
import java.lang.reflect.Method;
42
import java.util.ArrayList;
43
44
public class InlineMatcherTest {
45
46
/** Instance of WhiteBox */
47
protected static final WhiteBox WHITE_BOX = WhiteBox.getWhiteBox();
48
49
Method helper;
50
Method getDate;
51
Method inner;
52
Method toString;
53
54
final public static int FORCE_INLINE = 2;
55
final public static int DONT_INLINE = 1;
56
final public static int NO_MATCH = 0;
57
final public static int PARSING_FAILURE = -1;
58
59
public InlineMatcherTest() {
60
61
}
62
63
public void test() throws Exception {
64
// instantiate before calling getMethod on innerHelper
65
TestCases testCases = new TestCases();
66
67
helper = getMethod(InlineMatcherTest.class, "helper");
68
69
testCases.add(helper, "*.*", PARSING_FAILURE);
70
testCases.add(helper, "+*.*", FORCE_INLINE);
71
testCases.add(helper, "++*.*", NO_MATCH); // + is a valid part of the
72
// class name
73
testCases.add(helper, "-*.*", DONT_INLINE);
74
testCases.add(helper, "--*.*", NO_MATCH); // - is a valid part of the
75
// class name
76
77
String className = this.getClass().getName().replace('.', '/');
78
testCases.add(helper, "+" + className + ".*", FORCE_INLINE);
79
testCases.add(helper, "+" + className + ".helper", FORCE_INLINE);
80
testCases.add(helper, "+" + className + ".helper()", FORCE_INLINE);
81
testCases.add(helper, "+" + className + ".helper()V", FORCE_INLINE);
82
testCases.add(helper, "+" + className + ".helper(", FORCE_INLINE);
83
84
testCases.add(helper, "-" + className + ".*", DONT_INLINE);
85
testCases.add(helper, "-" + className + ".helper", DONT_INLINE);
86
testCases.add(helper, "-" + className + ".helper()", DONT_INLINE);
87
testCases.add(helper, "-" + className + ".helper()V", DONT_INLINE);
88
testCases.add(helper, "-" + className + ".helper(", DONT_INLINE);
89
90
testCases.add(helper, "+abc.*", NO_MATCH);
91
testCases.add(helper, "+*.abc", NO_MATCH);
92
testCases.add(helper, "-abc.*", NO_MATCH);
93
testCases.add(helper, "-*.abcls ", NO_MATCH);
94
95
int failures = 0;
96
97
for (TestCase t : testCases) {
98
System.out.println("Test case: " + t.pattern);
99
if (!t.test()) {
100
failures++;
101
System.out.println(" * FAILED");
102
}
103
}
104
if (failures != 0) {
105
throw new Exception("There where " + failures + " failures in this test");
106
}
107
}
108
109
public static void main(String... args) throws Exception {
110
InlineMatcherTest test = new InlineMatcherTest();
111
test.test();
112
}
113
114
public void helper() {
115
116
}
117
118
private static Method getMethod(Class klass, String name, Class<?>... parameterTypes) {
119
try {
120
return klass.getDeclaredMethod(name, parameterTypes);
121
} catch (NoSuchMethodException | SecurityException e) {
122
throw new RuntimeException("exception on getting method Helper." + name, e);
123
}
124
}
125
126
class TestCase {
127
String pattern;
128
Method testTarget;
129
int expectedResult;
130
131
public TestCase(Method testTarget, String pattern, int expectedResult) {
132
this.testTarget = testTarget;
133
this.pattern = pattern;
134
this.expectedResult = expectedResult;
135
}
136
137
public String resultAsStr(int errorCode) {
138
switch (errorCode) {
139
case PARSING_FAILURE:
140
return "Parsing failed";
141
case NO_MATCH:
142
return "No match";
143
case DONT_INLINE:
144
return "Dont Inline";
145
case FORCE_INLINE:
146
return "Force Inline";
147
default:
148
return "Unknown error";
149
}
150
}
151
152
boolean test() {
153
int result = WHITE_BOX.matchesInline(testTarget, pattern);
154
if (result != expectedResult) {
155
System.out
156
.println("FAIL Wrong result, Got: " + resultAsStr(result) + "\n TestCase: " + this.toString());
157
return false;
158
}
159
return true;
160
}
161
162
@Override
163
public String toString() {
164
return "Method: '" + testTarget.toString() + "' Pattern: '" + pattern + "' Expected: "
165
+ resultAsStr(expectedResult);
166
}
167
168
public void innerHelper() {
169
170
}
171
}
172
173
class TestCases extends ArrayList<TestCase> {
174
private static final long serialVersionUID = 1L;
175
176
public boolean add(Method testTarget, String pattern, int expectedResult) {
177
return super.add(new TestCase(testTarget, pattern, expectedResult));
178
}
179
}
180
}
181
182