Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/hotspot/jtreg/compiler/jvmci/compilerToVM/GetVtableIndexForInterfaceTest.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.GetVtableIndexForInterfaceTest
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.AnotherSingleImplementer;
49
import compiler.jvmci.common.testcases.AnotherSingleImplementerInterface;
50
import compiler.jvmci.common.testcases.DoNotExtendClass;
51
import compiler.jvmci.common.testcases.MultipleAbstractImplementer;
52
import compiler.jvmci.common.testcases.MultipleImplementersInterface;
53
import compiler.jvmci.common.testcases.MultipleImplementersInterfaceExtender;
54
import compiler.jvmci.common.testcases.SingleImplementer;
55
import compiler.jvmci.common.testcases.SingleImplementerInterface;
56
import compiler.jvmci.common.testcases.SingleSubclass;
57
import compiler.jvmci.common.testcases.SingleSubclassedClass;
58
import jdk.test.lib.Asserts;
59
import jdk.test.lib.Utils;
60
import jdk.vm.ci.hotspot.CompilerToVMHelper;
61
import jdk.vm.ci.hotspot.HotSpotResolvedJavaMethod;
62
import jdk.vm.ci.hotspot.HotSpotResolvedObjectType;
63
64
import java.lang.reflect.Method;
65
import java.util.HashSet;
66
import java.util.Set;
67
import java.util.stream.Stream;
68
69
public class GetVtableIndexForInterfaceTest {
70
private static final int INVALID_VTABLE_INDEX = -4; // see method.hpp: VtableIndexFlag
71
72
public static void main(String args[]) {
73
GetVtableIndexForInterfaceTest test
74
= new GetVtableIndexForInterfaceTest();
75
try {
76
for (TestCase tcase : createTestCases()) {
77
test.runTest(tcase);
78
}
79
} catch (NoSuchMethodException e) {
80
throw new Error("TEST BUG: can't find requested method", e);
81
}
82
}
83
84
private static Set<TestCase> createTestCases() {
85
Set<TestCase> result = new HashSet<>();
86
Stream.of(
87
AbstractClass.class,
88
SingleImplementer.class,
89
SingleImplementerInterface.class,
90
MultipleImplementersInterface.class,
91
MultipleImplementersInterfaceExtender.class,
92
SingleSubclass.class,
93
SingleSubclassedClass.class,
94
DoNotExtendClass.class,
95
MultipleAbstractImplementer.class
96
)
97
.forEach(Utils::ensureClassIsLoaded);
98
// non iface method
99
result.add(new TestCase(SingleImplementer.class,
100
SingleImplementer.class, "nonInterfaceMethod",
101
false, InternalError.class));
102
// iface method w/o default implementation
103
result.add(new TestCase(SingleImplementer.class,
104
SingleImplementerInterface.class, "interfaceMethod", false));
105
/* another iface which provides default implementation for the
106
original iface*/
107
result.add(new TestCase(MultipleImplementersInterfaceExtender.class,
108
MultipleImplementersInterface.class, "testMethod", false,
109
InternalError.class));
110
// iface method w/ default implementation
111
result.add(new TestCase(SingleImplementer.class,
112
SingleImplementerInterface.class, "defaultMethod", true));
113
// non iface class
114
result.add(new TestCase(SingleSubclass.class,
115
SingleSubclassedClass.class, "inheritedMethod", false,
116
InternalError.class));
117
// class not implementing iface
118
result.add(new TestCase(DoNotExtendClass.class,
119
SingleImplementerInterface.class, "defaultMethod", false,
120
InternalError.class));
121
// abstract class which doesn't implement iface
122
result.add(new TestCase(AbstractClass.class,
123
SingleImplementerInterface.class, "defaultMethod", false,
124
InternalError.class));
125
// abstract class which implements iface
126
result.add(new TestCase(MultipleAbstractImplementer.class,
127
MultipleImplementersInterface.class, "defaultMethod", true));
128
// class not initialized
129
result.add(new TestCase(AnotherSingleImplementer.class,
130
AnotherSingleImplementerInterface.class, "defaultMethod", false,
131
InternalError.class));
132
return result;
133
}
134
135
private void runTest(TestCase tcase) throws NoSuchMethodException {
136
System.out.println(tcase);
137
Method method = tcase.holder.getDeclaredMethod(tcase.methodName);
138
HotSpotResolvedObjectType metaspaceKlass = CompilerToVMHelper
139
.lookupTypeHelper(Utils.toJVMTypeSignature(tcase.receiver),
140
getClass(), /* resolve = */ true);
141
HotSpotResolvedJavaMethod metaspaceMethod = CTVMUtilities
142
.getResolvedMethod(tcase.holder, method);
143
int index = 0;
144
try {
145
index = CompilerToVMHelper
146
.getVtableIndexForInterfaceMethod(metaspaceKlass,
147
metaspaceMethod);
148
} catch (Throwable t) {
149
if (tcase.isPositive || tcase.expectedException == null) {
150
throw new Error("Caught unexpected exception " + t);
151
}
152
if (!tcase.expectedException.equals(t.getClass())) {
153
throw new Error(String.format("Caught %s while expected %s",
154
t.getClass().getName(),
155
tcase.expectedException.getName()));
156
}
157
return;
158
}
159
if (tcase.expectedException != null) {
160
throw new AssertionError("Expected exception wasn't caught: "
161
+ tcase.expectedException.getName());
162
}
163
if (tcase.isPositive) {
164
Asserts.assertNE(index, INVALID_VTABLE_INDEX,
165
"Unexpected: got invalid index");
166
} else {
167
Asserts.assertEQ(index, INVALID_VTABLE_INDEX,
168
"Unexpected: got valid index ");
169
}
170
}
171
172
private static class TestCase {
173
public final Class<?> receiver;
174
public final Class<?> holder;
175
public final String methodName;
176
public final boolean isPositive;
177
public final Class<? extends Throwable> expectedException;
178
179
public TestCase(Class<?> receiver, Class<?> holder, String methodName,
180
boolean isPositive,
181
Class<? extends Throwable> expectedException) {
182
this.receiver = receiver;
183
this.holder = holder;
184
this.methodName = methodName;
185
this.isPositive = isPositive;
186
this.expectedException = expectedException;
187
}
188
189
public TestCase(Class<?> receiver, Class<?> holder, String methodName,
190
boolean isPositive) {
191
this(receiver, holder, methodName, isPositive, null);
192
}
193
194
@Override
195
public String toString() {
196
return String.format("CASE: receiver=%s, holder=%s, method=%s,"
197
+ " isPositive=%s%n", receiver.getName(), holder.getName(),
198
methodName, isPositive);
199
}
200
}
201
}
202
203