Mercurial > hg > truffle
comparison graal/com.oracle.jvmci.asm.amd64.test/src/com/oracle/jvmci/asm/amd64/test/IncrementDecrementMacroTest.java @ 21709:3c17c0c41a6b
moved com.oracle.asm.**.test to JVMCI namespace (JBS:GRAAL-53)
author | Doug Simon <doug.simon@oracle.com> |
---|---|
date | Wed, 03 Jun 2015 18:33:23 +0200 |
parents | graal/com.oracle.graal.asm.amd64.test/src/com/oracle/graal/asm/amd64/test/IncrementDecrementMacroTest.java@6df25b1418be |
children |
comparison
equal
deleted
inserted
replaced
21708:6df25b1418be | 21709:3c17c0c41a6b |
---|---|
1 /* | |
2 * Copyright (c) 2015, 2015, Oracle and/or its affiliates. All rights reserved. | |
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. | |
4 * | |
5 * This code is free software; you can redistribute it and/or modify it | |
6 * under the terms of the GNU General Public License version 2 only, as | |
7 * published by the Free Software Foundation. | |
8 * | |
9 * This code is distributed in the hope that it will be useful, but WITHOUT | |
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | |
12 * version 2 for more details (a copy is included in the LICENSE file that | |
13 * accompanied this code). | |
14 * | |
15 * You should have received a copy of the GNU General Public License version | |
16 * 2 along with this work; if not, write to the Free Software Foundation, | |
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. | |
18 * | |
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA | |
20 * or visit www.oracle.com if you need additional information or have any | |
21 * questions. | |
22 */ | |
23 package com.oracle.jvmci.asm.amd64.test; | |
24 | |
25 import com.oracle.jvmci.amd64.*; | |
26 import com.oracle.jvmci.asm.amd64.*; | |
27 import com.oracle.jvmci.asm.test.*; | |
28 import com.oracle.jvmci.code.RegisterConfig; | |
29 import com.oracle.jvmci.code.TargetDescription; | |
30 import com.oracle.jvmci.code.Register; | |
31 import com.oracle.jvmci.code.CallingConvention; | |
32 import com.oracle.jvmci.code.CompilationResult; | |
33 import com.oracle.jvmci.meta.Kind; | |
34 | |
35 import static com.oracle.jvmci.code.ValueUtil.*; | |
36 import static com.oracle.jvmci.common.UnsafeAccess.*; | |
37 import static org.junit.Assume.*; | |
38 | |
39 import java.lang.reflect.*; | |
40 | |
41 import org.junit.*; | |
42 | |
43 public class IncrementDecrementMacroTest extends AssemblerTest { | |
44 | |
45 @Before | |
46 public void checkAMD64() { | |
47 assumeTrue("skipping AMD64 specific test", codeCache.getTarget().arch instanceof AMD64); | |
48 } | |
49 | |
50 public static class LongField { | |
51 public long x; | |
52 | |
53 LongField(long x) { | |
54 this.x = x; | |
55 } | |
56 } | |
57 | |
58 private static class IncrementCodeGenTest implements CodeGenTest { | |
59 final int value; | |
60 | |
61 public IncrementCodeGenTest(int value) { | |
62 this.value = value; | |
63 } | |
64 | |
65 @Override | |
66 public byte[] generateCode(CompilationResult compResult, TargetDescription target, RegisterConfig registerConfig, CallingConvention cc) { | |
67 AMD64MacroAssembler asm = new AMD64MacroAssembler(target, registerConfig); | |
68 Register ret = registerConfig.getReturnRegister(Kind.Int); | |
69 try { | |
70 Field f = LongField.class.getDeclaredField("x"); | |
71 AMD64Address arg = new AMD64Address(asRegister(cc.getArgument(0)), (int) unsafe.objectFieldOffset(f)); | |
72 asm.incrementq(arg, value); | |
73 asm.movq(ret, arg); | |
74 asm.ret(0); | |
75 return asm.close(true); | |
76 } catch (Exception e) { | |
77 throw new RuntimeException("exception while trying to generate field access:", e); | |
78 } | |
79 } | |
80 } | |
81 | |
82 private void assertIncrement(long initValue, int increment) { | |
83 assertReturn("longFieldStubIncrement", new IncrementCodeGenTest(increment), initValue + increment, new LongField(initValue)); | |
84 } | |
85 | |
86 private void assertIncrements(int increment) { | |
87 assertIncrement(0x4242_4242_4242_4242L, increment); | |
88 } | |
89 | |
90 @SuppressWarnings("unused") | |
91 public static long longFieldStubIncrement(LongField arg) { | |
92 return 0; | |
93 } | |
94 | |
95 private static class DecrementCodeGenTest implements CodeGenTest { | |
96 final int value; | |
97 | |
98 public DecrementCodeGenTest(int value) { | |
99 this.value = value; | |
100 } | |
101 | |
102 @Override | |
103 public byte[] generateCode(CompilationResult compResult, TargetDescription target, RegisterConfig registerConfig, CallingConvention cc) { | |
104 AMD64MacroAssembler asm = new AMD64MacroAssembler(target, registerConfig); | |
105 Register ret = registerConfig.getReturnRegister(Kind.Int); | |
106 try { | |
107 Field f = LongField.class.getDeclaredField("x"); | |
108 AMD64Address arg = new AMD64Address(asRegister(cc.getArgument(0)), (int) unsafe.objectFieldOffset(f)); | |
109 asm.decrementq(arg, value); | |
110 asm.movq(ret, arg); | |
111 asm.ret(0); | |
112 return asm.close(true); | |
113 } catch (Exception e) { | |
114 throw new RuntimeException("exception while trying to generate field access:", e); | |
115 } | |
116 } | |
117 } | |
118 | |
119 private void assertDecrement(long initValue, int increment) { | |
120 assertReturn("longFieldStubDecrement", new DecrementCodeGenTest(increment), initValue - increment, new LongField(initValue)); | |
121 } | |
122 | |
123 private void assertDecrements(int increment) { | |
124 assertDecrement(0x4242_4242_4242_4242L, increment); | |
125 } | |
126 | |
127 @SuppressWarnings("unused") | |
128 public static long longFieldStubDecrement(LongField arg) { | |
129 return 0; | |
130 } | |
131 | |
132 @Test | |
133 public void incrementMemTest0() { | |
134 int increment = 0; | |
135 assertIncrements(increment); | |
136 } | |
137 | |
138 @Test | |
139 public void incrementMemTest1() { | |
140 int increment = 1; | |
141 assertIncrements(increment); | |
142 } | |
143 | |
144 @Test | |
145 public void incrementMemTest2() { | |
146 int increment = 2; | |
147 assertIncrements(increment); | |
148 } | |
149 | |
150 @Test | |
151 public void incrementMemTest3() { | |
152 int increment = Integer.MAX_VALUE; | |
153 assertIncrements(increment); | |
154 } | |
155 | |
156 @Test | |
157 public void incrementMemTest4() { | |
158 int increment = Integer.MIN_VALUE; | |
159 assertIncrements(increment); | |
160 } | |
161 | |
162 @Test | |
163 public void incrementMemTest5() { | |
164 int increment = -1; | |
165 assertIncrements(increment); | |
166 } | |
167 | |
168 @Test | |
169 public void incrementMemTest6() { | |
170 int increment = -2; | |
171 assertIncrements(increment); | |
172 } | |
173 | |
174 @Test | |
175 public void incrementMemTest7() { | |
176 int increment = -0x1000_0000; | |
177 assertIncrements(increment); | |
178 } | |
179 | |
180 @Test | |
181 public void decrementMemTest0() { | |
182 int decrement = 0; | |
183 assertDecrements(decrement); | |
184 } | |
185 | |
186 @Test | |
187 public void decrementMemTest1() { | |
188 int decrement = 1; | |
189 assertDecrements(decrement); | |
190 } | |
191 | |
192 @Test | |
193 public void decrementMemTest2() { | |
194 int decrement = 2; | |
195 assertDecrements(decrement); | |
196 } | |
197 | |
198 @Test | |
199 public void decrementMemTest3() { | |
200 int decrement = Integer.MAX_VALUE; | |
201 assertDecrements(decrement); | |
202 } | |
203 | |
204 @Test | |
205 public void decrementMemTest4() { | |
206 int decrement = Integer.MIN_VALUE; | |
207 assertDecrements(decrement); | |
208 } | |
209 | |
210 @Test | |
211 public void decrementMemTest5() { | |
212 int decrement = -1; | |
213 assertDecrements(decrement); | |
214 } | |
215 | |
216 @Test | |
217 public void decrementMemTest6() { | |
218 int decrement = -2; | |
219 assertDecrements(decrement); | |
220 } | |
221 | |
222 @Test | |
223 public void decrementMemTest7() { | |
224 int decrement = -0x1000_0000; | |
225 assertDecrements(decrement); | |
226 } | |
227 | |
228 } |