src/share/vm/ci/ciInstanceKlass.cpp
Index Unified diffs Context diffs Sdiffs Patch New Old Previous File Next File cik Sdiff src/share/vm/ci

src/share/vm/ci/ciInstanceKlass.cpp

Print this page




  26 #include "ci/ciField.hpp"
  27 #include "ci/ciInstance.hpp"
  28 #include "ci/ciInstanceKlass.hpp"
  29 #include "ci/ciUtilities.hpp"
  30 #include "classfile/systemDictionary.hpp"
  31 #include "memory/allocation.hpp"
  32 #include "memory/allocation.inline.hpp"
  33 #include "oops/oop.inline.hpp"
  34 #include "runtime/fieldDescriptor.hpp"
  35 
  36 // ciInstanceKlass
  37 //
  38 // This class represents a klassOop in the HotSpot virtual machine
  39 // whose Klass part in an instanceKlass.
  40 
  41 // ------------------------------------------------------------------
  42 // ciInstanceKlass::ciInstanceKlass
  43 //
  44 // Loaded instance klass.
  45 ciInstanceKlass::ciInstanceKlass(KlassHandle h_k) :
  46   ciKlass(h_k), _non_static_fields(NULL)
  47 {
  48   assert(get_Klass()->oop_is_instance(), "wrong type");
  49   assert(get_instanceKlass()->is_loaded(), "must be at least loaded");
  50   instanceKlass* ik = get_instanceKlass();
  51 
  52   AccessFlags access_flags = ik->access_flags();
  53   _flags = ciFlags(access_flags);
  54   _has_finalizer = access_flags.has_finalizer();
  55   _has_subklass = ik->subklass() != NULL;
  56   _init_state = (instanceKlass::ClassState)ik->get_init_state();
  57   _nonstatic_field_size = ik->nonstatic_field_size();
  58   _has_nonstatic_fields = ik->has_nonstatic_fields();
  59   _nonstatic_fields = NULL; // initialized lazily by compute_nonstatic_fields:
  60 
  61   _nof_implementors = ik->nof_implementors();
  62   for (int i = 0; i < implementors_limit; i++) {
  63     _implementors[i] = NULL;  // we will fill these lazily
  64   }
  65 
  66   Thread *thread = Thread::current();
  67   if (ciObjectFactory::is_initialized()) {
  68     _loader = JNIHandles::make_local(thread, ik->class_loader());
  69     _protection_domain = JNIHandles::make_local(thread,
  70                                                 ik->protection_domain());
  71     _is_shared = false;
  72   } else {
  73     Handle h_loader(thread, ik->class_loader());
  74     Handle h_protection_domain(thread, ik->protection_domain());
  75     _loader = JNIHandles::make_global(h_loader);
  76     _protection_domain = JNIHandles::make_global(h_protection_domain);
  77     _is_shared = true;
  78   }
  79 
  80   // Lazy fields get filled in only upon request.
  81   _super  = NULL;
  82   _java_mirror = NULL;
  83 
  84   if (is_shared()) {

  85     if (h_k() != SystemDictionary::Object_klass()) {
  86       super();
  87     }
  88     java_mirror();
  89     //compute_nonstatic_fields();  // done outside of constructor
  90   }
  91 
  92   _field_cache = NULL;
  93 }
  94 
  95 // Version for unloaded classes:
  96 ciInstanceKlass::ciInstanceKlass(ciSymbol* name,
  97                                  jobject loader, jobject protection_domain)
  98   : ciKlass(name, ciInstanceKlassKlass::make())
  99 {
 100   assert(name->byte_at(0) != '[', "not an instance klass");
 101   _init_state = (instanceKlass::ClassState)0;
 102   _nonstatic_field_size = -1;
 103   _has_nonstatic_fields = false;
 104   _nonstatic_fields = NULL;
 105   _nof_implementors = -1;
 106   _loader = loader;
 107   _protection_domain = protection_domain;
 108   _is_shared = false;
 109   _super = NULL;


 190 //
 191 ciInstanceKlass* ciInstanceKlass::get_canonical_holder(int offset) {
 192   #ifdef ASSERT
 193   if (!(offset >= 0 && offset < layout_helper())) {
 194     tty->print("*** get_canonical_holder(%d) on ", offset);
 195     this->print();
 196     tty->print_cr(" ***");
 197   };
 198   assert(offset >= 0 && offset < layout_helper(), "offset must be tame");
 199   #endif
 200 
 201   if (offset < instanceOopDesc::base_offset_in_bytes()) {
 202     // All header offsets belong properly to java/lang/Object.
 203     return CURRENT_ENV->Object_klass();
 204   }
 205 
 206   ciInstanceKlass* self = this;
 207   for (;;) {
 208     assert(self->is_loaded(), "must be loaded to have size");
 209     ciInstanceKlass* super = self->super();
 210     if (super == NULL || super->nof_nonstatic_fields() == 0 ||
 211         !super->contains_field_offset(offset)) {
 212       return self;
 213     } else {
 214       self = super;  // return super->get_canonical_holder(offset)
 215     }
 216   }
 217 }
 218 
 219 // ------------------------------------------------------------------
 220 // ciInstanceKlass::is_java_lang_Object
 221 //
 222 // Is this klass java.lang.Object?
 223 bool ciInstanceKlass::is_java_lang_Object() {
 224   return equals(CURRENT_ENV->Object_klass());
 225 }
 226 
 227 // ------------------------------------------------------------------
 228 // ciInstanceKlass::uses_default_loader
 229 bool ciInstanceKlass::uses_default_loader() {
 230   // Note:  We do not need to resolve the handle or enter the VM


 337   Klass* up = ik->up_cast_abstract();
 338   assert(up->oop_is_instance(), "must be instanceKlass");
 339   if (ik == up) {
 340     return NULL;
 341   }
 342   return CURRENT_THREAD_ENV->get_object(up->as_klassOop())->as_instance_klass();
 343 }
 344 
 345 // ------------------------------------------------------------------
 346 // ciInstanceKlass::has_finalizable_subclass
 347 bool ciInstanceKlass::has_finalizable_subclass() {
 348   if (!is_loaded())     return true;
 349   VM_ENTRY_MARK;
 350   return Dependencies::find_finalizable_subclass(get_instanceKlass()) != NULL;
 351 }
 352 
 353 // ------------------------------------------------------------------
 354 // ciInstanceKlass::get_field_by_offset
 355 ciField* ciInstanceKlass::get_field_by_offset(int field_offset, bool is_static) {
 356   if (!is_static) {
 357     for (int i = 0, len = nof_nonstatic_fields(); i < len; i++) {
 358       ciField* field = _nonstatic_fields->at(i);
 359       int  field_off = field->offset_in_bytes();
 360       if (field_off == field_offset)
 361         return field;
 362       if (field_off > field_offset)
 363         break;
 364       // could do binary search or check bins, but probably not worth it
 365     }
 366     return NULL;









 367   }
 368   VM_ENTRY_MARK;
 369   instanceKlass* k = get_instanceKlass();
 370   fieldDescriptor fd;
 371   if (!k->find_field_from_offset(field_offset, is_static, &fd)) {
 372     return NULL;
 373   }
 374   ciField* field = new (CURRENT_THREAD_ENV->arena()) ciField(&fd);
 375   return field;
 376 }
 377 
 378 // ------------------------------------------------------------------
 379 // ciInstanceKlass::get_field_by_name
 380 ciField* ciInstanceKlass::get_field_by_name(ciSymbol* name, ciSymbol* signature, bool is_static) {
 381   VM_ENTRY_MARK;
 382   instanceKlass* k = get_instanceKlass();
 383   fieldDescriptor fd;
 384   klassOop def = k->find_field(name->get_symbol(), signature->get_symbol(), is_static, &fd);
 385   if (def == NULL) {
 386     return NULL;
 387   }
 388   ciField* field = new (CURRENT_THREAD_ENV->arena()) ciField(&fd);





 389   return field;
 390 }
 391 
 392 // ------------------------------------------------------------------
 393 // ciInstanceKlass::non_static_fields.
 394 
 395 class NonStaticFieldFiller: public FieldClosure {
 396   GrowableArray<ciField*>* _arr;
 397   ciEnv* _curEnv;
 398 public:
 399   NonStaticFieldFiller(ciEnv* curEnv, GrowableArray<ciField*>* arr) :
 400     _curEnv(curEnv), _arr(arr)
 401   {}
 402   void do_field(fieldDescriptor* fd) {
 403     ciField* field = new (_curEnv->arena()) ciField(fd);
 404     _arr->append(field);
 405   }
 406 };
 407 
 408 GrowableArray<ciField*>* ciInstanceKlass::non_static_fields() {
 409   if (_non_static_fields == NULL) {
 410     VM_ENTRY_MARK;
 411     ciEnv* curEnv = ciEnv::current();
 412     instanceKlass* ik = get_instanceKlass();
 413     int max_n_fields = ik->fields()->length()/instanceKlass::next_offset;
 414 
 415     Arena* arena = curEnv->arena();
 416     _non_static_fields =
 417       new (arena) GrowableArray<ciField*>(arena, max_n_fields, 0, NULL);
 418     NonStaticFieldFiller filler(curEnv, _non_static_fields);
 419     ik->do_nonstatic_fields(&filler);
 420   }
 421   return _non_static_fields;

 422 }
 423 
 424 static int sort_field_by_offset(ciField** a, ciField** b) {
 425   return (*a)->offset_in_bytes() - (*b)->offset_in_bytes();
 426   // (no worries about 32-bit overflow...)
 427 }
 428 
 429 // ------------------------------------------------------------------
 430 // ciInstanceKlass::compute_nonstatic_fields
 431 int ciInstanceKlass::compute_nonstatic_fields() {
 432   assert(is_loaded(), "must be loaded");
 433 
 434   if (_nonstatic_fields != NULL)
 435     return _nonstatic_fields->length();
 436 
 437   if (!has_nonstatic_fields()) {
 438     Arena* arena = CURRENT_ENV->arena();
 439     _nonstatic_fields = new (arena) GrowableArray<ciField*>(arena, 0, 0, NULL);
 440     return 0;
 441   }
 442   assert(!is_java_lang_Object(), "bootstrap OK");
 443 
 444   // Size in bytes of my fields, including inherited fields.
 445   int fsize = nonstatic_field_size() * heapOopSize;
 446 
 447   ciInstanceKlass* super = this->super();
 448   GrowableArray<ciField*>* super_fields = NULL;
 449   if (super != NULL && super->has_nonstatic_fields()) {
 450     int super_fsize  = super->nonstatic_field_size() * heapOopSize;
 451     int super_flen   = super->nof_nonstatic_fields();
 452     super_fields = super->_nonstatic_fields;
 453     assert(super_flen == 0 || super_fields != NULL, "first get nof_fields");
 454     // See if I am no larger than my super; if so, I can use his fields.
 455     if (fsize == super_fsize) {
 456       _nonstatic_fields = super_fields;
 457       return super_fields->length();
 458     }
 459   }
 460 
 461   GrowableArray<ciField*>* fields = NULL;
 462   GUARDED_VM_ENTRY({
 463       fields = compute_nonstatic_fields_impl(super_fields);
 464     });
 465 
 466   if (fields == NULL) {
 467     // This can happen if this class (java.lang.Class) has invisible fields.
 468     _nonstatic_fields = super_fields;
 469     return super_fields->length();
 470   }
 471 
 472   int flen = fields->length();
 473 
 474   // Now sort them by offset, ascending.
 475   // (In principle, they could mix with superclass fields.)
 476   fields->sort(sort_field_by_offset);

 477 #ifdef ASSERT
 478   int last_offset = instanceOopDesc::base_offset_in_bytes();
 479   for (int i = 0; i < fields->length(); i++) {
 480     ciField* field = fields->at(i);
 481     int offset = field->offset_in_bytes();
 482     int size   = (field->_type == NULL) ? heapOopSize : field->size_in_bytes();
 483     assert(last_offset <= offset, err_msg("no field overlap: %d <= %d", last_offset, offset));
 484     if (last_offset > (int)sizeof(oopDesc))
 485       assert((offset - last_offset) < BytesPerLong, "no big holes");
 486     // Note:  Two consecutive T_BYTE fields will be separated by wordSize-1
 487     // padding bytes if one of them is declared by a superclass.
 488     // This is a minor inefficiency classFileParser.cpp.
 489     last_offset = offset + size;
 490   }
 491   assert(last_offset <= (int)instanceOopDesc::base_offset_in_bytes() + fsize, "no overflow");
 492 #endif
 493 
 494   _nonstatic_fields = fields;
 495   return flen;
 496 }
 497 
 498 GrowableArray<ciField*>*
 499 ciInstanceKlass::compute_nonstatic_fields_impl(GrowableArray<ciField*>*
 500                                                super_fields) {
 501   ASSERT_IN_VM;
 502   Arena* arena = CURRENT_ENV->arena();
 503   int flen = 0;
 504   GrowableArray<ciField*>* fields = NULL;



 505   instanceKlass* k = get_instanceKlass();
 506   typeArrayOop fields_array = k->fields();
 507   for (int pass = 0; pass <= 1; pass++) {
 508     for (int i = 0, alen = fields_array->length(); i < alen; i += instanceKlass::next_offset) {
 509       fieldDescriptor fd;
 510       fd.initialize(k->as_klassOop(), i);
 511       if (fd.is_static())  continue;
 512       if (pass == 0) {
 513         flen += 1;

 514       } else {
 515         ciField* field = new (arena) ciField(&fd);
 516         fields->append(field);

 517       }
 518     }
 519 
 520     // Between passes, allocate the array:
 521     if (pass == 0) {
 522       if (flen == 0) {
 523         return NULL;  // return nothing if none are locally declared
 524       }
 525       if (super_fields != NULL) {
 526         flen += super_fields->length();

 527       }
 528       fields = new (arena) GrowableArray<ciField*>(arena, flen, 0, NULL);




 529       if (super_fields != NULL) {
 530         fields->appendAll(super_fields);
 531       }

 532     }
 533   }
 534   assert(fields->length() == flen, "sanity");
 535   return fields;



 536 }
 537 
 538 // ------------------------------------------------------------------
 539 // ciInstanceKlass::find_method
 540 //
 541 // Find a method in this klass.
 542 ciMethod* ciInstanceKlass::find_method(ciSymbol* name, ciSymbol* signature) {
 543   VM_ENTRY_MARK;
 544   instanceKlass* k = get_instanceKlass();
 545   Symbol* name_sym = name->get_symbol();
 546   Symbol* sig_sym= signature->get_symbol();
 547 
 548   methodOop m = k->find_method(name_sym, sig_sym);
 549   if (m == NULL)  return NULL;
 550 
 551   return CURRENT_THREAD_ENV->get_object(m)->as_method();
 552 }
 553 
 554 // ------------------------------------------------------------------
 555 // ciInstanceKlass::is_leaf_type




  26 #include "ci/ciField.hpp"
  27 #include "ci/ciInstance.hpp"
  28 #include "ci/ciInstanceKlass.hpp"
  29 #include "ci/ciUtilities.hpp"
  30 #include "classfile/systemDictionary.hpp"
  31 #include "memory/allocation.hpp"
  32 #include "memory/allocation.inline.hpp"
  33 #include "oops/oop.inline.hpp"
  34 #include "runtime/fieldDescriptor.hpp"
  35 
  36 // ciInstanceKlass
  37 //
  38 // This class represents a klassOop in the HotSpot virtual machine
  39 // whose Klass part in an instanceKlass.
  40 
  41 // ------------------------------------------------------------------
  42 // ciInstanceKlass::ciInstanceKlass
  43 //
  44 // Loaded instance klass.
  45 ciInstanceKlass::ciInstanceKlass(KlassHandle h_k) :
  46   ciKlass(h_k), _nonstatic_fields(NULL)
  47 {
  48   assert(get_Klass()->oop_is_instance(), "wrong type");
  49   assert(get_instanceKlass()->is_loaded(), "must be at least loaded");
  50   instanceKlass* ik = get_instanceKlass();
  51 
  52   AccessFlags access_flags = ik->access_flags();
  53   _flags = ciFlags(access_flags);
  54   _has_finalizer = access_flags.has_finalizer();
  55   _has_subklass = ik->subklass() != NULL;
  56   _init_state = (instanceKlass::ClassState)ik->get_init_state();
  57   _nonstatic_field_size = ik->nonstatic_field_size();
  58   _has_nonstatic_fields = ik->has_nonstatic_fields();
  59   _nonstatic_fields = NULL; // initialized lazily by compute_fields:
  60 
  61   _nof_implementors = ik->nof_implementors();
  62   for (int i = 0; i < implementors_limit; i++) {
  63     _implementors[i] = NULL;  // we will fill these lazily
  64   }
  65 
  66   Thread *thread = Thread::current();
  67   if (ciObjectFactory::is_initialized()) {
  68     _loader = JNIHandles::make_local(thread, ik->class_loader());
  69     _protection_domain = JNIHandles::make_local(thread,
  70                                                 ik->protection_domain());
  71     _is_shared = false;
  72   } else {
  73     Handle h_loader(thread, ik->class_loader());
  74     Handle h_protection_domain(thread, ik->protection_domain());
  75     _loader = JNIHandles::make_global(h_loader);
  76     _protection_domain = JNIHandles::make_global(h_protection_domain);
  77     _is_shared = true;
  78   }
  79 
  80   // Lazy fields get filled in only upon request.
  81   _super  = NULL;
  82   _java_mirror = NULL;
  83 
  84   if (is_shared()) {
  85     assert(is_initialized() || is_interface(), "shared classes should be fully initialized");
  86     if (h_k() != SystemDictionary::Object_klass()) {
  87       super();
  88     }
  89     java_mirror();
  90     //compute_fields();  // done outside of constructor
  91   }
  92 
  93   _field_cache = NULL;
  94 }
  95 
  96 // Version for unloaded classes:
  97 ciInstanceKlass::ciInstanceKlass(ciSymbol* name,
  98                                  jobject loader, jobject protection_domain)
  99   : ciKlass(name, ciInstanceKlassKlass::make())
 100 {
 101   assert(name->byte_at(0) != '[', "not an instance klass");
 102   _init_state = (instanceKlass::ClassState)0;
 103   _nonstatic_field_size = -1;
 104   _has_nonstatic_fields = false;
 105   _nonstatic_fields = NULL;
 106   _nof_implementors = -1;
 107   _loader = loader;
 108   _protection_domain = protection_domain;
 109   _is_shared = false;
 110   _super = NULL;


 191 //
 192 ciInstanceKlass* ciInstanceKlass::get_canonical_holder(int offset) {
 193   #ifdef ASSERT
 194   if (!(offset >= 0 && offset < layout_helper())) {
 195     tty->print("*** get_canonical_holder(%d) on ", offset);
 196     this->print();
 197     tty->print_cr(" ***");
 198   };
 199   assert(offset >= 0 && offset < layout_helper(), "offset must be tame");
 200   #endif
 201 
 202   if (offset < instanceOopDesc::base_offset_in_bytes()) {
 203     // All header offsets belong properly to java/lang/Object.
 204     return CURRENT_ENV->Object_klass();
 205   }
 206 
 207   ciInstanceKlass* self = this;
 208   for (;;) {
 209     assert(self->is_loaded(), "must be loaded to have size");
 210     ciInstanceKlass* super = self->super();
 211     if (super == NULL || super->nonstatic_fields()->length() == 0 ||
 212         !super->contains_field_offset(offset)) {
 213       return self;
 214     } else {
 215       self = super;  // return super->get_canonical_holder(offset)
 216     }
 217   }
 218 }
 219 
 220 // ------------------------------------------------------------------
 221 // ciInstanceKlass::is_java_lang_Object
 222 //
 223 // Is this klass java.lang.Object?
 224 bool ciInstanceKlass::is_java_lang_Object() {
 225   return equals(CURRENT_ENV->Object_klass());
 226 }
 227 
 228 // ------------------------------------------------------------------
 229 // ciInstanceKlass::uses_default_loader
 230 bool ciInstanceKlass::uses_default_loader() {
 231   // Note:  We do not need to resolve the handle or enter the VM


 338   Klass* up = ik->up_cast_abstract();
 339   assert(up->oop_is_instance(), "must be instanceKlass");
 340   if (ik == up) {
 341     return NULL;
 342   }
 343   return CURRENT_THREAD_ENV->get_object(up->as_klassOop())->as_instance_klass();
 344 }
 345 
 346 // ------------------------------------------------------------------
 347 // ciInstanceKlass::has_finalizable_subclass
 348 bool ciInstanceKlass::has_finalizable_subclass() {
 349   if (!is_loaded())     return true;
 350   VM_ENTRY_MARK;
 351   return Dependencies::find_finalizable_subclass(get_instanceKlass()) != NULL;
 352 }
 353 
 354 // ------------------------------------------------------------------
 355 // ciInstanceKlass::get_field_by_offset
 356 ciField* ciInstanceKlass::get_field_by_offset(int field_offset, bool is_static) {
 357   if (!is_static) {
 358     for (int i = 0, len = nonstatic_fields()->length(); i < len; i++) {
 359       ciField* field = _nonstatic_fields->at(i);
 360       int  field_off = field->offset_in_bytes();
 361       if (field_off == field_offset)
 362         return field;
 363       if (field_off > field_offset)
 364         break;
 365       // could do binary search or check bins, but probably not worth it
 366     }
 367     return NULL;
 368   } else {
 369     for (int i = 0, len = static_fields()->length(); i < len; i++) {
 370       ciField* field = _static_fields->at(i);
 371       int  field_off = field->offset_in_bytes();
 372       if (field_off == field_offset)
 373         return field;
 374       if (field_off > field_offset)
 375         break;
 376       // could do binary search or check bins, but probably not worth it
 377     }




 378     return NULL;
 379   }


 380 }
 381 
 382 // ------------------------------------------------------------------
 383 // ciInstanceKlass::get_field_by_name
 384 ciField* ciInstanceKlass::get_field_by_name(ciSymbol* name, ciSymbol* signature, bool is_static) {
 385   if (!is_static) {
 386     for (int i = 0, len = nonstatic_fields()->length(); i < len; i++) {
 387       ciField* field = _nonstatic_fields->at(i);
 388       if (field->name() == name && field->signature() == signature) {
 389         return field;

 390       }
 391     }
 392     return NULL;
 393   } else {
 394     for (int i = 0, len = static_fields()->length(); i < len; i++) {
 395       ciField* field = _static_fields->at(i);
 396       if (field->name() == name && field->signature() == signature) {
 397         return field;















 398       }














 399     }
 400     return NULL;
 401   }
 402 }
 403 
 404 static int sort_field_by_offset(ciField** a, ciField** b) {
 405   return (*a)->offset_in_bytes() - (*b)->offset_in_bytes();
 406   // (no worries about 32-bit overflow...)
 407 }
 408 
 409 // ------------------------------------------------------------------
 410 // ciInstanceKlass::compute_fields
 411 int ciInstanceKlass::compute_fields() {
 412   assert(is_loaded(), "must be loaded");
 413 
 414   if (_nonstatic_fields != NULL)
 415     return _nonstatic_fields->length();
 416 
 417   if (!has_nonstatic_fields()) {
 418     Arena* arena = CURRENT_ENV->arena();
 419     _nonstatic_fields = new (arena) GrowableArray<ciField*>(arena, 0, 0, NULL);
 420     return 0;
 421   }
 422   assert(!is_java_lang_Object(), "bootstrap OK");
 423 
 424   // Size in bytes of my fields, including inherited fields.
 425   int fsize = _nonstatic_field_size * heapOopSize;
 426 
 427   ciInstanceKlass* super = this->super();
 428   GrowableArray<ciField*>* super_fields = NULL;
 429   if (super != NULL && super->has_nonstatic_fields()) {
 430     int super_fsize  = super->_nonstatic_field_size * heapOopSize;
 431     int super_flen   = super->nonstatic_fields()->length();
 432     super_fields = super->_nonstatic_fields;
 433     assert(super_flen == 0 || super_fields != NULL, "first get nof_fields");
 434     // See if I am no larger than my super; if so, I can use his fields.
 435     if (fsize == super_fsize) {
 436       _nonstatic_fields = super_fields;
 437       return super_fields->length();
 438     }
 439   }
 440 

 441   GUARDED_VM_ENTRY({
 442       compute_fields_impl(super_fields);
 443     });
 444 








 445   // Now sort them by offset, ascending.
 446   // (In principle, they could mix with superclass fields.)
 447   _static_fields->sort(sort_field_by_offset);
 448   _nonstatic_fields->sort(sort_field_by_offset);
 449 #ifdef ASSERT
 450   int last_offset = instanceOopDesc::base_offset_in_bytes();
 451   for (int i = 0; i < _nonstatic_fields->length(); i++) {
 452     ciField* field = _nonstatic_fields->at(i);
 453     int offset = field->offset_in_bytes();
 454     int size   = (field->_type == NULL) ? heapOopSize : field->size_in_bytes();
 455     assert(last_offset <= offset, err_msg("no field overlap: %d <= %d", last_offset, offset));
 456     if (last_offset > (int)sizeof(oopDesc))
 457       assert((offset - last_offset) < BytesPerLong, "no big holes");
 458     // Note:  Two consecutive T_BYTE fields will be separated by wordSize-1
 459     // padding bytes if one of them is declared by a superclass.
 460     // This is a minor inefficiency classFileParser.cpp.
 461     last_offset = offset + size;
 462   }
 463   assert(last_offset <= (int)instanceOopDesc::base_offset_in_bytes() + fsize, "no overflow");
 464 #endif
 465 
 466   return _nonstatic_fields->length();

 467 }
 468 
 469 void ciInstanceKlass::compute_fields_impl(GrowableArray<ciField*>* super_fields) {


 470   ASSERT_IN_VM;
 471   Arena* arena = CURRENT_ENV->arena();
 472   int static_len = 0;
 473   int nonstatic_len = 0;
 474 
 475   GrowableArray<ciField*>* static_fields = NULL;
 476   GrowableArray<ciField*>* nonstatic_fields = NULL;
 477   instanceKlass* k = get_instanceKlass();
 478   typeArrayOop fields_array = k->fields();
 479   for (int pass = 0; pass <= 1; pass++) {
 480     for (int i = 0, alen = fields_array->length(); i < alen; i += instanceKlass::next_offset) {
 481       fieldDescriptor fd;
 482       fd.initialize(k->as_klassOop(), i);

 483       if (pass == 0) {
 484         if (fd.is_static()) static_len++;
 485         else nonstatic_len++;
 486       } else {
 487         ciField* field = new (arena) ciField(&fd);
 488         if (fd.is_static()) static_fields->append(field);
 489         else nonstatic_fields->append(field);
 490       }
 491     }
 492 
 493     // Between passes, allocate the array:
 494     if (pass == 0) {



 495       if (super_fields != NULL) {
 496         if (nonstatic_len == 0) {
 497           nonstatic_fields = super_fields;
 498         }
 499         nonstatic_len += super_fields->length();
 500       }
 501       if (nonstatic_fields == NULL) {
 502         nonstatic_fields = new (arena) GrowableArray<ciField*>(arena, nonstatic_len, 0, NULL);
 503       }
 504       if (super_fields != NULL) {
 505         nonstatic_fields->appendAll(super_fields);
 506       }
 507       static_fields = new (arena) GrowableArray<ciField*>(arena, nonstatic_len, 0, NULL);
 508     }
 509   }
 510   assert(nonstatic_fields->length() == nonstatic_len, "sanity");
 511   assert(static_fields->length() == static_len, "sanity");
 512 
 513   _nonstatic_fields = nonstatic_fields;
 514   _static_fields = static_fields;
 515 }
 516 
 517 // ------------------------------------------------------------------
 518 // ciInstanceKlass::find_method
 519 //
 520 // Find a method in this klass.
 521 ciMethod* ciInstanceKlass::find_method(ciSymbol* name, ciSymbol* signature) {
 522   VM_ENTRY_MARK;
 523   instanceKlass* k = get_instanceKlass();
 524   Symbol* name_sym = name->get_symbol();
 525   Symbol* sig_sym= signature->get_symbol();
 526 
 527   methodOop m = k->find_method(name_sym, sig_sym);
 528   if (m == NULL)  return NULL;
 529 
 530   return CURRENT_THREAD_ENV->get_object(m)->as_method();
 531 }
 532 
 533 // ------------------------------------------------------------------
 534 // ciInstanceKlass::is_leaf_type


src/share/vm/ci/ciInstanceKlass.cpp
Index Unified diffs Context diffs Sdiffs Patch New Old Previous File Next File