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

7088955: add C2 IR support to the SA Reviewed-by: kvn
author never
date Sun, 11 Sep 2011 14:48:24 -0700
parents c18cbe5936b8
children 117bb0519114
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
a61af66fc99e Initial load
duke
parents:
diff changeset
1 /*
3939
f6f3bb0ee072 7088955: add C2 IR support to the SA
never
parents: 1552
diff changeset
2 * Copyright (c) 2000, 2011, Oracle and/or its affiliates. All rights reserved.
0
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 *
1552
c18cbe5936b8 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 196
diff changeset
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
c18cbe5936b8 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 196
diff changeset
20 * or visit www.oracle.com if you need additional information or have any
c18cbe5936b8 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 196
diff changeset
21 * questions.
0
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
3939
f6f3bb0ee072 7088955: add C2 IR support to the SA
never
parents: 1552
diff changeset
153 static HashMap typeToVtbl = new HashMap();
f6f3bb0ee072 7088955: add C2 IR support to the SA
never
parents: 1552
diff changeset
154
f6f3bb0ee072 7088955: add C2 IR support to the SA
never
parents: 1552
diff changeset
155 private Address vtblForType(Type type) {
f6f3bb0ee072 7088955: add C2 IR support to the SA
never
parents: 1552
diff changeset
156 Address vtblAddr = (Address)typeToVtbl.get(type);
f6f3bb0ee072 7088955: add C2 IR support to the SA
never
parents: 1552
diff changeset
157 if (vtblAddr == null) {
f6f3bb0ee072 7088955: add C2 IR support to the SA
never
parents: 1552
diff changeset
158 vtblAddr = vtblAccess.getVtblForType(type);
f6f3bb0ee072 7088955: add C2 IR support to the SA
never
parents: 1552
diff changeset
159 if (vtblAddr != null) {
f6f3bb0ee072 7088955: add C2 IR support to the SA
never
parents: 1552
diff changeset
160 typeToVtbl.put(type, vtblAddr);
f6f3bb0ee072 7088955: add C2 IR support to the SA
never
parents: 1552
diff changeset
161 }
f6f3bb0ee072 7088955: add C2 IR support to the SA
never
parents: 1552
diff changeset
162 }
f6f3bb0ee072 7088955: add C2 IR support to the SA
never
parents: 1552
diff changeset
163 return vtblAddr;
f6f3bb0ee072 7088955: add C2 IR support to the SA
never
parents: 1552
diff changeset
164 }
f6f3bb0ee072 7088955: add C2 IR support to the SA
never
parents: 1552
diff changeset
165
0
a61af66fc99e Initial load
duke
parents:
diff changeset
166 public boolean addressTypeIsEqualToType(Address addr, Type type) {
a61af66fc99e Initial load
duke
parents:
diff changeset
167 if (addr == null) {
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 // This implementation should be suitably platform-independent; we
a61af66fc99e Initial load
duke
parents:
diff changeset
172 // search nearby memory for the vtbl value of the given type.
a61af66fc99e Initial load
duke
parents:
diff changeset
173
3939
f6f3bb0ee072 7088955: add C2 IR support to the SA
never
parents: 1552
diff changeset
174 Address vtblAddr = vtblForType(type);
0
a61af66fc99e Initial load
duke
parents:
diff changeset
175
a61af66fc99e Initial load
duke
parents:
diff changeset
176 if (vtblAddr == null) {
a61af66fc99e Initial load
duke
parents:
diff changeset
177 // Type was not polymorphic, or an error occurred during lookup
a61af66fc99e Initial load
duke
parents:
diff changeset
178 if (DEBUG) {
a61af66fc99e Initial load
duke
parents:
diff changeset
179 System.err.println("BasicTypeDataBase.addressTypeIsEqualToType: vtblAddr == null");
a61af66fc99e Initial load
duke
parents:
diff changeset
180 }
a61af66fc99e Initial load
duke
parents:
diff changeset
181
a61af66fc99e Initial load
duke
parents:
diff changeset
182 return false;
a61af66fc99e Initial load
duke
parents:
diff changeset
183 }
a61af66fc99e Initial load
duke
parents:
diff changeset
184
a61af66fc99e Initial load
duke
parents:
diff changeset
185 // The first implementation searched three locations for this vtbl
a61af66fc99e Initial load
duke
parents:
diff changeset
186 // value; scanning through the entire object was considered, but
a61af66fc99e Initial load
duke
parents:
diff changeset
187 // we thought we knew where we were looking, and looking only in
a61af66fc99e Initial load
duke
parents:
diff changeset
188 // these specific locations should reduce the probability of
a61af66fc99e Initial load
duke
parents:
diff changeset
189 // mistaking random bits as a pointer (although, realistically
a61af66fc99e Initial load
duke
parents:
diff changeset
190 // speaking, the likelihood of finding a match between the bit
a61af66fc99e Initial load
duke
parents:
diff changeset
191 // pattern of, for example, a double and the vtbl is vanishingly
a61af66fc99e Initial load
duke
parents:
diff changeset
192 // small.)
a61af66fc99e Initial load
duke
parents:
diff changeset
193 // 1. The first word of the object (should handle MSVC++ as
a61af66fc99e Initial load
duke
parents:
diff changeset
194 // well as the SparcWorks compilers with compatibility set to
a61af66fc99e Initial load
duke
parents:
diff changeset
195 // v5.0 or greater)
a61af66fc99e Initial load
duke
parents:
diff changeset
196 // 2. and 3. The last two Address-aligned words of the part of
a61af66fc99e Initial load
duke
parents:
diff changeset
197 // the object defined by its topmost polymorphic superclass.
a61af66fc99e Initial load
duke
parents:
diff changeset
198 // This should handle the SparcWorks compilers, v4.2 or
a61af66fc99e Initial load
duke
parents:
diff changeset
199 // earlier, as well as any other compilers which place the vptr
a61af66fc99e Initial load
duke
parents:
diff changeset
200 // at the end of the user-defined fields of the first base
a61af66fc99e Initial load
duke
parents:
diff changeset
201 // class with virtual functions.
a61af66fc99e Initial load
duke
parents:
diff changeset
202 //
a61af66fc99e Initial load
duke
parents:
diff changeset
203 // Unfortunately this algorithm did not work properly for the
a61af66fc99e Initial load
duke
parents:
diff changeset
204 // specific case of the ThreadShadow/Thread inheritance situation,
a61af66fc99e Initial load
duke
parents:
diff changeset
205 // because the Solaris compiler seems to cleverly eliminate the
a61af66fc99e Initial load
duke
parents:
diff changeset
206 // vtbl for ThreadShadow since the only virtual is empty. (We
a61af66fc99e Initial load
duke
parents:
diff changeset
207 // should get rid of the ThreadShadow and fix the include
a61af66fc99e Initial load
duke
parents:
diff changeset
208 // databases, but need to postpone this for the present.) The
a61af66fc99e Initial load
duke
parents:
diff changeset
209 // current solution performs the three-location check for this
a61af66fc99e Initial load
duke
parents:
diff changeset
210 // class and all of its known superclasses rather than just the
a61af66fc99e Initial load
duke
parents:
diff changeset
211 // topmost polymorphic one.
a61af66fc99e Initial load
duke
parents:
diff changeset
212
a61af66fc99e Initial load
duke
parents:
diff changeset
213 Type curType = type;
a61af66fc99e Initial load
duke
parents:
diff changeset
214
a61af66fc99e Initial load
duke
parents:
diff changeset
215 try {
a61af66fc99e Initial load
duke
parents:
diff changeset
216 while (curType != null) {
a61af66fc99e Initial load
duke
parents:
diff changeset
217 // Using the size information we have for this type, check the
a61af66fc99e Initial load
duke
parents:
diff changeset
218 // three locations described above.
a61af66fc99e Initial load
duke
parents:
diff changeset
219
a61af66fc99e Initial load
duke
parents:
diff changeset
220 // (1)
a61af66fc99e Initial load
duke
parents:
diff changeset
221 if (vtblAddr.equals(addr.getAddressAt(0))) {
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
a61af66fc99e Initial load
duke
parents:
diff changeset
225 // (2)
a61af66fc99e Initial load
duke
parents:
diff changeset
226 long offset = curType.getSize();
a61af66fc99e Initial load
duke
parents:
diff changeset
227 // I don't think this should be misaligned under any
a61af66fc99e Initial load
duke
parents:
diff changeset
228 // circumstances, but I'm not sure (FIXME: also not sure which
a61af66fc99e Initial load
duke
parents:
diff changeset
229 // way to go here, up or down -- assuming down)
a61af66fc99e Initial load
duke
parents:
diff changeset
230 offset -= (offset % getAddressSize());
a61af66fc99e Initial load
duke
parents:
diff changeset
231 if (offset <= 0) {
a61af66fc99e Initial load
duke
parents:
diff changeset
232 return false;
a61af66fc99e Initial load
duke
parents:
diff changeset
233 }
a61af66fc99e Initial load
duke
parents:
diff changeset
234 if (vtblAddr.equals(addr.getAddressAt(offset))) {
a61af66fc99e Initial load
duke
parents:
diff changeset
235 return true;
a61af66fc99e Initial load
duke
parents:
diff changeset
236 }
a61af66fc99e Initial load
duke
parents:
diff changeset
237 offset -= getAddressSize();
a61af66fc99e Initial load
duke
parents:
diff changeset
238 if (offset <= 0) {
a61af66fc99e Initial load
duke
parents:
diff changeset
239 return false;
a61af66fc99e Initial load
duke
parents:
diff changeset
240 }
a61af66fc99e Initial load
duke
parents:
diff changeset
241 if (vtblAddr.equals(addr.getAddressAt(offset))) {
a61af66fc99e Initial load
duke
parents:
diff changeset
242 return true;
a61af66fc99e Initial load
duke
parents:
diff changeset
243 }
a61af66fc99e Initial load
duke
parents:
diff changeset
244
a61af66fc99e Initial load
duke
parents:
diff changeset
245 curType = curType.getSuperclass();
a61af66fc99e Initial load
duke
parents:
diff changeset
246 }
a61af66fc99e Initial load
duke
parents:
diff changeset
247 }
a61af66fc99e Initial load
duke
parents:
diff changeset
248 catch (Exception e) {
a61af66fc99e Initial load
duke
parents:
diff changeset
249 // Any UnmappedAddressExceptions, etc. are a good indication
a61af66fc99e Initial load
duke
parents:
diff changeset
250 // that the pointer is not of the specified type
a61af66fc99e Initial load
duke
parents:
diff changeset
251 if (DEBUG) {
a61af66fc99e Initial load
duke
parents:
diff changeset
252 System.err.println("BasicTypeDataBase.addressTypeIsEqualToType: exception occurred during lookup:");
a61af66fc99e Initial load
duke
parents:
diff changeset
253 e.printStackTrace();
a61af66fc99e Initial load
duke
parents:
diff changeset
254 }
a61af66fc99e Initial load
duke
parents:
diff changeset
255
a61af66fc99e Initial load
duke
parents:
diff changeset
256 return false;
a61af66fc99e Initial load
duke
parents:
diff changeset
257 }
a61af66fc99e Initial load
duke
parents:
diff changeset
258
a61af66fc99e Initial load
duke
parents:
diff changeset
259 if (DEBUG) {
a61af66fc99e Initial load
duke
parents:
diff changeset
260 System.err.println("BasicTypeDataBase.addressTypeIsEqualToType: all vptr tests failed for type " +
a61af66fc99e Initial load
duke
parents:
diff changeset
261 type.getName());
a61af66fc99e Initial load
duke
parents:
diff changeset
262 }
a61af66fc99e Initial load
duke
parents:
diff changeset
263
a61af66fc99e Initial load
duke
parents:
diff changeset
264 return false;
a61af66fc99e Initial load
duke
parents:
diff changeset
265 }
a61af66fc99e Initial load
duke
parents:
diff changeset
266
3939
f6f3bb0ee072 7088955: add C2 IR support to the SA
never
parents: 1552
diff changeset
267 public Type findDynamicTypeForAddress(Address addr, Type baseType) {
f6f3bb0ee072 7088955: add C2 IR support to the SA
never
parents: 1552
diff changeset
268 // This implementation should be suitably platform-independent; we
f6f3bb0ee072 7088955: add C2 IR support to the SA
never
parents: 1552
diff changeset
269 // search nearby memory for the vtbl value of the given type.
f6f3bb0ee072 7088955: add C2 IR support to the SA
never
parents: 1552
diff changeset
270
f6f3bb0ee072 7088955: add C2 IR support to the SA
never
parents: 1552
diff changeset
271 if (vtblForType(baseType) == null) {
f6f3bb0ee072 7088955: add C2 IR support to the SA
never
parents: 1552
diff changeset
272 // Type was not polymorphic which is an error of some sort
f6f3bb0ee072 7088955: add C2 IR support to the SA
never
parents: 1552
diff changeset
273 throw new InternalError(baseType + " does not appear to be polymorphic");
f6f3bb0ee072 7088955: add C2 IR support to the SA
never
parents: 1552
diff changeset
274 }
f6f3bb0ee072 7088955: add C2 IR support to the SA
never
parents: 1552
diff changeset
275
f6f3bb0ee072 7088955: add C2 IR support to the SA
never
parents: 1552
diff changeset
276 // This is a more restricted version of guessTypeForAddress since
f6f3bb0ee072 7088955: add C2 IR support to the SA
never
parents: 1552
diff changeset
277 // that function has some limitations since it doesn't really know
f6f3bb0ee072 7088955: add C2 IR support to the SA
never
parents: 1552
diff changeset
278 // where in the hierarchy a virtual type starts and just poking
f6f3bb0ee072 7088955: add C2 IR support to the SA
never
parents: 1552
diff changeset
279 // around in memory is likely to trip over some vtable address,
f6f3bb0ee072 7088955: add C2 IR support to the SA
never
parents: 1552
diff changeset
280 // resulting in false positives. Eventually all uses should
f6f3bb0ee072 7088955: add C2 IR support to the SA
never
parents: 1552
diff changeset
281 // switch to this logic but in the interests of stability it will
f6f3bb0ee072 7088955: add C2 IR support to the SA
never
parents: 1552
diff changeset
282 // be separate for the moment.
f6f3bb0ee072 7088955: add C2 IR support to the SA
never
parents: 1552
diff changeset
283
f6f3bb0ee072 7088955: add C2 IR support to the SA
never
parents: 1552
diff changeset
284 // Assuming that the base type is truly the first polymorphic type
f6f3bb0ee072 7088955: add C2 IR support to the SA
never
parents: 1552
diff changeset
285 // then the vtbl for all subclasss should be at several defined
f6f3bb0ee072 7088955: add C2 IR support to the SA
never
parents: 1552
diff changeset
286 // locations so only those locations will be checked. It's also
f6f3bb0ee072 7088955: add C2 IR support to the SA
never
parents: 1552
diff changeset
287 // required that the caller knows that the static type is at least
f6f3bb0ee072 7088955: add C2 IR support to the SA
never
parents: 1552
diff changeset
288 // baseType. See the notes in guessTypeForAddress for the logic of
f6f3bb0ee072 7088955: add C2 IR support to the SA
never
parents: 1552
diff changeset
289 // the locations searched.
f6f3bb0ee072 7088955: add C2 IR support to the SA
never
parents: 1552
diff changeset
290
f6f3bb0ee072 7088955: add C2 IR support to the SA
never
parents: 1552
diff changeset
291 Address loc1 = addr.getAddressAt(0);
f6f3bb0ee072 7088955: add C2 IR support to the SA
never
parents: 1552
diff changeset
292 Address loc2 = null;
f6f3bb0ee072 7088955: add C2 IR support to the SA
never
parents: 1552
diff changeset
293 Address loc3 = null;
f6f3bb0ee072 7088955: add C2 IR support to the SA
never
parents: 1552
diff changeset
294 long offset2 = baseType.getSize();
f6f3bb0ee072 7088955: add C2 IR support to the SA
never
parents: 1552
diff changeset
295 // I don't think this should be misaligned under any
f6f3bb0ee072 7088955: add C2 IR support to the SA
never
parents: 1552
diff changeset
296 // circumstances, but I'm not sure (FIXME: also not sure which
f6f3bb0ee072 7088955: add C2 IR support to the SA
never
parents: 1552
diff changeset
297 // way to go here, up or down -- assuming down)
f6f3bb0ee072 7088955: add C2 IR support to the SA
never
parents: 1552
diff changeset
298 offset2 = offset2 - (offset2 % getAddressSize()) - getAddressSize();
f6f3bb0ee072 7088955: add C2 IR support to the SA
never
parents: 1552
diff changeset
299 if (offset2 > 0) {
f6f3bb0ee072 7088955: add C2 IR support to the SA
never
parents: 1552
diff changeset
300 loc2 = addr.getAddressAt(offset2);
f6f3bb0ee072 7088955: add C2 IR support to the SA
never
parents: 1552
diff changeset
301 }
f6f3bb0ee072 7088955: add C2 IR support to the SA
never
parents: 1552
diff changeset
302 long offset3 = offset2 - getAddressSize();
f6f3bb0ee072 7088955: add C2 IR support to the SA
never
parents: 1552
diff changeset
303 if (offset3 > 0) {
f6f3bb0ee072 7088955: add C2 IR support to the SA
never
parents: 1552
diff changeset
304 loc3 = addr.getAddressAt(offset3);
f6f3bb0ee072 7088955: add C2 IR support to the SA
never
parents: 1552
diff changeset
305 }
f6f3bb0ee072 7088955: add C2 IR support to the SA
never
parents: 1552
diff changeset
306
f6f3bb0ee072 7088955: add C2 IR support to the SA
never
parents: 1552
diff changeset
307 Type loc2Match = null;
f6f3bb0ee072 7088955: add C2 IR support to the SA
never
parents: 1552
diff changeset
308 Type loc3Match = null;
f6f3bb0ee072 7088955: add C2 IR support to the SA
never
parents: 1552
diff changeset
309 for (Iterator iter = getTypes(); iter.hasNext(); ) {
f6f3bb0ee072 7088955: add C2 IR support to the SA
never
parents: 1552
diff changeset
310 Type type = (Type) iter.next();
f6f3bb0ee072 7088955: add C2 IR support to the SA
never
parents: 1552
diff changeset
311 Type superClass = type;
f6f3bb0ee072 7088955: add C2 IR support to the SA
never
parents: 1552
diff changeset
312 while (superClass != baseType && superClass != null) {
f6f3bb0ee072 7088955: add C2 IR support to the SA
never
parents: 1552
diff changeset
313 superClass = superClass.getSuperclass();
f6f3bb0ee072 7088955: add C2 IR support to the SA
never
parents: 1552
diff changeset
314 }
f6f3bb0ee072 7088955: add C2 IR support to the SA
never
parents: 1552
diff changeset
315 if (superClass == null) continue;
f6f3bb0ee072 7088955: add C2 IR support to the SA
never
parents: 1552
diff changeset
316 Address vtblAddr = vtblForType(type);
f6f3bb0ee072 7088955: add C2 IR support to the SA
never
parents: 1552
diff changeset
317 if (vtblAddr == null) {
f6f3bb0ee072 7088955: add C2 IR support to the SA
never
parents: 1552
diff changeset
318 // This occurs sometimes for intermediate types that are never
f6f3bb0ee072 7088955: add C2 IR support to the SA
never
parents: 1552
diff changeset
319 // instantiated.
f6f3bb0ee072 7088955: add C2 IR support to the SA
never
parents: 1552
diff changeset
320 if (DEBUG) {
f6f3bb0ee072 7088955: add C2 IR support to the SA
never
parents: 1552
diff changeset
321 System.err.println("null vtbl for " + type);
f6f3bb0ee072 7088955: add C2 IR support to the SA
never
parents: 1552
diff changeset
322 }
f6f3bb0ee072 7088955: add C2 IR support to the SA
never
parents: 1552
diff changeset
323 continue;
f6f3bb0ee072 7088955: add C2 IR support to the SA
never
parents: 1552
diff changeset
324 }
f6f3bb0ee072 7088955: add C2 IR support to the SA
never
parents: 1552
diff changeset
325 // Prefer loc1 match
f6f3bb0ee072 7088955: add C2 IR support to the SA
never
parents: 1552
diff changeset
326 if (vtblAddr.equals(loc1)) return type;
f6f3bb0ee072 7088955: add C2 IR support to the SA
never
parents: 1552
diff changeset
327 if (loc2 != null && loc2Match == null && vtblAddr.equals(loc2)) {
f6f3bb0ee072 7088955: add C2 IR support to the SA
never
parents: 1552
diff changeset
328 loc2Match = type;
f6f3bb0ee072 7088955: add C2 IR support to the SA
never
parents: 1552
diff changeset
329 }
f6f3bb0ee072 7088955: add C2 IR support to the SA
never
parents: 1552
diff changeset
330 if (loc3 != null && loc3Match == null && vtblAddr.equals(loc3)) {
f6f3bb0ee072 7088955: add C2 IR support to the SA
never
parents: 1552
diff changeset
331 loc3Match = type;
f6f3bb0ee072 7088955: add C2 IR support to the SA
never
parents: 1552
diff changeset
332 }
f6f3bb0ee072 7088955: add C2 IR support to the SA
never
parents: 1552
diff changeset
333 }
f6f3bb0ee072 7088955: add C2 IR support to the SA
never
parents: 1552
diff changeset
334 if (loc2Match != null) return loc2Match;
f6f3bb0ee072 7088955: add C2 IR support to the SA
never
parents: 1552
diff changeset
335 if (loc3Match != null) return loc3Match;
f6f3bb0ee072 7088955: add C2 IR support to the SA
never
parents: 1552
diff changeset
336 return null;
f6f3bb0ee072 7088955: add C2 IR support to the SA
never
parents: 1552
diff changeset
337 }
f6f3bb0ee072 7088955: add C2 IR support to the SA
never
parents: 1552
diff changeset
338
0
a61af66fc99e Initial load
duke
parents:
diff changeset
339 public Type guessTypeForAddress(Address addr) {
a61af66fc99e Initial load
duke
parents:
diff changeset
340 for (Iterator iter = getTypes(); iter.hasNext(); ) {
a61af66fc99e Initial load
duke
parents:
diff changeset
341 Type t = (Type) iter.next();
a61af66fc99e Initial load
duke
parents:
diff changeset
342 if (addressTypeIsEqualToType(addr, t)) {
a61af66fc99e Initial load
duke
parents:
diff changeset
343 return t;
a61af66fc99e Initial load
duke
parents:
diff changeset
344 }
a61af66fc99e Initial load
duke
parents:
diff changeset
345 }
a61af66fc99e Initial load
duke
parents:
diff changeset
346 return null;
a61af66fc99e Initial load
duke
parents:
diff changeset
347 }
a61af66fc99e Initial load
duke
parents:
diff changeset
348
a61af66fc99e Initial load
duke
parents:
diff changeset
349 public long cIntegerTypeMaxValue(long sizeInBytes, boolean isUnsigned) {
a61af66fc99e Initial load
duke
parents:
diff changeset
350 return machDesc.cIntegerTypeMaxValue(sizeInBytes, isUnsigned);
a61af66fc99e Initial load
duke
parents:
diff changeset
351 }
a61af66fc99e Initial load
duke
parents:
diff changeset
352
a61af66fc99e Initial load
duke
parents:
diff changeset
353 public long cIntegerTypeMinValue(long sizeInBytes, boolean isUnsigned) {
a61af66fc99e Initial load
duke
parents:
diff changeset
354 return machDesc.cIntegerTypeMinValue(sizeInBytes, isUnsigned);
a61af66fc99e Initial load
duke
parents:
diff changeset
355 }
a61af66fc99e Initial load
duke
parents:
diff changeset
356
a61af66fc99e Initial load
duke
parents:
diff changeset
357 public Iterator getTypes() {
a61af66fc99e Initial load
duke
parents:
diff changeset
358 return nameToTypeMap.values().iterator();
a61af66fc99e Initial load
duke
parents:
diff changeset
359 }
a61af66fc99e Initial load
duke
parents:
diff changeset
360
a61af66fc99e Initial load
duke
parents:
diff changeset
361 public Iterator getIntConstants() {
a61af66fc99e Initial load
duke
parents:
diff changeset
362 return nameToIntConstantMap.keySet().iterator();
a61af66fc99e Initial load
duke
parents:
diff changeset
363 }
a61af66fc99e Initial load
duke
parents:
diff changeset
364
a61af66fc99e Initial load
duke
parents:
diff changeset
365 public Iterator getLongConstants() {
a61af66fc99e Initial load
duke
parents:
diff changeset
366 return nameToLongConstantMap.keySet().iterator();
a61af66fc99e Initial load
duke
parents:
diff changeset
367 }
a61af66fc99e Initial load
duke
parents:
diff changeset
368
a61af66fc99e Initial load
duke
parents:
diff changeset
369 //--------------------------------------------------------------------------------
a61af66fc99e Initial load
duke
parents:
diff changeset
370 // Public routines only for use by the database builder
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 called by the builder of the
a61af66fc99e Initial load
duke
parents:
diff changeset
374 TypeDataBase and at most once */
a61af66fc99e Initial load
duke
parents:
diff changeset
375 public void setJBooleanType(Type type) {
a61af66fc99e Initial load
duke
parents:
diff changeset
376 jbooleanType = type;
a61af66fc99e Initial load
duke
parents:
diff changeset
377 }
a61af66fc99e Initial load
duke
parents:
diff changeset
378
a61af66fc99e Initial load
duke
parents:
diff changeset
379 /** This method should only be called by the builder of the
a61af66fc99e Initial load
duke
parents:
diff changeset
380 TypeDataBase and at most once */
a61af66fc99e Initial load
duke
parents:
diff changeset
381 public void setJByteType(Type type) {
a61af66fc99e Initial load
duke
parents:
diff changeset
382 jbyteType = type;
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 called by the builder of the
a61af66fc99e Initial load
duke
parents:
diff changeset
386 TypeDataBase and at most once */
a61af66fc99e Initial load
duke
parents:
diff changeset
387 public void setJCharType(Type type) {
a61af66fc99e Initial load
duke
parents:
diff changeset
388 jcharType = type;
a61af66fc99e Initial load
duke
parents:
diff changeset
389 }
a61af66fc99e Initial load
duke
parents:
diff changeset
390
a61af66fc99e Initial load
duke
parents:
diff changeset
391 /** This method should only be called by the builder of the
a61af66fc99e Initial load
duke
parents:
diff changeset
392 TypeDataBase and at most once */
a61af66fc99e Initial load
duke
parents:
diff changeset
393 public void setJDoubleType(Type type) {
a61af66fc99e Initial load
duke
parents:
diff changeset
394 jdoubleType = type;
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 called by the builder of the
a61af66fc99e Initial load
duke
parents:
diff changeset
398 TypeDataBase and at most once */
a61af66fc99e Initial load
duke
parents:
diff changeset
399 public void setJFloatType(Type type) {
a61af66fc99e Initial load
duke
parents:
diff changeset
400 jfloatType = type;
a61af66fc99e Initial load
duke
parents:
diff changeset
401 }
a61af66fc99e Initial load
duke
parents:
diff changeset
402
a61af66fc99e Initial load
duke
parents:
diff changeset
403 /** This method should only be called by the builder of the
a61af66fc99e Initial load
duke
parents:
diff changeset
404 TypeDataBase and at most once */
a61af66fc99e Initial load
duke
parents:
diff changeset
405 public void setJIntType(Type type) {
a61af66fc99e Initial load
duke
parents:
diff changeset
406 jintType = type;
a61af66fc99e Initial load
duke
parents:
diff changeset
407 }
a61af66fc99e Initial load
duke
parents:
diff changeset
408
a61af66fc99e Initial load
duke
parents:
diff changeset
409 /** This method should only be called by the builder of the
a61af66fc99e Initial load
duke
parents:
diff changeset
410 TypeDataBase and at most once */
a61af66fc99e Initial load
duke
parents:
diff changeset
411 public void setJLongType(Type type) {
a61af66fc99e Initial load
duke
parents:
diff changeset
412 jlongType = type;
a61af66fc99e Initial load
duke
parents:
diff changeset
413 }
a61af66fc99e Initial load
duke
parents:
diff changeset
414
a61af66fc99e Initial load
duke
parents:
diff changeset
415 /** This method should only be called by the builder of the
a61af66fc99e Initial load
duke
parents:
diff changeset
416 TypeDataBase and at most once */
a61af66fc99e Initial load
duke
parents:
diff changeset
417 public void setJShortType(Type type) {
a61af66fc99e Initial load
duke
parents:
diff changeset
418 jshortType = type;
a61af66fc99e Initial load
duke
parents:
diff changeset
419 }
a61af66fc99e Initial load
duke
parents:
diff changeset
420
a61af66fc99e Initial load
duke
parents:
diff changeset
421 /** This method should only be used by the builder of the
a61af66fc99e Initial load
duke
parents:
diff changeset
422 TypeDataBase. Throws a RuntimeException if a class with this
a61af66fc99e Initial load
duke
parents:
diff changeset
423 name was already present. */
a61af66fc99e Initial load
duke
parents:
diff changeset
424 public void addType(Type type) {
a61af66fc99e Initial load
duke
parents:
diff changeset
425 if (nameToTypeMap.get(type.getName()) != null) {
a61af66fc99e Initial load
duke
parents:
diff changeset
426 throw new RuntimeException("type of name \"" + type.getName() + "\" already present");
a61af66fc99e Initial load
duke
parents:
diff changeset
427 }
a61af66fc99e Initial load
duke
parents:
diff changeset
428
a61af66fc99e Initial load
duke
parents:
diff changeset
429 nameToTypeMap.put(type.getName(), type);
a61af66fc99e Initial load
duke
parents:
diff changeset
430 }
a61af66fc99e Initial load
duke
parents:
diff changeset
431
a61af66fc99e Initial load
duke
parents:
diff changeset
432 /** This method should only be used by the builder of the
a61af66fc99e Initial load
duke
parents:
diff changeset
433 TypeDataBase. Throws a RuntimeException if this class was not
a61af66fc99e Initial load
duke
parents:
diff changeset
434 present. */
a61af66fc99e Initial load
duke
parents:
diff changeset
435 public void removeType(Type type) {
a61af66fc99e Initial load
duke
parents:
diff changeset
436 Type curType = (Type) nameToTypeMap.get(type.getName());
a61af66fc99e Initial load
duke
parents:
diff changeset
437 if (curType == null) {
a61af66fc99e Initial load
duke
parents:
diff changeset
438 throw new RuntimeException("type of name \"" + type.getName() + "\" not present");
a61af66fc99e Initial load
duke
parents:
diff changeset
439 }
a61af66fc99e Initial load
duke
parents:
diff changeset
440
a61af66fc99e Initial load
duke
parents:
diff changeset
441 if (!curType.equals(type)) {
a61af66fc99e Initial load
duke
parents:
diff changeset
442 throw new RuntimeException("a different type of name \"" + type.getName() + "\" was present");
a61af66fc99e Initial load
duke
parents:
diff changeset
443 }
a61af66fc99e Initial load
duke
parents:
diff changeset
444
a61af66fc99e Initial load
duke
parents:
diff changeset
445 nameToTypeMap.remove(type.getName());
a61af66fc99e Initial load
duke
parents:
diff changeset
446 }
a61af66fc99e Initial load
duke
parents:
diff changeset
447
a61af66fc99e Initial load
duke
parents:
diff changeset
448 /** This method should only be used by the builder of the
a61af66fc99e Initial load
duke
parents:
diff changeset
449 TypeDataBase. Throws a RuntimeException if an integer constant
a61af66fc99e Initial load
duke
parents:
diff changeset
450 with this name was already present. */
a61af66fc99e Initial load
duke
parents:
diff changeset
451 public void addIntConstant(String name, int value) {
a61af66fc99e Initial load
duke
parents:
diff changeset
452 if (nameToIntConstantMap.get(name) != null) {
a61af66fc99e Initial load
duke
parents:
diff changeset
453 throw new RuntimeException("int constant of name \"" + name + "\" already present");
a61af66fc99e Initial load
duke
parents:
diff changeset
454 }
a61af66fc99e Initial load
duke
parents:
diff changeset
455
a61af66fc99e Initial load
duke
parents:
diff changeset
456 nameToIntConstantMap.put(name, new Integer(value));
a61af66fc99e Initial load
duke
parents:
diff changeset
457 }
a61af66fc99e Initial load
duke
parents:
diff changeset
458
a61af66fc99e Initial load
duke
parents:
diff changeset
459 /** This method should only be used by the builder of the
a61af66fc99e Initial load
duke
parents:
diff changeset
460 TypeDataBase. Throws a RuntimeException if an integer constant
a61af66fc99e Initial load
duke
parents:
diff changeset
461 with this name was not present. */
a61af66fc99e Initial load
duke
parents:
diff changeset
462 public void removeIntConstant(String name) {
a61af66fc99e Initial load
duke
parents:
diff changeset
463 Integer curConstant = (Integer) nameToIntConstantMap.get(name);
a61af66fc99e Initial load
duke
parents:
diff changeset
464 if (curConstant == null) {
a61af66fc99e Initial load
duke
parents:
diff changeset
465 throw new RuntimeException("int constant of name \"" + name + "\" not present");
a61af66fc99e Initial load
duke
parents:
diff changeset
466 }
a61af66fc99e Initial load
duke
parents:
diff changeset
467
a61af66fc99e Initial load
duke
parents:
diff changeset
468 nameToIntConstantMap.remove(name);
a61af66fc99e Initial load
duke
parents:
diff changeset
469 }
a61af66fc99e Initial load
duke
parents:
diff changeset
470
a61af66fc99e Initial load
duke
parents:
diff changeset
471 /** This method should only be used by the builder of the
a61af66fc99e Initial load
duke
parents:
diff changeset
472 TypeDataBase. Throws a RuntimeException if a long constant with
a61af66fc99e Initial load
duke
parents:
diff changeset
473 this name was already present. */
a61af66fc99e Initial load
duke
parents:
diff changeset
474 public void addLongConstant(String name, long value) {
a61af66fc99e Initial load
duke
parents:
diff changeset
475 if (nameToLongConstantMap.get(name) != null) {
a61af66fc99e Initial load
duke
parents:
diff changeset
476 throw new RuntimeException("long constant of name \"" + name + "\" already present");
a61af66fc99e Initial load
duke
parents:
diff changeset
477 }
a61af66fc99e Initial load
duke
parents:
diff changeset
478
a61af66fc99e Initial load
duke
parents:
diff changeset
479 nameToLongConstantMap.put(name, new Long(value));
a61af66fc99e Initial load
duke
parents:
diff changeset
480 }
a61af66fc99e Initial load
duke
parents:
diff changeset
481
a61af66fc99e Initial load
duke
parents:
diff changeset
482 /** This method should only be used by the builder of the
a61af66fc99e Initial load
duke
parents:
diff changeset
483 TypeDataBase. Throws a RuntimeException if a long constant with
a61af66fc99e Initial load
duke
parents:
diff changeset
484 this name was not present. */
a61af66fc99e Initial load
duke
parents:
diff changeset
485 public void removeLongConstant(String name) {
a61af66fc99e Initial load
duke
parents:
diff changeset
486 Long curConstant = (Long) nameToLongConstantMap.get(name);
a61af66fc99e Initial load
duke
parents:
diff changeset
487 if (curConstant == null) {
a61af66fc99e Initial load
duke
parents:
diff changeset
488 throw new RuntimeException("long constant of name \"" + name + "\" not present");
a61af66fc99e Initial load
duke
parents:
diff changeset
489 }
a61af66fc99e Initial load
duke
parents:
diff changeset
490
a61af66fc99e Initial load
duke
parents:
diff changeset
491 nameToLongConstantMap.remove(name);
a61af66fc99e Initial load
duke
parents:
diff changeset
492 }
a61af66fc99e Initial load
duke
parents:
diff changeset
493 }