comparison graal/com.oracle.jvmci.code/src/com/oracle/jvmci/code/Architecture.java @ 21556:48c1ebd24120

renamed com.oracle.graal.api[meta|code] modules to com.oracle.jvmci.[meta|code] (JBS:GRAAL-53)
author Doug Simon <doug.simon@oracle.com>
date Wed, 27 May 2015 00:36:16 +0200
parents graal/com.oracle.graal.api.code/src/com/oracle/graal/api/code/Architecture.java@d60dd21329f2
children
comparison
equal deleted inserted replaced
21555:d12eaef9af72 21556:48c1ebd24120
1 /*
2 * Copyright (c) 2009, 2011, 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.code;
24
25 import com.oracle.jvmci.meta.Kind;
26 import com.oracle.jvmci.meta.PlatformKind;
27 import java.nio.*;
28 import java.util.*;
29
30 import com.oracle.jvmci.code.Register.RegisterCategory;
31
32 /**
33 * Represents a CPU architecture, including information such as its endianness, CPU registers, word
34 * width, etc.
35 */
36 public abstract class Architecture {
37
38 /**
39 * The number of entries required in a {@link ReferenceMap} covering all the registers that may
40 * store references. The index of a register in the reference map is given by
41 * {@link Register#getReferenceMapIndex()}.
42 */
43 private final int registerReferenceMapSize;
44
45 /**
46 * Represents the natural size of words (typically registers and pointers) of this architecture,
47 * in bytes.
48 */
49 private final int wordSize;
50
51 /**
52 * The name of this architecture (e.g. "AMD64", "SPARCv9").
53 */
54 private final String name;
55
56 /**
57 * Array of all available registers on this architecture. The index of each register in this
58 * array is equal to its {@linkplain Register#number number}.
59 */
60 private final Register[] registers;
61
62 /**
63 * The byte ordering can be either little or big endian.
64 */
65 private final ByteOrder byteOrder;
66
67 /**
68 * Whether the architecture supports unaligned memory accesses.
69 */
70 private final boolean unalignedMemoryAccess;
71
72 /**
73 * Mask of the barrier constants denoting the barriers that are not required to be explicitly
74 * inserted under this architecture.
75 */
76 private final int implicitMemoryBarriers;
77
78 /**
79 * Offset in bytes from the beginning of a call instruction to the displacement.
80 */
81 private final int machineCodeCallDisplacementOffset;
82
83 /**
84 * The size of the return address pushed to the stack by a call instruction. A value of 0
85 * denotes that call linkage uses registers instead (e.g. SPARC).
86 */
87 private final int returnAddressSize;
88
89 protected Architecture(String name, int wordSize, ByteOrder byteOrder, boolean unalignedMemoryAccess, Register[] registers, int implicitMemoryBarriers, int nativeCallDisplacementOffset,
90 int registerReferenceMapSize, int returnAddressSize) {
91 this.name = name;
92 this.registers = registers;
93 this.wordSize = wordSize;
94 this.byteOrder = byteOrder;
95 this.unalignedMemoryAccess = unalignedMemoryAccess;
96 this.implicitMemoryBarriers = implicitMemoryBarriers;
97 this.machineCodeCallDisplacementOffset = nativeCallDisplacementOffset;
98 this.registerReferenceMapSize = registerReferenceMapSize;
99 this.returnAddressSize = returnAddressSize;
100 }
101
102 /**
103 * Converts this architecture to a string.
104 *
105 * @return the string representation of this architecture
106 */
107 @Override
108 public final String toString() {
109 return getName().toLowerCase();
110 }
111
112 public int getRegisterReferenceMapSize() {
113 return registerReferenceMapSize;
114 }
115
116 /**
117 * Gets the natural size of words (typically registers and pointers) of this architecture, in
118 * bytes.
119 */
120 public int getWordSize() {
121 return wordSize;
122 }
123
124 /**
125 * Gets the name of this architecture.
126 */
127 public String getName() {
128 return name;
129 }
130
131 /**
132 * Gets an array of all available registers on this architecture. The index of each register in
133 * this array is equal to its {@linkplain Register#number number}.
134 */
135 public Register[] getRegisters() {
136 return registers.clone();
137 }
138
139 public ByteOrder getByteOrder() {
140 return byteOrder;
141 }
142
143 /**
144 * @return true if the architecture supports unaligned memory accesses.
145 */
146 public boolean supportsUnalignedMemoryAccess() {
147 return unalignedMemoryAccess;
148 }
149
150 /**
151 * Gets the size of the return address pushed to the stack by a call instruction. A value of 0
152 * denotes that call linkage uses registers instead.
153 */
154 public int getReturnAddressSize() {
155 return returnAddressSize;
156 }
157
158 /**
159 * Gets the offset in bytes from the beginning of a call instruction to the displacement.
160 */
161 public int getMachineCodeCallDisplacementOffset() {
162 return machineCodeCallDisplacementOffset;
163 }
164
165 /**
166 * Determines the barriers in a given barrier mask that are explicitly required on this
167 * architecture.
168 *
169 * @param barriers a mask of the barrier constants
170 * @return the value of {@code barriers} minus the barriers unnecessary on this architecture
171 */
172 public final int requiredBarriers(int barriers) {
173 return barriers & ~implicitMemoryBarriers;
174 }
175
176 /**
177 * Gets the size in bytes of the specified kind for this target.
178 *
179 * @param kind the kind for which to get the size
180 *
181 * @return the size in bytes of {@code kind}
182 */
183 public int getSizeInBytes(PlatformKind kind) {
184 switch ((Kind) kind) {
185 case Boolean:
186 return 1;
187 case Byte:
188 return 1;
189 case Char:
190 return 2;
191 case Short:
192 return 2;
193 case Int:
194 return 4;
195 case Long:
196 return 8;
197 case Float:
198 return 4;
199 case Double:
200 return 8;
201 case Object:
202 return wordSize;
203 default:
204 return 0;
205 }
206 }
207
208 /**
209 * Determine whether a kind can be stored in a register of a given category.
210 *
211 * @param category the category of the register
212 * @param kind the kind that should be stored in the register
213 */
214 public abstract boolean canStoreValue(RegisterCategory category, PlatformKind kind);
215
216 /**
217 * Return the largest kind that can be stored in a register of a given category.
218 *
219 * @param category the category of the register
220 * @return the largest kind that can be stored in a register {@code category}
221 */
222 public abstract PlatformKind getLargestStorableKind(RegisterCategory category);
223
224 @Override
225 public final boolean equals(Object obj) {
226 if (obj == this) {
227 return true;
228 }
229 if (obj instanceof Architecture) {
230 Architecture that = (Architecture) obj;
231 if (this.name.equals(that.name)) {
232 assert this.byteOrder.equals(that.byteOrder);
233 assert this.implicitMemoryBarriers == that.implicitMemoryBarriers;
234 assert this.machineCodeCallDisplacementOffset == that.machineCodeCallDisplacementOffset;
235 assert this.registerReferenceMapSize == that.registerReferenceMapSize;
236 assert Arrays.equals(this.registers, that.registers);
237 assert this.returnAddressSize == that.returnAddressSize;
238 assert this.unalignedMemoryAccess == that.unalignedMemoryAccess;
239 assert this.wordSize == that.wordSize;
240 return true;
241 }
242 }
243 return false;
244 }
245
246 @Override
247 public final int hashCode() {
248 return name.hashCode();
249 }
250 }