author | alanb |
Thu, 01 Dec 2016 08:56:41 +0000 | |
changeset 42307 | cefc81dc1d52 |
parent 40631 | ed82623d7831 |
child 42646 | 591ef3658bb0 |
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 |
|
39291
a4efe145313d
8157831: JVMCI tests should not be executed on linux-arm32
lmesnik
parents:
38152
diff
changeset
|
27 |
* @requires (vm.simpleArch == "x64" | vm.simpleArch == "sparcv9" | vm.simpleArch == "aarch64") |
40631
ed82623d7831
8157957: ClassNotFoundException: jdk.test.lib.JDKToolFinder
ctornqvi
parents:
40059
diff
changeset
|
28 |
* @library / /test/lib |
36508 | 29 |
* @library ../common/patches |
42307
cefc81dc1d52
8169069: Module system implementation refresh (11/2016)
alanb
parents:
40631
diff
changeset
|
30 |
* @modules java.base/jdk.internal.misc:+open |
36508 | 31 |
* @modules java.base/jdk.internal.org.objectweb.asm |
32 |
* java.base/jdk.internal.org.objectweb.asm.tree |
|
42307
cefc81dc1d52
8169069: Module system implementation refresh (11/2016)
alanb
parents:
40631
diff
changeset
|
33 |
* @modules jdk.vm.ci/jdk.vm.ci.hotspot:+open |
36508 | 34 |
* jdk.vm.ci/jdk.vm.ci.code |
35 |
* jdk.vm.ci/jdk.vm.ci.meta |
|
36 |
* @build jdk.vm.ci/jdk.vm.ci.hotspot.CompilerToVMHelper |
|
33160 | 37 |
* @run main/othervm -XX:+UnlockExperimentalVMOptions -XX:+EnableJVMCI |
36508 | 38 |
* compiler.jvmci.compilerToVM.GetSymbolTest |
33160 | 39 |
*/ |
40 |
||
41 |
package compiler.jvmci.compilerToVM; |
|
42 |
||
43 |
import compiler.jvmci.common.CTVMUtilities; |
|
44 |
import compiler.jvmci.common.testcases.SingleImplementer; |
|
40059 | 45 |
import jdk.test.lib.Utils; |
46 |
import jdk.vm.ci.hotspot.CompilerToVMHelper; |
|
47 |
import jdk.vm.ci.hotspot.HotSpotResolvedJavaMethod; |
|
48 |
import jdk.vm.ci.meta.ConstantPool; |
|
49 |
||
33160 | 50 |
import java.lang.reflect.Field; |
51 |
import java.lang.reflect.Member; |
|
52 |
import java.lang.reflect.Method; |
|
53 |
import java.util.ArrayList; |
|
54 |
import java.util.List; |
|
55 |
import java.util.function.Function; |
|
56 |
import java.util.stream.Collectors; |
|
57 |
import java.util.stream.Stream; |
|
58 |
||
59 |
public class GetSymbolTest { |
|
60 |
private static final int CONSTANT_POOL_UTF8_TAG = 1; // see jvms, section 4.4 |
|
61 |
||
62 |
private static final Function<Member[], List<String>> NAMES = members -> |
|
63 |
Stream.of(members) |
|
64 |
.map(Member::getName) |
|
65 |
.collect(Collectors.toList()); |
|
66 |
||
67 |
public static void main(String[] args) { |
|
68 |
new GetSymbolTest().test(SingleImplementer.class); |
|
69 |
} |
|
70 |
||
71 |
private void test(Class<?> aClass) { |
|
72 |
Utils.ensureClassIsLoaded(aClass); |
|
73 |
Method method; |
|
74 |
try { |
|
75 |
method = aClass.getDeclaredMethod("nonInterfaceMethod"); |
|
76 |
} catch (NoSuchMethodException e) { |
|
77 |
throw new Error("TEST BUG: can't find test method", e); |
|
78 |
} |
|
33632 | 79 |
HotSpotResolvedJavaMethod resolvedMethod |
33160 | 80 |
= CTVMUtilities.getResolvedMethod(aClass, method); |
81 |
List<String> symbols; |
|
82 |
try { |
|
83 |
symbols = getSymbols(resolvedMethod); |
|
84 |
} catch (ReflectiveOperationException e) { |
|
85 |
throw new Error("TEST BUG: can't access private members", e); |
|
86 |
} |
|
87 |
List<String> classSymbols = new ArrayList<>(); |
|
88 |
classSymbols.addAll(NAMES.apply(aClass.getDeclaredFields())); |
|
89 |
classSymbols.addAll(NAMES.apply(aClass.getDeclaredMethods())); |
|
90 |
// Check that all members of test class have symbols from constant pool |
|
91 |
for (String s : classSymbols) { |
|
92 |
if (!symbols.contains(s)) { |
|
93 |
// failed. print all symbols found by getSymbol |
|
94 |
System.out.println("getSymbol data:"); |
|
95 |
for (String ctvmValue : symbols) { |
|
96 |
System.out.println(ctvmValue); |
|
97 |
} |
|
98 |
throw new AssertionError("Unable to find symbol " + s |
|
99 |
+ " using CompilerToVM.getSymbol"); |
|
100 |
} |
|
101 |
} |
|
102 |
} |
|
103 |
||
33632 | 104 |
private List<String> getSymbols(HotSpotResolvedJavaMethod |
33160 | 105 |
metaspaceMethod) throws ReflectiveOperationException { |
106 |
List<String> symbols = new ArrayList<>(); |
|
107 |
ConstantPool pool = metaspaceMethod.getConstantPool(); |
|
108 |
long length = pool.length(); |
|
109 |
// jvms-4.1: The constant_pool table is indexed from 1 ... |
|
110 |
for (int i = 1; i < length; i++) { |
|
111 |
if (getTag(pool, i) == CONSTANT_POOL_UTF8_TAG) { |
|
112 |
long entryPointer; |
|
113 |
Method getEntryAt = pool.getClass() |
|
114 |
.getDeclaredMethod("getEntryAt", int.class); |
|
115 |
getEntryAt.setAccessible(true); |
|
116 |
entryPointer = (Long) getEntryAt.invoke(pool, i); |
|
117 |
String symbol = CompilerToVMHelper.getSymbol(entryPointer); |
|
118 |
symbols.add(symbol); |
|
119 |
} |
|
120 |
} |
|
121 |
return symbols; |
|
122 |
} |
|
123 |
||
124 |
private int getTag(ConstantPool pool, int index) |
|
125 |
throws ReflectiveOperationException { |
|
126 |
Object jvmConstant; |
|
127 |
Method getTag = pool.getClass().getDeclaredMethod("getTagAt", |
|
128 |
int.class); |
|
129 |
getTag.setAccessible(true); |
|
130 |
jvmConstant = getTag.invoke(pool, index); |
|
131 |
Field tagCode = jvmConstant.getClass().getDeclaredField("tag"); |
|
132 |
tagCode.setAccessible(true); |
|
133 |
return tagCode.getInt(jvmConstant); |
|
134 |
} |
|
135 |
} |