Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/hotspot/jtreg/compiler/oracle/MethodMatcherTest.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 MethodMatcherTest
26
* @summary Testing of compiler/MethodMatcher
27
* @bug 8135068
28
* @library /test/lib
29
* @modules java.base/jdk.internal.misc
30
* @build sun.hotspot.WhiteBox
31
* @run driver jdk.test.lib.helpers.ClassFileInstaller sun.hotspot.WhiteBox
32
* @run main/othervm -Xbootclasspath/a:. -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI
33
* compiler.oracle.MethodMatcherTest
34
*/
35
36
package compiler.oracle;
37
38
import sun.hotspot.WhiteBox;
39
40
import java.lang.reflect.Method;
41
import java.util.ArrayList;
42
43
public class MethodMatcherTest {
44
45
/** Instance of WhiteBox */
46
protected static final WhiteBox WHITE_BOX = WhiteBox.getWhiteBox();
47
48
Method helper;
49
Method getDate;
50
Method inner;
51
Method toString;
52
53
static final int MATCH = 1;
54
static final int NO_MATCH = 0;
55
static final int PARSING_FAILURE = -1;
56
57
public MethodMatcherTest() {
58
}
59
60
public void test() throws Exception {
61
// instantiate before calling getMethod on innerHelper
62
TestCases testCases = new TestCases();
63
64
helper = getMethod(MethodMatcherTest.class, "helper");
65
getDate = getMethod(java.util.Date.class, "getDate");
66
inner = getMethod(TestCases.class, "innerHelper");
67
toString = getMethod(String.class, "toString");
68
69
testCases.add(helper, "pool/sub/Klass.method(I[Ljava/lang/String;Ljava/lang/Integer;[B[[D)V", NO_MATCH);
70
71
// These should be improved to parsing failed in the future
72
testCases.add(helper, "*Klass*,*$method*::", NO_MATCH);
73
testCases.add(helper, "*Klass *+*", NO_MATCH);
74
testCases.add(helper, "*Klass*::*method*", NO_MATCH);
75
76
testCases.add(helper, "*,**", PARSING_FAILURE);
77
testCases.add(helper, "*,*(I[Ljava/lang/String;Lj]ava/lang/Integer;[B[[D)V", PARSING_FAILURE);
78
testCases.add(helper, "*,*)method*.", PARSING_FAILURE);
79
testCases.add(helper, "{pool.subpack.Klass}* *", PARSING_FAILURE);
80
testCases.add(helper, "*Klass met]hod/", PARSING_FAILURE);
81
testCases.add(helper, "pool::su@%b::Klass* *)method.", PARSING_FAILURE);
82
testCases.add(helper, "0pool/sub/Klass,*{method}*.(I[Ljava/lang/String;Lj]ava/lang/Integer;[B[[D)V", PARSING_FAILURE);
83
testCases.add(helper, "*Klass nonexistent::)(I[Ljava/lang/String;Ljava/lang/Integer;[B[[D)V", PARSING_FAILURE);
84
testCases.add(helper, "pool,su]b,Klass*,*)method*/", PARSING_FAILURE);
85
testCases.add(helper, "_pool,sub,Klass*,met@%hod,(0)V", PARSING_FAILURE);
86
87
testCases.add(helper, "*.*", MATCH);
88
testCases.add(helper, "compiler/oracle/MethodMatcherTest.*", MATCH);
89
testCases.add(helper, "compiler/oracle/MethodMatcherTest.helper", MATCH);
90
testCases.add(helper, "compiler/oracle/MethodMatcherTest.helper()", MATCH);
91
testCases.add(helper, "compiler/oracle/MethodMatcherTest.helper()V", MATCH);
92
testCases.add(helper, "compiler/oracle/MethodMatcherTest.helper()V;", NO_MATCH);
93
testCases.add(helper, "compiler/oracle/MethodMatcherTest.helper()I", NO_MATCH);
94
testCases.add(helper, "compiler/oracle/MethodMatcherTest.helperX", NO_MATCH);
95
testCases.add(helper, "compiler/oracle/MethodMatcherTest.helper;", NO_MATCH);
96
testCases.add(helper, "abc.*", NO_MATCH);
97
testCases.add(helper, "*.abc", NO_MATCH);
98
99
testCases.add(getDate, "*.*", MATCH);
100
testCases.add(getDate, "*.getDate", MATCH);
101
testCases.add(getDate, "java/util/Date.getDate", MATCH);
102
testCases.add(getDate, "java/util/Date.*", MATCH);
103
104
testCases.add(inner, "*.*", MATCH);
105
testCases.add(inner, "compiler/oracle/MethodMatcherTest$TestCases.innerHelper", MATCH);
106
testCases.add(inner, "compiler/oracle/MethodMatcherTest*.innerHelper", MATCH);
107
testCases.add(inner, "compiler/oracle/MethodMatcherTest$*.innerHelper", MATCH);
108
testCases.add(inner, "*$TestCases.innerHelper", MATCH);
109
testCases.add(inner, "*TestCases.innerHelper", MATCH);
110
testCases.add(inner, "TestCases.innerHelper", NO_MATCH);
111
testCases.add(inner, "compiler/oracle/MethodMatcherTest.innerHelper", NO_MATCH);
112
113
testCases.add(toString, "*.*", MATCH);
114
testCases.add(toString, "java/lang/String.toString", MATCH);
115
testCases.add(toString, "java.lang.String::toString", MATCH);
116
117
testCases.add(toString, "java/lang/String::toString", PARSING_FAILURE);
118
testCases.add(toString, "java.lang/String::toString", PARSING_FAILURE);
119
testCases.add(toString, "java.lang/String.toString", PARSING_FAILURE);
120
testCases.add(toString, "java::lang::String::toString", PARSING_FAILURE);
121
122
testCases.add(toString, "java/lang/String.toString(*)", PARSING_FAILURE);
123
testCases.add(toString, "java/lang/String.toString(L*", PARSING_FAILURE);
124
testCases.add(toString, "java/lang/String.toString*(lsd)l", NO_MATCH);
125
testCases.add(toString, "java/lang/String.toString(lsd)l", NO_MATCH);
126
testCases.add(toString, "java/lang/String.toString (", MATCH);
127
testCases.add(toString, "java/lang/String.toString ()", MATCH);
128
testCases.add(toString, "java/lang/String.toString ()L", MATCH);
129
testCases.add(toString, "java/lang/String.toString ()Lj", MATCH);
130
testCases.add(toString, "java/lang/String.toString ()Ls", NO_MATCH);
131
testCases.add(toString, "java/lang/String.toString*(", MATCH);
132
testCases.add(toString, "java/lang/String.toString* (", MATCH);
133
testCases.add(toString, "java/lang/String.toString*(;", NO_MATCH);
134
testCases.add(toString, "java/lang/String.toString*();sf", NO_MATCH);
135
testCases.add(toString, "java/lang/String.toString*()Ljava/lang/String;", MATCH);
136
testCases.add(toString, "java/lang/String.toString()Ljava/lang/String;", MATCH);
137
testCases.add(toString, "java/lang/String.toString ()Ljava/lang/String;", MATCH);
138
testCases.add(toString, "java/lang/String.toString ()Ljava/lang/String", MATCH);
139
testCases.add(toString, "java/lang/String.toString ()L", MATCH);
140
testCases.add(toString, "java/lang/String.toString ()I;", NO_MATCH);
141
142
testCases.add(toString, "*Internal.*", NO_MATCH);
143
testCases.add(toString, "*Internal.**", PARSING_FAILURE);
144
testCases.add(toString, "*Internal.***", PARSING_FAILURE);
145
testCases.add(toString, "*Internal.*a**", PARSING_FAILURE);
146
testCases.add(toString, "*Internal.**a*", PARSING_FAILURE);
147
148
testCases.add(toString, "java.lang.String::<init>(Ljava/lang/String;)V", NO_MATCH);
149
testCases.add(toString, "java.lang.String::<clinit>(Ljava/lang/String;)V", NO_MATCH);
150
testCases.add(toString, "java.lang.String::<init(Ljava/lang/String;)V", PARSING_FAILURE);
151
testCases.add(toString, "java.lang.String::init>(Ljava/lang/String;)V", PARSING_FAILURE);
152
153
testCases.add(toString, "java/lang/String.toString()Ljava/lang/String;", MATCH);
154
testCases.add(toString, "java/lang/Str<ing.toString()Ljava/lang/String;", PARSING_FAILURE);
155
testCases.add(toString, "java/lang/Str>ing.toString()Ljava/lang/String;", PARSING_FAILURE);
156
testCases.add(toString, "java/lang/<init>.toString()Ljava/lang/String;", PARSING_FAILURE);
157
testCases.add(toString, "java/lang/<clinit>.toString()Ljava/lang/String;", PARSING_FAILURE);
158
159
int failures = 0;
160
for (TestCase t : testCases) {
161
System.out.println("Test case: " + t.pattern);
162
if (!t.test()) {
163
failures++;
164
System.out.println(" * FAILED");
165
}
166
}
167
if (failures != 0) {
168
throw new Exception("There where " + failures + " failures in this test");
169
}
170
}
171
172
public static void main(String... args) throws Exception {
173
MethodMatcherTest test = new MethodMatcherTest();
174
test.test();
175
}
176
177
public void helper() {
178
179
}
180
181
private static Method getMethod(Class klass, String name, Class<?>... parameterTypes) {
182
try {
183
return klass.getDeclaredMethod(name, parameterTypes);
184
} catch (NoSuchMethodException | SecurityException e) {
185
throw new RuntimeException("exception on getting method Helper." + name, e);
186
}
187
}
188
189
class TestCase {
190
String pattern;
191
Method testTarget;
192
int expectedResult;
193
194
public TestCase(Method testTarget, String pattern, int expectedResult) {
195
this.testTarget = testTarget;
196
this.pattern = pattern;
197
this.expectedResult = expectedResult;
198
}
199
200
public String resultAsStr(int errorCode) {
201
switch (errorCode) {
202
case PARSING_FAILURE:
203
return "Parsing failed";
204
case NO_MATCH:
205
return "No match";
206
case MATCH:
207
return "Match";
208
default:
209
return "Unknown error";
210
}
211
}
212
213
boolean test() {
214
int result = WHITE_BOX.matchesMethod(testTarget, pattern);
215
if (result != expectedResult) {
216
System.out
217
.println("FAIL Wrong result, Got: " + resultAsStr(result) + "\n TestCase: " + this.toString());
218
return false;
219
}
220
return true;
221
}
222
223
@Override
224
public String toString() {
225
return "Method: '" + testTarget.toString() + "' Pattern: '" + pattern + "' Expected: "
226
+ resultAsStr(expectedResult);
227
}
228
229
public void innerHelper() {
230
}
231
}
232
233
class TestCases extends ArrayList<TestCase> {
234
private static final long serialVersionUID = 1L;
235
236
public boolean add(Method testTarget, String pattern, int expectedResult) {
237
return super.add(new TestCase(testTarget, pattern, expectedResult));
238
}
239
240
public void innerHelper() {
241
}
242
}
243
}
244
245