Mercurial > hg > graal-compiler
annotate graal/com.oracle.graal.hotspot.amd64.test/src/com/oracle/graal/hotspot/amd64/test/AMD64HotSpotFrameOmissionTest.java @ 8582:6a5a980714d4
Move code of InstalledCode substitution to graal.hotspot
author | Matthias Grimmer <grimmer@ssw.jku.at> |
---|---|
date | Fri, 29 Mar 2013 18:06:01 +0100 |
parents | 48daec24df96 |
children | 8a339b567533 |
rev | line source |
---|---|
8351
9ac11897f727
added tests for ensuring frame omission on AMD64 works for simple cases
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
1 /* |
9ac11897f727
added tests for ensuring frame omission on AMD64 works for simple cases
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
2 * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved. |
9ac11897f727
added tests for ensuring frame omission on AMD64 works for simple cases
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
9ac11897f727
added tests for ensuring frame omission on AMD64 works for simple cases
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
4 * |
9ac11897f727
added tests for ensuring frame omission on AMD64 works for simple cases
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
5 * This code is free software; you can redistribute it and/or modify it |
9ac11897f727
added tests for ensuring frame omission on AMD64 works for simple cases
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
6 * under the terms of the GNU General Public License version 2 only, as |
9ac11897f727
added tests for ensuring frame omission on AMD64 works for simple cases
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
7 * published by the Free Software Foundation. |
9ac11897f727
added tests for ensuring frame omission on AMD64 works for simple cases
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
8 * |
9ac11897f727
added tests for ensuring frame omission on AMD64 works for simple cases
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
9 * This code is distributed in the hope that it will be useful, but WITHOUT |
9ac11897f727
added tests for ensuring frame omission on AMD64 works for simple cases
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
9ac11897f727
added tests for ensuring frame omission on AMD64 works for simple cases
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
9ac11897f727
added tests for ensuring frame omission on AMD64 works for simple cases
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
12 * version 2 for more details (a copy is included in the LICENSE file that |
9ac11897f727
added tests for ensuring frame omission on AMD64 works for simple cases
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
13 * accompanied this code). |
9ac11897f727
added tests for ensuring frame omission on AMD64 works for simple cases
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
14 * |
9ac11897f727
added tests for ensuring frame omission on AMD64 works for simple cases
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
15 * You should have received a copy of the GNU General Public License version |
9ac11897f727
added tests for ensuring frame omission on AMD64 works for simple cases
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
16 * 2 along with this work; if not, write to the Free Software Foundation, |
9ac11897f727
added tests for ensuring frame omission on AMD64 works for simple cases
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
9ac11897f727
added tests for ensuring frame omission on AMD64 works for simple cases
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
18 * |
9ac11897f727
added tests for ensuring frame omission on AMD64 works for simple cases
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
9ac11897f727
added tests for ensuring frame omission on AMD64 works for simple cases
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
20 * or visit www.oracle.com if you need additional information or have any |
9ac11897f727
added tests for ensuring frame omission on AMD64 works for simple cases
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
21 * questions. |
9ac11897f727
added tests for ensuring frame omission on AMD64 works for simple cases
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
22 */ |
8366
733e2b88ff26
moved HotSpot specific AMD64FrameOmissionTest to (new) project com.oracle.graal.hotspot.amd64.test and renamed it to AMD64HotSpotFrameOmissionTest
Doug Simon <doug.simon@oracle.com>
parents:
8359
diff
changeset
|
23 package com.oracle.graal.hotspot.amd64.test; |
8351
9ac11897f727
added tests for ensuring frame omission on AMD64 works for simple cases
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
24 |
9ac11897f727
added tests for ensuring frame omission on AMD64 works for simple cases
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
25 import static com.oracle.graal.amd64.AMD64.*; |
9ac11897f727
added tests for ensuring frame omission on AMD64 works for simple cases
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
26 |
9ac11897f727
added tests for ensuring frame omission on AMD64 works for simple cases
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
27 import java.lang.reflect.*; |
8369
8448cbac78e4
made frame omission test ignore padding instructions at the end of installed code
Doug Simon <doug.simon@oracle.com>
parents:
8366
diff
changeset
|
28 import java.util.*; |
8351
9ac11897f727
added tests for ensuring frame omission on AMD64 works for simple cases
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
29 |
9ac11897f727
added tests for ensuring frame omission on AMD64 works for simple cases
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
30 import org.junit.*; |
9ac11897f727
added tests for ensuring frame omission on AMD64 works for simple cases
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
31 |
9ac11897f727
added tests for ensuring frame omission on AMD64 works for simple cases
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
32 import com.oracle.graal.api.code.*; |
9ac11897f727
added tests for ensuring frame omission on AMD64 works for simple cases
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
33 import com.oracle.graal.api.meta.*; |
9ac11897f727
added tests for ensuring frame omission on AMD64 works for simple cases
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
34 import com.oracle.graal.api.runtime.*; |
9ac11897f727
added tests for ensuring frame omission on AMD64 works for simple cases
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
35 import com.oracle.graal.asm.amd64.*; |
9ac11897f727
added tests for ensuring frame omission on AMD64 works for simple cases
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
36 import com.oracle.graal.compiler.test.*; |
9ac11897f727
added tests for ensuring frame omission on AMD64 works for simple cases
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
37 |
9ac11897f727
added tests for ensuring frame omission on AMD64 works for simple cases
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
38 /** |
9ac11897f727
added tests for ensuring frame omission on AMD64 works for simple cases
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
39 * Ensures that frame omission works in cases where it is expected to. |
9ac11897f727
added tests for ensuring frame omission on AMD64 works for simple cases
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
40 */ |
8366
733e2b88ff26
moved HotSpot specific AMD64FrameOmissionTest to (new) project com.oracle.graal.hotspot.amd64.test and renamed it to AMD64HotSpotFrameOmissionTest
Doug Simon <doug.simon@oracle.com>
parents:
8359
diff
changeset
|
41 public class AMD64HotSpotFrameOmissionTest extends GraalCompilerTest { |
8351
9ac11897f727
added tests for ensuring frame omission on AMD64 works for simple cases
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
42 |
9ac11897f727
added tests for ensuring frame omission on AMD64 works for simple cases
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
43 interface CodeGenerator { |
9ac11897f727
added tests for ensuring frame omission on AMD64 works for simple cases
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
44 |
9ac11897f727
added tests for ensuring frame omission on AMD64 works for simple cases
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
45 void generateCode(AMD64Assembler asm); |
9ac11897f727
added tests for ensuring frame omission on AMD64 works for simple cases
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
46 } |
9ac11897f727
added tests for ensuring frame omission on AMD64 works for simple cases
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
47 |
9ac11897f727
added tests for ensuring frame omission on AMD64 works for simple cases
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
48 public static void test1snippet() { |
9ac11897f727
added tests for ensuring frame omission on AMD64 works for simple cases
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
49 return; |
9ac11897f727
added tests for ensuring frame omission on AMD64 works for simple cases
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
50 } |
9ac11897f727
added tests for ensuring frame omission on AMD64 works for simple cases
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
51 |
9ac11897f727
added tests for ensuring frame omission on AMD64 works for simple cases
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
52 @Test |
9ac11897f727
added tests for ensuring frame omission on AMD64 works for simple cases
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
53 public void test1() { |
9ac11897f727
added tests for ensuring frame omission on AMD64 works for simple cases
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
54 testHelper("test1snippet", new CodeGenerator() { |
9ac11897f727
added tests for ensuring frame omission on AMD64 works for simple cases
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
55 |
9ac11897f727
added tests for ensuring frame omission on AMD64 works for simple cases
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
56 @Override |
9ac11897f727
added tests for ensuring frame omission on AMD64 works for simple cases
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
57 public void generateCode(AMD64Assembler asm) { |
9ac11897f727
added tests for ensuring frame omission on AMD64 works for simple cases
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
58 asm.ret(0); |
9ac11897f727
added tests for ensuring frame omission on AMD64 works for simple cases
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
59 } |
9ac11897f727
added tests for ensuring frame omission on AMD64 works for simple cases
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
60 }); |
9ac11897f727
added tests for ensuring frame omission on AMD64 works for simple cases
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
61 } |
9ac11897f727
added tests for ensuring frame omission on AMD64 works for simple cases
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
62 |
9ac11897f727
added tests for ensuring frame omission on AMD64 works for simple cases
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
63 public static int test2snippet(int x) { |
9ac11897f727
added tests for ensuring frame omission on AMD64 works for simple cases
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
64 return x + 5; |
9ac11897f727
added tests for ensuring frame omission on AMD64 works for simple cases
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
65 } |
9ac11897f727
added tests for ensuring frame omission on AMD64 works for simple cases
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
66 |
9ac11897f727
added tests for ensuring frame omission on AMD64 works for simple cases
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
67 @Test |
9ac11897f727
added tests for ensuring frame omission on AMD64 works for simple cases
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
68 public void test2() { |
9ac11897f727
added tests for ensuring frame omission on AMD64 works for simple cases
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
69 testHelper("test2snippet", new CodeGenerator() { |
9ac11897f727
added tests for ensuring frame omission on AMD64 works for simple cases
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
70 |
9ac11897f727
added tests for ensuring frame omission on AMD64 works for simple cases
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
71 @Override |
9ac11897f727
added tests for ensuring frame omission on AMD64 works for simple cases
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
72 public void generateCode(AMD64Assembler asm) { |
9ac11897f727
added tests for ensuring frame omission on AMD64 works for simple cases
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
73 asm.addl(rsi, 5); |
9ac11897f727
added tests for ensuring frame omission on AMD64 works for simple cases
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
74 asm.movl(rax, rsi); |
9ac11897f727
added tests for ensuring frame omission on AMD64 works for simple cases
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
75 asm.ret(0); |
9ac11897f727
added tests for ensuring frame omission on AMD64 works for simple cases
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
76 } |
9ac11897f727
added tests for ensuring frame omission on AMD64 works for simple cases
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
77 }); |
9ac11897f727
added tests for ensuring frame omission on AMD64 works for simple cases
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
78 } |
9ac11897f727
added tests for ensuring frame omission on AMD64 works for simple cases
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
79 |
8374
48daec24df96
made frame omission test work in -graal as well as -server VM
Doug Simon <doug.simon@oracle.com>
parents:
8371
diff
changeset
|
80 public static long test3snippet(long x) { |
48daec24df96
made frame omission test work in -graal as well as -server VM
Doug Simon <doug.simon@oracle.com>
parents:
8371
diff
changeset
|
81 return 1 + x; |
8351
9ac11897f727
added tests for ensuring frame omission on AMD64 works for simple cases
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
82 } |
9ac11897f727
added tests for ensuring frame omission on AMD64 works for simple cases
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
83 |
9ac11897f727
added tests for ensuring frame omission on AMD64 works for simple cases
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
84 @Test |
9ac11897f727
added tests for ensuring frame omission on AMD64 works for simple cases
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
85 public void test3() { |
9ac11897f727
added tests for ensuring frame omission on AMD64 works for simple cases
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
86 testHelper("test3snippet", new CodeGenerator() { |
9ac11897f727
added tests for ensuring frame omission on AMD64 works for simple cases
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
87 |
9ac11897f727
added tests for ensuring frame omission on AMD64 works for simple cases
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
88 @Override |
9ac11897f727
added tests for ensuring frame omission on AMD64 works for simple cases
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
89 public void generateCode(AMD64Assembler asm) { |
8374
48daec24df96
made frame omission test work in -graal as well as -server VM
Doug Simon <doug.simon@oracle.com>
parents:
8371
diff
changeset
|
90 asm.addq(rsi, 1); |
48daec24df96
made frame omission test work in -graal as well as -server VM
Doug Simon <doug.simon@oracle.com>
parents:
8371
diff
changeset
|
91 asm.movq(rax, rsi); |
8351
9ac11897f727
added tests for ensuring frame omission on AMD64 works for simple cases
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
92 asm.ret(0); |
9ac11897f727
added tests for ensuring frame omission on AMD64 works for simple cases
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
93 } |
9ac11897f727
added tests for ensuring frame omission on AMD64 works for simple cases
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
94 }); |
9ac11897f727
added tests for ensuring frame omission on AMD64 works for simple cases
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
95 } |
9ac11897f727
added tests for ensuring frame omission on AMD64 works for simple cases
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
96 |
9ac11897f727
added tests for ensuring frame omission on AMD64 works for simple cases
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
97 private void testHelper(String name, CodeGenerator gen) { |
9ac11897f727
added tests for ensuring frame omission on AMD64 works for simple cases
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
98 Method method = getMethod(name); |
9ac11897f727
added tests for ensuring frame omission on AMD64 works for simple cases
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
99 ResolvedJavaMethod javaMethod = runtime.lookupJavaMethod(method); |
9ac11897f727
added tests for ensuring frame omission on AMD64 works for simple cases
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
100 InstalledCode installedCode = getCode(javaMethod, parse(method)); |
9ac11897f727
added tests for ensuring frame omission on AMD64 works for simple cases
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
101 |
9ac11897f727
added tests for ensuring frame omission on AMD64 works for simple cases
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
102 CodeCacheProvider codeCache = Graal.getRequiredCapability(CodeCacheProvider.class); |
9ac11897f727
added tests for ensuring frame omission on AMD64 works for simple cases
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
103 TargetDescription target = codeCache.getTarget(); |
9ac11897f727
added tests for ensuring frame omission on AMD64 works for simple cases
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
104 RegisterConfig registerConfig = codeCache.lookupRegisterConfig(); |
9ac11897f727
added tests for ensuring frame omission on AMD64 works for simple cases
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
105 AMD64Assembler asm = new AMD64Assembler(target, registerConfig); |
9ac11897f727
added tests for ensuring frame omission on AMD64 works for simple cases
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
106 |
9ac11897f727
added tests for ensuring frame omission on AMD64 works for simple cases
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
107 gen.generateCode(asm); |
9ac11897f727
added tests for ensuring frame omission on AMD64 works for simple cases
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
108 byte[] expectedCode = asm.codeBuffer.close(true); |
8369
8448cbac78e4
made frame omission test ignore padding instructions at the end of installed code
Doug Simon <doug.simon@oracle.com>
parents:
8366
diff
changeset
|
109 |
8448cbac78e4
made frame omission test ignore padding instructions at the end of installed code
Doug Simon <doug.simon@oracle.com>
parents:
8366
diff
changeset
|
110 // Only compare up to expectedCode.length bytes to ignore |
8448cbac78e4
made frame omission test ignore padding instructions at the end of installed code
Doug Simon <doug.simon@oracle.com>
parents:
8366
diff
changeset
|
111 // padding instructions adding during code installation |
8448cbac78e4
made frame omission test ignore padding instructions at the end of installed code
Doug Simon <doug.simon@oracle.com>
parents:
8366
diff
changeset
|
112 byte[] actualCode = Arrays.copyOf(installedCode.getCode(), expectedCode.length); |
8351
9ac11897f727
added tests for ensuring frame omission on AMD64 works for simple cases
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
113 |
9ac11897f727
added tests for ensuring frame omission on AMD64 works for simple cases
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
114 Assert.assertArrayEquals(expectedCode, actualCode); |
9ac11897f727
added tests for ensuring frame omission on AMD64 works for simple cases
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
115 } |
9ac11897f727
added tests for ensuring frame omission on AMD64 works for simple cases
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
116 } |