Mercurial > hg > truffle
annotate graal/com.oracle.graal.asm.test/src/com/oracle/graal/asm/test/AssemblerTest.java @ 8349:8d6ea1915d42
merged CodeInfo into InstalledCode (GRAAL-156)
author | Doug Simon <doug.simon@oracle.com> |
---|---|
date | Mon, 18 Mar 2013 18:26:12 +0100 |
parents | 06ecee106195 |
children | f94bb5d20e5d |
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 */ |
7746
2c1ae1a125bd
Pull out test code that's useful for other assemblers.
Roland Schatz <roland.schatz@oracle.com>
parents:
7718
diff
changeset
|
23 package com.oracle.graal.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 |
7503fdc516d1
simple unit tests for graal.asm.amd64
Roland Schatz <roland.schatz@oracle.com>
parents:
diff
changeset
|
29 import com.oracle.graal.api.code.*; |
7503fdc516d1
simple unit tests for graal.asm.amd64
Roland Schatz <roland.schatz@oracle.com>
parents:
diff
changeset
|
30 import com.oracle.graal.api.meta.*; |
7503fdc516d1
simple unit tests for graal.asm.amd64
Roland Schatz <roland.schatz@oracle.com>
parents:
diff
changeset
|
31 import com.oracle.graal.api.runtime.*; |
7746
2c1ae1a125bd
Pull out test code that's useful for other assemblers.
Roland Schatz <roland.schatz@oracle.com>
parents:
7718
diff
changeset
|
32 import com.oracle.graal.asm.*; |
7718
7503fdc516d1
simple unit tests for graal.asm.amd64
Roland Schatz <roland.schatz@oracle.com>
parents:
diff
changeset
|
33 import com.oracle.graal.test.*; |
7503fdc516d1
simple unit tests for graal.asm.amd64
Roland Schatz <roland.schatz@oracle.com>
parents:
diff
changeset
|
34 |
7749 | 35 public abstract class AssemblerTest extends GraalTest { |
7718
7503fdc516d1
simple unit tests for graal.asm.amd64
Roland Schatz <roland.schatz@oracle.com>
parents:
diff
changeset
|
36 |
7503fdc516d1
simple unit tests for graal.asm.amd64
Roland Schatz <roland.schatz@oracle.com>
parents:
diff
changeset
|
37 protected final CodeCacheProvider codeCache; |
7503fdc516d1
simple unit tests for graal.asm.amd64
Roland Schatz <roland.schatz@oracle.com>
parents:
diff
changeset
|
38 |
7749 | 39 public interface CodeGenTest { |
7718
7503fdc516d1
simple unit tests for graal.asm.amd64
Roland Schatz <roland.schatz@oracle.com>
parents:
diff
changeset
|
40 |
7756
98143feb3879
provide calling convention for assembler tests
Roland Schatz <roland.schatz@oracle.com>
parents:
7749
diff
changeset
|
41 Buffer 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
|
42 } |
7503fdc516d1
simple unit tests for graal.asm.amd64
Roland Schatz <roland.schatz@oracle.com>
parents:
diff
changeset
|
43 |
7746
2c1ae1a125bd
Pull out test code that's useful for other assemblers.
Roland Schatz <roland.schatz@oracle.com>
parents:
7718
diff
changeset
|
44 public AssemblerTest() { |
7718
7503fdc516d1
simple unit tests for graal.asm.amd64
Roland Schatz <roland.schatz@oracle.com>
parents:
diff
changeset
|
45 this.codeCache = Graal.getRequiredCapability(CodeCacheProvider.class); |
7503fdc516d1
simple unit tests for graal.asm.amd64
Roland Schatz <roland.schatz@oracle.com>
parents:
diff
changeset
|
46 } |
7503fdc516d1
simple unit tests for graal.asm.amd64
Roland Schatz <roland.schatz@oracle.com>
parents:
diff
changeset
|
47 |
7749 | 48 protected InstalledCode assembleMethod(Method m, CodeGenTest test) { |
7718
7503fdc516d1
simple unit tests for graal.asm.amd64
Roland Schatz <roland.schatz@oracle.com>
parents:
diff
changeset
|
49 ResolvedJavaMethod method = codeCache.lookupJavaMethod(m); |
7838
a063308816d9
Complete first PTX unit test.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
7798
diff
changeset
|
50 RegisterConfig registerConfig = codeCache.lookupRegisterConfig(); |
7798
60c010b8e1c1
Pull out utility method.
Roland Schatz <roland.schatz@oracle.com>
parents:
7797
diff
changeset
|
51 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
|
52 |
7503fdc516d1
simple unit tests for graal.asm.amd64
Roland Schatz <roland.schatz@oracle.com>
parents:
diff
changeset
|
53 CompilationResult compResult = new CompilationResult(); |
7756
98143feb3879
provide calling convention for assembler tests
Roland Schatz <roland.schatz@oracle.com>
parents:
7749
diff
changeset
|
54 Buffer codeBuffer = test.generateCode(compResult, codeCache.getTarget(), registerConfig, cc); |
7749 | 55 compResult.setTargetCode(codeBuffer.close(true), codeBuffer.position()); |
7718
7503fdc516d1
simple unit tests for graal.asm.amd64
Roland Schatz <roland.schatz@oracle.com>
parents:
diff
changeset
|
56 |
8349
8d6ea1915d42
merged CodeInfo into InstalledCode (GRAAL-156)
Doug Simon <doug.simon@oracle.com>
parents:
7912
diff
changeset
|
57 InstalledCode code = codeCache.addMethod(method, compResult); |
7912
06ecee106195
added unit tests for bytecode and machine code disassembly
Doug Simon <doug.simon@oracle.com>
parents:
7838
diff
changeset
|
58 |
06ecee106195
added unit tests for bytecode and machine code disassembly
Doug Simon <doug.simon@oracle.com>
parents:
7838
diff
changeset
|
59 DisassemblerProvider dis = Graal.getRuntime().getCapability(DisassemblerProvider.class); |
06ecee106195
added unit tests for bytecode and machine code disassembly
Doug Simon <doug.simon@oracle.com>
parents:
7838
diff
changeset
|
60 if (dis != null) { |
06ecee106195
added unit tests for bytecode and machine code disassembly
Doug Simon <doug.simon@oracle.com>
parents:
7838
diff
changeset
|
61 String disasm = dis.disassemble(code); |
06ecee106195
added unit tests for bytecode and machine code disassembly
Doug Simon <doug.simon@oracle.com>
parents:
7838
diff
changeset
|
62 Assert.assertTrue(String.valueOf(code.getMethod()), disasm == null || disasm.length() > 0); |
06ecee106195
added unit tests for bytecode and machine code disassembly
Doug Simon <doug.simon@oracle.com>
parents:
7838
diff
changeset
|
63 } |
06ecee106195
added unit tests for bytecode and machine code disassembly
Doug Simon <doug.simon@oracle.com>
parents:
7838
diff
changeset
|
64 return code; |
7718
7503fdc516d1
simple unit tests for graal.asm.amd64
Roland Schatz <roland.schatz@oracle.com>
parents:
diff
changeset
|
65 } |
7503fdc516d1
simple unit tests for graal.asm.amd64
Roland Schatz <roland.schatz@oracle.com>
parents:
diff
changeset
|
66 |
7756
98143feb3879
provide calling convention for assembler tests
Roland Schatz <roland.schatz@oracle.com>
parents:
7749
diff
changeset
|
67 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
|
68 Method method = getMethod(methodName); |
7503fdc516d1
simple unit tests for graal.asm.amd64
Roland Schatz <roland.schatz@oracle.com>
parents:
diff
changeset
|
69 InstalledCode code = assembleMethod(method, test); |
7756
98143feb3879
provide calling convention for assembler tests
Roland Schatz <roland.schatz@oracle.com>
parents:
7749
diff
changeset
|
70 return code.executeVarargs(args); |
98143feb3879
provide calling convention for assembler tests
Roland Schatz <roland.schatz@oracle.com>
parents:
7749
diff
changeset
|
71 } |
7718
7503fdc516d1
simple unit tests for graal.asm.amd64
Roland Schatz <roland.schatz@oracle.com>
parents:
diff
changeset
|
72 |
7756
98143feb3879
provide calling convention for assembler tests
Roland Schatz <roland.schatz@oracle.com>
parents:
7749
diff
changeset
|
73 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
|
74 Object actual = runTest(methodName, test, args); |
7797
b792a2f3c4da
fix error message
Roland Schatz <roland.schatz@oracle.com>
parents:
7756
diff
changeset
|
75 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
|
76 } |
7503fdc516d1
simple unit tests for graal.asm.amd64
Roland Schatz <roland.schatz@oracle.com>
parents:
diff
changeset
|
77 } |