annotate agent/src/share/classes/sun/jvm/hotspot/types/basic/BasicTypeDataBase.java @ 0:a61af66fc99e jdk7-b24

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