Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/hotspot/jtreg/compiler/jvmci/compilerToVM/ResolveMethodTest.java
41153 views
1
/*
2
* Copyright (c) 2015, 2019, 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
26
* @bug 8136421
27
* @requires vm.jvmci
28
* @library / /test/lib
29
* @library ../common/patches
30
* @modules java.base/jdk.internal.misc
31
* @modules java.base/jdk.internal.org.objectweb.asm
32
* java.base/jdk.internal.org.objectweb.asm.tree
33
* jdk.internal.vm.ci/jdk.vm.ci.hotspot
34
* jdk.internal.vm.ci/jdk.vm.ci.code
35
* jdk.internal.vm.ci/jdk.vm.ci.meta
36
* jdk.internal.vm.ci/jdk.vm.ci.runtime
37
*
38
* @build jdk.internal.vm.ci/jdk.vm.ci.hotspot.CompilerToVMHelper
39
* @run main/othervm -XX:+UnlockExperimentalVMOptions -XX:+EnableJVMCI
40
* -XX:-UseJVMCICompiler
41
* compiler.jvmci.compilerToVM.ResolveMethodTest
42
*/
43
44
package compiler.jvmci.compilerToVM;
45
46
import compiler.jvmci.common.CTVMUtilities;
47
import compiler.jvmci.common.testcases.AbstractClass;
48
import compiler.jvmci.common.testcases.AbstractClassExtender;
49
import compiler.jvmci.common.testcases.MultipleImplementer1;
50
import compiler.jvmci.common.testcases.MultipleImplementer2;
51
import compiler.jvmci.common.testcases.MultipleImplementersInterface;
52
import compiler.jvmci.common.testcases.SingleImplementer;
53
import compiler.jvmci.common.testcases.SingleImplementerInterface;
54
import compiler.jvmci.common.testcases.SingleSubclass;
55
import compiler.jvmci.common.testcases.SingleSubclassedClass;
56
import jdk.internal.misc.Unsafe;
57
import jdk.test.lib.Asserts;
58
import jdk.test.lib.Utils;
59
import jdk.vm.ci.hotspot.CompilerToVMHelper;
60
import jdk.vm.ci.hotspot.HotSpotResolvedJavaMethod;
61
import jdk.vm.ci.hotspot.HotSpotResolvedObjectType;
62
63
import java.util.HashSet;
64
import java.util.Set;
65
66
public class ResolveMethodTest {
67
private static final Unsafe UNSAFE = Unsafe.getUnsafe();
68
69
public static void main(String args[]) {
70
ResolveMethodTest test = new ResolveMethodTest();
71
// positive cases
72
try {
73
for (TestCase tcase: createTestCases()) {
74
test.runTest(tcase);
75
}
76
} catch (NoSuchMethodException e) {
77
throw new Error("TEST BUG: can't find requested method", e);
78
}
79
}
80
81
private static Set<TestCase> createTestCases() {
82
Set<TestCase> result = new HashSet<>();
83
// a usual class public method
84
result.add(new TestCase(SingleSubclass.class, SingleSubclass.class,
85
"usualMethod", ResolveMethodTest.class, true));
86
// an array method
87
result.add(new TestCase(int[].class, Object.class, "toString",
88
ResolveMethodTest.class, true));
89
// a method from base class, which was overriden in tested one
90
result.add(new TestCase(SingleSubclass.class, SingleSubclass.class,
91
"overridenMethod", ResolveMethodTest.class, true));
92
// a method from base class, which was not overriden in tested one
93
result.add(new TestCase(SingleSubclass.class,
94
SingleSubclassedClass.class, "inheritedMethod",
95
ResolveMethodTest.class, true));
96
/* a method from base class, which was overriden in tested one with
97
base class as holder */
98
result.add(new TestCase(SingleSubclass.class,
99
SingleSubclassedClass.class, "overridenMethod",
100
ResolveMethodTest.class, true));
101
// an interface method
102
result.add(new TestCase(SingleImplementer.class,
103
SingleImplementerInterface.class, "interfaceMethod",
104
ResolveMethodTest.class, true));
105
// an interface default method overriden in implementer
106
result.add(new TestCase(MultipleImplementer1.class,
107
MultipleImplementersInterface.class, "defaultMethod",
108
ResolveMethodTest.class, true));
109
// an interface default method not overriden in implementer
110
result.add(new TestCase(MultipleImplementer2.class,
111
MultipleImplementersInterface.class, "defaultMethod",
112
ResolveMethodTest.class, true));
113
// an abstract method
114
result.add(new TestCase(AbstractClassExtender.class, AbstractClass.class,
115
"abstractMethod", ResolveMethodTest.class, true));
116
// private method with right accessor
117
result.add(new TestCase(SingleSubclass.class, SingleSubclass.class,
118
"privateMethod", SingleSubclass.class, true));
119
// package-private method with right accessor
120
result.add(new TestCase(SingleSubclass.class, SingleSubclass.class,
121
"defaultAccessMethod", SingleSubclass.class, true));
122
123
// negative cases
124
125
// private method of another class
126
result.add(new TestCase(SingleSubclass.class, SingleSubclass.class,
127
"privateMethod", ResolveMethodTest.class, false));
128
// package-private method from another package
129
result.add(new TestCase(SingleSubclass.class, SingleSubclass.class,
130
"defaultAccessMethod", ResolveMethodTest.class, false));
131
return result;
132
}
133
134
private void runTest(TestCase tcase) throws NoSuchMethodException {
135
System.out.println(tcase);
136
HotSpotResolvedJavaMethod metaspaceMethod = CTVMUtilities
137
.getResolvedMethod(tcase.holder,
138
tcase.holder.getDeclaredMethod(tcase.methodName));
139
HotSpotResolvedObjectType holderMetaspace = CompilerToVMHelper
140
.lookupTypeHelper(Utils.toJVMTypeSignature(tcase.holder),
141
getClass(), /* resolve = */ true);
142
HotSpotResolvedObjectType callerMetaspace = CompilerToVMHelper
143
.lookupTypeHelper(Utils.toJVMTypeSignature(tcase.caller),
144
getClass(), /* resolve = */ true);
145
HotSpotResolvedObjectType receiverMetaspace = CompilerToVMHelper
146
.lookupTypeHelper(Utils.toJVMTypeSignature(tcase.receiver),
147
getClass(), /* resolve = */ true);
148
149
// Can only resolve methods on a linked class so force initialization
150
receiverMetaspace.initialize();
151
HotSpotResolvedJavaMethod resolvedMetaspaceMethod
152
= CompilerToVMHelper.resolveMethod(receiverMetaspace,
153
metaspaceMethod, callerMetaspace);
154
if (tcase.isPositive) {
155
Asserts.assertNotNull(resolvedMetaspaceMethod,
156
"Unexpected null resolved method value for "
157
+ tcase.methodName);
158
Asserts.assertEQ(metaspaceMethod.getName(), tcase.methodName,
159
"Reflection and c2vm method names doesn't match");
160
} else {
161
Asserts.assertNull(resolvedMetaspaceMethod,
162
"Method unexpectedly resolved");
163
}
164
}
165
166
private static class TestCase {
167
public final Class<?> receiver;
168
public final Class<?> holder;
169
public final Class<?> caller;
170
public final String methodName;
171
public final boolean isPositive;
172
173
public TestCase(Class<?> recv, Class<?> holder, String methodName,
174
Class<?> caller, boolean isPositive) {
175
this.receiver = recv;
176
this.holder = holder;
177
this.caller = caller;
178
this.methodName = methodName;
179
this.isPositive = isPositive;
180
}
181
182
@Override
183
public String toString() {
184
return String.format("CASE: receiver=%s, holder=%s, method=%s,"
185
+ "caller=%s, isPositive=%s%n", receiver.getName(),
186
holder.getName(), methodName, caller.getName(), isPositive);
187
}
188
}
189
}
190
191