hotspot/src/share/vm/classfile/javaClasses.cpp
changeset 33611 9abd65805e19
parent 33602 16053580a684
child 33638 ef49ed90010b
equal deleted inserted replaced
33602:16053580a684 33611:9abd65805e19
   553 void java_lang_Class::fixup_mirror(KlassHandle k, TRAPS) {
   553 void java_lang_Class::fixup_mirror(KlassHandle k, TRAPS) {
   554   assert(InstanceMirrorKlass::offset_of_static_fields() != 0, "must have been computed already");
   554   assert(InstanceMirrorKlass::offset_of_static_fields() != 0, "must have been computed already");
   555 
   555 
   556   // If the offset was read from the shared archive, it was fixed up already
   556   // If the offset was read from the shared archive, it was fixed up already
   557   if (!k->is_shared()) {
   557   if (!k->is_shared()) {
   558     if (k->oop_is_instance()) {
   558     if (k->is_instance_klass()) {
   559       // During bootstrap, java.lang.Class wasn't loaded so static field
   559       // During bootstrap, java.lang.Class wasn't loaded so static field
   560       // offsets were computed without the size added it.  Go back and
   560       // offsets were computed without the size added it.  Go back and
   561       // update all the static field offsets to included the size.
   561       // update all the static field offsets to included the size.
   562         for (JavaFieldStream fs(InstanceKlass::cast(k())); !fs.done(); fs.next()) {
   562         for (JavaFieldStream fs(InstanceKlass::cast(k())); !fs.done(); fs.next()) {
   563         if (fs.access_flags().is_static()) {
   563         if (fs.access_flags().is_static()) {
   611     assert(oop_size(mirror()) == mk->instance_size(k), "should have been set");
   611     assert(oop_size(mirror()) == mk->instance_size(k), "should have been set");
   612 
   612 
   613     java_lang_Class::set_static_oop_field_count(mirror(), mk->compute_static_oop_field_count(mirror()));
   613     java_lang_Class::set_static_oop_field_count(mirror(), mk->compute_static_oop_field_count(mirror()));
   614 
   614 
   615     // It might also have a component mirror.  This mirror must already exist.
   615     // It might also have a component mirror.  This mirror must already exist.
   616     if (k->oop_is_array()) {
   616     if (k->is_array_klass()) {
   617       Handle comp_mirror;
   617       Handle comp_mirror;
   618       if (k->oop_is_typeArray()) {
   618       if (k->is_typeArray_klass()) {
   619         BasicType type = TypeArrayKlass::cast(k())->element_type();
   619         BasicType type = TypeArrayKlass::cast(k())->element_type();
   620         comp_mirror = Universe::java_mirror(type);
   620         comp_mirror = Universe::java_mirror(type);
   621       } else {
   621       } else {
   622         assert(k->oop_is_objArray(), "Must be");
   622         assert(k->is_objArray_klass(), "Must be");
   623         Klass* element_klass = ObjArrayKlass::cast(k())->element_klass();
   623         Klass* element_klass = ObjArrayKlass::cast(k())->element_klass();
   624         assert(element_klass != NULL, "Must have an element klass");
   624         assert(element_klass != NULL, "Must have an element klass");
   625         comp_mirror = element_klass->java_mirror();
   625         comp_mirror = element_klass->java_mirror();
   626       }
   626       }
   627       assert(comp_mirror.not_null(), "must have a mirror");
   627       assert(comp_mirror.not_null(), "must have a mirror");
   629       // Two-way link between the array klass and its component mirror:
   629       // Two-way link between the array klass and its component mirror:
   630       // (array_klass) k -> mirror -> component_mirror -> array_klass -> k
   630       // (array_klass) k -> mirror -> component_mirror -> array_klass -> k
   631       set_component_mirror(mirror(), comp_mirror());
   631       set_component_mirror(mirror(), comp_mirror());
   632       set_array_klass(comp_mirror(), k());
   632       set_array_klass(comp_mirror(), k());
   633     } else {
   633     } else {
   634       assert(k->oop_is_instance(), "Must be");
   634       assert(k->is_instance_klass(), "Must be");
   635 
   635 
   636       initialize_mirror_fields(k, mirror, protection_domain, THREAD);
   636       initialize_mirror_fields(k, mirror, protection_domain, THREAD);
   637       if (HAS_PENDING_EXCEPTION) {
   637       if (HAS_PENDING_EXCEPTION) {
   638         // If any of the fields throws an exception like OOM remove the klass field
   638         // If any of the fields throws an exception like OOM remove the klass field
   639         // from the mirror so GC doesn't follow it after the klass has been deallocated.
   639         // from the mirror so GC doesn't follow it after the klass has been deallocated.
   768   bool is_instance = false;
   768   bool is_instance = false;
   769   if (is_primitive(java_class)) {
   769   if (is_primitive(java_class)) {
   770     name = vmSymbols::type_signature(primitive_type(java_class));
   770     name = vmSymbols::type_signature(primitive_type(java_class));
   771   } else {
   771   } else {
   772     Klass* k = as_Klass(java_class);
   772     Klass* k = as_Klass(java_class);
   773     is_instance = k->oop_is_instance();
   773     is_instance = k->is_instance_klass();
   774     name = k->name();
   774     name = k->name();
   775   }
   775   }
   776   if (name == NULL) {
   776   if (name == NULL) {
   777     st->print("<null>");
   777     st->print("<null>");
   778     return;
   778     return;
   791     // the refcount, so make adjustment here and below for symbols returned
   791     // the refcount, so make adjustment here and below for symbols returned
   792     // that are not created or incremented due to a successful lookup.
   792     // that are not created or incremented due to a successful lookup.
   793     name->increment_refcount();
   793     name->increment_refcount();
   794   } else {
   794   } else {
   795     Klass* k = as_Klass(java_class);
   795     Klass* k = as_Klass(java_class);
   796     if (!k->oop_is_instance()) {
   796     if (!k->is_instance_klass()) {
   797       name = k->name();
   797       name = k->name();
   798       name->increment_refcount();
   798       name->increment_refcount();
   799     } else {
   799     } else {
   800       ResourceMark rm;
   800       ResourceMark rm;
   801       const char* sigstr = k->signature_name();
   801       const char* sigstr = k->signature_name();
   827   return name;
   827   return name;
   828 }
   828 }
   829 
   829 
   830 Klass* java_lang_Class::array_klass(oop java_class) {
   830 Klass* java_lang_Class::array_klass(oop java_class) {
   831   Klass* k = ((Klass*)java_class->metadata_field(_array_klass_offset));
   831   Klass* k = ((Klass*)java_class->metadata_field(_array_klass_offset));
   832   assert(k == NULL || k->is_klass() && k->oop_is_array(), "should be array klass");
   832   assert(k == NULL || k->is_klass() && k->is_array_klass(), "should be array klass");
   833   return k;
   833   return k;
   834 }
   834 }
   835 
   835 
   836 
   836 
   837 void java_lang_Class::set_array_klass(oop java_class, Klass* klass) {
   837 void java_lang_Class::set_array_klass(oop java_class, Klass* klass) {
   838   assert(klass->is_klass() && klass->oop_is_array(), "should be array klass");
   838   assert(klass->is_klass() && klass->is_array_klass(), "should be array klass");
   839   java_class->metadata_field_put(_array_klass_offset, klass);
   839   java_class->metadata_field_put(_array_klass_offset, klass);
   840 }
   840 }
   841 
   841 
   842 
   842 
   843 bool java_lang_Class::is_primitive(oop java_class) {
   843 bool java_lang_Class::is_primitive(oop java_class) {
  2504 ConstantPool* sun_reflect_ConstantPool::get_cp(oop reflect) {
  2504 ConstantPool* sun_reflect_ConstantPool::get_cp(oop reflect) {
  2505   assert(Universe::is_fully_initialized(), "Need to find another solution to the reflection problem");
  2505   assert(Universe::is_fully_initialized(), "Need to find another solution to the reflection problem");
  2506 
  2506 
  2507   oop mirror = reflect->obj_field(_oop_offset);
  2507   oop mirror = reflect->obj_field(_oop_offset);
  2508   Klass* k = java_lang_Class::as_Klass(mirror);
  2508   Klass* k = java_lang_Class::as_Klass(mirror);
  2509   assert(k->oop_is_instance(), "Must be");
  2509   assert(k->is_instance_klass(), "Must be");
  2510 
  2510 
  2511   // Get the constant pool back from the klass.  Since class redefinition
  2511   // Get the constant pool back from the klass.  Since class redefinition
  2512   // merges the new constant pool into the old, this is essentially the
  2512   // merges the new constant pool into the old, this is essentially the
  2513   // same constant pool as the original.  If constant pool merging is
  2513   // same constant pool as the original.  If constant pool merging is
  2514   // no longer done in the future, this will have to change to save
  2514   // no longer done in the future, this will have to change to save