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 |
/* |
54669
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
47216
diff
changeset
|
2 |
* Copyright (c) 2015, 2019, 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:
41330
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 |
54669
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
47216
diff
changeset
|
30 |
* @ignore Not supported JVMCI API |
42307
cefc81dc1d52
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41330
diff
changeset
|
31 |
* @modules java.base/jdk.internal.misc:+open |
43972 | 32 |
* @modules jdk.internal.vm.ci/jdk.vm.ci.hotspot:+open |
40053
b3617982544e
8160657: Compiler HotSpot tests should use the "run driver" directive where applicable
iignatyev
parents:
39291
diff
changeset
|
33 |
* |
43972 | 34 |
* @build jdk.internal.vm.ci/jdk.vm.ci.hotspot.CompilerToVMHelper |
35 |
* jdk.internal.vm.ci/jdk.vm.ci.hotspot.PublicMetaspaceWrapperObject |
|
40631
ed82623d7831
8157957: ClassNotFoundException: jdk.test.lib.JDKToolFinder
ctornqvi
parents:
40059
diff
changeset
|
36 |
* sun.hotspot.WhiteBox |
40053
b3617982544e
8160657: Compiler HotSpot tests should use the "run driver" directive where applicable
iignatyev
parents:
39291
diff
changeset
|
37 |
* @run driver ClassFileInstaller sun.hotspot.WhiteBox |
b3617982544e
8160657: Compiler HotSpot tests should use the "run driver" directive where applicable
iignatyev
parents:
39291
diff
changeset
|
38 |
* sun.hotspot.WhiteBox$WhiteBoxPermission |
36508 | 39 |
* @run main/othervm -Xbootclasspath/a:. |
40 |
* -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI |
|
41 |
* -XX:+UnlockExperimentalVMOptions -XX:+EnableJVMCI |
|
44836 | 42 |
* -Djvmci.Compiler=null |
36508 | 43 |
* compiler.jvmci.compilerToVM.GetResolvedJavaMethodTest |
33160 | 44 |
*/ |
45 |
||
46 |
package compiler.jvmci.compilerToVM; |
|
47 |
||
40059 | 48 |
import jdk.internal.misc.Unsafe; |
49 |
import jdk.test.lib.Asserts; |
|
33160 | 50 |
import jdk.vm.ci.hotspot.CompilerToVMHelper; |
33632 | 51 |
import jdk.vm.ci.hotspot.HotSpotResolvedJavaMethod; |
52 |
import jdk.vm.ci.hotspot.PublicMetaspaceWrapperObject; |
|
33160 | 53 |
import sun.hotspot.WhiteBox; |
54 |
||
55 |
import java.lang.reflect.Field; |
|
41325 | 56 |
import java.lang.reflect.Method; |
33160 | 57 |
|
58 |
public class GetResolvedJavaMethodTest { |
|
59 |
private static enum TestCase { |
|
60 |
NULL_BASE { |
|
61 |
@Override |
|
33632 | 62 |
HotSpotResolvedJavaMethod getResolvedJavaMethod() { |
33160 | 63 |
return CompilerToVMHelper.getResolvedJavaMethod( |
64 |
null, getPtrToMethod()); |
|
65 |
} |
|
66 |
}, |
|
67 |
JAVA_METHOD_BASE { |
|
68 |
@Override |
|
33632 | 69 |
HotSpotResolvedJavaMethod getResolvedJavaMethod() { |
41325 | 70 |
HotSpotResolvedJavaMethod methodInstance = TEST_METHOD; |
33160 | 71 |
try { |
33632 | 72 |
METASPACE_METHOD_FIELD.set(methodInstance, |
73 |
getPtrToMethod()); |
|
33160 | 74 |
} catch (ReflectiveOperationException e) { |
75 |
throw new Error("TEST BUG : " + e, e); |
|
76 |
} |
|
77 |
return CompilerToVMHelper.getResolvedJavaMethod( |
|
78 |
methodInstance, 0L); |
|
79 |
} |
|
80 |
}, |
|
81 |
JAVA_METHOD_BASE_IN_TWO { |
|
82 |
@Override |
|
33632 | 83 |
HotSpotResolvedJavaMethod getResolvedJavaMethod() { |
33160 | 84 |
long ptr = getPtrToMethod(); |
41325 | 85 |
HotSpotResolvedJavaMethod methodInstance = TEST_METHOD; |
33160 | 86 |
try { |
33632 | 87 |
METASPACE_METHOD_FIELD.set(methodInstance, ptr / 2L); |
33160 | 88 |
} catch (ReflectiveOperationException e) { |
33632 | 89 |
throw new Error("TESTBUG : " + e, e); |
33160 | 90 |
} |
91 |
return CompilerToVMHelper.getResolvedJavaMethod(methodInstance, |
|
92 |
ptr - ptr / 2L); |
|
93 |
} |
|
94 |
}, |
|
95 |
JAVA_METHOD_BASE_ZERO { |
|
96 |
@Override |
|
33632 | 97 |
HotSpotResolvedJavaMethod getResolvedJavaMethod() { |
33160 | 98 |
long ptr = getPtrToMethod(); |
41325 | 99 |
HotSpotResolvedJavaMethod methodInstance = TEST_METHOD; |
33160 | 100 |
try { |
33632 | 101 |
METASPACE_METHOD_FIELD.set(methodInstance, 0L); |
33160 | 102 |
} catch (ReflectiveOperationException e) { |
33632 | 103 |
throw new Error("TESTBUG : " + e, e); |
33160 | 104 |
} |
105 |
return CompilerToVMHelper.getResolvedJavaMethod(methodInstance, |
|
106 |
ptr); |
|
107 |
} |
|
108 |
} |
|
109 |
; |
|
33632 | 110 |
abstract HotSpotResolvedJavaMethod getResolvedJavaMethod(); |
33160 | 111 |
} |
112 |
||
41092
c388d897472d
8165889: Remove jdk.test.lib.unsafe.UnsafeHelper
gtriantafill
parents:
40855
diff
changeset
|
113 |
private static final Unsafe UNSAFE = Unsafe.getUnsafe(); |
33160 | 114 |
private static final WhiteBox WB = WhiteBox.getWhiteBox(); |
33632 | 115 |
private static final Field METASPACE_METHOD_FIELD; |
33160 | 116 |
private static final Class<?> TEST_CLASS = GetResolvedJavaMethodTest.class; |
41325 | 117 |
private static final HotSpotResolvedJavaMethod TEST_METHOD; |
33160 | 118 |
private static final long PTR; |
119 |
static { |
|
41325 | 120 |
try { |
121 |
Method method = TEST_CLASS.getDeclaredMethod("test", TestCase.class); |
|
122 |
TEST_METHOD = CompilerToVMHelper.asResolvedJavaMethod(method); |
|
123 |
} catch (NoSuchMethodException e) { |
|
124 |
throw new Error("TESTBUG : " + e, e); |
|
125 |
} |
|
33632 | 126 |
try { |
127 |
// jdk.vm.ci.hotspot.HotSpotResolvedJavaMethodImpl.metaspaceMethod |
|
41325 | 128 |
METASPACE_METHOD_FIELD = TEST_METHOD.getClass() |
33632 | 129 |
.getDeclaredField("metaspaceMethod"); |
130 |
METASPACE_METHOD_FIELD.setAccessible(true); |
|
41325 | 131 |
PTR = (long) METASPACE_METHOD_FIELD.get(TEST_METHOD); |
33632 | 132 |
} catch (ReflectiveOperationException e) { |
133 |
throw new Error("TESTBUG : " + e, e); |
|
134 |
} |
|
135 |
||
33160 | 136 |
} |
137 |
||
138 |
private static long getPtrToMethod() { |
|
139 |
Field field; |
|
140 |
try { |
|
141 |
field = TEST_CLASS.getDeclaredField("PTR"); |
|
142 |
} catch (NoSuchFieldException e) { |
|
143 |
throw new Error("TEST BUG : " + e, e); |
|
144 |
} |
|
145 |
Object base = UNSAFE.staticFieldBase(field); |
|
146 |
return WB.getObjectAddress(base) + UNSAFE.staticFieldOffset(field); |
|
147 |
} |
|
148 |
||
149 |
public void test(TestCase testCase) { |
|
150 |
System.out.println(testCase.name()); |
|
33632 | 151 |
HotSpotResolvedJavaMethod result = testCase.getResolvedJavaMethod(); |
33160 | 152 |
Asserts.assertNotNull(result, testCase + " : got null"); |
33632 | 153 |
Asserts.assertEQ(TEST_CLASS, |
154 |
CompilerToVMHelper.getMirror(result.getDeclaringClass()), |
|
155 |
testCase + " : unexpected declaring class"); |
|
33160 | 156 |
} |
157 |
||
158 |
public static void main(String[] args) { |
|
159 |
GetResolvedJavaMethodTest test = new GetResolvedJavaMethodTest(); |
|
160 |
for (TestCase testCase : TestCase.values()) { |
|
161 |
test.test(testCase); |
|
162 |
} |
|
163 |
testObjectBase(); |
|
164 |
testMetaspaceWrapperBase(); |
|
165 |
} |
|
166 |
||
167 |
private static void testMetaspaceWrapperBase() { |
|
168 |
try { |
|
33632 | 169 |
HotSpotResolvedJavaMethod method |
33160 | 170 |
= CompilerToVMHelper.getResolvedJavaMethod( |
33632 | 171 |
new PublicMetaspaceWrapperObject() { |
33160 | 172 |
@Override |
173 |
public long getMetaspacePointer() { |
|
174 |
return getPtrToMethod(); |
|
175 |
} |
|
176 |
}, 0L); |
|
177 |
throw new AssertionError("Test METASPACE_WRAPPER_BASE." |
|
178 |
+ " Expected IllegalArgumentException has not been caught"); |
|
33632 | 179 |
} catch (IllegalArgumentException e) { |
33160 | 180 |
// expected |
181 |
} |
|
182 |
} |
|
183 |
||
184 |
private static void testObjectBase() { |
|
185 |
try { |
|
33632 | 186 |
HotSpotResolvedJavaMethod method |
33160 | 187 |
= CompilerToVMHelper.getResolvedJavaMethod(new Object(), 0L); |
188 |
throw new AssertionError("Test OBJECT_BASE." |
|
189 |
+ " Expected IllegalArgumentException has not been caught"); |
|
33632 | 190 |
} catch (IllegalArgumentException e) { |
33160 | 191 |
// expected |
192 |
} |
|
193 |
} |
|
194 |
} |