annotate agent/src/share/classes/sun/jvm/hotspot/types/basic/BasicTypeDataBase.java @ 113:ba764ed4b6f2

6420645: Create a vm that uses compressed oops for up to 32gb heapsizes Summary: Compressed oops in instances, arrays, and headers. Code contributors are coleenp, phh, never, swamyv Reviewed-by: jmasa, kamg, acorn, tbell, kvn, rasbold
author coleenp
date Sun, 13 Apr 2008 17:43:42 -0400
parents a61af66fc99e
children d1605aabd0a1
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
a61af66fc99e Initial load
duke
parents:
diff changeset
1 /*
a61af66fc99e Initial load
duke
parents:
diff changeset
2 * Copyright 2000-2004 Sun Microsystems, Inc. All Rights Reserved.
a61af66fc99e Initial load
duke
parents:
diff changeset
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
a61af66fc99e Initial load
duke
parents:
diff changeset
4 *
a61af66fc99e Initial load
duke
parents:
diff changeset
5 * This code is free software; you can redistribute it and/or modify it
a61af66fc99e Initial load
duke
parents:
diff changeset
6 * under the terms of the GNU General Public License version 2 only, as
a61af66fc99e Initial load
duke
parents:
diff changeset
7 * published by the Free Software Foundation.
a61af66fc99e Initial load
duke
parents:
diff changeset
8 *
a61af66fc99e Initial load
duke
parents:
diff changeset
9 * This code is distributed in the hope that it will be useful, but WITHOUT
a61af66fc99e Initial load
duke
parents:
diff changeset
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
a61af66fc99e Initial load
duke
parents:
diff changeset
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
a61af66fc99e Initial load
duke
parents:
diff changeset
12 * version 2 for more details (a copy is included in the LICENSE file that
a61af66fc99e Initial load
duke
parents:
diff changeset
13 * accompanied this code).
a61af66fc99e Initial load
duke
parents:
diff changeset
14 *
a61af66fc99e Initial load
duke
parents:
diff changeset
15 * You should have received a copy of the GNU General Public License version
a61af66fc99e Initial load
duke
parents:
diff changeset
16 * 2 along with this work; if not, write to the Free Software Foundation,
a61af66fc99e Initial load
duke
parents:
diff changeset
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
a61af66fc99e Initial load
duke
parents:
diff changeset
18 *
a61af66fc99e Initial load
duke
parents:
diff changeset
19 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
a61af66fc99e Initial load
duke
parents:
diff changeset
20 * CA 95054 USA or visit www.sun.com if you need additional information or
a61af66fc99e Initial load
duke
parents:
diff changeset
21 * have any questions.
a61af66fc99e Initial load
duke
parents:
diff changeset
22 *
a61af66fc99e Initial load
duke
parents:
diff changeset
23 */
a61af66fc99e Initial load
duke
parents:
diff changeset
24
a61af66fc99e Initial load
duke
parents:
diff changeset
25 package sun.jvm.hotspot.types.basic;
a61af66fc99e Initial load
duke
parents:
diff changeset
26
a61af66fc99e Initial load
duke
parents:
diff changeset
27 import java.util.*;
a61af66fc99e Initial load
duke
parents:
diff changeset
28 import sun.jvm.hotspot.debugger.*;
a61af66fc99e Initial load
duke
parents:
diff changeset
29 import sun.jvm.hotspot.types.*;
113
ba764ed4b6f2 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 0
diff changeset
30 import sun.jvm.hotspot.runtime.VM;
0
a61af66fc99e Initial load
duke
parents:
diff changeset
31
a61af66fc99e Initial load
duke
parents:
diff changeset
32 /** <P> This is a basic implementation of the TypeDataBase interface.
a61af66fc99e Initial load
duke
parents:
diff changeset
33 It allows an external type database builder to add types to be
a61af66fc99e Initial load
duke
parents:
diff changeset
34 consumed by a client through the Type interfaces. It has no
a61af66fc99e Initial load
duke
parents:
diff changeset
35 knowledge of symbol lookup; for example, the builder is
a61af66fc99e Initial load
duke
parents:
diff changeset
36 responsible for providing the addresses of static fields. </P>
a61af66fc99e Initial load
duke
parents:
diff changeset
37
a61af66fc99e Initial load
duke
parents:
diff changeset
38 <P> Among other things, the database builder is responsible for
a61af66fc99e Initial load
duke
parents:
diff changeset
39 providing the Types for the Java primitive types, as well as their
a61af66fc99e Initial load
duke
parents:
diff changeset
40 sizes. </P>
a61af66fc99e Initial load
duke
parents:
diff changeset
41 */
a61af66fc99e Initial load
duke
parents:
diff changeset
42
a61af66fc99e Initial load
duke
parents:
diff changeset
43 public class BasicTypeDataBase implements TypeDataBase {
a61af66fc99e Initial load
duke
parents:
diff changeset
44 private MachineDescription machDesc;
a61af66fc99e Initial load
duke
parents:
diff changeset
45 private VtblAccess vtblAccess;
a61af66fc99e Initial load
duke
parents:
diff changeset
46 /** Maps strings to Type objects. This does not contain the primitive types. */
a61af66fc99e Initial load
duke
parents:
diff changeset
47 private Map nameToTypeMap = new HashMap();
a61af66fc99e Initial load
duke
parents:
diff changeset
48 /** Maps strings to Integers, used for enums, etc. */
a61af66fc99e Initial load
duke
parents:
diff changeset
49 private Map nameToIntConstantMap = new HashMap();
a61af66fc99e Initial load
duke
parents:
diff changeset
50 /** Maps strings to Longs, used for 32/64-bit constants, etc. */
a61af66fc99e Initial load
duke
parents:
diff changeset
51 private Map nameToLongConstantMap = new HashMap();
a61af66fc99e Initial load
duke
parents:
diff changeset
52 /** Primitive types. */
a61af66fc99e Initial load
duke
parents:
diff changeset
53 private Type jbooleanType;
a61af66fc99e Initial load
duke
parents:
diff changeset
54 private Type jbyteType;
a61af66fc99e Initial load
duke
parents:
diff changeset
55 private Type jcharType;
a61af66fc99e Initial load
duke
parents:
diff changeset
56 private Type jdoubleType;
a61af66fc99e Initial load
duke
parents:
diff changeset
57 private Type jfloatType;
a61af66fc99e Initial load
duke
parents:
diff changeset
58 private Type jintType;
a61af66fc99e Initial load
duke
parents:
diff changeset
59 private Type jlongType;
a61af66fc99e Initial load
duke
parents:
diff changeset
60 private Type jshortType;
a61af66fc99e Initial load
duke
parents:
diff changeset
61
a61af66fc99e Initial load
duke
parents:
diff changeset
62 /** For debugging */
a61af66fc99e Initial load
duke
parents:
diff changeset
63 private static final boolean DEBUG;
a61af66fc99e Initial load
duke
parents:
diff changeset
64 static {
a61af66fc99e Initial load
duke
parents:
diff changeset
65 DEBUG = System.getProperty("sun.jvm.hotspot.types.basic.BasicTypeDataBase.DEBUG") != null;
a61af66fc99e Initial load
duke
parents:
diff changeset
66 }
a61af66fc99e Initial load
duke
parents:
diff changeset
67
a61af66fc99e Initial load
duke
parents:
diff changeset
68 public BasicTypeDataBase(MachineDescription machDesc, VtblAccess vtblAccess) {
a61af66fc99e Initial load
duke
parents:
diff changeset
69 this.machDesc = machDesc;
a61af66fc99e Initial load
duke
parents:
diff changeset
70 this.vtblAccess = vtblAccess;
a61af66fc99e Initial load
duke
parents:
diff changeset
71 }
a61af66fc99e Initial load
duke
parents:
diff changeset
72
a61af66fc99e Initial load
duke
parents:
diff changeset
73 public Type lookupType(String cTypeName) {
a61af66fc99e Initial load
duke
parents:
diff changeset
74 return lookupType(cTypeName, true);
a61af66fc99e Initial load
duke
parents:
diff changeset
75 }
a61af66fc99e Initial load
duke
parents:
diff changeset
76
a61af66fc99e Initial load
duke
parents:
diff changeset
77 public Type lookupType(String cTypeName, boolean throwException) {
a61af66fc99e Initial load
duke
parents:
diff changeset
78 Type type = (Type) nameToTypeMap.get(cTypeName);
a61af66fc99e Initial load
duke
parents:
diff changeset
79 if (type == null && throwException) {
a61af66fc99e Initial load
duke
parents:
diff changeset
80 throw new RuntimeException("No type named \"" + cTypeName + "\" in database");
a61af66fc99e Initial load
duke
parents:
diff changeset
81 }
a61af66fc99e Initial load
duke
parents:
diff changeset
82 return type;
a61af66fc99e Initial load
duke
parents:
diff changeset
83 }
a61af66fc99e Initial load
duke
parents:
diff changeset
84
a61af66fc99e Initial load
duke
parents:
diff changeset
85 public Integer lookupIntConstant(String constantName) {
a61af66fc99e Initial load
duke
parents:
diff changeset
86 return lookupIntConstant(constantName, true);
a61af66fc99e Initial load
duke
parents:
diff changeset
87 }
a61af66fc99e Initial load
duke
parents:
diff changeset
88
a61af66fc99e Initial load
duke
parents:
diff changeset
89 public Integer lookupIntConstant(String constantName, boolean throwException) {
a61af66fc99e Initial load
duke
parents:
diff changeset
90 Integer i = (Integer) nameToIntConstantMap.get(constantName);
a61af66fc99e Initial load
duke
parents:
diff changeset
91 if (i == null) {
a61af66fc99e Initial load
duke
parents:
diff changeset
92 if (throwException) {
a61af66fc99e Initial load
duke
parents:
diff changeset
93 throw new RuntimeException("No integer constant named \"" + constantName + "\" present in type database");
a61af66fc99e Initial load
duke
parents:
diff changeset
94 }
a61af66fc99e Initial load
duke
parents:
diff changeset
95 }
a61af66fc99e Initial load
duke
parents:
diff changeset
96 return i;
a61af66fc99e Initial load
duke
parents:
diff changeset
97 }
a61af66fc99e Initial load
duke
parents:
diff changeset
98
a61af66fc99e Initial load
duke
parents:
diff changeset
99 public Long lookupLongConstant(String constantName) {
a61af66fc99e Initial load
duke
parents:
diff changeset
100 return lookupLongConstant(constantName, true);
a61af66fc99e Initial load
duke
parents:
diff changeset
101 }
a61af66fc99e Initial load
duke
parents:
diff changeset
102
a61af66fc99e Initial load
duke
parents:
diff changeset
103 public Long lookupLongConstant(String constantName, boolean throwException) {
a61af66fc99e Initial load
duke
parents:
diff changeset
104 Long i = (Long) nameToLongConstantMap.get(constantName);
a61af66fc99e Initial load
duke
parents:
diff changeset
105 if (i == null) {
a61af66fc99e Initial load
duke
parents:
diff changeset
106 if (throwException) {
a61af66fc99e Initial load
duke
parents:
diff changeset
107 throw new RuntimeException("No long constant named \"" + constantName + "\" present in type database");
a61af66fc99e Initial load
duke
parents:
diff changeset
108 }
a61af66fc99e Initial load
duke
parents:
diff changeset
109 }
a61af66fc99e Initial load
duke
parents:
diff changeset
110 return i;
a61af66fc99e Initial load
duke
parents:
diff changeset
111 }
a61af66fc99e Initial load
duke
parents:
diff changeset
112
a61af66fc99e Initial load
duke
parents:
diff changeset
113 public Type getJBooleanType() {
a61af66fc99e Initial load
duke
parents:
diff changeset
114 return jbooleanType;
a61af66fc99e Initial load
duke
parents:
diff changeset
115 }
a61af66fc99e Initial load
duke
parents:
diff changeset
116
a61af66fc99e Initial load
duke
parents:
diff changeset
117 public Type getJByteType() {
a61af66fc99e Initial load
duke
parents:
diff changeset
118 return jbyteType;
a61af66fc99e Initial load
duke
parents:
diff changeset
119 }
a61af66fc99e Initial load
duke
parents:
diff changeset
120
a61af66fc99e Initial load
duke
parents:
diff changeset
121 public Type getJCharType() {
a61af66fc99e Initial load
duke
parents:
diff changeset
122 return jcharType;
a61af66fc99e Initial load
duke
parents:
diff changeset
123 }
a61af66fc99e Initial load
duke
parents:
diff changeset
124
a61af66fc99e Initial load
duke
parents:
diff changeset
125 public Type getJDoubleType() {
a61af66fc99e Initial load
duke
parents:
diff changeset
126 return jdoubleType;
a61af66fc99e Initial load
duke
parents:
diff changeset
127 }
a61af66fc99e Initial load
duke
parents:
diff changeset
128
a61af66fc99e Initial load
duke
parents:
diff changeset
129 public Type getJFloatType() {
a61af66fc99e Initial load
duke
parents:
diff changeset
130 return jfloatType;
a61af66fc99e Initial load
duke
parents:
diff changeset
131 }
a61af66fc99e Initial load
duke
parents:
diff changeset
132
a61af66fc99e Initial load
duke
parents:
diff changeset
133 public Type getJIntType() {
a61af66fc99e Initial load
duke
parents:
diff changeset
134 return jintType;
a61af66fc99e Initial load
duke
parents:
diff changeset
135 }
a61af66fc99e Initial load
duke
parents:
diff changeset
136
a61af66fc99e Initial load
duke
parents:
diff changeset
137 public Type getJLongType() {
a61af66fc99e Initial load
duke
parents:
diff changeset
138 return jlongType;
a61af66fc99e Initial load
duke
parents:
diff changeset
139 }
a61af66fc99e Initial load
duke
parents:
diff changeset
140
a61af66fc99e Initial load
duke
parents:
diff changeset
141 public Type getJShortType() {
a61af66fc99e Initial load
duke
parents:
diff changeset
142 return jshortType;
a61af66fc99e Initial load
duke
parents:
diff changeset
143 }
a61af66fc99e Initial load
duke
parents:
diff changeset
144
a61af66fc99e Initial load
duke
parents:
diff changeset
145 public long getAddressSize() {
a61af66fc99e Initial load
duke
parents:
diff changeset
146 return machDesc.getAddressSize();
a61af66fc99e Initial load
duke
parents:
diff changeset
147 }
a61af66fc99e Initial load
duke
parents:
diff changeset
148
a61af66fc99e Initial load
duke
parents:
diff changeset
149 public long getOopSize() {
113
ba764ed4b6f2 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 0
diff changeset
150 return VM.getVM().getOopSize();
0
a61af66fc99e Initial load
duke
parents:
diff changeset
151 }
a61af66fc99e Initial load
duke
parents:
diff changeset
152
a61af66fc99e Initial load
duke
parents:
diff changeset
153 public boolean addressTypeIsEqualToType(Address addr, Type type) {
a61af66fc99e Initial load
duke
parents:
diff changeset
154 if (addr == null) {
a61af66fc99e Initial load
duke
parents:
diff changeset
155 return false;
a61af66fc99e Initial load
duke
parents:
diff changeset
156 }
a61af66fc99e Initial load
duke
parents:
diff changeset
157
a61af66fc99e Initial load
duke
parents:
diff changeset
158 // This implementation should be suitably platform-independent; we
a61af66fc99e Initial load
duke
parents:
diff changeset
159 // search nearby memory for the vtbl value of the given type.
a61af66fc99e Initial load
duke
parents:
diff changeset
160
a61af66fc99e Initial load
duke
parents:
diff changeset
161 Address vtblAddr = vtblAccess.getVtblForType(type);
a61af66fc99e Initial load
duke
parents:
diff changeset
162
a61af66fc99e Initial load
duke
parents:
diff changeset
163 if (vtblAddr == null) {
a61af66fc99e Initial load
duke
parents:
diff changeset
164 // Type was not polymorphic, or an error occurred during lookup
a61af66fc99e Initial load
duke
parents:
diff changeset
165 if (DEBUG) {
a61af66fc99e Initial load
duke
parents:
diff changeset
166 System.err.println("BasicTypeDataBase.addressTypeIsEqualToType: vtblAddr == null");
a61af66fc99e Initial load
duke
parents:
diff changeset
167 }
a61af66fc99e Initial load
duke
parents:
diff changeset
168
a61af66fc99e Initial load
duke
parents:
diff changeset
169 return false;
a61af66fc99e Initial load
duke
parents:
diff changeset
170 }
a61af66fc99e Initial load
duke
parents:
diff changeset
171
a61af66fc99e Initial load
duke
parents:
diff changeset
172 // The first implementation searched three locations for this vtbl
a61af66fc99e Initial load
duke
parents:
diff changeset
173 // value; scanning through the entire object was considered, but
a61af66fc99e Initial load
duke
parents:
diff changeset
174 // we thought we knew where we were looking, and looking only in
a61af66fc99e Initial load
duke
parents:
diff changeset
175 // these specific locations should reduce the probability of
a61af66fc99e Initial load
duke
parents:
diff changeset
176 // mistaking random bits as a pointer (although, realistically
a61af66fc99e Initial load
duke
parents:
diff changeset
177 // speaking, the likelihood of finding a match between the bit
a61af66fc99e Initial load
duke
parents:
diff changeset
178 // pattern of, for example, a double and the vtbl is vanishingly
a61af66fc99e Initial load
duke
parents:
diff changeset
179 // small.)
a61af66fc99e Initial load
duke
parents:
diff changeset
180 // 1. The first word of the object (should handle MSVC++ as
a61af66fc99e Initial load
duke
parents:
diff changeset
181 // well as the SparcWorks compilers with compatibility set to
a61af66fc99e Initial load
duke
parents:
diff changeset
182 // v5.0 or greater)
a61af66fc99e Initial load
duke
parents:
diff changeset
183 // 2. and 3. The last two Address-aligned words of the part of
a61af66fc99e Initial load
duke
parents:
diff changeset
184 // the object defined by its topmost polymorphic superclass.
a61af66fc99e Initial load
duke
parents:
diff changeset
185 // This should handle the SparcWorks compilers, v4.2 or
a61af66fc99e Initial load
duke
parents:
diff changeset
186 // earlier, as well as any other compilers which place the vptr
a61af66fc99e Initial load
duke
parents:
diff changeset
187 // at the end of the user-defined fields of the first base
a61af66fc99e Initial load
duke
parents:
diff changeset
188 // class with virtual functions.
a61af66fc99e Initial load
duke
parents:
diff changeset
189 //
a61af66fc99e Initial load
duke
parents:
diff changeset
190 // Unfortunately this algorithm did not work properly for the
a61af66fc99e Initial load
duke
parents:
diff changeset
191 // specific case of the ThreadShadow/Thread inheritance situation,
a61af66fc99e Initial load
duke
parents:
diff changeset
192 // because the Solaris compiler seems to cleverly eliminate the
a61af66fc99e Initial load
duke
parents:
diff changeset
193 // vtbl for ThreadShadow since the only virtual is empty. (We
a61af66fc99e Initial load
duke
parents:
diff changeset
194 // should get rid of the ThreadShadow and fix the include
a61af66fc99e Initial load
duke
parents:
diff changeset
195 // databases, but need to postpone this for the present.) The
a61af66fc99e Initial load
duke
parents:
diff changeset
196 // current solution performs the three-location check for this
a61af66fc99e Initial load
duke
parents:
diff changeset
197 // class and all of its known superclasses rather than just the
a61af66fc99e Initial load
duke
parents:
diff changeset
198 // topmost polymorphic one.
a61af66fc99e Initial load
duke
parents:
diff changeset
199
a61af66fc99e Initial load
duke
parents:
diff changeset
200 Type curType = type;
a61af66fc99e Initial load
duke
parents:
diff changeset
201
a61af66fc99e Initial load
duke
parents:
diff changeset
202 try {
a61af66fc99e Initial load
duke
parents:
diff changeset
203 while (curType != null) {
a61af66fc99e Initial load
duke
parents:
diff changeset
204 // Using the size information we have for this type, check the
a61af66fc99e Initial load
duke
parents:
diff changeset
205 // three locations described above.
a61af66fc99e Initial load
duke
parents:
diff changeset
206
a61af66fc99e Initial load
duke
parents:
diff changeset
207 // (1)
a61af66fc99e Initial load
duke
parents:
diff changeset
208 if (vtblAddr.equals(addr.getAddressAt(0))) {
a61af66fc99e Initial load
duke
parents:
diff changeset
209 return true;
a61af66fc99e Initial load
duke
parents:
diff changeset
210 }
a61af66fc99e Initial load
duke
parents:
diff changeset
211
a61af66fc99e Initial load
duke
parents:
diff changeset
212 // (2)
a61af66fc99e Initial load
duke
parents:
diff changeset
213 long offset = curType.getSize();
a61af66fc99e Initial load
duke
parents:
diff changeset
214 // I don't think this should be misaligned under any
a61af66fc99e Initial load
duke
parents:
diff changeset
215 // circumstances, but I'm not sure (FIXME: also not sure which
a61af66fc99e Initial load
duke
parents:
diff changeset
216 // way to go here, up or down -- assuming down)
a61af66fc99e Initial load
duke
parents:
diff changeset
217 offset -= (offset % getAddressSize());
a61af66fc99e Initial load
duke
parents:
diff changeset
218 if (offset <= 0) {
a61af66fc99e Initial load
duke
parents:
diff changeset
219 return false;
a61af66fc99e Initial load
duke
parents:
diff changeset
220 }
a61af66fc99e Initial load
duke
parents:
diff changeset
221 if (vtblAddr.equals(addr.getAddressAt(offset))) {
a61af66fc99e Initial load
duke
parents:
diff changeset
222 return true;
a61af66fc99e Initial load
duke
parents:
diff changeset
223 }
a61af66fc99e Initial load
duke
parents:
diff changeset
224 offset -= getAddressSize();
a61af66fc99e Initial load
duke
parents:
diff changeset
225 if (offset <= 0) {
a61af66fc99e Initial load
duke
parents:
diff changeset
226 return false;
a61af66fc99e Initial load
duke
parents:
diff changeset
227 }
a61af66fc99e Initial load
duke
parents:
diff changeset
228 if (vtblAddr.equals(addr.getAddressAt(offset))) {
a61af66fc99e Initial load
duke
parents:
diff changeset
229 return true;
a61af66fc99e Initial load
duke
parents:
diff changeset
230 }
a61af66fc99e Initial load
duke
parents:
diff changeset
231
a61af66fc99e Initial load
duke
parents:
diff changeset
232 curType = curType.getSuperclass();
a61af66fc99e Initial load
duke
parents:
diff changeset
233 }
a61af66fc99e Initial load
duke
parents:
diff changeset
234 }
a61af66fc99e Initial load
duke
parents:
diff changeset
235 catch (Exception e) {
a61af66fc99e Initial load
duke
parents:
diff changeset
236 // Any UnmappedAddressExceptions, etc. are a good indication
a61af66fc99e Initial load
duke
parents:
diff changeset
237 // that the pointer is not of the specified type
a61af66fc99e Initial load
duke
parents:
diff changeset
238 if (DEBUG) {
a61af66fc99e Initial load
duke
parents:
diff changeset
239 System.err.println("BasicTypeDataBase.addressTypeIsEqualToType: exception occurred during lookup:");
a61af66fc99e Initial load
duke
parents:
diff changeset
240 e.printStackTrace();
a61af66fc99e Initial load
duke
parents:
diff changeset
241 }
a61af66fc99e Initial load
duke
parents:
diff changeset
242
a61af66fc99e Initial load
duke
parents:
diff changeset
243 return false;
a61af66fc99e Initial load
duke
parents:
diff changeset
244 }
a61af66fc99e Initial load
duke
parents:
diff changeset
245
a61af66fc99e Initial load
duke
parents:
diff changeset
246 if (DEBUG) {
a61af66fc99e Initial load
duke
parents:
diff changeset
247 System.err.println("BasicTypeDataBase.addressTypeIsEqualToType: all vptr tests failed for type " +
a61af66fc99e Initial load
duke
parents:
diff changeset
248 type.getName());
a61af66fc99e Initial load
duke
parents:
diff changeset
249 }
a61af66fc99e Initial load
duke
parents:
diff changeset
250
a61af66fc99e Initial load
duke
parents:
diff changeset
251 return false;
a61af66fc99e Initial load
duke
parents:
diff changeset
252 }
a61af66fc99e Initial load
duke
parents:
diff changeset
253
a61af66fc99e Initial load
duke
parents:
diff changeset
254 public Type guessTypeForAddress(Address addr) {
a61af66fc99e Initial load
duke
parents:
diff changeset
255 for (Iterator iter = getTypes(); iter.hasNext(); ) {
a61af66fc99e Initial load
duke
parents:
diff changeset
256 Type t = (Type) iter.next();
a61af66fc99e Initial load
duke
parents:
diff changeset
257 if (addressTypeIsEqualToType(addr, t)) {
a61af66fc99e Initial load
duke
parents:
diff changeset
258 return t;
a61af66fc99e Initial load
duke
parents:
diff changeset
259 }
a61af66fc99e Initial load
duke
parents:
diff changeset
260 }
a61af66fc99e Initial load
duke
parents:
diff changeset
261 return null;
a61af66fc99e Initial load
duke
parents:
diff changeset
262 }
a61af66fc99e Initial load
duke
parents:
diff changeset
263
a61af66fc99e Initial load
duke
parents:
diff changeset
264 public long cIntegerTypeMaxValue(long sizeInBytes, boolean isUnsigned) {
a61af66fc99e Initial load
duke
parents:
diff changeset
265 return machDesc.cIntegerTypeMaxValue(sizeInBytes, isUnsigned);
a61af66fc99e Initial load
duke
parents:
diff changeset
266 }
a61af66fc99e Initial load
duke
parents:
diff changeset
267
a61af66fc99e Initial load
duke
parents:
diff changeset
268 public long cIntegerTypeMinValue(long sizeInBytes, boolean isUnsigned) {
a61af66fc99e Initial load
duke
parents:
diff changeset
269 return machDesc.cIntegerTypeMinValue(sizeInBytes, isUnsigned);
a61af66fc99e Initial load
duke
parents:
diff changeset
270 }
a61af66fc99e Initial load
duke
parents:
diff changeset
271
a61af66fc99e Initial load
duke
parents:
diff changeset
272 public Iterator getTypes() {
a61af66fc99e Initial load
duke
parents:
diff changeset
273 return nameToTypeMap.values().iterator();
a61af66fc99e Initial load
duke
parents:
diff changeset
274 }
a61af66fc99e Initial load
duke
parents:
diff changeset
275
a61af66fc99e Initial load
duke
parents:
diff changeset
276 public Iterator getIntConstants() {
a61af66fc99e Initial load
duke
parents:
diff changeset
277 return nameToIntConstantMap.keySet().iterator();
a61af66fc99e Initial load
duke
parents:
diff changeset
278 }
a61af66fc99e Initial load
duke
parents:
diff changeset
279
a61af66fc99e Initial load
duke
parents:
diff changeset
280 public Iterator getLongConstants() {
a61af66fc99e Initial load
duke
parents:
diff changeset
281 return nameToLongConstantMap.keySet().iterator();
a61af66fc99e Initial load
duke
parents:
diff changeset
282 }
a61af66fc99e Initial load
duke
parents:
diff changeset
283
a61af66fc99e Initial load
duke
parents:
diff changeset
284 //--------------------------------------------------------------------------------
a61af66fc99e Initial load
duke
parents:
diff changeset
285 // Public routines only for use by the database builder
a61af66fc99e Initial load
duke
parents:
diff changeset
286 //
a61af66fc99e Initial load
duke
parents:
diff changeset
287
a61af66fc99e Initial load
duke
parents:
diff changeset
288 /** This method should only be called by the builder of the
a61af66fc99e Initial load
duke
parents:
diff changeset
289 TypeDataBase and at most once */
a61af66fc99e Initial load
duke
parents:
diff changeset
290 public void setJBooleanType(Type type) {
a61af66fc99e Initial load
duke
parents:
diff changeset
291 jbooleanType = type;
a61af66fc99e Initial load
duke
parents:
diff changeset
292 }
a61af66fc99e Initial load
duke
parents:
diff changeset
293
a61af66fc99e Initial load
duke
parents:
diff changeset
294 /** This method should only be called by the builder of the
a61af66fc99e Initial load
duke
parents:
diff changeset
295 TypeDataBase and at most once */
a61af66fc99e Initial load
duke
parents:
diff changeset
296 public void setJByteType(Type type) {
a61af66fc99e Initial load
duke
parents:
diff changeset
297 jbyteType = type;
a61af66fc99e Initial load
duke
parents:
diff changeset
298 }
a61af66fc99e Initial load
duke
parents:
diff changeset
299
a61af66fc99e Initial load
duke
parents:
diff changeset
300 /** This method should only be called by the builder of the
a61af66fc99e Initial load
duke
parents:
diff changeset
301 TypeDataBase and at most once */
a61af66fc99e Initial load
duke
parents:
diff changeset
302 public void setJCharType(Type type) {
a61af66fc99e Initial load
duke
parents:
diff changeset
303 jcharType = type;
a61af66fc99e Initial load
duke
parents:
diff changeset
304 }
a61af66fc99e Initial load
duke
parents:
diff changeset
305
a61af66fc99e Initial load
duke
parents:
diff changeset
306 /** This method should only be called by the builder of the
a61af66fc99e Initial load
duke
parents:
diff changeset
307 TypeDataBase and at most once */
a61af66fc99e Initial load
duke
parents:
diff changeset
308 public void setJDoubleType(Type type) {
a61af66fc99e Initial load
duke
parents:
diff changeset
309 jdoubleType = type;
a61af66fc99e Initial load
duke
parents:
diff changeset
310 }
a61af66fc99e Initial load
duke
parents:
diff changeset
311
a61af66fc99e Initial load
duke
parents:
diff changeset
312 /** This method should only be called by the builder of the
a61af66fc99e Initial load
duke
parents:
diff changeset
313 TypeDataBase and at most once */
a61af66fc99e Initial load
duke
parents:
diff changeset
314 public void setJFloatType(Type type) {
a61af66fc99e Initial load
duke
parents:
diff changeset
315 jfloatType = type;
a61af66fc99e Initial load
duke
parents:
diff changeset
316 }
a61af66fc99e Initial load
duke
parents:
diff changeset
317
a61af66fc99e Initial load
duke
parents:
diff changeset
318 /** This method should only be called by the builder of the
a61af66fc99e Initial load
duke
parents:
diff changeset
319 TypeDataBase and at most once */
a61af66fc99e Initial load
duke
parents:
diff changeset
320 public void setJIntType(Type type) {
a61af66fc99e Initial load
duke
parents:
diff changeset
321 jintType = type;
a61af66fc99e Initial load
duke
parents:
diff changeset
322 }
a61af66fc99e Initial load
duke
parents:
diff changeset
323
a61af66fc99e Initial load
duke
parents:
diff changeset
324 /** This method should only be called by the builder of the
a61af66fc99e Initial load
duke
parents:
diff changeset
325 TypeDataBase and at most once */
a61af66fc99e Initial load
duke
parents:
diff changeset
326 public void setJLongType(Type type) {
a61af66fc99e Initial load
duke
parents:
diff changeset
327 jlongType = type;
a61af66fc99e Initial load
duke
parents:
diff changeset
328 }
a61af66fc99e Initial load
duke
parents:
diff changeset
329
a61af66fc99e Initial load
duke
parents:
diff changeset
330 /** This method should only be called by the builder of the
a61af66fc99e Initial load
duke
parents:
diff changeset
331 TypeDataBase and at most once */
a61af66fc99e Initial load
duke
parents:
diff changeset
332 public void setJShortType(Type type) {
a61af66fc99e Initial load
duke
parents:
diff changeset
333 jshortType = type;
a61af66fc99e Initial load
duke
parents:
diff changeset
334 }
a61af66fc99e Initial load
duke
parents:
diff changeset
335
a61af66fc99e Initial load
duke
parents:
diff changeset
336 /** This method should only be used by the builder of the
a61af66fc99e Initial load
duke
parents:
diff changeset
337 TypeDataBase. Throws a RuntimeException if a class with this
a61af66fc99e Initial load
duke
parents:
diff changeset
338 name was already present. */
a61af66fc99e Initial load
duke
parents:
diff changeset
339 public void addType(Type type) {
a61af66fc99e Initial load
duke
parents:
diff changeset
340 if (nameToTypeMap.get(type.getName()) != null) {
a61af66fc99e Initial load
duke
parents:
diff changeset
341 throw new RuntimeException("type of name \"" + type.getName() + "\" already present");
a61af66fc99e Initial load
duke
parents:
diff changeset
342 }
a61af66fc99e Initial load
duke
parents:
diff changeset
343
a61af66fc99e Initial load
duke
parents:
diff changeset
344 nameToTypeMap.put(type.getName(), type);
a61af66fc99e Initial load
duke
parents:
diff changeset
345 }
a61af66fc99e Initial load
duke
parents:
diff changeset
346
a61af66fc99e Initial load
duke
parents:
diff changeset
347 /** This method should only be used by the builder of the
a61af66fc99e Initial load
duke
parents:
diff changeset
348 TypeDataBase. Throws a RuntimeException if this class was not
a61af66fc99e Initial load
duke
parents:
diff changeset
349 present. */
a61af66fc99e Initial load
duke
parents:
diff changeset
350 public void removeType(Type type) {
a61af66fc99e Initial load
duke
parents:
diff changeset
351 Type curType = (Type) nameToTypeMap.get(type.getName());
a61af66fc99e Initial load
duke
parents:
diff changeset
352 if (curType == null) {
a61af66fc99e Initial load
duke
parents:
diff changeset
353 throw new RuntimeException("type of name \"" + type.getName() + "\" not present");
a61af66fc99e Initial load
duke
parents:
diff changeset
354 }
a61af66fc99e Initial load
duke
parents:
diff changeset
355
a61af66fc99e Initial load
duke
parents:
diff changeset
356 if (!curType.equals(type)) {
a61af66fc99e Initial load
duke
parents:
diff changeset
357 throw new RuntimeException("a different type of name \"" + type.getName() + "\" was present");
a61af66fc99e Initial load
duke
parents:
diff changeset
358 }
a61af66fc99e Initial load
duke
parents:
diff changeset
359
a61af66fc99e Initial load
duke
parents:
diff changeset
360 nameToTypeMap.remove(type.getName());
a61af66fc99e Initial load
duke
parents:
diff changeset
361 }
a61af66fc99e Initial load
duke
parents:
diff changeset
362
a61af66fc99e Initial load
duke
parents:
diff changeset
363 /** This method should only be used by the builder of the
a61af66fc99e Initial load
duke
parents:
diff changeset
364 TypeDataBase. Throws a RuntimeException if an integer constant
a61af66fc99e Initial load
duke
parents:
diff changeset
365 with this name was already present. */
a61af66fc99e Initial load
duke
parents:
diff changeset
366 public void addIntConstant(String name, int value) {
a61af66fc99e Initial load
duke
parents:
diff changeset
367 if (nameToIntConstantMap.get(name) != null) {
a61af66fc99e Initial load
duke
parents:
diff changeset
368 throw new RuntimeException("int constant of name \"" + name + "\" already present");
a61af66fc99e Initial load
duke
parents:
diff changeset
369 }
a61af66fc99e Initial load
duke
parents:
diff changeset
370
a61af66fc99e Initial load
duke
parents:
diff changeset
371 nameToIntConstantMap.put(name, new Integer(value));
a61af66fc99e Initial load
duke
parents:
diff changeset
372 }
a61af66fc99e Initial load
duke
parents:
diff changeset
373
a61af66fc99e Initial load
duke
parents:
diff changeset
374 /** This method should only be used by the builder of the
a61af66fc99e Initial load
duke
parents:
diff changeset
375 TypeDataBase. Throws a RuntimeException if an integer constant
a61af66fc99e Initial load
duke
parents:
diff changeset
376 with this name was not present. */
a61af66fc99e Initial load
duke
parents:
diff changeset
377 public void removeIntConstant(String name) {
a61af66fc99e Initial load
duke
parents:
diff changeset
378 Integer curConstant = (Integer) nameToIntConstantMap.get(name);
a61af66fc99e Initial load
duke
parents:
diff changeset
379 if (curConstant == null) {
a61af66fc99e Initial load
duke
parents:
diff changeset
380 throw new RuntimeException("int constant of name \"" + name + "\" not present");
a61af66fc99e Initial load
duke
parents:
diff changeset
381 }
a61af66fc99e Initial load
duke
parents:
diff changeset
382
a61af66fc99e Initial load
duke
parents:
diff changeset
383 nameToIntConstantMap.remove(name);
a61af66fc99e Initial load
duke
parents:
diff changeset
384 }
a61af66fc99e Initial load
duke
parents:
diff changeset
385
a61af66fc99e Initial load
duke
parents:
diff changeset
386 /** This method should only be used by the builder of the
a61af66fc99e Initial load
duke
parents:
diff changeset
387 TypeDataBase. Throws a RuntimeException if a long constant with
a61af66fc99e Initial load
duke
parents:
diff changeset
388 this name was already present. */
a61af66fc99e Initial load
duke
parents:
diff changeset
389 public void addLongConstant(String name, long value) {
a61af66fc99e Initial load
duke
parents:
diff changeset
390 if (nameToLongConstantMap.get(name) != null) {
a61af66fc99e Initial load
duke
parents:
diff changeset
391 throw new RuntimeException("long constant of name \"" + name + "\" already present");
a61af66fc99e Initial load
duke
parents:
diff changeset
392 }
a61af66fc99e Initial load
duke
parents:
diff changeset
393
a61af66fc99e Initial load
duke
parents:
diff changeset
394 nameToLongConstantMap.put(name, new Long(value));
a61af66fc99e Initial load
duke
parents:
diff changeset
395 }
a61af66fc99e Initial load
duke
parents:
diff changeset
396
a61af66fc99e Initial load
duke
parents:
diff changeset
397 /** This method should only be used by the builder of the
a61af66fc99e Initial load
duke
parents:
diff changeset
398 TypeDataBase. Throws a RuntimeException if a long constant with
a61af66fc99e Initial load
duke
parents:
diff changeset
399 this name was not present. */
a61af66fc99e Initial load
duke
parents:
diff changeset
400 public void removeLongConstant(String name) {
a61af66fc99e Initial load
duke
parents:
diff changeset
401 Long curConstant = (Long) nameToLongConstantMap.get(name);
a61af66fc99e Initial load
duke
parents:
diff changeset
402 if (curConstant == null) {
a61af66fc99e Initial load
duke
parents:
diff changeset
403 throw new RuntimeException("long constant of name \"" + name + "\" not present");
a61af66fc99e Initial load
duke
parents:
diff changeset
404 }
a61af66fc99e Initial load
duke
parents:
diff changeset
405
a61af66fc99e Initial load
duke
parents:
diff changeset
406 nameToLongConstantMap.remove(name);
a61af66fc99e Initial load
duke
parents:
diff changeset
407 }
a61af66fc99e Initial load
duke
parents:
diff changeset
408 }