author | kvn |
Wed, 01 May 2019 12:31:29 -0700 | |
changeset 54669 | ad45b3802d4e |
parent 47216 | 71c04702a3d5 |
child 55206 | 2fe2063fe567 |
permissions | -rw-r--r-- |
33160 | 1 |
/* |
40631
ed82623d7831
8157957: ClassNotFoundException: jdk.test.lib.JDKToolFinder
ctornqvi
parents:
40059
diff
changeset
|
2 |
* Copyright (c) 2015, 2016, Oracle and/or its affiliates. All rights reserved. |
33160 | 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 |
|
42607
acd91f1875d4
8170227: use vm.jvmci property in compiler/jvmci tests
iignatyev
parents:
41092
diff
changeset
|
27 |
* @requires vm.jvmci |
40631
ed82623d7831
8157957: ClassNotFoundException: jdk.test.lib.JDKToolFinder
ctornqvi
parents:
40059
diff
changeset
|
28 |
* @library / /test/lib |
36508 | 29 |
* @library ../common/patches |
38152
80e5da81fb2c
8154258: [TESTBUG] Various serviceability tests fail compilation
dsamersoff
parents:
38139
diff
changeset
|
30 |
* @modules java.base/jdk.internal.misc |
36508 | 31 |
* @modules java.base/jdk.internal.org.objectweb.asm |
32 |
* java.base/jdk.internal.org.objectweb.asm.tree |
|
43972 | 33 |
* jdk.internal.vm.ci/jdk.vm.ci.hotspot |
34 |
* jdk.internal.vm.ci/jdk.vm.ci.code |
|
35 |
* @build jdk.internal.vm.ci/jdk.vm.ci.hotspot.CompilerToVMHelper |
|
36508 | 36 |
* @run main/othervm -XX:+UnlockExperimentalVMOptions -XX:+EnableJVMCI |
44836 | 37 |
* -Djvmci.Compiler=null |
36508 | 38 |
* compiler.jvmci.compilerToVM.ResolveMethodTest |
33160 | 39 |
*/ |
40 |
||
41 |
package compiler.jvmci.compilerToVM; |
|
42 |
||
40059 | 43 |
import compiler.jvmci.common.CTVMUtilities; |
33160 | 44 |
import compiler.jvmci.common.testcases.AbstractClass; |
45 |
import compiler.jvmci.common.testcases.AbstractClassExtender; |
|
46 |
import compiler.jvmci.common.testcases.MultipleImplementer1; |
|
47 |
import compiler.jvmci.common.testcases.MultipleImplementer2; |
|
48 |
import compiler.jvmci.common.testcases.MultipleImplementersInterface; |
|
49 |
import compiler.jvmci.common.testcases.SingleImplementer; |
|
50 |
import compiler.jvmci.common.testcases.SingleImplementerInterface; |
|
51 |
import compiler.jvmci.common.testcases.SingleSubclass; |
|
52 |
import compiler.jvmci.common.testcases.SingleSubclassedClass; |
|
40059 | 53 |
import jdk.internal.misc.Unsafe; |
54 |
import jdk.test.lib.Asserts; |
|
55 |
import jdk.test.lib.Utils; |
|
33160 | 56 |
import jdk.vm.ci.hotspot.CompilerToVMHelper; |
33632 | 57 |
import jdk.vm.ci.hotspot.HotSpotResolvedJavaMethod; |
58 |
import jdk.vm.ci.hotspot.HotSpotResolvedObjectType; |
|
40059 | 59 |
|
60 |
import java.util.HashSet; |
|
61 |
import java.util.Set; |
|
33160 | 62 |
|
63 |
public class ResolveMethodTest { |
|
41092
c388d897472d
8165889: Remove jdk.test.lib.unsafe.UnsafeHelper
gtriantafill
parents:
40855
diff
changeset
|
64 |
private static final Unsafe UNSAFE = Unsafe.getUnsafe(); |
33160 | 65 |
|
66 |
public static void main(String args[]) { |
|
67 |
ResolveMethodTest test = new ResolveMethodTest(); |
|
68 |
// positive cases |
|
69 |
try { |
|
70 |
for (TestCase tcase: createTestCases()) { |
|
71 |
test.runTest(tcase); |
|
72 |
} |
|
73 |
} catch (NoSuchMethodException e) { |
|
74 |
throw new Error("TEST BUG: can't find requested method", e); |
|
75 |
} |
|
76 |
} |
|
77 |
||
78 |
private static Set<TestCase> createTestCases() { |
|
79 |
Set<TestCase> result = new HashSet<>(); |
|
80 |
// a usual class public method |
|
81 |
result.add(new TestCase(SingleSubclass.class, SingleSubclass.class, |
|
82 |
"usualMethod", ResolveMethodTest.class, true)); |
|
83 |
// an array method |
|
84 |
result.add(new TestCase(int[].class, Object.class, "toString", |
|
85 |
ResolveMethodTest.class, true)); |
|
86 |
// a method from base class, which was overriden in tested one |
|
87 |
result.add(new TestCase(SingleSubclass.class, SingleSubclass.class, |
|
88 |
"overridenMethod", ResolveMethodTest.class, true)); |
|
89 |
// a method from base class, which was not overriden in tested one |
|
90 |
result.add(new TestCase(SingleSubclass.class, |
|
91 |
SingleSubclassedClass.class, "inheritedMethod", |
|
92 |
ResolveMethodTest.class, true)); |
|
93 |
/* a method from base class, which was overriden in tested one with |
|
94 |
base class as holder */ |
|
95 |
result.add(new TestCase(SingleSubclass.class, |
|
96 |
SingleSubclassedClass.class, "overridenMethod", |
|
97 |
ResolveMethodTest.class, true)); |
|
98 |
// an interface method |
|
99 |
result.add(new TestCase(SingleImplementer.class, |
|
100 |
SingleImplementerInterface.class, "interfaceMethod", |
|
101 |
ResolveMethodTest.class, true)); |
|
102 |
// an interface default method overriden in implementer |
|
103 |
result.add(new TestCase(MultipleImplementer1.class, |
|
104 |
MultipleImplementersInterface.class, "defaultMethod", |
|
105 |
ResolveMethodTest.class, true)); |
|
106 |
// an interface default method not overriden in implementer |
|
107 |
result.add(new TestCase(MultipleImplementer2.class, |
|
108 |
MultipleImplementersInterface.class, "defaultMethod", |
|
109 |
ResolveMethodTest.class, true)); |
|
110 |
// an abstract method |
|
111 |
result.add(new TestCase(AbstractClassExtender.class, AbstractClass.class, |
|
112 |
"abstractMethod", ResolveMethodTest.class, true)); |
|
113 |
// private method with right accessor |
|
114 |
result.add(new TestCase(SingleSubclass.class, SingleSubclass.class, |
|
115 |
"privateMethod", SingleSubclass.class, true)); |
|
116 |
// package-private method with right accessor |
|
117 |
result.add(new TestCase(SingleSubclass.class, SingleSubclass.class, |
|
118 |
"defaultAccessMethod", SingleSubclass.class, true)); |
|
119 |
||
120 |
// negative cases |
|
121 |
||
122 |
// private method of another class |
|
123 |
result.add(new TestCase(SingleSubclass.class, SingleSubclass.class, |
|
124 |
"privateMethod", ResolveMethodTest.class, false)); |
|
125 |
// package-private method from another package |
|
126 |
result.add(new TestCase(SingleSubclass.class, SingleSubclass.class, |
|
127 |
"defaultAccessMethod", ResolveMethodTest.class, false)); |
|
128 |
return result; |
|
129 |
} |
|
130 |
||
131 |
private void runTest(TestCase tcase) throws NoSuchMethodException { |
|
132 |
System.out.println(tcase); |
|
33632 | 133 |
HotSpotResolvedJavaMethod metaspaceMethod = CTVMUtilities |
33160 | 134 |
.getResolvedMethod(tcase.holder, |
135 |
tcase.holder.getDeclaredMethod(tcase.methodName)); |
|
33632 | 136 |
HotSpotResolvedObjectType holderMetaspace = CompilerToVMHelper |
46972
3e88de95fccf
8186459: [JVMCI] ClassNotFoundException thrown by CompilerToVM.lookupType() should be converted to a LinkageError
dnsimon
parents:
44836
diff
changeset
|
137 |
.lookupTypeHelper(Utils.toJVMTypeSignature(tcase.holder), |
33160 | 138 |
getClass(), /* resolve = */ true); |
33632 | 139 |
HotSpotResolvedObjectType callerMetaspace = CompilerToVMHelper |
46972
3e88de95fccf
8186459: [JVMCI] ClassNotFoundException thrown by CompilerToVM.lookupType() should be converted to a LinkageError
dnsimon
parents:
44836
diff
changeset
|
140 |
.lookupTypeHelper(Utils.toJVMTypeSignature(tcase.caller), |
33160 | 141 |
getClass(), /* resolve = */ true); |
38139
cf6f5c1b7205
8152903: [JVMCI] CompilerToVM::resolveMethod should correctly handle private methods in interfaces
never
parents:
36508
diff
changeset
|
142 |
HotSpotResolvedObjectType receiverMetaspace = CompilerToVMHelper |
46972
3e88de95fccf
8186459: [JVMCI] ClassNotFoundException thrown by CompilerToVM.lookupType() should be converted to a LinkageError
dnsimon
parents:
44836
diff
changeset
|
143 |
.lookupTypeHelper(Utils.toJVMTypeSignature(tcase.receiver), |
38139
cf6f5c1b7205
8152903: [JVMCI] CompilerToVM::resolveMethod should correctly handle private methods in interfaces
never
parents:
36508
diff
changeset
|
144 |
getClass(), /* resolve = */ true); |
cf6f5c1b7205
8152903: [JVMCI] CompilerToVM::resolveMethod should correctly handle private methods in interfaces
never
parents:
36508
diff
changeset
|
145 |
|
cf6f5c1b7205
8152903: [JVMCI] CompilerToVM::resolveMethod should correctly handle private methods in interfaces
never
parents:
36508
diff
changeset
|
146 |
// Can only resolve methods on a linked class so force initialization |
cf6f5c1b7205
8152903: [JVMCI] CompilerToVM::resolveMethod should correctly handle private methods in interfaces
never
parents:
36508
diff
changeset
|
147 |
receiverMetaspace.initialize(); |
33632 | 148 |
HotSpotResolvedJavaMethod resolvedMetaspaceMethod |
38139
cf6f5c1b7205
8152903: [JVMCI] CompilerToVM::resolveMethod should correctly handle private methods in interfaces
never
parents:
36508
diff
changeset
|
149 |
= CompilerToVMHelper.resolveMethod(receiverMetaspace, |
33160 | 150 |
metaspaceMethod, callerMetaspace); |
151 |
if (tcase.isPositive) { |
|
152 |
Asserts.assertNotNull(resolvedMetaspaceMethod, |
|
153 |
"Unexpected null resolved method value for " |
|
154 |
+ tcase.methodName); |
|
155 |
Asserts.assertEQ(metaspaceMethod.getName(), tcase.methodName, |
|
156 |
"Reflection and c2vm method names doesn't match"); |
|
157 |
} else { |
|
158 |
Asserts.assertNull(resolvedMetaspaceMethod, |
|
159 |
"Method unexpectedly resolved"); |
|
160 |
} |
|
161 |
} |
|
162 |
||
163 |
private static class TestCase { |
|
164 |
public final Class<?> receiver; |
|
165 |
public final Class<?> holder; |
|
166 |
public final Class<?> caller; |
|
167 |
public final String methodName; |
|
168 |
public final boolean isPositive; |
|
169 |
||
170 |
public TestCase(Class<?> recv, Class<?> holder, String methodName, |
|
171 |
Class<?> caller, boolean isPositive) { |
|
172 |
this.receiver = recv; |
|
173 |
this.holder = holder; |
|
174 |
this.caller = caller; |
|
175 |
this.methodName = methodName; |
|
176 |
this.isPositive = isPositive; |
|
177 |
} |
|
178 |
||
179 |
@Override |
|
180 |
public String toString() { |
|
181 |
return String.format("CASE: receiver=%s, holder=%s, method=%s," |
|
182 |
+ "caller=%s, isPositive=%s%n", receiver.getName(), |
|
183 |
holder.getName(), methodName, caller.getName(), isPositive); |
|
184 |
} |
|
185 |
} |
|
186 |
} |