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

src/share/vm/ci/ciInstanceKlass.cpp

Print this page




  42 // ------------------------------------------------------------------
  43 // ciInstanceKlass::ciInstanceKlass
  44 //
  45 // Loaded instance klass.
  46 ciInstanceKlass::ciInstanceKlass(KlassHandle h_k) :
  47   ciKlass(h_k)
  48 {
  49   assert(get_Klass()->is_instance_klass(), "wrong type");
  50   assert(get_instanceKlass()->is_loaded(), "must be at least loaded");
  51   InstanceKlass* ik = get_instanceKlass();
  52 
  53   AccessFlags access_flags = ik->access_flags();
  54   _flags = ciFlags(access_flags);
  55   _has_finalizer = access_flags.has_finalizer();
  56   _has_subklass = ik->subklass() != NULL;
  57   _init_state = ik->init_state();
  58   _nonstatic_field_size = ik->nonstatic_field_size();
  59   _has_nonstatic_fields = ik->has_nonstatic_fields();
  60   _has_default_methods = ik->has_default_methods();
  61   _is_anonymous = ik->is_anonymous();
  62   _nonstatic_fields = NULL; // initialized lazily by compute_nonstatic_fields:

  63   _has_injected_fields = -1;
  64   _implementor = NULL; // we will fill these lazily
  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     //compute_nonstatic_fields();  // done outside of constructor
  89   }
  90 
  91   _field_cache = NULL;
  92 }
  93 
  94 // Version for unloaded classes:
  95 ciInstanceKlass::ciInstanceKlass(ciSymbol* name,
  96                                  jobject loader, jobject protection_domain)
  97   : ciKlass(name, T_OBJECT)
  98 {
  99   assert(name->byte_at(0) != '[', "not an instance klass");
 100   _init_state = (InstanceKlass::ClassState)0;
 101   _nonstatic_field_size = -1;
 102   _has_nonstatic_fields = false;
 103   _nonstatic_fields = NULL;

 104   _has_injected_fields = -1;
 105   _is_anonymous = false;
 106   _loader = loader;
 107   _protection_domain = protection_domain;
 108   _is_shared = false;
 109   _super = NULL;
 110   _java_mirror = NULL;
 111   _field_cache = NULL;
 112 }
 113 
 114 
 115 
 116 // ------------------------------------------------------------------
 117 // ciInstanceKlass::compute_shared_is_initialized
 118 void ciInstanceKlass::compute_shared_init_state() {
 119   GUARDED_VM_ENTRY(
 120     InstanceKlass* ik = get_instanceKlass();
 121     _init_state = ik->init_state();
 122   )
 123 }


 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 // ------------------------------------------------------------------
 443 // ciInstanceKlass::compute_nonstatic_fields
 444 int ciInstanceKlass::compute_nonstatic_fields() {
 445   assert(is_loaded(), "must be loaded");
 446 
 447   if (_nonstatic_fields != NULL)
 448     return _nonstatic_fields->length();
 449 
 450   if (!has_nonstatic_fields()) {
 451     Arena* arena = CURRENT_ENV->arena();
 452     _nonstatic_fields = new (arena) GrowableArray<ciField*>(arena, 0, 0, NULL);

 453     return 0;
 454   }
 455   assert(!is_java_lang_Object(), "bootstrap OK");
 456 
 457   // Size in bytes of my fields, including inherited fields.
 458   int fsize = nonstatic_field_size() * heapOopSize;
 459 
 460   ciInstanceKlass* super = this->super();
 461   GrowableArray<ciField*>* super_fields = NULL;
 462   if (super != NULL && super->has_nonstatic_fields()) {
 463     int super_fsize  = super->nonstatic_field_size() * heapOopSize;
 464     int super_flen   = super->nof_nonstatic_fields();
 465     super_fields = super->_nonstatic_fields;
 466     assert(super_flen == 0 || super_fields != NULL, "first get nof_fields");
 467     // See if I am no larger than my super; if so, I can use his fields.
 468     if (fsize == super_fsize) {
 469       _nonstatic_fields = super_fields;

 470       return super_fields->length();
 471     }
 472   }
 473 
 474   GrowableArray<ciField*>* fields = NULL;
 475   GUARDED_VM_ENTRY({
 476       fields = compute_nonstatic_fields_impl(super_fields);
 477     });
 478 
 479   if (fields == NULL) {
 480     // This can happen if this class (java.lang.Class) has invisible fields.
 481     if (super_fields != NULL) {
 482       _nonstatic_fields = super_fields;

 483       return super_fields->length();
 484     } else {

 485       return 0;
 486     }
 487   }
 488 
 489   int flen = fields->length();
 490 
 491   // Now sort them by offset, ascending.
 492   // (In principle, they could mix with superclass fields.)
 493   fields->sort(sort_field_by_offset);
 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   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




  42 // ------------------------------------------------------------------
  43 // ciInstanceKlass::ciInstanceKlass
  44 //
  45 // Loaded instance klass.
  46 ciInstanceKlass::ciInstanceKlass(KlassHandle h_k) :
  47   ciKlass(h_k)
  48 {
  49   assert(get_Klass()->is_instance_klass(), "wrong type");
  50   assert(get_instanceKlass()->is_loaded(), "must be at least loaded");
  51   InstanceKlass* ik = get_instanceKlass();
  52 
  53   AccessFlags access_flags = ik->access_flags();
  54   _flags = ciFlags(access_flags);
  55   _has_finalizer = access_flags.has_finalizer();
  56   _has_subklass = ik->subklass() != NULL;
  57   _init_state = ik->init_state();
  58   _nonstatic_field_size = ik->nonstatic_field_size();
  59   _has_nonstatic_fields = ik->has_nonstatic_fields();
  60   _has_default_methods = ik->has_default_methods();
  61   _is_anonymous = ik->is_anonymous();
  62   _nonstatic_fields = NULL;            // initialized lazily by compute_nonstatic_fields
  63   _nof_declared_nonstatic_fields = -1; // initialized lazily by compute_nonstatic_fields
  64   _has_injected_fields = -1;
  65   _implementor = NULL; // we will fill these lazily
  66 
  67   Thread *thread = Thread::current();
  68   if (ciObjectFactory::is_initialized()) {
  69     _loader = JNIHandles::make_local(thread, ik->class_loader());
  70     _protection_domain = JNIHandles::make_local(thread,
  71                                                 ik->protection_domain());
  72     _is_shared = false;
  73   } else {
  74     Handle h_loader(thread, ik->class_loader());
  75     Handle h_protection_domain(thread, ik->protection_domain());
  76     _loader = JNIHandles::make_global(h_loader);
  77     _protection_domain = JNIHandles::make_global(h_protection_domain);
  78     _is_shared = true;
  79   }
  80 
  81   // Lazy fields get filled in only upon request.
  82   _super  = NULL;
  83   _java_mirror = NULL;
  84 
  85   if (is_shared()) {
  86     if (h_k() != SystemDictionary::Object_klass()) {
  87       super();
  88     }
  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, T_OBJECT)
  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;            // initialized lazily by compute_nonstatic_fields
 105   _nof_declared_nonstatic_fields = -1; // initialized lazily by compute_nonstatic_fields
 106   _has_injected_fields = -1;
 107   _is_anonymous = false;
 108   _loader = loader;
 109   _protection_domain = protection_domain;
 110   _is_shared = false;
 111   _super = NULL;
 112   _java_mirror = NULL;
 113   _field_cache = NULL;
 114 }
 115 
 116 
 117 
 118 // ------------------------------------------------------------------
 119 // ciInstanceKlass::compute_shared_is_initialized
 120 void ciInstanceKlass::compute_shared_init_state() {
 121   GUARDED_VM_ENTRY(
 122     InstanceKlass* ik = get_instanceKlass();
 123     _init_state = ik->init_state();
 124   )
 125 }


 435   return field;
 436 }
 437 
 438 
 439 static int sort_field_by_offset(ciField** a, ciField** b) {
 440   return (*a)->offset_in_bytes() - (*b)->offset_in_bytes();
 441   // (no worries about 32-bit overflow...)
 442 }
 443 
 444 // ------------------------------------------------------------------
 445 // ciInstanceKlass::compute_nonstatic_fields
 446 int ciInstanceKlass::compute_nonstatic_fields() {
 447   assert(is_loaded(), "must be loaded");
 448 
 449   if (_nonstatic_fields != NULL)
 450     return _nonstatic_fields->length();
 451 
 452   if (!has_nonstatic_fields()) {
 453     Arena* arena = CURRENT_ENV->arena();
 454     _nonstatic_fields = new (arena) GrowableArray<ciField*>(arena, 0, 0, NULL);
 455     _nof_declared_nonstatic_fields = 0;
 456     return 0;
 457   }
 458   assert(!is_java_lang_Object(), "bootstrap OK");
 459 
 460   // Size in bytes of my fields, including inherited fields.
 461   int fsize = nonstatic_field_size() * heapOopSize;
 462 
 463   ciInstanceKlass* super = this->super();
 464   GrowableArray<ciField*>* super_fields = NULL;
 465   if (super != NULL && super->has_nonstatic_fields()) {
 466     int super_fsize  = super->nonstatic_field_size() * heapOopSize;
 467     int super_flen   = super->nof_nonstatic_fields();
 468     super_fields = super->_nonstatic_fields;
 469     assert(super_flen == 0 || super_fields != NULL, "first get nof_fields");
 470     // See if I am no larger than my super; if so, I can use his fields.
 471     if (fsize == super_fsize) {
 472       _nonstatic_fields = super_fields;
 473       _nof_declared_nonstatic_fields = super->nof_declared_nonstatic_fields();
 474       return super_fields->length();
 475     }
 476   }
 477 
 478   GrowableArray<ciField*>* fields = NULL;
 479   GUARDED_VM_ENTRY({
 480       fields = compute_nonstatic_fields_impl(super_fields);
 481     });
 482 
 483   if (fields == NULL) {
 484     // This can happen if this class (java.lang.Class) has invisible fields.
 485     if (super_fields != NULL) {
 486       _nonstatic_fields = super_fields;
 487       _nof_declared_nonstatic_fields = super->nof_declared_nonstatic_fields();
 488       return super_fields->length();
 489     } else {
 490       _nof_declared_nonstatic_fields = 0;
 491       return 0;
 492     }
 493   }
 494 
 495   int flen = fields->length();
 496 
 497   // Now sort them by offset, ascending.
 498   // (In principle, they could mix with superclass fields.)
 499   fields->sort(sort_field_by_offset);
 500   _nonstatic_fields = fields;
 501   return flen;
 502 }
 503 
 504 GrowableArray<ciField*>*
 505 ciInstanceKlass::compute_nonstatic_fields_impl(GrowableArray<ciField*>*
 506                                                super_fields) {
 507   ASSERT_IN_VM;
 508   Arena* arena = CURRENT_ENV->arena();
 509   int flen = 0;
 510   GrowableArray<ciField*>* fields = NULL;
 511   InstanceKlass* k = get_instanceKlass();
 512   for (JavaFieldStream fs(k); !fs.done(); fs.next()) {
 513     if (fs.access_flags().is_static())  continue;
 514     flen += 1;
 515   }
 516 
 517   // allocate the array:
 518   if (flen == 0) {
 519     _nof_declared_nonstatic_fields = flen;
 520     return NULL;  // return nothing if none are locally declared
 521   }
 522 
 523   if (super_fields != NULL) {
 524     flen += super_fields->length();
 525   }
 526   _nof_declared_nonstatic_fields = flen;
 527 
 528   fields = new (arena) GrowableArray<ciField*>(arena, flen, 0, NULL);
 529   if (super_fields != NULL) {
 530     fields->appendAll(super_fields);
 531   }
 532 
 533   for (JavaFieldStream fs(k); !fs.done(); fs.next()) {
 534     if (fs.access_flags().is_static())  continue;
 535     fieldDescriptor& fd = fs.field_descriptor();
 536     if (fd.field_type() == T_VALUETYPE) {
 537       // Value type fields are embedded
 538       int field_offset = fd.offset();
 539       // Get ValueKlass and adjust number of fields
 540       ciValueKlass* vk = get_field_type_by_offset(field_offset)->as_value_klass();
 541       flen += vk->get_field_count() - 1;
 542       // Iterate over fields of flattened value type and copy them to 'this'
 543       for (int i = 0; i < vk->nof_nonstatic_fields(); ++i) {
 544         ciField* flattened_field = vk->nonstatic_field_at(i);
 545         // Adjust offset to account for missing oop header
 546         int offset = field_offset + (flattened_field->offset() - vk->get_first_field_offset());
 547         bool is_final = is_valuetype(); // flattened fields are final if holder is a value type


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