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 package jdk.vm.ci.code.test;
24
25 import jdk.vm.ci.amd64.AMD64;
26 import jdk.vm.ci.code.Architecture;
27 import jdk.vm.ci.code.CodeCacheProvider;
28 import jdk.vm.ci.code.InstalledCode;
29 import jdk.vm.ci.code.TargetDescription;
30 import jdk.vm.ci.code.test.amd64.AMD64TestAssembler;
31 import jdk.vm.ci.code.test.sparc.SPARCTestAssembler;
32 import jdk.vm.ci.hotspot.HotSpotCompiledCode;
33 import jdk.vm.ci.hotspot.HotSpotJVMCIRuntime;
34 import jdk.vm.ci.hotspot.HotSpotResolvedJavaMethod;
35 import jdk.vm.ci.meta.ConstantReflectionProvider;
36 import jdk.vm.ci.meta.MetaAccessProvider;
37 import jdk.vm.ci.runtime.JVMCI;
38 import jdk.vm.ci.runtime.JVMCIBackend;
39 import jdk.vm.ci.sparc.SPARC;
40 import org.junit.Assert;
41
42 import java.lang.reflect.Method;
43
44 /**
45 * Base class for code installation tests.
46 */
47 public class CodeInstallationTest {
48
49 protected final MetaAccessProvider metaAccess;
50 protected final CodeCacheProvider codeCache;
51 protected final TargetDescription target;
52 protected final ConstantReflectionProvider constantReflection;
53 protected final TestHotSpotVMConfig config;
54
55 public CodeInstallationTest() {
56 JVMCIBackend backend = JVMCI.getRuntime().getHostJVMCIBackend();
57 metaAccess = backend.getMetaAccess();
58 codeCache = backend.getCodeCache();
59 target = backend.getTarget();
60 constantReflection = backend.getConstantReflection();
61 config = new TestHotSpotVMConfig(HotSpotJVMCIRuntime.runtime().getConfigStore());
62 }
63
64 protected interface TestCompiler {
65
66 void compile(TestAssembler asm);
67 }
68
69 private TestAssembler createAssembler() {
70 Architecture arch = codeCache.getTarget().arch;
71 if (arch instanceof AMD64) {
72 return new AMD64TestAssembler(codeCache, config);
73 } else if (arch instanceof SPARC) {
74 return new SPARCTestAssembler(codeCache, config);
75 } else {
76 Assert.fail("unsupported architecture");
77 return null;
78 }
79 }
80
81 protected Method getMethod(String name, Class<?>... args) {
82 try {
83 return getClass().getMethod(name, args);
84 } catch (NoSuchMethodException e) {
85 Assert.fail("method not found");
86 return null;
87 }
88 }
89
90 protected void test(TestCompiler compiler, Method method, Object... args) {
91 try {
92 HotSpotResolvedJavaMethod resolvedMethod = (HotSpotResolvedJavaMethod) metaAccess.lookupJavaMethod(method);
93 TestAssembler asm = createAssembler();
94
|
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 package jdk.vm.ci.code.test;
24
25 import jdk.vm.ci.amd64.AMD64;
26 import jdk.vm.ci.code.Architecture;
27 import jdk.vm.ci.code.CodeCacheProvider;
28 import jdk.vm.ci.code.InstalledCode;
29 import jdk.vm.ci.code.TargetDescription;
30 import jdk.vm.ci.code.test.amd64.AMD64TestAssembler;
31 import jdk.vm.ci.hotspot.HotSpotCompiledCode;
32 import jdk.vm.ci.hotspot.HotSpotJVMCIRuntime;
33 import jdk.vm.ci.hotspot.HotSpotResolvedJavaMethod;
34 import jdk.vm.ci.meta.ConstantReflectionProvider;
35 import jdk.vm.ci.meta.MetaAccessProvider;
36 import jdk.vm.ci.runtime.JVMCI;
37 import jdk.vm.ci.runtime.JVMCIBackend;
38 import org.junit.Assert;
39
40 import java.lang.reflect.Method;
41
42 /**
43 * Base class for code installation tests.
44 */
45 public class CodeInstallationTest {
46
47 protected final MetaAccessProvider metaAccess;
48 protected final CodeCacheProvider codeCache;
49 protected final TargetDescription target;
50 protected final ConstantReflectionProvider constantReflection;
51 protected final TestHotSpotVMConfig config;
52
53 public CodeInstallationTest() {
54 JVMCIBackend backend = JVMCI.getRuntime().getHostJVMCIBackend();
55 metaAccess = backend.getMetaAccess();
56 codeCache = backend.getCodeCache();
57 target = backend.getTarget();
58 constantReflection = backend.getConstantReflection();
59 config = new TestHotSpotVMConfig(HotSpotJVMCIRuntime.runtime().getConfigStore());
60 }
61
62 protected interface TestCompiler {
63
64 void compile(TestAssembler asm);
65 }
66
67 private TestAssembler createAssembler() {
68 Architecture arch = codeCache.getTarget().arch;
69 if (arch instanceof AMD64) {
70 return new AMD64TestAssembler(codeCache, config);
71 } else {
72 Assert.fail("unsupported architecture");
73 return null;
74 }
75 }
76
77 protected Method getMethod(String name, Class<?>... args) {
78 try {
79 return getClass().getMethod(name, args);
80 } catch (NoSuchMethodException e) {
81 Assert.fail("method not found");
82 return null;
83 }
84 }
85
86 protected void test(TestCompiler compiler, Method method, Object... args) {
87 try {
88 HotSpotResolvedJavaMethod resolvedMethod = (HotSpotResolvedJavaMethod) metaAccess.lookupJavaMethod(method);
89 TestAssembler asm = createAssembler();
90
|