author | lmesnik |
Fri, 17 Jun 2016 13:07:27 +0300 | |
changeset 39291 | a4efe145313d |
parent 38152 | 80e5da81fb2c |
child 40053 | b3617982544e |
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:
38152
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 |
* @build jdk.vm.ci/jdk.vm.ci.hotspot.CompilerToVMHelper |
|
33 |
* jdk.vm.ci/jdk.vm.ci.hotspot.PublicMetaspaceWrapperObject |
|
33160 | 34 |
* @build compiler.jvmci.compilerToVM.GetResolvedJavaMethodTest |
35 |
* @run main ClassFileInstaller |
|
36 |
* sun.hotspot.WhiteBox |
|
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 |
||
46 |
import jdk.vm.ci.hotspot.CompilerToVMHelper; |
|
33632 | 47 |
import jdk.vm.ci.hotspot.HotSpotResolvedJavaMethod; |
48 |
import jdk.vm.ci.hotspot.PublicMetaspaceWrapperObject; |
|
33160 | 49 |
import jdk.test.lib.Asserts; |
50 |
import jdk.test.lib.Utils; |
|
51 |
import sun.hotspot.WhiteBox; |
|
38152
80e5da81fb2c
8154258: [TESTBUG] Various serviceability tests fail compilation
dsamersoff
parents:
36508
diff
changeset
|
52 |
import jdk.internal.misc.Unsafe; |
33160 | 53 |
|
54 |
import java.lang.reflect.Field; |
|
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() { |
68 |
HotSpotResolvedJavaMethod methodInstance |
|
33160 | 69 |
= CompilerToVMHelper.getResolvedJavaMethodAtSlot( |
33632 | 70 |
TEST_CLASS, 0); |
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(); |
33632 | 85 |
HotSpotResolvedJavaMethod methodInstance |
33160 | 86 |
= CompilerToVMHelper.getResolvedJavaMethodAtSlot( |
87 |
TEST_CLASS, 0); |
|
88 |
try { |
|
33632 | 89 |
METASPACE_METHOD_FIELD.set(methodInstance, ptr / 2L); |
33160 | 90 |
} catch (ReflectiveOperationException e) { |
33632 | 91 |
throw new Error("TESTBUG : " + e, e); |
33160 | 92 |
} |
93 |
return CompilerToVMHelper.getResolvedJavaMethod(methodInstance, |
|
94 |
ptr - ptr / 2L); |
|
95 |
} |
|
96 |
}, |
|
97 |
JAVA_METHOD_BASE_ZERO { |
|
98 |
@Override |
|
33632 | 99 |
HotSpotResolvedJavaMethod getResolvedJavaMethod() { |
33160 | 100 |
long ptr = getPtrToMethod(); |
33632 | 101 |
HotSpotResolvedJavaMethod methodInstance |
33160 | 102 |
= CompilerToVMHelper.getResolvedJavaMethodAtSlot( |
103 |
TEST_CLASS, 0); |
|
104 |
try { |
|
33632 | 105 |
METASPACE_METHOD_FIELD.set(methodInstance, 0L); |
33160 | 106 |
} catch (ReflectiveOperationException e) { |
33632 | 107 |
throw new Error("TESTBUG : " + e, e); |
33160 | 108 |
} |
109 |
return CompilerToVMHelper.getResolvedJavaMethod(methodInstance, |
|
110 |
ptr); |
|
111 |
} |
|
112 |
} |
|
113 |
; |
|
33632 | 114 |
abstract HotSpotResolvedJavaMethod getResolvedJavaMethod(); |
33160 | 115 |
} |
116 |
||
117 |
private static final Unsafe UNSAFE = Utils.getUnsafe(); |
|
118 |
private static final WhiteBox WB = WhiteBox.getWhiteBox(); |
|
33632 | 119 |
private static final Field METASPACE_METHOD_FIELD; |
33160 | 120 |
private static final Class<?> TEST_CLASS = GetResolvedJavaMethodTest.class; |
121 |
private static final long PTR; |
|
122 |
static { |
|
33632 | 123 |
HotSpotResolvedJavaMethod method |
33160 | 124 |
= CompilerToVMHelper.getResolvedJavaMethodAtSlot(TEST_CLASS, 0); |
33632 | 125 |
try { |
126 |
// jdk.vm.ci.hotspot.HotSpotResolvedJavaMethodImpl.metaspaceMethod |
|
127 |
METASPACE_METHOD_FIELD = method.getClass() |
|
128 |
.getDeclaredField("metaspaceMethod"); |
|
129 |
METASPACE_METHOD_FIELD.setAccessible(true); |
|
130 |
PTR = (long) METASPACE_METHOD_FIELD.get(method); |
|
131 |
} catch (ReflectiveOperationException e) { |
|
132 |
throw new Error("TESTBUG : " + e, e); |
|
133 |
} |
|
134 |
||
33160 | 135 |
} |
136 |
||
137 |
private static long getPtrToMethod() { |
|
138 |
Field field; |
|
139 |
try { |
|
140 |
field = TEST_CLASS.getDeclaredField("PTR"); |
|
141 |
} catch (NoSuchFieldException e) { |
|
142 |
throw new Error("TEST BUG : " + e, e); |
|
143 |
} |
|
144 |
Object base = UNSAFE.staticFieldBase(field); |
|
145 |
return WB.getObjectAddress(base) + UNSAFE.staticFieldOffset(field); |
|
146 |
} |
|
147 |
||
148 |
public void test(TestCase testCase) { |
|
149 |
System.out.println(testCase.name()); |
|
33632 | 150 |
HotSpotResolvedJavaMethod result = testCase.getResolvedJavaMethod(); |
33160 | 151 |
Asserts.assertNotNull(result, testCase + " : got null"); |
33632 | 152 |
Asserts.assertEQ(TEST_CLASS, |
153 |
CompilerToVMHelper.getMirror(result.getDeclaringClass()), |
|
154 |
testCase + " : unexpected declaring class"); |
|
33160 | 155 |
} |
156 |
||
157 |
public static void main(String[] args) { |
|
158 |
GetResolvedJavaMethodTest test = new GetResolvedJavaMethodTest(); |
|
159 |
for (TestCase testCase : TestCase.values()) { |
|
160 |
test.test(testCase); |
|
161 |
} |
|
162 |
testObjectBase(); |
|
163 |
testMetaspaceWrapperBase(); |
|
164 |
} |
|
165 |
||
166 |
private static void testMetaspaceWrapperBase() { |
|
167 |
try { |
|
33632 | 168 |
HotSpotResolvedJavaMethod method |
33160 | 169 |
= CompilerToVMHelper.getResolvedJavaMethod( |
33632 | 170 |
new PublicMetaspaceWrapperObject() { |
33160 | 171 |
@Override |
172 |
public long getMetaspacePointer() { |
|
173 |
return getPtrToMethod(); |
|
174 |
} |
|
175 |
}, 0L); |
|
176 |
throw new AssertionError("Test METASPACE_WRAPPER_BASE." |
|
177 |
+ " Expected IllegalArgumentException has not been caught"); |
|
33632 | 178 |
} catch (IllegalArgumentException e) { |
33160 | 179 |
// expected |
180 |
} |
|
181 |
} |
|
182 |
||
183 |
private static void testObjectBase() { |
|
184 |
try { |
|
33632 | 185 |
HotSpotResolvedJavaMethod method |
33160 | 186 |
= CompilerToVMHelper.getResolvedJavaMethod(new Object(), 0L); |
187 |
throw new AssertionError("Test OBJECT_BASE." |
|
188 |
+ " Expected IllegalArgumentException has not been caught"); |
|
33632 | 189 |
} catch (IllegalArgumentException e) { |
33160 | 190 |
// expected |
191 |
} |
|
192 |
} |
|
193 |
} |