comparison graal/com.oracle.max.cri/src/com/oracle/max/cri/ci/CiTarget.java @ 4199:aaac4894175c

Renamed cri packages from sun to oracle.
author Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
date Tue, 03 Jan 2012 16:29:28 +0100
parents graal/com.oracle.max.cri/src/com/sun/cri/ci/CiTarget.java@319860ae697a
children 438ab53efdd0
comparison
equal deleted inserted replaced
4198:8c9c0e1eaab1 4199:aaac4894175c
1 /*
2 * Copyright (c) 2009, 2012, 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.max.cri.ci;
24
25
26 /**
27 * Represents the target machine for a compiler, including the CPU architecture, the size of pointers and references,
28 * alignment of stacks, caches, etc.
29 */
30 public class CiTarget {
31 public final CiArchitecture arch;
32
33 /**
34 * The OS page size.
35 */
36 public final int pageSize;
37
38 /**
39 * Specifies if this is a multi-processor system.
40 */
41 public final boolean isMP;
42
43 /**
44 * Specifies if this target supports encoding objects inline in the machine code.
45 */
46 public final boolean inlineObjects;
47
48 /**
49 * The machine word size on this target.
50 */
51 public final int wordSize;
52
53 /**
54 * The CiKind to be used for representing raw pointers and CPU registers.
55 */
56 public final CiKind wordKind;
57
58 /**
59 * The stack alignment requirement of the platform. For example,
60 * from Appendix D of <a href="http://www.intel.com/Assets/PDF/manual/248966.pdf">Intel 64 and IA-32 Architectures Optimization Reference Manual</a>:
61 * <pre>
62 * "It is important to ensure that the stack frame is aligned to a
63 * 16-byte boundary upon function entry to keep local __m128 data,
64 * parameters, and XMM register spill locations aligned throughout
65 * a function invocation."
66 * </pre>
67 */
68 public final int stackAlignment;
69
70 /**
71 * @see http://docs.sun.com/app/docs/doc/806-0477/6j9r2e2b9?a=view
72 */
73 public final int stackBias;
74
75 /**
76 * The cache alignment.
77 */
78 public final int cacheAlignment;
79
80 /**
81 * Specifies how {@code long} and {@code double} constants are to be stored
82 * in {@linkplain CiFrame frames}. This is useful for VMs such as HotSpot
83 * where convention the interpreter uses is that the second local
84 * holds the first raw word of the native long or double representation.
85 * This is actually reasonable, since locals and stack arrays
86 * grow downwards in all implementations.
87 * If, on some machine, the interpreter's Java locals or stack
88 * were to grow upwards, the embedded doubles would be word-swapped.)
89 */
90 public final boolean debugInfoDoubleWordsInSecondSlot;
91
92 /**
93 * Temporary flag to distinguish between the semantics necessary for HotSpot and Maxine.
94 */
95 // TODO This should go away when XIR goes away, and the logic be part of the VM-specific lowering.
96 public final boolean invokeSnippetAfterArguments;
97
98 public CiTarget(CiArchitecture arch,
99 boolean isMP,
100 int stackAlignment,
101 int pageSize,
102 int cacheAlignment,
103 boolean inlineObjects,
104 boolean debugInfoDoubleWordsInSecondSlot,
105 boolean invokeSnippetAfterArguments) {
106 this.arch = arch;
107 this.pageSize = pageSize;
108 this.isMP = isMP;
109 this.wordSize = arch.wordSize;
110 if (wordSize == 8) {
111 this.wordKind = CiKind.Long;
112 } else {
113 this.wordKind = CiKind.Int;
114 }
115 this.stackAlignment = stackAlignment;
116 this.stackBias = 0; // TODO: configure with param once SPARC port exists
117 this.cacheAlignment = cacheAlignment;
118 this.inlineObjects = inlineObjects;
119 this.debugInfoDoubleWordsInSecondSlot = debugInfoDoubleWordsInSecondSlot;
120 this.invokeSnippetAfterArguments = invokeSnippetAfterArguments;
121 }
122
123 /**
124 * Gets the size in bytes of the specified kind for this target.
125 *
126 * @param kind the kind for which to get the size
127 * @return the size in bytes of {@code kind}
128 */
129 public int sizeInBytes(CiKind kind) {
130 // Checkstyle: stop
131 switch (kind) {
132 case Boolean: return 1;
133 case Byte: return 1;
134 case Char: return 2;
135 case Short: return 2;
136 case Int: return 4;
137 case Long: return 8;
138 case Float: return 4;
139 case Double: return 8;
140 case Object: return wordSize;
141 case Jsr: return 4;
142 default: return 0;
143 }
144 // Checkstyle: resume
145 }
146
147 /**
148 * Aligns the given frame size (without return instruction pointer) to the stack
149 * alignment size and return the aligned size (without return instruction pointer).
150 * @param frameSize the initial frame size to be aligned
151 * @return the aligned frame size
152 */
153 public int alignFrameSize(int frameSize) {
154 int x = frameSize + arch.returnAddressSize + (stackAlignment - 1);
155 return (x / stackAlignment) * stackAlignment - arch.returnAddressSize;
156 }
157 }