comparison agent/src/share/classes/sun/jvm/hotspot/HotSpotTypeDataBase.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 1d1603768966
children da91efe96a93
comparison
equal deleted inserted replaced
3938:e6b1331a51d2 3939:f6f3bb0ee072
85 readVMTypes(); 85 readVMTypes();
86 initializePrimitiveTypes(); 86 initializePrimitiveTypes();
87 readVMStructs(); 87 readVMStructs();
88 readVMIntConstants(); 88 readVMIntConstants();
89 readVMLongConstants(); 89 readVMLongConstants();
90 readExternalDefinitions();
90 } 91 }
91 92
92 public Type lookupType(String cTypeName, boolean throwException) { 93 public Type lookupType(String cTypeName, boolean throwException) {
93 Type fieldType = super.lookupType(cTypeName, false); 94 Type fieldType = super.lookupType(cTypeName, false);
94 if (fieldType == null && cTypeName.startsWith("const ")) { 95 if (fieldType == null && cTypeName.startsWith("const ")) {
96 } 97 }
97 if (fieldType == null && cTypeName.endsWith(" const")) { 98 if (fieldType == null && cTypeName.endsWith(" const")) {
98 fieldType = (BasicType)lookupType(cTypeName.substring(0, cTypeName.length() - 6), false); 99 fieldType = (BasicType)lookupType(cTypeName.substring(0, cTypeName.length() - 6), false);
99 } 100 }
100 if (fieldType == null) { 101 if (fieldType == null) {
101 if (cTypeName.startsWith("GrowableArray<") && cTypeName.endsWith(">*")) { 102 if (cTypeName.startsWith("GrowableArray<") && cTypeName.endsWith(">")) {
102 String ttype = cTypeName.substring("GrowableArray<".length(), 103 String ttype = cTypeName.substring("GrowableArray<".length(),
103 cTypeName.length() - 2); 104 cTypeName.length() - 1);
104 Type templateType = lookupType(ttype, false); 105 Type templateType = lookupType(ttype, false);
105 if (templateType == null && typeNameIsPointerType(ttype)) { 106 if (templateType == null && typeNameIsPointerType(ttype)) {
106 templateType = recursiveCreateBasicPointerType(ttype); 107 templateType = recursiveCreateBasicPointerType(ttype);
107 } 108 }
108 if (templateType == null) { 109 if (templateType == null) {
109 lookupOrFail(ttype); 110 lookupOrFail(ttype);
110 } 111 }
111 fieldType = recursiveCreateBasicPointerType(cTypeName); 112
113 BasicType basicTargetType = createBasicType(cTypeName, false, false, false);
114
115 // transfer fields from GenericGrowableArray to template instance
116 BasicType generic = lookupOrFail("GenericGrowableArray");
117 BasicType specific = lookupOrFail("GrowableArray<int>");
118 basicTargetType.setSize(specific.getSize());
119 Iterator fields = generic.getFields();
120 while (fields.hasNext()) {
121 Field f = (Field)fields.next();
122 basicTargetType.addField(internalCreateField(basicTargetType, f.getName(),
123 f.getType(), f.isStatic(),
124 f.getOffset(), null));
125 }
126 fieldType = basicTargetType;
112 } 127 }
113 } 128 }
114 if (fieldType == null && typeNameIsPointerType(cTypeName)) { 129 if (fieldType == null && typeNameIsPointerType(cTypeName)) {
115 fieldType = recursiveCreateBasicPointerType(cTypeName); 130 fieldType = recursiveCreateBasicPointerType(cTypeName);
116 } 131 }
204 throw new RuntimeException("Error initializing the HotSpotDataBase: could not find the primitive type \"" + 219 throw new RuntimeException("Error initializing the HotSpotDataBase: could not find the primitive type \"" +
205 typeName + "\" in the remote VM's VMStructs table. This type is required in " + 220 typeName + "\" in the remote VM's VMStructs table. This type is required in " +
206 "order to determine the size of Java primitive types. Can not continue."); 221 "order to determine the size of Java primitive types. Can not continue.");
207 } 222 }
208 return type; 223 return type;
224 }
225
226 private void readExternalDefinitions() {
227 String file = System.getProperty("sun.jvm.hotspot.typedb");
228 if (file != null) {
229 System.out.println("Reading " + file);
230 BufferedReader in = null;
231 try {
232 StreamTokenizer t = new StreamTokenizer(in = new BufferedReader(new InputStreamReader(new FileInputStream(file))));
233 t.resetSyntax();
234 t.wordChars('\u0000','\uFFFF');
235 t.whitespaceChars(' ', ' ');
236 t.whitespaceChars('\n', '\n');
237 t.whitespaceChars('\r', '\r');
238 t.quoteChar('\"');
239 t.eolIsSignificant(true);
240 while (t.nextToken() != StreamTokenizer.TT_EOF) {
241 if (t.ttype == StreamTokenizer.TT_EOL) {
242 continue;
243 }
244
245 if (t.sval.equals("field")) {
246 t.nextToken();
247 BasicType containingType = (BasicType)lookupType(t.sval);
248 t.nextToken();
249 String fieldName = t.sval;
250
251 // The field's Type must already be in the database -- no exceptions
252 t.nextToken();
253 Type fieldType = lookupType(t.sval);
254 t.nextToken();
255 boolean isStatic = Boolean.valueOf(t.sval).booleanValue();
256 t.nextToken();
257 long offset = Long.parseLong(t.sval);
258 t.nextToken();
259 Address staticAddress = null;
260 if (isStatic) {
261 throw new InternalError("static fields not supported");
262 }
263
264 // check to see if the field already exists
265 Iterator i = containingType.getFields();
266 boolean defined = false;
267 while (i.hasNext()) {
268 Field f = (Field) i.next();
269 if (f.getName().equals(fieldName)) {
270 if (f.isStatic() != isStatic) {
271 throw new RuntimeException("static/nonstatic mismatch: " + fieldName);
272 }
273 if (!isStatic) {
274 if (f.getOffset() != offset) {
275 throw new RuntimeException("bad redefinition of field offset: " + fieldName);
276 }
277 } else {
278 if (!f.getStaticFieldAddress().equals(staticAddress)) {
279 throw new RuntimeException("bad redefinition of field location: " + fieldName);
280 }
281 }
282 if (f.getType() != fieldType) {
283 System.out.println(fieldType);
284 System.out.println(f.getType());
285 throw new RuntimeException("bad redefinition of field type: " + fieldName);
286 }
287 defined = true;
288 break;
289 }
290 }
291
292 if (!defined) {
293 // Create field by type
294 createField(containingType,
295 fieldName, fieldType,
296 isStatic,
297 offset,
298 staticAddress);
299 }
300 } else if (t.sval.equals("type")) {
301 t.nextToken();
302 String typeName = t.sval;
303 t.nextToken();
304 String superclassName = t.sval;
305 if (superclassName.equals("null")) {
306 superclassName = null;
307 }
308 t.nextToken();
309 boolean isOop = Boolean.valueOf(t.sval).booleanValue();
310 t.nextToken();
311 boolean isInteger = Boolean.valueOf(t.sval).booleanValue();
312 t.nextToken();
313 boolean isUnsigned = Boolean.valueOf(t.sval).booleanValue();
314 t.nextToken();
315 long size = Long.parseLong(t.sval);
316
317 BasicType type = null;
318 try {
319 type = (BasicType)lookupType(typeName);
320 } catch (RuntimeException e) {
321 }
322 if (type != null) {
323 if (type.isOopType() != isOop) {
324 throw new RuntimeException("oop mismatch in type definition: " + typeName);
325 }
326 if (type.isCIntegerType() != isInteger) {
327 throw new RuntimeException("integer type mismatch in type definition: " + typeName);
328 }
329 if (type.isCIntegerType() && (((CIntegerType)type).isUnsigned()) != isUnsigned) {
330 throw new RuntimeException("unsigned mismatch in type definition: " + typeName);
331 }
332 if (type.getSuperclass() == null) {
333 if (superclassName != null) {
334 if (type.getSize() == -1) {
335 type.setSuperclass(lookupType(superclassName));
336 } else {
337 throw new RuntimeException("unexpected superclass in type definition: " + typeName);
338 }
339 }
340 } else {
341 if (superclassName == null) {
342 throw new RuntimeException("missing superclass in type definition: " + typeName);
343 }
344 if (!type.getSuperclass().getName().equals(superclassName)) {
345 throw new RuntimeException("incorrect superclass in type definition: " + typeName);
346 }
347 }
348 if (type.getSize() != size) {
349 if (type.getSize() == -1 || type.getSize() == 0) {
350 type.setSize(size);
351 } else {
352 throw new RuntimeException("size mismatch in type definition: " + typeName + ": " + type.getSize() + " != " + size);
353 }
354 }
355 }
356
357 if (lookupType(typeName, false) == null) {
358 // Create type
359 createType(typeName, superclassName, isOop, isInteger, isUnsigned, size);
360 }
361 } else {
362 throw new InternalError("\"" + t.sval + "\"");
363 }
364 }
365 } catch (IOException ioe) {
366 ioe.printStackTrace();
367 } finally {
368 try {
369 in.close();
370 } catch (Exception e) {
371 }
372 }
373 }
209 } 374 }
210 375
211 private void readVMStructs() { 376 private void readVMStructs() {
212 // Get the variables we need in order to traverse the VMStructEntry[] 377 // Get the variables we need in order to traverse the VMStructEntry[]
213 long structEntryTypeNameOffset; 378 long structEntryTypeNameOffset;
502 targetType = basicTargetType; 667 targetType = basicTargetType;
503 } else if (targetTypeName.equals("u_char")) { 668 } else if (targetTypeName.equals("u_char")) {
504 BasicType basicTargetType = createBasicType(targetTypeName, false, true, true); 669 BasicType basicTargetType = createBasicType(targetTypeName, false, true, true);
505 basicTargetType.setSize(1); 670 basicTargetType.setSize(1);
506 targetType = basicTargetType; 671 targetType = basicTargetType;
507 } else if (targetTypeName.startsWith("GrowableArray<")) {
508 BasicType basicTargetType = createBasicType(targetTypeName, false, false, false);
509
510 // transfer fields from GenericGrowableArray to template instance
511 BasicType generic = lookupOrFail("GenericGrowableArray");
512 basicTargetType.setSize(generic.getSize());
513 Iterator fields = generic.getFields();
514 while (fields.hasNext()) {
515 Field f = (Field)fields.next();
516 basicTargetType.addField(internalCreateField(basicTargetType, f.getName(),
517 f.getType(), f.isStatic(),
518 f.getOffset(), null));
519 }
520 targetType = basicTargetType;
521 } else { 672 } else {
522 if (DEBUG) { 673 if (DEBUG) {
523 System.err.println("WARNING: missing target type \"" + targetTypeName + "\" for pointer type \"" + typeName + "\""); 674 System.err.println("WARNING: missing target type \"" + targetTypeName + "\" for pointer type \"" + typeName + "\"");
524 } 675 }
525 targetType = createBasicType(targetTypeName, false, false, false); 676 targetType = createBasicType(targetTypeName, false, false, false);
570 } 721 }
571 } 722 }
572 723
573 // Classes are created with a size of UNINITIALIZED_SIZE. 724 // Classes are created with a size of UNINITIALIZED_SIZE.
574 // Set size if necessary. 725 // Set size if necessary.
575 if (curType.getSize() == UNINITIALIZED_SIZE) { 726 if (curType.getSize() == UNINITIALIZED_SIZE || curType.getSize() == 0) {
576 curType.setSize(size); 727 curType.setSize(size);
577 } else { 728 } else {
578 if (curType.getSize() != size) { 729 if (curType.getSize() != size) {
579 throw new RuntimeException("Error: the type \"" + typeName + "\" (declared in the remote VM in VMStructs::localHotSpotVMTypes) " + 730 throw new RuntimeException("Error: the type \"" + typeName + "\" (declared in the remote VM in VMStructs::localHotSpotVMTypes) " +
580 "had its size redefined (old was " + curType.getSize() + ", new is " + size + ")."); 731 "had its size redefined (old was " + curType.getSize() + ", new is " + size + ").");