annotate graal/com.oracle.graal.asm.test/src/com/oracle/graal/asm/test/AssemblerTest.java @ 13669:034706a93f27

CodeCacheProvider.addMethod: add speculationLog argument
author Gilles Duboscq <duboscq@ssw.jku.at>
date Fri, 17 Jan 2014 14:02:42 +0100
parents 1a4dc163cd0a
children 390c4b742890
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 */
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.*;
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
33 import com.oracle.graal.phases.util.*;
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
34 import com.oracle.graal.runtime.*;
7718
7503fdc516d1 simple unit tests for graal.asm.amd64
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
35 import com.oracle.graal.test.*;
7503fdc516d1 simple unit tests for graal.asm.amd64
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
36
7749
52fd6491fca8 avoid generics
Roland Schatz <roland.schatz@oracle.com>
parents: 7746
diff changeset
37 public abstract class AssemblerTest extends GraalTest {
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 {
7718
7503fdc516d1 simple unit tests for graal.asm.amd64
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
43
7756
98143feb3879 provide calling convention for assembler tests
Roland Schatz <roland.schatz@oracle.com>
parents: 7749
diff changeset
44 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
45 }
7503fdc516d1 simple unit tests for graal.asm.amd64
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
46
7746
2c1ae1a125bd Pull out test code that's useful for other assemblers.
Roland Schatz <roland.schatz@oracle.com>
parents: 7718
diff changeset
47 public AssemblerTest() {
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 Providers providers = Graal.getRequiredCapability(RuntimeProvider.class).getHostBackend().getProviders();
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.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
50 this.codeCache = providers.getCodeCache();
7718
7503fdc516d1 simple unit tests for graal.asm.amd64
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
51 }
7503fdc516d1 simple unit tests for graal.asm.amd64
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
52
11959
23ccaa863eda made CodeCacheProvider independent of MetaAccessProvider (GRAAL-511)
Doug Simon <doug.simon@oracle.com>
parents: 9653
diff changeset
53 public MetaAccessProvider getMetaAccess() {
23ccaa863eda made CodeCacheProvider independent of MetaAccessProvider (GRAAL-511)
Doug Simon <doug.simon@oracle.com>
parents: 9653
diff changeset
54 return metaAccess;
23ccaa863eda made CodeCacheProvider independent of MetaAccessProvider (GRAAL-511)
Doug Simon <doug.simon@oracle.com>
parents: 9653
diff changeset
55 }
23ccaa863eda made CodeCacheProvider independent of MetaAccessProvider (GRAAL-511)
Doug Simon <doug.simon@oracle.com>
parents: 9653
diff changeset
56
7749
52fd6491fca8 avoid generics
Roland Schatz <roland.schatz@oracle.com>
parents: 7746
diff changeset
57 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
58 ResolvedJavaMethod method = getMetaAccess().lookupJavaMethod(m);
12051
9c2111d10e40 rename: lookupRegisterConfig -> getRegisterConfig (part 2)
Doug Simon <doug.simon@oracle.com>
parents: 11959
diff changeset
59 RegisterConfig registerConfig = codeCache.getRegisterConfig();
7798
60c010b8e1c1 Pull out utility method.
Roland Schatz <roland.schatz@oracle.com>
parents: 7797
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
7503fdc516d1 simple unit tests for graal.asm.amd64
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
62 CompilationResult compResult = new CompilationResult();
7756
98143feb3879 provide calling convention for assembler tests
Roland Schatz <roland.schatz@oracle.com>
parents: 7749
diff changeset
63 Buffer codeBuffer = test.generateCode(compResult, codeCache.getTarget(), registerConfig, cc);
7749
52fd6491fca8 avoid generics
Roland Schatz <roland.schatz@oracle.com>
parents: 7746
diff changeset
64 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
65
13669
034706a93f27 CodeCacheProvider.addMethod: add speculationLog argument
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 12488
diff changeset
66 InstalledCode code = codeCache.addMethod(method, compResult, null);
7912
06ecee106195 added unit tests for bytecode and machine code disassembly
Doug Simon <doug.simon@oracle.com>
parents: 7838
diff changeset
67
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
68 DisassemblerProvider dis = Graal.getRequiredCapability(RuntimeProvider.class).getHostBackend().getDisassembler();
7912
06ecee106195 added unit tests for bytecode and machine code disassembly
Doug Simon <doug.simon@oracle.com>
parents: 7838
diff changeset
69 if (dis != null) {
06ecee106195 added unit tests for bytecode and machine code disassembly
Doug Simon <doug.simon@oracle.com>
parents: 7838
diff changeset
70 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
71 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
72 }
06ecee106195 added unit tests for bytecode and machine code disassembly
Doug Simon <doug.simon@oracle.com>
parents: 7838
diff changeset
73 return code;
7718
7503fdc516d1 simple unit tests for graal.asm.amd64
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
74 }
7503fdc516d1 simple unit tests for graal.asm.amd64
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
75
7756
98143feb3879 provide calling convention for assembler tests
Roland Schatz <roland.schatz@oracle.com>
parents: 7749
diff changeset
76 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
77 Method method = getMethod(methodName);
7503fdc516d1 simple unit tests for graal.asm.amd64
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
78 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
79 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
80 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
81 } 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
82 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
83 }
7756
98143feb3879 provide calling convention for assembler tests
Roland Schatz <roland.schatz@oracle.com>
parents: 7749
diff changeset
84 }
7718
7503fdc516d1 simple unit tests for graal.asm.amd64
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
85
7756
98143feb3879 provide calling convention for assembler tests
Roland Schatz <roland.schatz@oracle.com>
parents: 7749
diff changeset
86 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
87 Object actual = runTest(methodName, test, args);
7797
b792a2f3c4da fix error message
Roland Schatz <roland.schatz@oracle.com>
parents: 7756
diff changeset
88 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
89 }
7503fdc516d1 simple unit tests for graal.asm.amd64
Roland Schatz <roland.schatz@oracle.com>
parents:
diff changeset
90 }