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