Mercurial > hg > truffle
annotate graal/com.oracle.graal.asm.test/src/com/oracle/graal/asm/test/AssemblerTest.java @ 11959:23ccaa863eda
made CodeCacheProvider independent of MetaAccessProvider (GRAAL-511)
author | Doug Simon <doug.simon@oracle.com> |
---|---|
date | Thu, 10 Oct 2013 16:14:55 +0200 |
parents | 36e12fbbefdf |
children | 9c2111d10e40 |
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 |
11959
23ccaa863eda
made CodeCacheProvider independent of MetaAccessProvider (GRAAL-511)
Doug Simon <doug.simon@oracle.com>
parents:
9653
diff
changeset
|
37 private final MetaAccessProvider metaAccess; |
7718
7503fdc516d1
simple unit tests for graal.asm.amd64
Roland Schatz <roland.schatz@oracle.com>
parents:
diff
changeset
|
38 protected final CodeCacheProvider codeCache; |
7503fdc516d1
simple unit tests for graal.asm.amd64
Roland Schatz <roland.schatz@oracle.com>
parents:
diff
changeset
|
39 |
7749 | 40 public interface CodeGenTest { |
7718
7503fdc516d1
simple unit tests for graal.asm.amd64
Roland Schatz <roland.schatz@oracle.com>
parents:
diff
changeset
|
41 |
7756
98143feb3879
provide calling convention for assembler tests
Roland Schatz <roland.schatz@oracle.com>
parents:
7749
diff
changeset
|
42 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
|
43 } |
7503fdc516d1
simple unit tests for graal.asm.amd64
Roland Schatz <roland.schatz@oracle.com>
parents:
diff
changeset
|
44 |
7746
2c1ae1a125bd
Pull out test code that's useful for other assemblers.
Roland Schatz <roland.schatz@oracle.com>
parents:
7718
diff
changeset
|
45 public AssemblerTest() { |
11959
23ccaa863eda
made CodeCacheProvider independent of MetaAccessProvider (GRAAL-511)
Doug Simon <doug.simon@oracle.com>
parents:
9653
diff
changeset
|
46 this.metaAccess = Graal.getRequiredCapability(MetaAccessProvider.class); |
7718
7503fdc516d1
simple unit tests for graal.asm.amd64
Roland Schatz <roland.schatz@oracle.com>
parents:
diff
changeset
|
47 this.codeCache = Graal.getRequiredCapability(CodeCacheProvider.class); |
7503fdc516d1
simple unit tests for graal.asm.amd64
Roland Schatz <roland.schatz@oracle.com>
parents:
diff
changeset
|
48 } |
7503fdc516d1
simple unit tests for graal.asm.amd64
Roland Schatz <roland.schatz@oracle.com>
parents:
diff
changeset
|
49 |
11959
23ccaa863eda
made CodeCacheProvider independent of MetaAccessProvider (GRAAL-511)
Doug Simon <doug.simon@oracle.com>
parents:
9653
diff
changeset
|
50 public MetaAccessProvider getMetaAccess() { |
23ccaa863eda
made CodeCacheProvider independent of MetaAccessProvider (GRAAL-511)
Doug Simon <doug.simon@oracle.com>
parents:
9653
diff
changeset
|
51 return metaAccess; |
23ccaa863eda
made CodeCacheProvider independent of MetaAccessProvider (GRAAL-511)
Doug Simon <doug.simon@oracle.com>
parents:
9653
diff
changeset
|
52 } |
23ccaa863eda
made CodeCacheProvider independent of MetaAccessProvider (GRAAL-511)
Doug Simon <doug.simon@oracle.com>
parents:
9653
diff
changeset
|
53 |
7749 | 54 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
|
55 ResolvedJavaMethod method = getMetaAccess().lookupJavaMethod(m); |
7838
a063308816d9
Complete first PTX unit test.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
7798
diff
changeset
|
56 RegisterConfig registerConfig = codeCache.lookupRegisterConfig(); |
7798
60c010b8e1c1
Pull out utility method.
Roland Schatz <roland.schatz@oracle.com>
parents:
7797
diff
changeset
|
57 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
|
58 |
7503fdc516d1
simple unit tests for graal.asm.amd64
Roland Schatz <roland.schatz@oracle.com>
parents:
diff
changeset
|
59 CompilationResult compResult = new CompilationResult(); |
7756
98143feb3879
provide calling convention for assembler tests
Roland Schatz <roland.schatz@oracle.com>
parents:
7749
diff
changeset
|
60 Buffer codeBuffer = test.generateCode(compResult, codeCache.getTarget(), registerConfig, cc); |
7749 | 61 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
|
62 |
8349
8d6ea1915d42
merged CodeInfo into InstalledCode (GRAAL-156)
Doug Simon <doug.simon@oracle.com>
parents:
7912
diff
changeset
|
63 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
|
64 |
06ecee106195
added unit tests for bytecode and machine code disassembly
Doug Simon <doug.simon@oracle.com>
parents:
7838
diff
changeset
|
65 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
|
66 if (dis != null) { |
06ecee106195
added unit tests for bytecode and machine code disassembly
Doug Simon <doug.simon@oracle.com>
parents:
7838
diff
changeset
|
67 String disasm = dis.disassemble(code); |
9653
36e12fbbefdf
replaced unnecessary call to Stub.getMethod() with Stub.toString()
Doug Simon <doug.simon@oracle.com>
parents:
9023
diff
changeset
|
68 Assert.assertTrue(code.toString(), disasm == null || disasm.length() > 0); |
7912
06ecee106195
added unit tests for bytecode and machine code disassembly
Doug Simon <doug.simon@oracle.com>
parents:
7838
diff
changeset
|
69 } |
06ecee106195
added unit tests for bytecode and machine code disassembly
Doug Simon <doug.simon@oracle.com>
parents:
7838
diff
changeset
|
70 return code; |
7718
7503fdc516d1
simple unit tests for graal.asm.amd64
Roland Schatz <roland.schatz@oracle.com>
parents:
diff
changeset
|
71 } |
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 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
|
74 Method method = getMethod(methodName); |
7503fdc516d1
simple unit tests for graal.asm.amd64
Roland Schatz <roland.schatz@oracle.com>
parents:
diff
changeset
|
75 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
|
76 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
|
77 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
|
78 } 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
|
79 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
|
80 } |
7756
98143feb3879
provide calling convention for assembler tests
Roland Schatz <roland.schatz@oracle.com>
parents:
7749
diff
changeset
|
81 } |
7718
7503fdc516d1
simple unit tests for graal.asm.amd64
Roland Schatz <roland.schatz@oracle.com>
parents:
diff
changeset
|
82 |
7756
98143feb3879
provide calling convention for assembler tests
Roland Schatz <roland.schatz@oracle.com>
parents:
7749
diff
changeset
|
83 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
|
84 Object actual = runTest(methodName, test, args); |
7797
b792a2f3c4da
fix error message
Roland Schatz <roland.schatz@oracle.com>
parents:
7756
diff
changeset
|
85 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
|
86 } |
7503fdc516d1
simple unit tests for graal.asm.amd64
Roland Schatz <roland.schatz@oracle.com>
parents:
diff
changeset
|
87 } |