annotate graal/com.oracle.jvmci.asm.test/src/com/oracle/jvmci/asm/test/AssemblerTest.java @ 21712:a59a0c85650a

removed redundant definition of JVM opcodes
author Doug Simon <doug.simon@oracle.com>
date Wed, 03 Jun 2015 21:53:28 +0200
parents 3c17c0c41a6b
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
7718
7503fdc516d1 simple unit tests for graal.asm.amd64
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
1 /*
7503fdc516d1 simple unit tests for graal.asm.amd64
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
2 * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved.
7503fdc516d1 simple unit tests for graal.asm.amd64
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
7503fdc516d1 simple unit tests for graal.asm.amd64
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
4 *
7503fdc516d1 simple unit tests for graal.asm.amd64
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
5 * This code is free software; you can redistribute it and/or modify it
7503fdc516d1 simple unit tests for graal.asm.amd64
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
6 * under the terms of the GNU General Public License version 2 only, as
7503fdc516d1 simple unit tests for graal.asm.amd64
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
7 * published by the Free Software Foundation.
7503fdc516d1 simple unit tests for graal.asm.amd64
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
8 *
7503fdc516d1 simple unit tests for graal.asm.amd64
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
9 * This code is distributed in the hope that it will be useful, but WITHOUT
7503fdc516d1 simple unit tests for graal.asm.amd64
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
7503fdc516d1 simple unit tests for graal.asm.amd64
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
7503fdc516d1 simple unit tests for graal.asm.amd64
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
12 * version 2 for more details (a copy is included in the LICENSE file that
7503fdc516d1 simple unit tests for graal.asm.amd64
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
13 * accompanied this code).
7503fdc516d1 simple unit tests for graal.asm.amd64
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
14 *
7503fdc516d1 simple unit tests for graal.asm.amd64
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
15 * You should have received a copy of the GNU General Public License version
7503fdc516d1 simple unit tests for graal.asm.amd64
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
16 * 2 along with this work; if not, write to the Free Software Foundation,
7503fdc516d1 simple unit tests for graal.asm.amd64
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
7503fdc516d1 simple unit tests for graal.asm.amd64
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
18 *
7503fdc516d1 simple unit tests for graal.asm.amd64
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
7503fdc516d1 simple unit tests for graal.asm.amd64
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
20 * or visit www.oracle.com if you need additional information or have any
7503fdc516d1 simple unit tests for graal.asm.amd64
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
21 * questions.
7503fdc516d1 simple unit tests for graal.asm.amd64
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
22 */
21709
3c17c0c41a6b moved com.oracle.asm.**.test to JVMCI namespace (JBS:GRAAL-53)
Doug Simon <doug.simon@oracle.com>
parents: 21707
diff changeset
23 package com.oracle.jvmci.asm.test;
7718
7503fdc516d1 simple unit tests for graal.asm.amd64
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
24
7503fdc516d1 simple unit tests for graal.asm.amd64
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
25 import java.lang.reflect.*;
7503fdc516d1 simple unit tests for graal.asm.amd64
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
26
7503fdc516d1 simple unit tests for graal.asm.amd64
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
27 import org.junit.*;
7503fdc516d1 simple unit tests for graal.asm.amd64
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
28
21707
e0f311284930 made HotSpotDisassemblerProvider a stand alone JVMCI service implementation of DisassemblerProvider
Doug Simon <doug.simon@oracle.com>
parents: 21561
diff changeset
29 import com.oracle.jvmci.code.*;
21554
b1530a6cce8c renamed com.oracle.graal.[debug|options|hotspotvmconfig]* modules to com.oracle.jvmci.[debug|options|hotspotvmconfig]* modules (JBS:GRAAL-53)
Doug Simon <doug.simon@oracle.com>
parents: 20087
diff changeset
30 import com.oracle.jvmci.debug.*;
b1530a6cce8c renamed com.oracle.graal.[debug|options|hotspotvmconfig]* modules to com.oracle.jvmci.[debug|options|hotspotvmconfig]* modules (JBS:GRAAL-53)
Doug Simon <doug.simon@oracle.com>
parents: 20087
diff changeset
31 import com.oracle.jvmci.debug.Debug.Scope;
21707
e0f311284930 made HotSpotDisassemblerProvider a stand alone JVMCI service implementation of DisassemblerProvider
Doug Simon <doug.simon@oracle.com>
parents: 21561
diff changeset
32 import com.oracle.jvmci.meta.*;
21709
3c17c0c41a6b moved com.oracle.asm.**.test to JVMCI namespace (JBS:GRAAL-53)
Doug Simon <doug.simon@oracle.com>
parents: 21707
diff changeset
33 import com.oracle.jvmci.runtime.*;
21707
e0f311284930 made HotSpotDisassemblerProvider a stand alone JVMCI service implementation of DisassemblerProvider
Doug Simon <doug.simon@oracle.com>
parents: 21561
diff changeset
34 import com.oracle.jvmci.service.*;
21709
3c17c0c41a6b moved com.oracle.asm.**.test to JVMCI namespace (JBS:GRAAL-53)
Doug Simon <doug.simon@oracle.com>
parents: 21707
diff changeset
35 import com.oracle.jvmci.test.*;
7718
7503fdc516d1 simple unit tests for graal.asm.amd64
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
36
21709
3c17c0c41a6b moved com.oracle.asm.**.test to JVMCI namespace (JBS:GRAAL-53)
Doug Simon <doug.simon@oracle.com>
parents: 21707
diff changeset
37 public abstract class AssemblerTest extends TestBase {
7718
7503fdc516d1 simple unit tests for graal.asm.amd64
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
38
11959
23ccaa863eda made CodeCacheProvider independent of MetaAccessProvider (GRAAL-511)
Doug Simon <doug.simon@oracle.com>
parents: 9653
diff changeset
39 private final MetaAccessProvider metaAccess;
7718
7503fdc516d1 simple unit tests for graal.asm.amd64
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
40 protected final CodeCacheProvider codeCache;
7503fdc516d1 simple unit tests for graal.asm.amd64
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
41
7749
52fd6491fca8 avoid generics
Roland Schatz <roland.schatz@oracle.com>
parents: 7746
diff changeset
42 public interface CodeGenTest {
14031
390c4b742890 made com.oracle.graal.asm.Buffer non-public and a private field in AbstractAssembler
twisti
parents: 13669
diff changeset
43 byte[] generateCode(CompilationResult compResult, TargetDescription target, RegisterConfig registerConfig, CallingConvention cc);
7718
7503fdc516d1 simple unit tests for graal.asm.amd64
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
44 }
7503fdc516d1 simple unit tests for graal.asm.amd64
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
45
7746
2c1ae1a125bd Pull out test code that's useful for other assemblers.
Roland Schatz <roland.schatz@oracle.com>
parents: 7718
diff changeset
46 public AssemblerTest() {
21709
3c17c0c41a6b moved com.oracle.asm.**.test to JVMCI namespace (JBS:GRAAL-53)
Doug Simon <doug.simon@oracle.com>
parents: 21707
diff changeset
47 JVMCIBackend providers = JVMCI.getRuntime().getHostJVMCIBackend();
12488
1a4dc163cd0a abstracted HotSpotGraalRuntime as a RuntimeProvider which removes the recent selector addition to the Graal capabilities API and also makes Truffle independent of the graal.hotspot project (GRAAL-363)
Doug Simon <doug.simon@oracle.com>
parents: 12051
diff changeset
48 this.metaAccess = providers.getMetaAccess();
1a4dc163cd0a abstracted HotSpotGraalRuntime as a RuntimeProvider which removes the recent selector addition to the Graal capabilities API and also makes Truffle independent of the graal.hotspot project (GRAAL-363)
Doug Simon <doug.simon@oracle.com>
parents: 12051
diff changeset
49 this.codeCache = providers.getCodeCache();
7718
7503fdc516d1 simple unit tests for graal.asm.amd64
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
50 }
7503fdc516d1 simple unit tests for graal.asm.amd64
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
51
11959
23ccaa863eda made CodeCacheProvider independent of MetaAccessProvider (GRAAL-511)
Doug Simon <doug.simon@oracle.com>
parents: 9653
diff changeset
52 public MetaAccessProvider getMetaAccess() {
23ccaa863eda made CodeCacheProvider independent of MetaAccessProvider (GRAAL-511)
Doug Simon <doug.simon@oracle.com>
parents: 9653
diff changeset
53 return metaAccess;
23ccaa863eda made CodeCacheProvider independent of MetaAccessProvider (GRAAL-511)
Doug Simon <doug.simon@oracle.com>
parents: 9653
diff changeset
54 }
23ccaa863eda made CodeCacheProvider independent of MetaAccessProvider (GRAAL-511)
Doug Simon <doug.simon@oracle.com>
parents: 9653
diff changeset
55
7749
52fd6491fca8 avoid generics
Roland Schatz <roland.schatz@oracle.com>
parents: 7746
diff changeset
56 protected InstalledCode assembleMethod(Method m, CodeGenTest test) {
11959
23ccaa863eda made CodeCacheProvider independent of MetaAccessProvider (GRAAL-511)
Doug Simon <doug.simon@oracle.com>
parents: 9653
diff changeset
57 ResolvedJavaMethod method = getMetaAccess().lookupJavaMethod(m);
20087
e6235961d404 AssemblerTest: add method and code cache provider to scope to enable dumping.
Josef Eisl <josef.eisl@jku.at>
parents: 15162
diff changeset
58 try (Scope s = Debug.scope("assembleMethod", method, codeCache)) {
e6235961d404 AssemblerTest: add method and code cache provider to scope to enable dumping.
Josef Eisl <josef.eisl@jku.at>
parents: 15162
diff changeset
59 RegisterConfig registerConfig = codeCache.getRegisterConfig();
e6235961d404 AssemblerTest: add method and code cache provider to scope to enable dumping.
Josef Eisl <josef.eisl@jku.at>
parents: 15162
diff changeset
60 CallingConvention cc = CodeUtil.getCallingConvention(codeCache, CallingConvention.Type.JavaCallee, method, false);
7718
7503fdc516d1 simple unit tests for graal.asm.amd64
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
61
20087
e6235961d404 AssemblerTest: add method and code cache provider to scope to enable dumping.
Josef Eisl <josef.eisl@jku.at>
parents: 15162
diff changeset
62 CompilationResult compResult = new CompilationResult();
e6235961d404 AssemblerTest: add method and code cache provider to scope to enable dumping.
Josef Eisl <josef.eisl@jku.at>
parents: 15162
diff changeset
63 byte[] targetCode = test.generateCode(compResult, codeCache.getTarget(), registerConfig, cc);
e6235961d404 AssemblerTest: add method and code cache provider to scope to enable dumping.
Josef Eisl <josef.eisl@jku.at>
parents: 15162
diff changeset
64 compResult.setTargetCode(targetCode, targetCode.length);
21506
5cbaf1e9ff2e Remove reference to CompilationResult from HotSpotCompiledCode.
Roland Schatz <roland.schatz@oracle.com>
parents: 20087
diff changeset
65 compResult.setTotalFrameSize(0);
20087
e6235961d404 AssemblerTest: add method and code cache provider to scope to enable dumping.
Josef Eisl <josef.eisl@jku.at>
parents: 15162
diff changeset
66
e6235961d404 AssemblerTest: add method and code cache provider to scope to enable dumping.
Josef Eisl <josef.eisl@jku.at>
parents: 15162
diff changeset
67 InstalledCode code = codeCache.addMethod(method, compResult, null, null);
7718
7503fdc516d1 simple unit tests for graal.asm.amd64
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
68
21707
e0f311284930 made HotSpotDisassemblerProvider a stand alone JVMCI service implementation of DisassemblerProvider
Doug Simon <doug.simon@oracle.com>
parents: 21561
diff changeset
69 for (DisassemblerProvider dis : Services.load(DisassemblerProvider.class)) {
20087
e6235961d404 AssemblerTest: add method and code cache provider to scope to enable dumping.
Josef Eisl <josef.eisl@jku.at>
parents: 15162
diff changeset
70 String disasm = dis.disassemble(code);
e6235961d404 AssemblerTest: add method and code cache provider to scope to enable dumping.
Josef Eisl <josef.eisl@jku.at>
parents: 15162
diff changeset
71 Assert.assertTrue(code.toString(), disasm == null || disasm.length() > 0);
e6235961d404 AssemblerTest: add method and code cache provider to scope to enable dumping.
Josef Eisl <josef.eisl@jku.at>
parents: 15162
diff changeset
72 }
e6235961d404 AssemblerTest: add method and code cache provider to scope to enable dumping.
Josef Eisl <josef.eisl@jku.at>
parents: 15162
diff changeset
73 return code;
e6235961d404 AssemblerTest: add method and code cache provider to scope to enable dumping.
Josef Eisl <josef.eisl@jku.at>
parents: 15162
diff changeset
74 } catch (Throwable e) {
e6235961d404 AssemblerTest: add method and code cache provider to scope to enable dumping.
Josef Eisl <josef.eisl@jku.at>
parents: 15162
diff changeset
75 throw Debug.handle(e);
7912
06ecee106195 added unit tests for bytecode and machine code disassembly
Doug Simon <doug.simon@oracle.com>
parents: 7838
diff changeset
76 }
7718
7503fdc516d1 simple unit tests for graal.asm.amd64
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
77 }
7503fdc516d1 simple unit tests for graal.asm.amd64
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
78
7756
98143feb3879 provide calling convention for assembler tests
Roland Schatz <roland.schatz@oracle.com>
parents: 7749
diff changeset
79 protected Object runTest(String methodName, CodeGenTest test, Object... args) {
7718
7503fdc516d1 simple unit tests for graal.asm.amd64
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
80 Method method = getMethod(methodName);
7503fdc516d1 simple unit tests for graal.asm.amd64
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
81 InstalledCode code = assembleMethod(method, test);
9023
f94bb5d20e5d Rename MethodInvalidatedException to InvalidInstalledCodeException (and make it a checked exception). Make sure that a compiled code object can always be directly called without first doing a check on the native method pointer.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 8349
diff changeset
82 try {
f94bb5d20e5d Rename MethodInvalidatedException to InvalidInstalledCodeException (and make it a checked exception). Make sure that a compiled code object can always be directly called without first doing a check on the native method pointer.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 8349
diff changeset
83 return code.executeVarargs(args);
f94bb5d20e5d Rename MethodInvalidatedException to InvalidInstalledCodeException (and make it a checked exception). Make sure that a compiled code object can always be directly called without first doing a check on the native method pointer.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 8349
diff changeset
84 } catch (InvalidInstalledCodeException e) {
f94bb5d20e5d Rename MethodInvalidatedException to InvalidInstalledCodeException (and make it a checked exception). Make sure that a compiled code object can always be directly called without first doing a check on the native method pointer.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 8349
diff changeset
85 throw new RuntimeException(e);
f94bb5d20e5d Rename MethodInvalidatedException to InvalidInstalledCodeException (and make it a checked exception). Make sure that a compiled code object can always be directly called without first doing a check on the native method pointer.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 8349
diff changeset
86 }
7756
98143feb3879 provide calling convention for assembler tests
Roland Schatz <roland.schatz@oracle.com>
parents: 7749
diff changeset
87 }
7718
7503fdc516d1 simple unit tests for graal.asm.amd64
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
88
7756
98143feb3879 provide calling convention for assembler tests
Roland Schatz <roland.schatz@oracle.com>
parents: 7749
diff changeset
89 protected void assertReturn(String methodName, CodeGenTest test, Object expected, Object... args) {
98143feb3879 provide calling convention for assembler tests
Roland Schatz <roland.schatz@oracle.com>
parents: 7749
diff changeset
90 Object actual = runTest(methodName, test, args);
7797
b792a2f3c4da fix error message
Roland Schatz <roland.schatz@oracle.com>
parents: 7756
diff changeset
91 Assert.assertEquals("unexpected return value", expected, actual);
7718
7503fdc516d1 simple unit tests for graal.asm.amd64
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
92 }
7503fdc516d1 simple unit tests for graal.asm.amd64
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
93 }