380 int field_off = field->offset_in_bytes(); 381 if (field_off == field_offset) 382 return field; 383 if (field_off > field_offset) 384 break; 385 // could do binary search or check bins, but probably not worth it 386 } 387 return NULL; 388 } 389 VM_ENTRY_MARK; 390 InstanceKlass* k = get_instanceKlass(); 391 fieldDescriptor fd; 392 if (!k->find_field_from_offset(field_offset, is_static, &fd)) { 393 return NULL; 394 } 395 ciField* field = new (CURRENT_THREAD_ENV->arena()) ciField(&fd); 396 return field; 397 } 398 399 // ------------------------------------------------------------------ 400 // ciInstanceKlass::get_field_by_name 401 ciField* ciInstanceKlass::get_field_by_name(ciSymbol* name, ciSymbol* signature, bool is_static) { 402 VM_ENTRY_MARK; 403 InstanceKlass* k = get_instanceKlass(); 404 fieldDescriptor fd; 405 Klass* def = k->find_field(name->get_symbol(), signature->get_symbol(), is_static, &fd); 406 if (def == NULL) { 407 return NULL; 408 } 409 ciField* field = new (CURRENT_THREAD_ENV->arena()) ciField(&fd); 410 return field; 411 } 412 413 414 static int sort_field_by_offset(ciField** a, ciField** b) { 415 return (*a)->offset_in_bytes() - (*b)->offset_in_bytes(); 416 // (no worries about 32-bit overflow...) 417 } 418 419 // ------------------------------------------------------------------ 483 for (JavaFieldStream fs(k); !fs.done(); fs.next()) { 484 if (fs.access_flags().is_static()) continue; 485 flen += 1; 486 } 487 488 // allocate the array: 489 if (flen == 0) { 490 return NULL; // return nothing if none are locally declared 491 } 492 if (super_fields != NULL) { 493 flen += super_fields->length(); 494 } 495 fields = new (arena) GrowableArray<ciField*>(arena, flen, 0, NULL); 496 if (super_fields != NULL) { 497 fields->appendAll(super_fields); 498 } 499 500 for (JavaFieldStream fs(k); !fs.done(); fs.next()) { 501 if (fs.access_flags().is_static()) continue; 502 fieldDescriptor& fd = fs.field_descriptor(); 503 ciField* field = new (arena) ciField(&fd); 504 fields->append(field); 505 } 506 assert(fields->length() == flen, "sanity"); 507 return fields; 508 } 509 510 bool ciInstanceKlass::compute_injected_fields_helper() { 511 ASSERT_IN_VM; 512 InstanceKlass* k = get_instanceKlass(); 513 514 for (InternalFieldStream fs(k); !fs.done(); fs.next()) { 515 if (fs.access_flags().is_static()) continue; 516 return true; 517 } 518 return false; 519 } 520 521 void ciInstanceKlass::compute_injected_fields() { 522 assert(is_loaded(), "must be loaded"); 523 524 int has_injected_fields = 0; | 380 int field_off = field->offset_in_bytes(); 381 if (field_off == field_offset) 382 return field; 383 if (field_off > field_offset) 384 break; 385 // could do binary search or check bins, but probably not worth it 386 } 387 return NULL; 388 } 389 VM_ENTRY_MARK; 390 InstanceKlass* k = get_instanceKlass(); 391 fieldDescriptor fd; 392 if (!k->find_field_from_offset(field_offset, is_static, &fd)) { 393 return NULL; 394 } 395 ciField* field = new (CURRENT_THREAD_ENV->arena()) ciField(&fd); 396 return field; 397 } 398 399 // ------------------------------------------------------------------ 400 // ciInstanceKlass::get_field_type_by_offset 401 ciType* ciInstanceKlass::get_field_type_by_offset(int field_offset) { 402 ASSERT_IN_VM; 403 fieldDescriptor fd; 404 InstanceKlass* klass = get_instanceKlass(); 405 // Important: We cannot get the field type via get_field_by_offset() because if the field 406 // is another value type, the offset would refer to the first field of that value type due 407 // to flattening. Instead, do a SystemDictionary lookup for the type of the declared field. 408 bool found = klass->find_field_from_offset(field_offset, false, &fd); 409 assert(found, "field not found"); 410 BasicType field_type = fd.field_type(); 411 if (is_java_primitive(field_type)) { 412 // Primitive type 413 return ciType::make(field_type); 414 } else { 415 // Do a SystemDictionary lookup for the type 416 ciEnv* env = CURRENT_ENV; 417 ciSymbol* signature = env->get_symbol(fd.signature()); 418 return env->get_klass_by_name_impl(this, constantPoolHandle(), signature, false); 419 } 420 } 421 422 // ------------------------------------------------------------------ 423 // ciInstanceKlass::get_field_by_name 424 ciField* ciInstanceKlass::get_field_by_name(ciSymbol* name, ciSymbol* signature, bool is_static) { 425 VM_ENTRY_MARK; 426 InstanceKlass* k = get_instanceKlass(); 427 fieldDescriptor fd; 428 Klass* def = k->find_field(name->get_symbol(), signature->get_symbol(), is_static, &fd); 429 if (def == NULL) { 430 return NULL; 431 } 432 ciField* field = new (CURRENT_THREAD_ENV->arena()) ciField(&fd); 433 return field; 434 } 435 436 437 static int sort_field_by_offset(ciField** a, ciField** b) { 438 return (*a)->offset_in_bytes() - (*b)->offset_in_bytes(); 439 // (no worries about 32-bit overflow...) 440 } 441 442 // ------------------------------------------------------------------ 506 for (JavaFieldStream fs(k); !fs.done(); fs.next()) { 507 if (fs.access_flags().is_static()) continue; 508 flen += 1; 509 } 510 511 // allocate the array: 512 if (flen == 0) { 513 return NULL; // return nothing if none are locally declared 514 } 515 if (super_fields != NULL) { 516 flen += super_fields->length(); 517 } 518 fields = new (arena) GrowableArray<ciField*>(arena, flen, 0, NULL); 519 if (super_fields != NULL) { 520 fields->appendAll(super_fields); 521 } 522 523 for (JavaFieldStream fs(k); !fs.done(); fs.next()) { 524 if (fs.access_flags().is_static()) continue; 525 fieldDescriptor& fd = fs.field_descriptor(); 526 if (fd.field_type() == T_VALUETYPE) { 527 // Value type fields are embedded 528 int field_offset = fd.offset(); 529 // Get ValueKlass and adjust number of fields 530 ciValueKlass* vk = get_field_type_by_offset(field_offset)->as_value_klass(); 531 flen += vk->get_field_count() - 1; 532 // Iterate over fields of flattened value type and copy them to 'this' 533 for (int i = 0; i < vk->nof_nonstatic_fields(); ++i) { 534 ciField* flattened_field = vk->nonstatic_field_at(i); 535 // Adjust offset to account for missing oop header 536 int offset = field_offset + (flattened_field->offset() - vk->get_first_field_offset()); 537 bool is_final = is_valuetype(); // flattened fields are final if holder is a value type 538 ciField* field = new (arena) ciField(flattened_field, this, offset, is_final); 539 fields->append(field); 540 } 541 } else { 542 ciField* field = new (arena) ciField(&fd); 543 fields->append(field); 544 } 545 } 546 assert(fields->length() == flen, "sanity"); 547 return fields; 548 } 549 550 bool ciInstanceKlass::compute_injected_fields_helper() { 551 ASSERT_IN_VM; 552 InstanceKlass* k = get_instanceKlass(); 553 554 for (InternalFieldStream fs(k); !fs.done(); fs.next()) { 555 if (fs.access_flags().is_static()) continue; 556 return true; 557 } 558 return false; 559 } 560 561 void ciInstanceKlass::compute_injected_fields() { 562 assert(is_loaded(), "must be loaded"); 563 564 int has_injected_fields = 0; |