annotate agent/src/share/classes/sun/jvm/hotspot/types/basic/BasicType.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-2005 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 import sun.jvm.hotspot.utilities.*;
a61af66fc99e Initial load
duke
parents:
diff changeset
31
a61af66fc99e Initial load
duke
parents:
diff changeset
32 /** <P> This is a basic implementation of the Type interface which
a61af66fc99e Initial load
duke
parents:
diff changeset
33 should be complete enough to be portable across platforms. The
a61af66fc99e Initial load
duke
parents:
diff changeset
34 only issue will be the construction of these objects and their
a61af66fc99e Initial load
duke
parents:
diff changeset
35 components from the platform-specific debugging information; see
a61af66fc99e Initial load
duke
parents:
diff changeset
36 BasicTypeDataBase. </P>
a61af66fc99e Initial load
duke
parents:
diff changeset
37
a61af66fc99e Initial load
duke
parents:
diff changeset
38 <P> There are two types of clients of this class. The first is
a61af66fc99e Initial load
duke
parents:
diff changeset
39 that which builds the TypeDatabase. This kind of client uses the
a61af66fc99e Initial load
duke
parents:
diff changeset
40 additional public methods beyond those in the Type interface to
a61af66fc99e Initial load
duke
parents:
diff changeset
41 properly configure the BasicType objects. The second is the
a61af66fc99e Initial load
duke
parents:
diff changeset
42 consumer of these types; this kind of client should deal only with
a61af66fc99e Initial load
duke
parents:
diff changeset
43 the Type interfaces. </P> */
a61af66fc99e Initial load
duke
parents:
diff changeset
44
a61af66fc99e Initial load
duke
parents:
diff changeset
45 public class BasicType implements Type {
a61af66fc99e Initial load
duke
parents:
diff changeset
46 protected BasicTypeDataBase db;
a61af66fc99e Initial load
duke
parents:
diff changeset
47
a61af66fc99e Initial load
duke
parents:
diff changeset
48 private String name;
a61af66fc99e Initial load
duke
parents:
diff changeset
49 private long size;
a61af66fc99e Initial load
duke
parents:
diff changeset
50 private boolean isJavaPrimitiveType;
a61af66fc99e Initial load
duke
parents:
diff changeset
51 private boolean isOopType;
a61af66fc99e Initial load
duke
parents:
diff changeset
52 // These are only the fields defined in this class, not any of this
a61af66fc99e Initial load
duke
parents:
diff changeset
53 // class's superclasses.
a61af66fc99e Initial load
duke
parents:
diff changeset
54 private Map nameToFieldMap = new HashMap();
a61af66fc99e Initial load
duke
parents:
diff changeset
55 private List fieldList = new LinkedList();
a61af66fc99e Initial load
duke
parents:
diff changeset
56 // Superclass, or null if none. Primitive types do not have any
a61af66fc99e Initial load
duke
parents:
diff changeset
57 // inheritance relationship.
a61af66fc99e Initial load
duke
parents:
diff changeset
58 private Type superclass;
a61af66fc99e Initial load
duke
parents:
diff changeset
59
a61af66fc99e Initial load
duke
parents:
diff changeset
60 /** superclass may be null */
a61af66fc99e Initial load
duke
parents:
diff changeset
61 public BasicType(BasicTypeDataBase db, String name, Type superclass) {
a61af66fc99e Initial load
duke
parents:
diff changeset
62 if (name == null) {
a61af66fc99e Initial load
duke
parents:
diff changeset
63 throw new IllegalArgumentException("name may not be null");
a61af66fc99e Initial load
duke
parents:
diff changeset
64 }
a61af66fc99e Initial load
duke
parents:
diff changeset
65 this.db = db;
a61af66fc99e Initial load
duke
parents:
diff changeset
66 this.name = name;
a61af66fc99e Initial load
duke
parents:
diff changeset
67 this.superclass = superclass;
a61af66fc99e Initial load
duke
parents:
diff changeset
68 }
a61af66fc99e Initial load
duke
parents:
diff changeset
69
a61af66fc99e Initial load
duke
parents:
diff changeset
70 /** Equivalent to BasicType(db, name, null) */
a61af66fc99e Initial load
duke
parents:
diff changeset
71 public BasicType(BasicTypeDataBase db, String name) {
a61af66fc99e Initial load
duke
parents:
diff changeset
72 this(db, name, null);
a61af66fc99e Initial load
duke
parents:
diff changeset
73 }
a61af66fc99e Initial load
duke
parents:
diff changeset
74
a61af66fc99e Initial load
duke
parents:
diff changeset
75 public boolean equals(Object obj) {
a61af66fc99e Initial load
duke
parents:
diff changeset
76 if (obj == null) {
a61af66fc99e Initial load
duke
parents:
diff changeset
77 return false;
a61af66fc99e Initial load
duke
parents:
diff changeset
78 }
a61af66fc99e Initial load
duke
parents:
diff changeset
79
a61af66fc99e Initial load
duke
parents:
diff changeset
80 if (!(obj instanceof BasicType)) {
a61af66fc99e Initial load
duke
parents:
diff changeset
81 return false;
a61af66fc99e Initial load
duke
parents:
diff changeset
82 }
a61af66fc99e Initial load
duke
parents:
diff changeset
83
a61af66fc99e Initial load
duke
parents:
diff changeset
84 BasicType arg = (BasicType) obj;
a61af66fc99e Initial load
duke
parents:
diff changeset
85
a61af66fc99e Initial load
duke
parents:
diff changeset
86 if (!name.equals(arg.name)) {
a61af66fc99e Initial load
duke
parents:
diff changeset
87 return false;
a61af66fc99e Initial load
duke
parents:
diff changeset
88 }
a61af66fc99e Initial load
duke
parents:
diff changeset
89
a61af66fc99e Initial load
duke
parents:
diff changeset
90 return true;
a61af66fc99e Initial load
duke
parents:
diff changeset
91 }
a61af66fc99e Initial load
duke
parents:
diff changeset
92
a61af66fc99e Initial load
duke
parents:
diff changeset
93 public int hashCode() {
a61af66fc99e Initial load
duke
parents:
diff changeset
94 return name.hashCode();
a61af66fc99e Initial load
duke
parents:
diff changeset
95 }
a61af66fc99e Initial load
duke
parents:
diff changeset
96
a61af66fc99e Initial load
duke
parents:
diff changeset
97 public String toString() {
a61af66fc99e Initial load
duke
parents:
diff changeset
98 return name;
a61af66fc99e Initial load
duke
parents:
diff changeset
99 }
a61af66fc99e Initial load
duke
parents:
diff changeset
100
a61af66fc99e Initial load
duke
parents:
diff changeset
101 public String getName() {
a61af66fc99e Initial load
duke
parents:
diff changeset
102 return name;
a61af66fc99e Initial load
duke
parents:
diff changeset
103 }
a61af66fc99e Initial load
duke
parents:
diff changeset
104
a61af66fc99e Initial load
duke
parents:
diff changeset
105 /** This should only be called at most once, and only by the builder
a61af66fc99e Initial load
duke
parents:
diff changeset
106 of the type database */
a61af66fc99e Initial load
duke
parents:
diff changeset
107 public void setSuperclass(Type superclass) {
a61af66fc99e Initial load
duke
parents:
diff changeset
108 this.superclass = superclass;
a61af66fc99e Initial load
duke
parents:
diff changeset
109 }
a61af66fc99e Initial load
duke
parents:
diff changeset
110
a61af66fc99e Initial load
duke
parents:
diff changeset
111 public Type getSuperclass() {
a61af66fc99e Initial load
duke
parents:
diff changeset
112 return superclass;
a61af66fc99e Initial load
duke
parents:
diff changeset
113 }
a61af66fc99e Initial load
duke
parents:
diff changeset
114
a61af66fc99e Initial load
duke
parents:
diff changeset
115 /** This should only be called at most once, and only by the builder
a61af66fc99e Initial load
duke
parents:
diff changeset
116 of the type database */
a61af66fc99e Initial load
duke
parents:
diff changeset
117 public void setSize(long sizeInBytes) {
a61af66fc99e Initial load
duke
parents:
diff changeset
118 this.size = sizeInBytes;
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 long getSize() {
a61af66fc99e Initial load
duke
parents:
diff changeset
122 return size;
a61af66fc99e Initial load
duke
parents:
diff changeset
123 }
a61af66fc99e Initial load
duke
parents:
diff changeset
124
a61af66fc99e Initial load
duke
parents:
diff changeset
125 /** Overridden by BasicCIntegerType */
a61af66fc99e Initial load
duke
parents:
diff changeset
126 public boolean isCIntegerType() {
a61af66fc99e Initial load
duke
parents:
diff changeset
127 return false;
a61af66fc99e Initial load
duke
parents:
diff changeset
128 }
a61af66fc99e Initial load
duke
parents:
diff changeset
129
a61af66fc99e Initial load
duke
parents:
diff changeset
130 public boolean isCStringType() {
a61af66fc99e Initial load
duke
parents:
diff changeset
131 if (isPointerType()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
132 Type target = ((PointerType)this).getTargetType();
a61af66fc99e Initial load
duke
parents:
diff changeset
133 return target.isCIntegerType() &&
a61af66fc99e Initial load
duke
parents:
diff changeset
134 target.getName().equals("const char");
a61af66fc99e Initial load
duke
parents:
diff changeset
135 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
136 return false;
a61af66fc99e Initial load
duke
parents:
diff changeset
137 }
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 boolean isJavaPrimitiveType() {
a61af66fc99e Initial load
duke
parents:
diff changeset
141 return isJavaPrimitiveType;
a61af66fc99e Initial load
duke
parents:
diff changeset
142 }
a61af66fc99e Initial load
duke
parents:
diff changeset
143
a61af66fc99e Initial load
duke
parents:
diff changeset
144 /** This should only be called at most once, and only by the builder
a61af66fc99e Initial load
duke
parents:
diff changeset
145 of the type database */
a61af66fc99e Initial load
duke
parents:
diff changeset
146 public void setIsJavaPrimitiveType(boolean isJavaPrimitiveType) {
a61af66fc99e Initial load
duke
parents:
diff changeset
147 this.isJavaPrimitiveType = isJavaPrimitiveType;
a61af66fc99e Initial load
duke
parents:
diff changeset
148 }
a61af66fc99e Initial load
duke
parents:
diff changeset
149
a61af66fc99e Initial load
duke
parents:
diff changeset
150 public boolean isOopType() {
a61af66fc99e Initial load
duke
parents:
diff changeset
151 return isOopType;
a61af66fc99e Initial load
duke
parents:
diff changeset
152 }
a61af66fc99e Initial load
duke
parents:
diff changeset
153
a61af66fc99e Initial load
duke
parents:
diff changeset
154 /** Overridden by BasicPointerType */
a61af66fc99e Initial load
duke
parents:
diff changeset
155 public boolean isPointerType() {
a61af66fc99e Initial load
duke
parents:
diff changeset
156 return false;
a61af66fc99e Initial load
duke
parents:
diff changeset
157 }
a61af66fc99e Initial load
duke
parents:
diff changeset
158
a61af66fc99e Initial load
duke
parents:
diff changeset
159 /** This should only be called at most once, and only by the builder
a61af66fc99e Initial load
duke
parents:
diff changeset
160 of the type database */
a61af66fc99e Initial load
duke
parents:
diff changeset
161 public void setIsOopType(boolean isOopType) {
a61af66fc99e Initial load
duke
parents:
diff changeset
162 this.isOopType = isOopType;
a61af66fc99e Initial load
duke
parents:
diff changeset
163 }
a61af66fc99e Initial load
duke
parents:
diff changeset
164
a61af66fc99e Initial load
duke
parents:
diff changeset
165 public Field getField(String fieldName, boolean searchSuperclassFields,
a61af66fc99e Initial load
duke
parents:
diff changeset
166 boolean throwExceptionIfNotFound) {
a61af66fc99e Initial load
duke
parents:
diff changeset
167 Field field = null;
a61af66fc99e Initial load
duke
parents:
diff changeset
168 if (nameToFieldMap != null) {
a61af66fc99e Initial load
duke
parents:
diff changeset
169 field = (Field) nameToFieldMap.get(fieldName);
a61af66fc99e Initial load
duke
parents:
diff changeset
170
a61af66fc99e Initial load
duke
parents:
diff changeset
171 if (field != null) {
a61af66fc99e Initial load
duke
parents:
diff changeset
172 return field;
a61af66fc99e Initial load
duke
parents:
diff changeset
173 }
a61af66fc99e Initial load
duke
parents:
diff changeset
174 }
a61af66fc99e Initial load
duke
parents:
diff changeset
175
a61af66fc99e Initial load
duke
parents:
diff changeset
176 if (searchSuperclassFields) {
a61af66fc99e Initial load
duke
parents:
diff changeset
177 if (superclass != null) {
a61af66fc99e Initial load
duke
parents:
diff changeset
178 field = superclass.getField(fieldName, searchSuperclassFields, false);
a61af66fc99e Initial load
duke
parents:
diff changeset
179 }
a61af66fc99e Initial load
duke
parents:
diff changeset
180 }
a61af66fc99e Initial load
duke
parents:
diff changeset
181
a61af66fc99e Initial load
duke
parents:
diff changeset
182 if (field == null && throwExceptionIfNotFound) {
a61af66fc99e Initial load
duke
parents:
diff changeset
183 throw new RuntimeException("field \"" + fieldName + "\" not found in type " + name);
a61af66fc99e Initial load
duke
parents:
diff changeset
184 }
a61af66fc99e Initial load
duke
parents:
diff changeset
185
a61af66fc99e Initial load
duke
parents:
diff changeset
186 return field;
a61af66fc99e Initial load
duke
parents:
diff changeset
187 }
a61af66fc99e Initial load
duke
parents:
diff changeset
188
a61af66fc99e Initial load
duke
parents:
diff changeset
189 public Field getField(String fieldName, boolean searchSuperclassFields) {
a61af66fc99e Initial load
duke
parents:
diff changeset
190 return getField(fieldName, searchSuperclassFields, true);
a61af66fc99e Initial load
duke
parents:
diff changeset
191 }
a61af66fc99e Initial load
duke
parents:
diff changeset
192
a61af66fc99e Initial load
duke
parents:
diff changeset
193 public Field getField(String fieldName) {
a61af66fc99e Initial load
duke
parents:
diff changeset
194 return getField(fieldName, true);
a61af66fc99e Initial load
duke
parents:
diff changeset
195 }
a61af66fc99e Initial load
duke
parents:
diff changeset
196
a61af66fc99e Initial load
duke
parents:
diff changeset
197 public Field getField(String fieldName, Type declaredType,
a61af66fc99e Initial load
duke
parents:
diff changeset
198 boolean searchSuperclassFields) throws WrongTypeException {
a61af66fc99e Initial load
duke
parents:
diff changeset
199 Field res = getField(fieldName, searchSuperclassFields);
a61af66fc99e Initial load
duke
parents:
diff changeset
200 if (res == null) {
a61af66fc99e Initial load
duke
parents:
diff changeset
201 return null;
a61af66fc99e Initial load
duke
parents:
diff changeset
202 }
a61af66fc99e Initial load
duke
parents:
diff changeset
203 if (!res.getType().equals(declaredType)) {
a61af66fc99e Initial load
duke
parents:
diff changeset
204 throw new WrongTypeException("field \"" + fieldName + "\" in type " + name +
a61af66fc99e Initial load
duke
parents:
diff changeset
205 " is not of type " + declaredType +
a61af66fc99e Initial load
duke
parents:
diff changeset
206 ", but instead of type " + res.getType());
a61af66fc99e Initial load
duke
parents:
diff changeset
207 }
a61af66fc99e Initial load
duke
parents:
diff changeset
208 return res;
a61af66fc99e Initial load
duke
parents:
diff changeset
209 }
a61af66fc99e Initial load
duke
parents:
diff changeset
210
a61af66fc99e Initial load
duke
parents:
diff changeset
211 public Field getField(String fieldName, Type declaredType) throws WrongTypeException {
a61af66fc99e Initial load
duke
parents:
diff changeset
212 return getField(fieldName, declaredType, false);
a61af66fc99e Initial load
duke
parents:
diff changeset
213 }
a61af66fc99e Initial load
duke
parents:
diff changeset
214
a61af66fc99e Initial load
duke
parents:
diff changeset
215 /** The returned iterator's "remove" method must not be called */
a61af66fc99e Initial load
duke
parents:
diff changeset
216 public Iterator getFields() {
a61af66fc99e Initial load
duke
parents:
diff changeset
217 return new ConstIterator(fieldList.iterator());
a61af66fc99e Initial load
duke
parents:
diff changeset
218 }
a61af66fc99e Initial load
duke
parents:
diff changeset
219
a61af66fc99e Initial load
duke
parents:
diff changeset
220 //--------------------------------------------------------------------------------
a61af66fc99e Initial load
duke
parents:
diff changeset
221 // Specialized field type accessors
a61af66fc99e Initial load
duke
parents:
diff changeset
222 //
a61af66fc99e Initial load
duke
parents:
diff changeset
223
a61af66fc99e Initial load
duke
parents:
diff changeset
224 public JBooleanField getJBooleanField(String fieldName) throws WrongTypeException {
a61af66fc99e Initial load
duke
parents:
diff changeset
225 return (JBooleanField) getField(fieldName, db.getJBooleanType());
a61af66fc99e Initial load
duke
parents:
diff changeset
226 }
a61af66fc99e Initial load
duke
parents:
diff changeset
227
a61af66fc99e Initial load
duke
parents:
diff changeset
228 public JByteField getJByteField(String fieldName) throws WrongTypeException {
a61af66fc99e Initial load
duke
parents:
diff changeset
229 return (JByteField) getField(fieldName, db.getJByteType());
a61af66fc99e Initial load
duke
parents:
diff changeset
230 }
a61af66fc99e Initial load
duke
parents:
diff changeset
231
a61af66fc99e Initial load
duke
parents:
diff changeset
232 public JCharField getJCharField(String fieldName) throws WrongTypeException {
a61af66fc99e Initial load
duke
parents:
diff changeset
233 return (JCharField) getField(fieldName, db.getJCharType());
a61af66fc99e Initial load
duke
parents:
diff changeset
234 }
a61af66fc99e Initial load
duke
parents:
diff changeset
235
a61af66fc99e Initial load
duke
parents:
diff changeset
236 public JDoubleField getJDoubleField(String fieldName) throws WrongTypeException {
a61af66fc99e Initial load
duke
parents:
diff changeset
237 return (JDoubleField) getField(fieldName, db.getJDoubleType());
a61af66fc99e Initial load
duke
parents:
diff changeset
238 }
a61af66fc99e Initial load
duke
parents:
diff changeset
239
a61af66fc99e Initial load
duke
parents:
diff changeset
240 public JFloatField getJFloatField(String fieldName) throws WrongTypeException {
a61af66fc99e Initial load
duke
parents:
diff changeset
241 return (JFloatField) getField(fieldName, db.getJFloatType());
a61af66fc99e Initial load
duke
parents:
diff changeset
242 }
a61af66fc99e Initial load
duke
parents:
diff changeset
243
a61af66fc99e Initial load
duke
parents:
diff changeset
244 public JIntField getJIntField(String fieldName) throws WrongTypeException {
a61af66fc99e Initial load
duke
parents:
diff changeset
245 return (JIntField) getField(fieldName, db.getJIntType());
a61af66fc99e Initial load
duke
parents:
diff changeset
246 }
a61af66fc99e Initial load
duke
parents:
diff changeset
247
a61af66fc99e Initial load
duke
parents:
diff changeset
248 public JLongField getJLongField(String fieldName) throws WrongTypeException {
a61af66fc99e Initial load
duke
parents:
diff changeset
249 return (JLongField) getField(fieldName, db.getJLongType());
a61af66fc99e Initial load
duke
parents:
diff changeset
250 }
a61af66fc99e Initial load
duke
parents:
diff changeset
251
a61af66fc99e Initial load
duke
parents:
diff changeset
252 public JShortField getJShortField(String fieldName) throws WrongTypeException {
a61af66fc99e Initial load
duke
parents:
diff changeset
253 return (JShortField) getField(fieldName, db.getJShortType());
a61af66fc99e Initial load
duke
parents:
diff changeset
254 }
a61af66fc99e Initial load
duke
parents:
diff changeset
255
a61af66fc99e Initial load
duke
parents:
diff changeset
256 public CIntegerField getCIntegerField(String fieldName) throws WrongTypeException {
a61af66fc99e Initial load
duke
parents:
diff changeset
257 Field field = getField(fieldName);
a61af66fc99e Initial load
duke
parents:
diff changeset
258 if (!(field.getType() instanceof CIntegerType)) {
a61af66fc99e Initial load
duke
parents:
diff changeset
259 throw new WrongTypeException("field \"" + fieldName + "\" in type " + name +
a61af66fc99e Initial load
duke
parents:
diff changeset
260 " is not of C integer type, but instead of type " +
a61af66fc99e Initial load
duke
parents:
diff changeset
261 field.getType());
a61af66fc99e Initial load
duke
parents:
diff changeset
262 }
a61af66fc99e Initial load
duke
parents:
diff changeset
263 return (CIntegerField) field;
a61af66fc99e Initial load
duke
parents:
diff changeset
264 }
a61af66fc99e Initial load
duke
parents:
diff changeset
265
a61af66fc99e Initial load
duke
parents:
diff changeset
266 public OopField getOopField(String fieldName) throws WrongTypeException {
a61af66fc99e Initial load
duke
parents:
diff changeset
267 Field field = getField(fieldName);
a61af66fc99e Initial load
duke
parents:
diff changeset
268 if (!field.getType().isOopType()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
269 throw new WrongTypeException("field \"" + fieldName + "\" in type " + name +
a61af66fc99e Initial load
duke
parents:
diff changeset
270 " is not of oop type, but instead of type " +
a61af66fc99e Initial load
duke
parents:
diff changeset
271 field.getType());
a61af66fc99e Initial load
duke
parents:
diff changeset
272 }
a61af66fc99e Initial load
duke
parents:
diff changeset
273 return (OopField) field;
a61af66fc99e Initial load
duke
parents:
diff changeset
274 }
a61af66fc99e Initial load
duke
parents:
diff changeset
275
113
ba764ed4b6f2 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 0
diff changeset
276 public NarrowOopField getNarrowOopField(String fieldName) throws WrongTypeException {
ba764ed4b6f2 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 0
diff changeset
277 return (NarrowOopField) new BasicNarrowOopField(getOopField(fieldName));
ba764ed4b6f2 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 0
diff changeset
278 }
ba764ed4b6f2 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 0
diff changeset
279
0
a61af66fc99e Initial load
duke
parents:
diff changeset
280 public AddressField getAddressField(String fieldName) {
a61af66fc99e Initial load
duke
parents:
diff changeset
281 // This type can not be inferred (for now), so provide a wrapper
a61af66fc99e Initial load
duke
parents:
diff changeset
282 Field field = getField(fieldName);
a61af66fc99e Initial load
duke
parents:
diff changeset
283 if (field == null) {
a61af66fc99e Initial load
duke
parents:
diff changeset
284 return null;
a61af66fc99e Initial load
duke
parents:
diff changeset
285 }
a61af66fc99e Initial load
duke
parents:
diff changeset
286 return new BasicAddressFieldWrapper(field);
a61af66fc99e Initial load
duke
parents:
diff changeset
287 }
a61af66fc99e Initial load
duke
parents:
diff changeset
288
a61af66fc99e Initial load
duke
parents:
diff changeset
289 /** This method should only be used by the builder of the
a61af66fc99e Initial load
duke
parents:
diff changeset
290 TypeDataBase. Throws a RuntimeException if a field with this
a61af66fc99e Initial load
duke
parents:
diff changeset
291 name was already present in this class. */
a61af66fc99e Initial load
duke
parents:
diff changeset
292 public void addField(Field field) {
a61af66fc99e Initial load
duke
parents:
diff changeset
293 if (nameToFieldMap.get(field.getName()) != null) {
113
ba764ed4b6f2 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 0
diff changeset
294 throw new RuntimeException("field of name \"" + field.getName() + "\" already present in type " + this);
0
a61af66fc99e Initial load
duke
parents:
diff changeset
295 }
a61af66fc99e Initial load
duke
parents:
diff changeset
296
a61af66fc99e Initial load
duke
parents:
diff changeset
297 nameToFieldMap.put(field.getName(), field);
a61af66fc99e Initial load
duke
parents:
diff changeset
298 fieldList.add(field);
a61af66fc99e Initial load
duke
parents:
diff changeset
299 }
a61af66fc99e Initial load
duke
parents:
diff changeset
300
a61af66fc99e Initial load
duke
parents:
diff changeset
301 /** This method should only be used by the builder of the
a61af66fc99e Initial load
duke
parents:
diff changeset
302 TypeDataBase. Throws a RuntimeException if a field with this
a61af66fc99e Initial load
duke
parents:
diff changeset
303 name was not present in this class. */
a61af66fc99e Initial load
duke
parents:
diff changeset
304 public void removeField(Field field) {
a61af66fc99e Initial load
duke
parents:
diff changeset
305 if (nameToFieldMap.remove(field.getName()) == null) {
a61af66fc99e Initial load
duke
parents:
diff changeset
306 throw new RuntimeException("field of name \"" + field.getName() + "\" was not present");
a61af66fc99e Initial load
duke
parents:
diff changeset
307 }
a61af66fc99e Initial load
duke
parents:
diff changeset
308 fieldList.remove(field);
a61af66fc99e Initial load
duke
parents:
diff changeset
309 }
a61af66fc99e Initial load
duke
parents:
diff changeset
310 }