Mercurial > hg > truffle
annotate agent/src/share/classes/sun/jvm/hotspot/HotSpotTypeDataBase.java @ 2072:d6cd0d55d0b5
6987812: 2/3 SAJDI: "gHotSpotVMTypes was not initialized properly in the remote process"
Summary: Change ExportDirectoryTableImpl to return the 'Export RVA' field without modification. Read 'Base Of Data' field in optional header when PE32 format COFF file is read. Refine search for dbgeng.dll and dbghelp.dll. Other cleanups.
Reviewed-by: swamyv, poonam
author | dcubed |
---|---|
date | Thu, 23 Dec 2010 07:58:35 -0800 |
parents | c18cbe5936b8 |
children | 3582bf76420e |
rev | line source |
---|---|
0 | 1 /* |
2072
d6cd0d55d0b5
6987812: 2/3 SAJDI: "gHotSpotVMTypes was not initialized properly in the remote process"
dcubed
parents:
1552
diff
changeset
|
2 * Copyright (c) 2000, 2010, Oracle and/or its affiliates. All rights reserved. |
0 | 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 * | |
5 * This code is free software; you can redistribute it and/or modify it | |
6 * under the terms of the GNU General Public License version 2 only, as | |
7 * published by the Free Software Foundation. | |
8 * | |
9 * This code is distributed in the hope that it will be useful, but WITHOUT | |
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | |
12 * version 2 for more details (a copy is included in the LICENSE file that | |
13 * accompanied this code). | |
14 * | |
15 * You should have received a copy of the GNU General Public License version | |
16 * 2 along with this work; if not, write to the Free Software Foundation, | |
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. | |
18 * | |
1552
c18cbe5936b8
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
844
diff
changeset
|
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
c18cbe5936b8
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
844
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:
844
diff
changeset
|
21 * questions. |
0 | 22 * |
23 */ | |
24 | |
25 package sun.jvm.hotspot; | |
26 | |
27 import java.io.*; | |
28 import java.util.*; | |
29 import sun.jvm.hotspot.debugger.*; | |
30 import sun.jvm.hotspot.types.*; | |
31 import sun.jvm.hotspot.types.basic.*; | |
32 import sun.jvm.hotspot.utilities.*; | |
33 | |
34 /** <P> This is the cross-platform TypeDataBase used by the Oop | |
35 hierarchy. The decision was made to make this cross-platform by | |
36 having the VM export the necessary symbols via a built-in table; | |
37 see src/share/vm/runtime/vmStructs.[ch]pp for more details. </P> | |
38 | |
39 <P> <B>WARNING</B>: clients should refer to this class through the | |
40 TypeDataBase interface and not directly to the HotSpotTypeDataBase | |
41 type. </P> | |
42 | |
43 <P> NOTE: since we are fetching the sizes of the Java primitive types | |
44 */ | |
45 | |
46 public class HotSpotTypeDataBase extends BasicTypeDataBase { | |
47 private Debugger symbolLookup; | |
48 private String[] jvmLibNames; | |
49 private static final int UNINITIALIZED_SIZE = -1; | |
50 private static final int C_INT8_SIZE = 1; | |
51 private static final int C_INT32_SIZE = 4; | |
52 private static final int C_INT64_SIZE = 8; | |
53 | |
54 private static final boolean DEBUG; | |
55 static { | |
56 DEBUG = System.getProperty("sun.jvm.hotspot.HotSpotTypeDataBase.DEBUG") | |
57 != null; | |
58 } | |
59 | |
60 /** <P> This requires a SymbolLookup mechanism as well as the | |
61 MachineDescription. Note that we do not need a NameMangler since | |
62 we use the vmStructs mechanism to avoid looking up C++ | |
63 symbols. </P> | |
64 | |
65 <P> NOTE that it is guaranteed that this constructor will not | |
66 attempt to fetch any Java values from the remote process, only C | |
67 integers and addresses. This is required because we are fetching | |
68 the sizes of the Java primitive types from the remote process, | |
69 implying that attempting to fetch them before their sizes are | |
70 known is illegal. </P> | |
71 | |
72 <P> Throws NoSuchSymbolException if a problem occurred while | |
73 looking up one of the bootstrapping symbols related to the | |
74 VMStructs table in the remote VM; this may indicate that the | |
75 remote process is not actually a HotSpot VM. </P> | |
76 */ | |
77 public HotSpotTypeDataBase(MachineDescription machDesc, | |
78 VtblAccess vtblAccess, | |
79 Debugger symbolLookup, | |
80 String[] jvmLibNames) throws NoSuchSymbolException { | |
81 super(machDesc, vtblAccess); | |
82 this.symbolLookup = symbolLookup; | |
83 this.jvmLibNames = jvmLibNames; | |
84 | |
85 readVMTypes(); | |
86 initializePrimitiveTypes(); | |
87 readVMStructs(); | |
88 readVMIntConstants(); | |
89 readVMLongConstants(); | |
90 } | |
91 | |
92 private void readVMTypes() { | |
93 // Get the variables we need in order to traverse the VMTypeEntry[] | |
94 long typeEntryTypeNameOffset; | |
95 long typeEntrySuperclassNameOffset; | |
96 long typeEntryIsOopTypeOffset; | |
97 long typeEntryIsIntegerTypeOffset; | |
98 long typeEntryIsUnsignedOffset; | |
99 long typeEntrySizeOffset; | |
100 long typeEntryArrayStride; | |
101 | |
2072
d6cd0d55d0b5
6987812: 2/3 SAJDI: "gHotSpotVMTypes was not initialized properly in the remote process"
dcubed
parents:
1552
diff
changeset
|
102 // Fetch the address of the VMTypeEntry*. We get this symbol first |
d6cd0d55d0b5
6987812: 2/3 SAJDI: "gHotSpotVMTypes was not initialized properly in the remote process"
dcubed
parents:
1552
diff
changeset
|
103 // and try to use it to make sure that symbol lookup is working. |
0 | 104 Address entryAddr = lookupInProcess("gHotSpotVMTypes"); |
105 // System.err.println("gHotSpotVMTypes address = " + entryAddr); | |
106 // Dereference this once to get the pointer to the first VMTypeEntry | |
107 // dumpMemory(entryAddr, 80); | |
108 entryAddr = entryAddr.getAddressAt(0); | |
109 | |
110 if (entryAddr == null) { | |
111 throw new RuntimeException("gHotSpotVMTypes was not initialized properly in the remote process; can not continue"); | |
112 } | |
113 | |
2072
d6cd0d55d0b5
6987812: 2/3 SAJDI: "gHotSpotVMTypes was not initialized properly in the remote process"
dcubed
parents:
1552
diff
changeset
|
114 typeEntryTypeNameOffset = getLongValueFromProcess("gHotSpotVMTypeEntryTypeNameOffset"); |
d6cd0d55d0b5
6987812: 2/3 SAJDI: "gHotSpotVMTypes was not initialized properly in the remote process"
dcubed
parents:
1552
diff
changeset
|
115 typeEntrySuperclassNameOffset = getLongValueFromProcess("gHotSpotVMTypeEntrySuperclassNameOffset"); |
d6cd0d55d0b5
6987812: 2/3 SAJDI: "gHotSpotVMTypes was not initialized properly in the remote process"
dcubed
parents:
1552
diff
changeset
|
116 typeEntryIsOopTypeOffset = getLongValueFromProcess("gHotSpotVMTypeEntryIsOopTypeOffset"); |
d6cd0d55d0b5
6987812: 2/3 SAJDI: "gHotSpotVMTypes was not initialized properly in the remote process"
dcubed
parents:
1552
diff
changeset
|
117 typeEntryIsIntegerTypeOffset = getLongValueFromProcess("gHotSpotVMTypeEntryIsIntegerTypeOffset"); |
d6cd0d55d0b5
6987812: 2/3 SAJDI: "gHotSpotVMTypes was not initialized properly in the remote process"
dcubed
parents:
1552
diff
changeset
|
118 typeEntryIsUnsignedOffset = getLongValueFromProcess("gHotSpotVMTypeEntryIsUnsignedOffset"); |
d6cd0d55d0b5
6987812: 2/3 SAJDI: "gHotSpotVMTypes was not initialized properly in the remote process"
dcubed
parents:
1552
diff
changeset
|
119 typeEntrySizeOffset = getLongValueFromProcess("gHotSpotVMTypeEntrySizeOffset"); |
d6cd0d55d0b5
6987812: 2/3 SAJDI: "gHotSpotVMTypes was not initialized properly in the remote process"
dcubed
parents:
1552
diff
changeset
|
120 typeEntryArrayStride = getLongValueFromProcess("gHotSpotVMTypeEntryArrayStride"); |
d6cd0d55d0b5
6987812: 2/3 SAJDI: "gHotSpotVMTypes was not initialized properly in the remote process"
dcubed
parents:
1552
diff
changeset
|
121 |
0 | 122 // Start iterating down it until we find an entry with no name |
123 Address typeNameAddr = null; | |
124 do { | |
125 // Fetch the type name first | |
126 typeNameAddr = entryAddr.getAddressAt(typeEntryTypeNameOffset); | |
127 if (typeNameAddr != null) { | |
128 String typeName = CStringUtilities.getString(typeNameAddr); | |
129 | |
130 String superclassName = null; | |
131 Address superclassNameAddr = entryAddr.getAddressAt(typeEntrySuperclassNameOffset); | |
132 if (superclassNameAddr != null) { | |
133 superclassName = CStringUtilities.getString(superclassNameAddr); | |
134 } | |
135 | |
136 boolean isOopType = (entryAddr.getCIntegerAt(typeEntryIsOopTypeOffset, C_INT32_SIZE, false) != 0); | |
137 boolean isIntegerType = (entryAddr.getCIntegerAt(typeEntryIsIntegerTypeOffset, C_INT32_SIZE, false) != 0); | |
138 boolean isUnsigned = (entryAddr.getCIntegerAt(typeEntryIsUnsignedOffset, C_INT32_SIZE, false) != 0); | |
139 long size = entryAddr.getCIntegerAt(typeEntrySizeOffset, C_INT64_SIZE, true); | |
140 | |
141 createType(typeName, superclassName, isOopType, isIntegerType, isUnsigned, size); | |
142 } | |
143 | |
144 entryAddr = entryAddr.addOffsetTo(typeEntryArrayStride); | |
145 } while (typeNameAddr != null); | |
146 } | |
147 | |
148 private void initializePrimitiveTypes() { | |
149 // Look up the needed primitive types by name...they had better be present | |
150 setJBooleanType(lookupPrimitiveType("jboolean")); | |
151 setJByteType (lookupPrimitiveType("jbyte")); | |
152 setJCharType (lookupPrimitiveType("jchar")); | |
153 setJDoubleType (lookupPrimitiveType("jdouble")); | |
154 setJFloatType (lookupPrimitiveType("jfloat")); | |
155 setJIntType (lookupPrimitiveType("jint")); | |
156 setJLongType (lookupPrimitiveType("jlong")); | |
157 setJShortType (lookupPrimitiveType("jshort")); | |
158 | |
159 // Indicate that these are the Java primitive types | |
160 ((BasicType) getJBooleanType()).setIsJavaPrimitiveType(true); | |
161 ((BasicType) getJByteType()).setIsJavaPrimitiveType(true); | |
162 ((BasicType) getJCharType()).setIsJavaPrimitiveType(true); | |
163 ((BasicType) getJDoubleType()).setIsJavaPrimitiveType(true); | |
164 ((BasicType) getJFloatType()).setIsJavaPrimitiveType(true); | |
165 ((BasicType) getJIntType()).setIsJavaPrimitiveType(true); | |
166 ((BasicType) getJLongType()).setIsJavaPrimitiveType(true); | |
167 ((BasicType) getJShortType()).setIsJavaPrimitiveType(true); | |
168 } | |
169 | |
170 private Type lookupPrimitiveType(String typeName) { | |
171 Type type = lookupType(typeName, false); | |
172 if (type == null) { | |
173 throw new RuntimeException("Error initializing the HotSpotDataBase: could not find the primitive type \"" + | |
174 typeName + "\" in the remote VM's VMStructs table. This type is required in " + | |
175 "order to determine the size of Java primitive types. Can not continue."); | |
176 } | |
177 return type; | |
178 } | |
179 | |
180 private void readVMStructs() { | |
181 // Get the variables we need in order to traverse the VMStructEntry[] | |
182 long structEntryTypeNameOffset; | |
183 long structEntryFieldNameOffset; | |
184 long structEntryTypeStringOffset; | |
185 long structEntryIsStaticOffset; | |
186 long structEntryOffsetOffset; | |
187 long structEntryAddressOffset; | |
188 long structEntryArrayStride; | |
189 | |
190 structEntryTypeNameOffset = getLongValueFromProcess("gHotSpotVMStructEntryTypeNameOffset"); | |
191 structEntryFieldNameOffset = getLongValueFromProcess("gHotSpotVMStructEntryFieldNameOffset"); | |
192 structEntryTypeStringOffset = getLongValueFromProcess("gHotSpotVMStructEntryTypeStringOffset"); | |
193 structEntryIsStaticOffset = getLongValueFromProcess("gHotSpotVMStructEntryIsStaticOffset"); | |
194 structEntryOffsetOffset = getLongValueFromProcess("gHotSpotVMStructEntryOffsetOffset"); | |
195 structEntryAddressOffset = getLongValueFromProcess("gHotSpotVMStructEntryAddressOffset"); | |
196 structEntryArrayStride = getLongValueFromProcess("gHotSpotVMStructEntryArrayStride"); | |
197 | |
198 // Fetch the address of the VMStructEntry* | |
199 Address entryAddr = lookupInProcess("gHotSpotVMStructs"); | |
200 // Dereference this once to get the pointer to the first VMStructEntry | |
201 entryAddr = entryAddr.getAddressAt(0); | |
202 if (entryAddr == null) { | |
203 throw new RuntimeException("gHotSpotVMStructs was not initialized properly in the remote process; can not continue"); | |
204 } | |
205 | |
206 // Start iterating down it until we find an entry with no name | |
207 Address fieldNameAddr = null; | |
208 String typeName = null; | |
209 String fieldName = null; | |
210 String typeString = null; | |
211 boolean isStatic = false; | |
212 long offset = 0; | |
213 Address staticFieldAddr = null; | |
214 long size = 0; | |
215 long index = 0; | |
216 String opaqueName = "<opaque>"; | |
217 lookupOrCreateClass(opaqueName, false, false, false); | |
218 | |
219 do { | |
220 // Fetch the field name first | |
221 fieldNameAddr = entryAddr.getAddressAt(structEntryFieldNameOffset); | |
222 if (fieldNameAddr != null) { | |
223 fieldName = CStringUtilities.getString(fieldNameAddr); | |
224 | |
225 // Now the rest of the names. Keep in mind that the type name | |
226 // may be NULL, indicating that the type is opaque. | |
227 Address addr = entryAddr.getAddressAt(structEntryTypeNameOffset); | |
228 if (addr == null) { | |
229 throw new RuntimeException("gHotSpotVMStructs unexpectedly had a NULL type name at index " + index); | |
230 } | |
231 typeName = CStringUtilities.getString(addr); | |
232 | |
233 addr = entryAddr.getAddressAt(structEntryTypeStringOffset); | |
234 if (addr == null) { | |
235 typeString = opaqueName; | |
236 } else { | |
237 typeString = CStringUtilities.getString(addr); | |
238 } | |
239 | |
240 isStatic = !(entryAddr.getCIntegerAt(structEntryIsStaticOffset, C_INT32_SIZE, false) == 0); | |
241 if (isStatic) { | |
242 staticFieldAddr = entryAddr.getAddressAt(structEntryAddressOffset); | |
243 offset = 0; | |
244 } else { | |
245 offset = entryAddr.getCIntegerAt(structEntryOffsetOffset, C_INT64_SIZE, true); | |
246 staticFieldAddr = null; | |
247 } | |
248 | |
249 // The containing Type must already be in the database -- no exceptions | |
250 BasicType containingType = lookupOrFail(typeName); | |
251 | |
252 // The field's Type must already be in the database -- no exceptions | |
253 BasicType fieldType = lookupOrFail(typeString); | |
254 | |
255 // Create field by type | |
256 createField(containingType, fieldName, fieldType, | |
257 isStatic, offset, staticFieldAddr); | |
258 } | |
259 | |
260 ++index; | |
261 entryAddr = entryAddr.addOffsetTo(structEntryArrayStride); | |
262 } while (fieldNameAddr != null); | |
263 } | |
264 | |
265 private void readVMIntConstants() { | |
266 // Get the variables we need in order to traverse the VMIntConstantEntry[] | |
267 long intConstantEntryNameOffset; | |
268 long intConstantEntryValueOffset; | |
269 long intConstantEntryArrayStride; | |
270 | |
271 intConstantEntryNameOffset = getLongValueFromProcess("gHotSpotVMIntConstantEntryNameOffset"); | |
272 intConstantEntryValueOffset = getLongValueFromProcess("gHotSpotVMIntConstantEntryValueOffset"); | |
273 intConstantEntryArrayStride = getLongValueFromProcess("gHotSpotVMIntConstantEntryArrayStride"); | |
274 | |
275 // Fetch the address of the VMIntConstantEntry* | |
276 Address entryAddr = lookupInProcess("gHotSpotVMIntConstants"); | |
277 // Dereference this once to get the pointer to the first VMIntConstantEntry | |
278 entryAddr = entryAddr.getAddressAt(0); | |
279 if (entryAddr == null) { | |
280 throw new RuntimeException("gHotSpotVMIntConstants was not initialized properly in the remote process; can not continue"); | |
281 } | |
282 | |
283 // Start iterating down it until we find an entry with no name | |
284 Address nameAddr = null; | |
285 do { | |
286 // Fetch the type name first | |
287 nameAddr = entryAddr.getAddressAt(intConstantEntryNameOffset); | |
288 if (nameAddr != null) { | |
289 String name = CStringUtilities.getString(nameAddr); | |
290 int value = (int) entryAddr.getCIntegerAt(intConstantEntryValueOffset, C_INT32_SIZE, false); | |
291 | |
292 // Be a little resilient | |
293 Integer oldValue = lookupIntConstant(name, false); | |
294 if (oldValue == null) { | |
295 addIntConstant(name, value); | |
296 } else { | |
297 if (oldValue.intValue() != value) { | |
298 throw new RuntimeException("Error: the integer constant \"" + name + | |
299 "\" had its value redefined (old was " + oldValue + | |
300 ", new is " + value + ". Aborting."); | |
301 } else { | |
302 System.err.println("Warning: the int constant \"" + name + "\" (declared in the remote VM in VMStructs::localHotSpotVMIntConstants) " + | |
303 "had its value declared as " + value + " twice. Continuing."); | |
304 } | |
305 } | |
306 } | |
307 | |
308 entryAddr = entryAddr.addOffsetTo(intConstantEntryArrayStride); | |
309 } while (nameAddr != null); | |
310 } | |
311 | |
312 private void readVMLongConstants() { | |
313 // Get the variables we need in order to traverse the VMLongConstantEntry[] | |
314 long longConstantEntryNameOffset; | |
315 long longConstantEntryValueOffset; | |
316 long longConstantEntryArrayStride; | |
317 | |
318 longConstantEntryNameOffset = getLongValueFromProcess("gHotSpotVMLongConstantEntryNameOffset"); | |
319 longConstantEntryValueOffset = getLongValueFromProcess("gHotSpotVMLongConstantEntryValueOffset"); | |
320 longConstantEntryArrayStride = getLongValueFromProcess("gHotSpotVMLongConstantEntryArrayStride"); | |
321 | |
322 // Fetch the address of the VMLongConstantEntry* | |
323 Address entryAddr = lookupInProcess("gHotSpotVMLongConstants"); | |
324 // Dereference this once to get the pointer to the first VMLongConstantEntry | |
325 entryAddr = entryAddr.getAddressAt(0); | |
326 if (entryAddr == null) { | |
327 throw new RuntimeException("gHotSpotVMLongConstants was not initialized properly in the remote process; can not continue"); | |
328 } | |
329 | |
330 // Start iterating down it until we find an entry with no name | |
331 Address nameAddr = null; | |
332 do { | |
333 // Fetch the type name first | |
334 nameAddr = entryAddr.getAddressAt(longConstantEntryNameOffset); | |
335 if (nameAddr != null) { | |
336 String name = CStringUtilities.getString(nameAddr); | |
337 int value = (int) entryAddr.getCIntegerAt(longConstantEntryValueOffset, C_INT64_SIZE, true); | |
338 | |
339 // Be a little resilient | |
340 Long oldValue = lookupLongConstant(name, false); | |
341 if (oldValue == null) { | |
342 addLongConstant(name, value); | |
343 } else { | |
344 if (oldValue.longValue() != value) { | |
345 throw new RuntimeException("Error: the long constant \"" + name + | |
346 "\" had its value redefined (old was " + oldValue + | |
347 ", new is " + value + ". Aborting."); | |
348 } else { | |
349 System.err.println("Warning: the long constant \"" + name + "\" (declared in the remote VM in VMStructs::localHotSpotVMLongConstants) " + | |
350 "had its value declared as " + value + " twice. Continuing."); | |
351 } | |
352 } | |
353 } | |
354 | |
355 entryAddr = entryAddr.addOffsetTo(longConstantEntryArrayStride); | |
356 } while (nameAddr != null); | |
357 } | |
358 | |
359 private BasicType lookupOrFail(String typeName) { | |
360 BasicType type = (BasicType) lookupType(typeName, false); | |
361 if (type == null) { | |
362 throw new RuntimeException("Type \"" + typeName + "\", referenced in VMStructs::localHotSpotVMStructs in the remote VM, " + | |
363 "was not present in the remote VMStructs::localHotSpotVMTypes table (should have been caught " + | |
364 "in the debug build of that VM). Can not continue."); | |
365 } | |
366 return type; | |
367 } | |
368 | |
369 private long getLongValueFromProcess(String symbol) { | |
370 return lookupInProcess(symbol).getCIntegerAt(0, C_INT64_SIZE, true); | |
371 } | |
372 | |
373 private Address lookupInProcess(String symbol) throws NoSuchSymbolException { | |
374 // FIXME: abstract away the loadobject name | |
375 for (int i = 0; i < jvmLibNames.length; i++) { | |
376 Address addr = symbolLookup.lookup(jvmLibNames[i], symbol); | |
377 if (addr != null) { | |
378 return addr; | |
379 } | |
380 } | |
381 String errStr = "("; | |
382 for (int i = 0; i < jvmLibNames.length; i++) { | |
383 errStr += jvmLibNames[i]; | |
384 if (i < jvmLibNames.length - 1) { | |
385 errStr += ", "; | |
386 } | |
387 } | |
388 errStr += ")"; | |
389 throw new NoSuchSymbolException(symbol, | |
390 "Could not find symbol \"" + symbol + | |
391 "\" in any of the known library names " + | |
392 errStr); | |
393 } | |
394 | |
395 private BasicType lookupOrCreateClass(String typeName, boolean isOopType, | |
396 boolean isIntegerType, boolean isUnsigned) { | |
397 BasicType type = (BasicType) lookupType(typeName, false); | |
398 if (type == null) { | |
399 // Create a new type | |
400 type = createBasicType(typeName, isOopType, isIntegerType, isUnsigned); | |
401 } | |
402 return type; | |
403 } | |
404 | |
405 /** Creates a new BasicType, initializes its size to -1 so we can | |
406 test to ensure that all types' sizes are initialized by VMTypes, | |
407 and adds it to the database. Takes care of initializing integer | |
408 and oop types properly. */ | |
409 private BasicType createBasicType(String typeName, boolean isOopType, | |
410 boolean isIntegerType, boolean isUnsigned) { | |
411 | |
412 BasicType type = null; | |
413 | |
414 if (isIntegerType) { | |
415 type = new BasicCIntegerType(this, typeName, isUnsigned); | |
416 } else { | |
417 if (typeNameIsPointerType(typeName)) { | |
418 type = recursiveCreateBasicPointerType(typeName); | |
419 } else { | |
420 type = new BasicType(this, typeName); | |
421 } | |
422 | |
423 if (isOopType) { | |
424 // HACK: turn markOop into a C integer type. This allows | |
425 // proper handling of it in the Serviceability Agent. (FIXME | |
426 // -- consider doing something different here) | |
427 if (typeName.equals("markOop")) { | |
428 type = new BasicCIntegerType(this, typeName, true); | |
429 } else { | |
430 type.setIsOopType(true); | |
431 } | |
432 } | |
433 } | |
434 | |
435 type.setSize(UNINITIALIZED_SIZE); | |
436 addType(type); | |
437 return type; | |
438 } | |
439 | |
440 /** Recursively creates a PointerType from the string representation | |
441 of the type's name. Note that this currently needs some | |
442 workarounds due to incomplete information in the VMStructs | |
443 database. */ | |
444 private BasicPointerType recursiveCreateBasicPointerType(String typeName) { | |
445 String targetTypeName = typeName.substring(0, typeName.lastIndexOf('*')).trim(); | |
446 Type targetType = null; | |
447 if (typeNameIsPointerType(targetTypeName)) { | |
448 targetType = recursiveCreateBasicPointerType(targetTypeName); | |
449 } else { | |
450 targetType = lookupType(targetTypeName, false); | |
451 if (targetType == null) { | |
452 // Workaround for missing C integer types in database. | |
453 // Also looks like we can't throw an exception for other | |
454 // missing target types because there are some in old | |
455 // VMStructs tables that didn't have the target type declared. | |
456 // For this case, we create basic types that never get filled | |
457 // in. | |
458 | |
459 if (targetTypeName.equals("char") || | |
460 targetTypeName.equals("const char")) { | |
461 // We don't have a representation of const-ness of C types in the SA | |
462 BasicType basicTargetType = createBasicType(targetTypeName, false, true, false); | |
463 basicTargetType.setSize(1); | |
464 targetType = basicTargetType; | |
465 } else if (targetTypeName.equals("u_char")) { | |
466 BasicType basicTargetType = createBasicType(targetTypeName, false, true, true); | |
467 basicTargetType.setSize(1); | |
468 targetType = basicTargetType; | |
469 } else { | |
470 if (DEBUG) { | |
471 System.err.println("WARNING: missing target type \"" + targetTypeName + "\" for pointer type \"" + typeName + "\""); | |
472 } | |
473 targetType = createBasicType(targetTypeName, false, false, false); | |
474 } | |
475 } | |
476 } | |
477 return new BasicPointerType(this, typeName, targetType); | |
478 } | |
479 | |
480 private boolean typeNameIsPointerType(String typeName) { | |
481 int i = typeName.length() - 1; | |
482 while (i >= 0 && Character.isWhitespace(typeName.charAt(i))) { | |
483 --i; | |
484 } | |
485 if (i >= 0 && typeName.charAt(i) == '*') { | |
486 return true; | |
487 } | |
488 return false; | |
489 } | |
490 | |
491 public void createType(String typeName, String superclassName, | |
492 boolean isOopType, boolean isIntegerType, | |
493 boolean isUnsigned, long size) { | |
494 // See whether we have a superclass | |
495 BasicType superclass = null; | |
496 if (superclassName != null) { | |
497 // Fetch or create it (FIXME: would get oop types wrong if | |
498 // they had a hierarchy; consider using lookupOrFail) | |
499 superclass = lookupOrCreateClass(superclassName, false, false, false); | |
500 } | |
501 | |
502 // Lookup or create the current type | |
503 BasicType curType = lookupOrCreateClass(typeName, isOopType, isIntegerType, isUnsigned); | |
504 // Set superclass and/or ensure it's correct | |
505 if (superclass != null) { | |
506 if (curType.getSuperclass() == null) { | |
507 // Set the superclass in the current type | |
508 curType.setSuperclass(superclass); | |
509 } | |
510 | |
511 if (curType.getSuperclass() != superclass) { | |
512 throw new RuntimeException("Error: the type \"" + typeName + "\" (declared in the remote VM in VMStructs::localHotSpotVMTypes) " + | |
513 "had its superclass redefined (old was " + curType.getSuperclass().getName() + ", new is " + | |
514 superclass.getName() + ")."); | |
515 } | |
516 } | |
517 | |
518 // Classes are created with a size of UNINITIALIZED_SIZE. | |
519 // Set size if necessary. | |
520 if (curType.getSize() == UNINITIALIZED_SIZE) { | |
521 curType.setSize(size); | |
522 } else { | |
523 if (curType.getSize() != size) { | |
524 throw new RuntimeException("Error: the type \"" + typeName + "\" (declared in the remote VM in VMStructs::localHotSpotVMTypes) " + | |
525 "had its size redefined (old was " + curType.getSize() + ", new is " + size + ")."); | |
526 } | |
527 | |
528 System.err.println("Warning: the type \"" + typeName + "\" (declared in the remote VM in VMStructs::localHotSpotVMTypes) " + | |
529 "had its size declared as " + size + " twice. Continuing."); | |
530 } | |
531 | |
532 } | |
533 | |
534 /** "Virtual constructor" for fields based on type */ | |
535 public void createField(BasicType containingType, | |
536 String name, Type type, boolean isStatic, | |
537 long offset, Address staticFieldAddress) { | |
538 // Add field to containing type | |
539 containingType.addField(internalCreateField(containingType, name, type, isStatic, offset, staticFieldAddress)); | |
540 } | |
541 | |
542 Field internalCreateField(BasicType containingType, | |
543 String name, Type type, boolean isStatic, | |
544 long offset, Address staticFieldAddress) { | |
545 // "Virtual constructor" based on type | |
546 if (type.isOopType()) { | |
547 return new BasicOopField(this, containingType, name, type, | |
548 isStatic, offset, staticFieldAddress); | |
549 } | |
550 | |
551 if (type instanceof CIntegerType) { | |
552 return new BasicCIntegerField(this, containingType, name, type, | |
553 isStatic, offset, staticFieldAddress); | |
554 } | |
555 | |
556 if (type.equals(getJBooleanType())) { | |
557 return new BasicJBooleanField(this, containingType, name, type, | |
558 isStatic, offset, staticFieldAddress); | |
559 } | |
560 | |
561 if (type.equals(getJByteType())) { | |
562 return new BasicJByteField(this, containingType, name, type, | |
563 isStatic, offset, staticFieldAddress); | |
564 } | |
565 | |
566 if (type.equals(getJCharType())) { | |
567 return new BasicJCharField(this, containingType, name, type, | |
568 isStatic, offset, staticFieldAddress); | |
569 } | |
570 | |
571 if (type.equals(getJDoubleType())) { | |
572 return new BasicJDoubleField(this, containingType, name, type, | |
573 isStatic, offset, staticFieldAddress); | |
574 } | |
575 | |
576 if (type.equals(getJFloatType())) { | |
577 return new BasicJFloatField(this, containingType, name, type, | |
578 isStatic, offset, staticFieldAddress); | |
579 } | |
580 | |
581 if (type.equals(getJIntType())) { | |
582 return new BasicJIntField(this, containingType, name, type, | |
583 isStatic, offset, staticFieldAddress); | |
584 } | |
585 | |
586 if (type.equals(getJLongType())) { | |
587 return new BasicJLongField(this, containingType, name, type, | |
588 isStatic, offset, staticFieldAddress); | |
589 } | |
590 | |
591 if (type.equals(getJShortType())) { | |
592 return new BasicJShortField(this, containingType, name, type, | |
593 isStatic, offset, staticFieldAddress); | |
594 } | |
595 | |
596 // Unknown ("opaque") type. Instantiate ordinary Field. | |
597 return new BasicField(this, containingType, name, type, | |
598 isStatic, offset, staticFieldAddress); | |
599 } | |
600 | |
601 // For debugging | |
602 private void dumpMemory(Address addr, int len) { | |
603 int i = 0; | |
604 while (i < len) { | |
605 System.err.print(addr.addOffsetTo(i) + ":"); | |
606 for (int j = 0; j < 8 && i < len; i++, j++) { | |
607 String s = Long.toHexString(addr.getCIntegerAt(i, 1, true)); | |
608 System.err.print(" 0x"); | |
609 for (int k = 0; k < 2 - s.length(); k++) { | |
610 System.err.print("0"); | |
611 } | |
612 System.err.print(s); | |
613 } | |
614 System.err.println(); | |
615 } | |
616 } | |
617 } |