author | iignatyev |
Fri, 08 Jul 2016 21:26:02 +0300 | |
changeset 40053 | b3617982544e |
parent 40030 | 274935bc5150 |
child 40059 | c2304140ed64 |
permissions | -rw-r--r-- |
33160 | 1 |
/* |
2 |
* Copyright (c) 2015, 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 |
|
39291
a4efe145313d
8157831: JVMCI tests should not be executed on linux-arm32
lmesnik
parents:
39260
diff
changeset
|
27 |
* @requires (vm.simpleArch == "x64" | vm.simpleArch == "sparcv9" | vm.simpleArch == "aarch64") |
33730
30e064828045
8140189: [TESTBUG] Get rid of "@library /../../test/lib" in jtreg tests
cjplummer
parents:
33160
diff
changeset
|
28 |
* @library / /testlibrary /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 |
36508 | 31 |
* @modules jdk.vm.ci/jdk.vm.ci.hotspot |
32 |
* jdk.vm.ci/jdk.vm.ci.meta |
|
40053
b3617982544e
8160657: Compiler HotSpot tests should use the "run driver" directive where applicable
iignatyev
parents:
40030
diff
changeset
|
33 |
* |
b3617982544e
8160657: Compiler HotSpot tests should use the "run driver" directive where applicable
iignatyev
parents:
40030
diff
changeset
|
34 |
* @ignore 8158860 |
36508 | 35 |
* @build jdk.vm.ci/jdk.vm.ci.hotspot.CompilerToVMHelper |
36 |
* jdk.vm.ci/jdk.vm.ci.hotspot.PublicMetaspaceWrapperObject |
|
33160 | 37 |
* @build compiler.jvmci.compilerToVM.GetResolvedJavaTypeTest |
36508 | 38 |
* @build sun.hotspot.WhiteBox |
40053
b3617982544e
8160657: Compiler HotSpot tests should use the "run driver" directive where applicable
iignatyev
parents:
40030
diff
changeset
|
39 |
* @run driver ClassFileInstaller sun.hotspot.WhiteBox |
b3617982544e
8160657: Compiler HotSpot tests should use the "run driver" directive where applicable
iignatyev
parents:
40030
diff
changeset
|
40 |
* sun.hotspot.WhiteBox$WhiteBoxPermission |
36508 | 41 |
* @run main/othervm -Xbootclasspath/a:. |
42 |
* -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI |
|
43 |
* -XX:+UnlockExperimentalVMOptions -XX:+EnableJVMCI |
|
44 |
* -XX:+UseCompressedOops |
|
45 |
* compiler.jvmci.compilerToVM.GetResolvedJavaTypeTest |
|
46 |
* @run main/othervm -Xbootclasspath/a:. |
|
47 |
* -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI |
|
48 |
* -XX:+UnlockExperimentalVMOptions -XX:+EnableJVMCI |
|
49 |
* -XX:-UseCompressedOops |
|
50 |
* compiler.jvmci.compilerToVM.GetResolvedJavaTypeTest |
|
33160 | 51 |
*/ |
52 |
||
53 |
package compiler.jvmci.compilerToVM; |
|
54 |
||
55 |
import java.lang.reflect.Field; |
|
33632 | 56 |
import jdk.vm.ci.meta.ConstantPool; |
33160 | 57 |
import jdk.vm.ci.hotspot.CompilerToVMHelper; |
33632 | 58 |
import jdk.vm.ci.hotspot.HotSpotResolvedJavaMethod; |
59 |
import jdk.vm.ci.hotspot.HotSpotResolvedObjectType; |
|
60 |
import jdk.vm.ci.hotspot.PublicMetaspaceWrapperObject; |
|
33160 | 61 |
import jdk.test.lib.Asserts; |
62 |
import jdk.test.lib.Utils; |
|
63 |
import sun.hotspot.WhiteBox; |
|
38152
80e5da81fb2c
8154258: [TESTBUG] Various serviceability tests fail compilation
dsamersoff
parents:
36508
diff
changeset
|
64 |
import jdk.internal.misc.Unsafe; |
33160 | 65 |
|
66 |
public class GetResolvedJavaTypeTest { |
|
67 |
private static enum TestCase { |
|
68 |
NULL_BASE { |
|
69 |
@Override |
|
33632 | 70 |
HotSpotResolvedObjectType getResolvedJavaType() { |
33160 | 71 |
return CompilerToVMHelper.getResolvedJavaType( |
72 |
null, getPtrToKlass(), COMPRESSED); |
|
73 |
} |
|
74 |
}, |
|
75 |
JAVA_METHOD_BASE { |
|
76 |
@Override |
|
33632 | 77 |
HotSpotResolvedObjectType getResolvedJavaType() { |
78 |
HotSpotResolvedJavaMethod methodInstance |
|
33160 | 79 |
= CompilerToVMHelper.getResolvedJavaMethodAtSlot( |
80 |
TEST_CLASS, 0); |
|
81 |
Field field; |
|
82 |
try { |
|
33632 | 83 |
// jdk.vm.ci.hotspot.HotSpotResolvedJavaMethodImpl.metaspaceMethod |
84 |
field = methodInstance.getClass() |
|
85 |
.getDeclaredField("metaspaceMethod"); |
|
33160 | 86 |
field.setAccessible(true); |
87 |
field.set(methodInstance, getPtrToKlass()); |
|
88 |
} catch (ReflectiveOperationException e) { |
|
89 |
throw new Error("TEST BUG : " + e, e); |
|
90 |
} |
|
91 |
||
92 |
return CompilerToVMHelper.getResolvedJavaType(methodInstance, |
|
93 |
0L, COMPRESSED); |
|
94 |
} |
|
95 |
}, |
|
96 |
CONSTANT_POOL_BASE { |
|
97 |
@Override |
|
33632 | 98 |
HotSpotResolvedObjectType getResolvedJavaType() { |
99 |
ConstantPool cpInst; |
|
33160 | 100 |
try { |
101 |
cpInst = CompilerToVMHelper.getConstantPool(null, |
|
102 |
getPtrToKlass()); |
|
33632 | 103 |
// jdk.vm.ci.hotspot.HotSpotConstantPool.metaspaceConstantPool |
104 |
Field field = cpInst.getClass() |
|
33160 | 105 |
.getDeclaredField("metaspaceConstantPool"); |
106 |
field.setAccessible(true); |
|
107 |
field.set(cpInst, getPtrToKlass()); |
|
108 |
} catch (ReflectiveOperationException e) { |
|
33632 | 109 |
throw new Error("TESTBUG : " + e, e); |
33160 | 110 |
} |
111 |
return CompilerToVMHelper.getResolvedJavaType(cpInst, |
|
112 |
0L, COMPRESSED); |
|
113 |
} |
|
114 |
}, |
|
115 |
CONSTANT_POOL_BASE_IN_TWO { |
|
116 |
@Override |
|
33632 | 117 |
HotSpotResolvedObjectType getResolvedJavaType() { |
33160 | 118 |
long ptr = getPtrToKlass(); |
33632 | 119 |
ConstantPool cpInst = HotSpotResolvedObjectType |
120 |
.fromObjectClass(TEST_CLASS) |
|
121 |
.getConstantPool(); |
|
33160 | 122 |
try { |
33632 | 123 |
Field field = cpInst.getClass() |
33160 | 124 |
.getDeclaredField("metaspaceConstantPool"); |
125 |
field.setAccessible(true); |
|
126 |
field.set(cpInst, ptr / 2L); |
|
127 |
} catch (ReflectiveOperationException e) { |
|
33632 | 128 |
throw new Error("TESTBUG : " + e, e); |
33160 | 129 |
} |
130 |
return CompilerToVMHelper.getResolvedJavaType(cpInst, |
|
131 |
ptr - ptr / 2L, COMPRESSED); |
|
132 |
} |
|
133 |
}, |
|
134 |
CONSTANT_POOL_BASE_ZERO { |
|
135 |
@Override |
|
33632 | 136 |
HotSpotResolvedObjectType getResolvedJavaType() { |
33160 | 137 |
long ptr = getPtrToKlass(); |
33632 | 138 |
ConstantPool cpInst = HotSpotResolvedObjectType |
139 |
.fromObjectClass(TEST_CLASS) |
|
140 |
.getConstantPool(); |
|
33160 | 141 |
try { |
33632 | 142 |
Field field = cpInst.getClass() |
33160 | 143 |
.getDeclaredField("metaspaceConstantPool"); |
144 |
field.setAccessible(true); |
|
145 |
field.set(cpInst, 0L); |
|
146 |
} catch (ReflectiveOperationException e) { |
|
33632 | 147 |
throw new Error("TESTBUG : " + e, e); |
33160 | 148 |
} |
149 |
return CompilerToVMHelper.getResolvedJavaType(cpInst, |
|
150 |
ptr, COMPRESSED); |
|
151 |
} |
|
152 |
}, |
|
153 |
; |
|
33632 | 154 |
abstract HotSpotResolvedObjectType getResolvedJavaType(); |
33160 | 155 |
} |
156 |
||
157 |
private static final Unsafe UNSAFE = Utils.getUnsafe(); |
|
158 |
private static final WhiteBox WB = WhiteBox.getWhiteBox(); |
|
159 |
private static final Class TEST_CLASS = GetResolvedJavaTypeTest.class; |
|
160 |
/* a compressed parameter for tested method is set to false because |
|
161 |
unsafe.getKlassPointer always returns uncompressed pointer */ |
|
162 |
private static final boolean COMPRESSED = false; |
|
163 |
// = WB.getBooleanVMFlag("UseCompressedClassPointers"); |
|
164 |
||
165 |
private static long getPtrToKlass() { |
|
166 |
Field field; |
|
167 |
try { |
|
168 |
field = TEST_CLASS.getDeclaredField("PTR"); |
|
169 |
} catch (NoSuchFieldException e) { |
|
170 |
throw new Error("TEST BUG : " + e, e); |
|
171 |
} |
|
172 |
Object base = UNSAFE.staticFieldBase(field); |
|
173 |
return WB.getObjectAddress(base) + UNSAFE.staticFieldOffset(field); |
|
174 |
} |
|
175 |
||
176 |
public void test(TestCase testCase) { |
|
177 |
System.out.println(testCase.name()); |
|
33632 | 178 |
HotSpotResolvedObjectType type = testCase.getResolvedJavaType(); |
179 |
Asserts.assertEQ(TEST_CLASS, |
|
180 |
CompilerToVMHelper.getMirror(type), |
|
181 |
testCase + " : unexpected class returned"); |
|
33160 | 182 |
} |
183 |
||
184 |
public static void main(String[] args) { |
|
185 |
GetResolvedJavaTypeTest test = new GetResolvedJavaTypeTest(); |
|
186 |
for (TestCase testCase : TestCase.values()) { |
|
187 |
test.test(testCase); |
|
188 |
} |
|
189 |
testObjectBase(); |
|
190 |
testMetaspaceWrapperBase(); |
|
191 |
} |
|
192 |
||
193 |
private static void testMetaspaceWrapperBase() { |
|
194 |
try { |
|
33632 | 195 |
HotSpotResolvedObjectType type |
33160 | 196 |
= CompilerToVMHelper.getResolvedJavaType( |
33632 | 197 |
new PublicMetaspaceWrapperObject() { |
33160 | 198 |
@Override |
199 |
public long getMetaspacePointer() { |
|
200 |
return getPtrToKlass(); |
|
201 |
} |
|
202 |
}, 0L, COMPRESSED); |
|
203 |
throw new AssertionError("Test METASPACE_WRAPPER_BASE." |
|
204 |
+ " Expected IllegalArgumentException has not been caught"); |
|
205 |
} catch (IllegalArgumentException iae) { |
|
206 |
// expected |
|
207 |
} |
|
208 |
} |
|
209 |
||
210 |
private static void testObjectBase() { |
|
211 |
try { |
|
33632 | 212 |
HotSpotResolvedObjectType type |
33160 | 213 |
= CompilerToVMHelper.getResolvedJavaType(new Object(), 0L, |
214 |
COMPRESSED); |
|
215 |
throw new AssertionError("Test OBJECT_BASE." |
|
216 |
+ " Expected IllegalArgumentException has not been caught"); |
|
217 |
} catch (IllegalArgumentException iae) { |
|
218 |
// expected |
|
219 |
} |
|
220 |
} |
|
221 |
} |