author | dnsimon |
Fri, 22 Dec 2017 18:34:36 +0100 | |
changeset 48480 | 614068b0ddd7 |
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:
40631
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:
36508
diff
changeset
|
30 |
* @modules java.base/jdk.internal.misc |
43972 | 31 |
* @modules jdk.internal.vm.ci/jdk.vm.ci.hotspot |
32 |
* @build jdk.internal.vm.ci/jdk.vm.ci.hotspot.CompilerToVMHelper |
|
36508 | 33 |
* @run main/othervm -XX:+UnlockExperimentalVMOptions -XX:+EnableJVMCI |
44836 | 34 |
* -Djvmci.Compiler=null |
36508 | 35 |
* compiler.jvmci.compilerToVM.GetImplementorTest |
33160 | 36 |
*/ |
37 |
||
38 |
package compiler.jvmci.compilerToVM; |
|
39 |
||
40 |
import compiler.jvmci.common.testcases.AbstractClass; |
|
41 |
import compiler.jvmci.common.testcases.AbstractClassExtender; |
|
40059 | 42 |
import compiler.jvmci.common.testcases.DoNotExtendClass; |
33160 | 43 |
import compiler.jvmci.common.testcases.DoNotImplementInterface; |
44 |
import compiler.jvmci.common.testcases.MultipleImplementer1; |
|
45 |
import compiler.jvmci.common.testcases.MultipleImplementer2; |
|
46 |
import compiler.jvmci.common.testcases.MultipleImplementersInterface; |
|
47 |
import compiler.jvmci.common.testcases.SingleImplementer; |
|
48 |
import compiler.jvmci.common.testcases.SingleImplementerInterface; |
|
49 |
import compiler.jvmci.common.testcases.SingleSubclass; |
|
50 |
import compiler.jvmci.common.testcases.SingleSubclassedClass; |
|
40059 | 51 |
import jdk.test.lib.Asserts; |
52 |
import jdk.test.lib.Utils; |
|
53 |
import jdk.vm.ci.hotspot.CompilerToVMHelper; |
|
54 |
import jdk.vm.ci.hotspot.HotSpotResolvedObjectType; |
|
55 |
||
33160 | 56 |
import java.util.HashSet; |
57 |
import java.util.Set; |
|
58 |
import java.util.stream.Stream; |
|
59 |
||
60 |
public class GetImplementorTest { |
|
61 |
public static void main(String args[]) { |
|
62 |
GetImplementorTest test = new GetImplementorTest(); |
|
63 |
for (TestCase tcase : createTestCases()) { |
|
64 |
test.runTest(tcase); |
|
65 |
} |
|
66 |
} |
|
67 |
||
68 |
private static Set<TestCase> createTestCases() { |
|
69 |
Set<TestCase> result = new HashSet<>(); |
|
70 |
Stream.of( |
|
71 |
SingleSubclass.class, |
|
72 |
AbstractClassExtender.class, |
|
73 |
MultipleImplementer2.class, |
|
74 |
MultipleImplementer1.class, |
|
75 |
MultipleImplementersInterface.class, |
|
76 |
DoNotImplementInterface.class, |
|
77 |
DoNotExtendClass.class, |
|
78 |
AbstractClass.class, |
|
79 |
SingleSubclassedClass.class) |
|
80 |
.forEach(Utils::ensureClassIsLoaded); |
|
81 |
// an interface with single class implementing it |
|
82 |
result.add(new TestCase(SingleImplementerInterface.class, |
|
83 |
SingleImplementer.class)); |
|
84 |
/* an interface with multiple implementers. According to getImplementor |
|
85 |
javadoc, an itself should be returned in case of more than one |
|
86 |
implementor |
|
87 |
*/ |
|
88 |
result.add(new TestCase(MultipleImplementersInterface.class, |
|
89 |
MultipleImplementersInterface.class)); |
|
90 |
// an interface with no implementors |
|
91 |
result.add(new TestCase(DoNotImplementInterface.class, null)); |
|
92 |
// an abstract class with extender class |
|
93 |
result.add(new TestCase(AbstractClass.class, null)); |
|
94 |
// a simple class, which is not extended |
|
95 |
result.add(new TestCase(DoNotExtendClass.class, null)); |
|
96 |
// a usual class, which is extended |
|
97 |
result.add(new TestCase(SingleSubclassedClass.class, null)); |
|
98 |
return result; |
|
99 |
} |
|
100 |
||
101 |
private void runTest(TestCase tcase) { |
|
102 |
System.out.println(tcase); |
|
33632 | 103 |
HotSpotResolvedObjectType resolvedIface = CompilerToVMHelper |
46972
3e88de95fccf
8186459: [JVMCI] ClassNotFoundException thrown by CompilerToVM.lookupType() should be converted to a LinkageError
dnsimon
parents:
44836
diff
changeset
|
104 |
.lookupTypeHelper(Utils.toJVMTypeSignature(tcase.anInterface), |
33160 | 105 |
getClass(), /* resolve = */ true); |
48480
614068b0ddd7
8193930: [JVMCI] calling ResolvedTypeType.getClassInitializer on an array type crashes
dnsimon
parents:
47216
diff
changeset
|
106 |
if (!resolvedIface.isInterface()) { |
614068b0ddd7
8193930: [JVMCI] calling ResolvedTypeType.getClassInitializer on an array type crashes
dnsimon
parents:
47216
diff
changeset
|
107 |
try { |
614068b0ddd7
8193930: [JVMCI] calling ResolvedTypeType.getClassInitializer on an array type crashes
dnsimon
parents:
47216
diff
changeset
|
108 |
CompilerToVMHelper.getImplementor(resolvedIface); |
614068b0ddd7
8193930: [JVMCI] calling ResolvedTypeType.getClassInitializer on an array type crashes
dnsimon
parents:
47216
diff
changeset
|
109 |
Asserts.fail("Expected " + IllegalArgumentException.class.getName()); |
614068b0ddd7
8193930: [JVMCI] calling ResolvedTypeType.getClassInitializer on an array type crashes
dnsimon
parents:
47216
diff
changeset
|
110 |
} catch (IllegalArgumentException e) { |
614068b0ddd7
8193930: [JVMCI] calling ResolvedTypeType.getClassInitializer on an array type crashes
dnsimon
parents:
47216
diff
changeset
|
111 |
} |
614068b0ddd7
8193930: [JVMCI] calling ResolvedTypeType.getClassInitializer on an array type crashes
dnsimon
parents:
47216
diff
changeset
|
112 |
return; |
614068b0ddd7
8193930: [JVMCI] calling ResolvedTypeType.getClassInitializer on an array type crashes
dnsimon
parents:
47216
diff
changeset
|
113 |
} |
33632 | 114 |
HotSpotResolvedObjectType resolvedImplementer = CompilerToVMHelper |
33160 | 115 |
.getImplementor(resolvedIface); |
33632 | 116 |
HotSpotResolvedObjectType resolvedExpected = null; |
33160 | 117 |
if (tcase.expectedImplementer != null) { |
46972
3e88de95fccf
8186459: [JVMCI] ClassNotFoundException thrown by CompilerToVM.lookupType() should be converted to a LinkageError
dnsimon
parents:
44836
diff
changeset
|
118 |
resolvedExpected = CompilerToVMHelper.lookupTypeHelper(Utils |
33160 | 119 |
.toJVMTypeSignature(tcase.expectedImplementer), |
120 |
getClass(), /* resolve = */ true); |
|
121 |
} |
|
122 |
Asserts.assertEQ(resolvedImplementer, resolvedExpected, |
|
123 |
"Unexpected implementer for " + tcase.anInterface.getName()); |
|
124 |
} |
|
125 |
||
126 |
private static class TestCase { |
|
127 |
public final Class<?> anInterface; |
|
128 |
public final Class<?> expectedImplementer; |
|
129 |
||
130 |
public TestCase(Class<?> iface, Class<?> expectedImplementer) { |
|
131 |
this.anInterface = iface; |
|
132 |
this.expectedImplementer = expectedImplementer; |
|
133 |
} |
|
134 |
||
135 |
@Override |
|
136 |
public String toString() { |
|
137 |
return String.format("CASE: interface=%s, expected=%s", |
|
138 |
anInterface.getName(), |
|
139 |
expectedImplementer == null |
|
140 |
? null |
|
141 |
: expectedImplementer.getName()); |
|
142 |
} |
|
143 |
} |
|
144 |
} |