< prev index next >

src/hotspot/share/oops/arrayKlass.cpp

Print this page


  32 #include "memory/resourceArea.hpp"
  33 #include "memory/universe.hpp"
  34 #include "oops/arrayKlass.hpp"
  35 #include "oops/arrayOop.hpp"
  36 #include "oops/instanceKlass.hpp"
  37 #include "oops/objArrayOop.hpp"
  38 #include "oops/oop.inline.hpp"
  39 #include "runtime/handles.inline.hpp"
  40 
  41 int ArrayKlass::static_size(int header_size) {
  42   // size of an array klass object
  43   assert(header_size <= InstanceKlass::header_size(), "bad header size");
  44   // If this assert fails, see comments in base_create_array_klass.
  45   header_size = InstanceKlass::header_size();
  46   int vtable_len = Universe::base_vtable_size();
  47   int size = header_size + vtable_len;
  48   return align_metadata_size(size);
  49 }
  50 
  51 
  52 Klass* ArrayKlass::java_super() const {
  53   if (super() == NULL)  return NULL;  // bootstrap case
  54   // Array klasses have primary supertypes which are not reported to Java.
  55   // Example super chain:  String[][] -> Object[][] -> Object[] -> Object
  56   return SystemDictionary::Object_klass();
  57 }
  58 
  59 
  60 oop ArrayKlass::multi_allocate(int rank, jint* sizes, TRAPS) {
  61   ShouldNotReachHere();
  62   return NULL;
  63 }
  64 
  65 // find field according to JVM spec 5.4.3.2, returns the klass in which the field is defined
  66 Klass* ArrayKlass::find_field(Symbol* name, Symbol* sig, fieldDescriptor* fd) const {
  67   // There are no fields in an array klass but look to the super class (Object)
  68   assert(super(), "super klass must be present");
  69   return super()->find_field(name, sig, fd);
  70 }
  71 
  72 Method* ArrayKlass::uncached_lookup_method(const Symbol* name,
  73                                            const Symbol* signature,
  74                                            OverpassLookupMode overpass_mode,
  75                                            PrivateLookupMode private_mode) const {
  76   // There are no methods in an array klass but the super class (Object) has some
  77   assert(super(), "super klass must be present");
  78   // Always ignore overpass methods in superclasses, although technically the
  79   // super klass of an array, (j.l.Object) should not have
  80   // any overpass methods present.
  81   return super()->uncached_lookup_method(name, signature, Klass::skip_overpass, private_mode);
  82 }
  83 
  84 ArrayKlass::ArrayKlass(Symbol* name, KlassID id) :
  85   Klass(id),
  86   _dimension(1),
  87   _higher_dimension(NULL),
  88   _lower_dimension(NULL) {
  89     // Arrays don't add any new methods, so their vtable is the same size as
  90     // the vtable of klass Object.
  91     set_vtable_length(Universe::base_vtable_size());
  92     set_name(name);
  93     set_super(Universe::is_bootstrapping() ? (Klass*)NULL : SystemDictionary::Object_klass());
  94     set_layout_helper(Klass::_lh_neutral_value);
  95     set_is_cloneable(); // All arrays are considered to be cloneable (See JLS 20.1.5)
  96     JFR_ONLY(INIT_ID(this);)
  97 }
  98 
  99 
 100 // Initialization of vtables and mirror object is done separatly from base_create_array_klass,
 101 // since a GC can happen. At this point all instance variables of the ArrayKlass must be setup.
 102 void ArrayKlass::complete_create_array_klass(ArrayKlass* k, Klass* super_klass, ModuleEntry* module_entry, TRAPS) {
 103   k->initialize_supers(super_klass, NULL, CHECK);
 104   k->vtable().initialize_vtable(false, CHECK);
 105 
 106   // During bootstrapping, before java.base is defined, the module_entry may not be present yet.
 107   // These classes will be put on a fixup list and their module fields will be patched once
 108   // java.base is defined.
 109   assert((module_entry != NULL) || ((module_entry == NULL) && !ModuleEntryTable::javabase_defined()),
 110          "module entry not available post " JAVA_BASE_NAME " definition");
 111   oop module = (module_entry != NULL) ? module_entry->module() : (oop)NULL;
 112   java_lang_Class::create_mirror(k, Handle(THREAD, k->class_loader()), Handle(THREAD, module), Handle(), CHECK);
 113 }
 114 
 115 GrowableArray<Klass*>* ArrayKlass::compute_secondary_supers(int num_extra_slots,
 116                                                             Array<Klass*>* transitive_interfaces) {
 117   // interfaces = { cloneable_klass, serializable_klass };
 118   assert(num_extra_slots == 0, "sanity of primitive array type");
 119   assert(transitive_interfaces == NULL, "sanity");
 120   // Must share this for correct bootstrapping!
 121   set_secondary_supers(Universe::the_array_interfaces_array());
 122   return NULL;
 123 }
 124 
 125 bool ArrayKlass::compute_is_subtype_of(Klass* k) {
 126   // An array is a subtype of Serializable, Clonable, and Object
 127   return    k == SystemDictionary::Object_klass()
 128          || k == SystemDictionary::Cloneable_klass()
 129          || k == SystemDictionary::Serializable_klass();
 130 }
 131 
 132 objArrayOop ArrayKlass::allocate_arrayArray(int n, int length, TRAPS) {
 133   if (length < 0) {
 134     THROW_MSG_0(vmSymbols::java_lang_NegativeArraySizeException(), err_msg("%d", length));
 135   }
 136   if (length > arrayOopDesc::max_array_length(T_ARRAY)) {




  32 #include "memory/resourceArea.hpp"
  33 #include "memory/universe.hpp"
  34 #include "oops/arrayKlass.hpp"
  35 #include "oops/arrayOop.hpp"
  36 #include "oops/instanceKlass.hpp"
  37 #include "oops/objArrayOop.hpp"
  38 #include "oops/oop.inline.hpp"
  39 #include "runtime/handles.inline.hpp"
  40 
  41 int ArrayKlass::static_size(int header_size) {
  42   // size of an array klass object
  43   assert(header_size <= InstanceKlass::header_size(), "bad header size");
  44   // If this assert fails, see comments in base_create_array_klass.
  45   header_size = InstanceKlass::header_size();
  46   int vtable_len = Universe::base_vtable_size();
  47   int size = header_size + vtable_len;
  48   return align_metadata_size(size);
  49 }
  50 
  51 
  52 InstanceKlass* ArrayKlass::java_super() const {
  53   if (super() == NULL)  return NULL;  // bootstrap case
  54   // Array klasses have primary supertypes which are not reported to Java.
  55   // Example super chain:  String[][] -> Object[][] -> Object[] -> Object
  56   return SystemDictionary::Object_klass();
  57 }
  58 
  59 
  60 oop ArrayKlass::multi_allocate(int rank, jint* sizes, TRAPS) {
  61   ShouldNotReachHere();
  62   return NULL;
  63 }
  64 
  65 // find field according to JVM spec 5.4.3.2, returns the klass in which the field is defined
  66 Klass* ArrayKlass::find_field(Symbol* name, Symbol* sig, fieldDescriptor* fd) const {
  67   // There are no fields in an array klass but look to the super class (Object)
  68   assert(super(), "super klass must be present");
  69   return super()->find_field(name, sig, fd);
  70 }
  71 
  72 Method* ArrayKlass::uncached_lookup_method(const Symbol* name,
  73                                            const Symbol* signature,
  74                                            OverpassLookupMode overpass_mode,
  75                                            PrivateLookupMode private_mode) const {
  76   // There are no methods in an array klass but the super class (Object) has some
  77   assert(super(), "super klass must be present");
  78   // Always ignore overpass methods in superclasses, although technically the
  79   // super klass of an array, (j.l.Object) should not have
  80   // any overpass methods present.
  81   return super()->uncached_lookup_method(name, signature, Klass::skip_overpass, private_mode);
  82 }
  83 
  84 ArrayKlass::ArrayKlass(Symbol* name, KlassID id) :
  85   Klass(id),
  86   _dimension(1),
  87   _higher_dimension(NULL),
  88   _lower_dimension(NULL) {
  89     // Arrays don't add any new methods, so their vtable is the same size as
  90     // the vtable of klass Object.
  91     set_vtable_length(Universe::base_vtable_size());
  92     set_name(name);
  93     set_super(Universe::is_bootstrapping() ? (InstanceKlass*)NULL : SystemDictionary::Object_klass());
  94     set_layout_helper(Klass::_lh_neutral_value);
  95     set_is_cloneable(); // All arrays are considered to be cloneable (See JLS 20.1.5)
  96     JFR_ONLY(INIT_ID(this);)
  97 }
  98 
  99 
 100 // Initialization of vtables and mirror object is done separatly from base_create_array_klass,
 101 // since a GC can happen. At this point all instance variables of the ArrayKlass must be setup.
 102 void ArrayKlass::complete_create_array_klass(ArrayKlass* k, Klass* super_klass, ModuleEntry* module_entry, TRAPS) {
 103   k->initialize_supers(super_klass, NULL, CHECK);
 104   k->vtable().initialize_vtable(false, CHECK);
 105 
 106   // During bootstrapping, before java.base is defined, the module_entry may not be present yet.
 107   // These classes will be put on a fixup list and their module fields will be patched once
 108   // java.base is defined.
 109   assert((module_entry != NULL) || ((module_entry == NULL) && !ModuleEntryTable::javabase_defined()),
 110          "module entry not available post " JAVA_BASE_NAME " definition");
 111   oop module = (module_entry != NULL) ? module_entry->module() : (oop)NULL;
 112   java_lang_Class::create_mirror(k, Handle(THREAD, k->class_loader()), Handle(THREAD, module), Handle(), CHECK);
 113 }
 114 
 115 GrowableArray<Klass*>* ArrayKlass::compute_secondary_supers(int num_extra_slots,
 116                                                             Array<InstanceKlass*>* transitive_interfaces) {
 117   // interfaces = { cloneable_klass, serializable_klass };
 118   assert(num_extra_slots == 0, "sanity of primitive array type");
 119   assert(transitive_interfaces == NULL, "sanity");
 120   // Must share this for correct bootstrapping!
 121   set_secondary_supers(Universe::the_array_interfaces_array());
 122   return NULL;
 123 }
 124 
 125 bool ArrayKlass::compute_is_subtype_of(Klass* k) {
 126   // An array is a subtype of Serializable, Clonable, and Object
 127   return    k == SystemDictionary::Object_klass()
 128          || k == SystemDictionary::Cloneable_klass()
 129          || k == SystemDictionary::Serializable_klass();
 130 }
 131 
 132 objArrayOop ArrayKlass::allocate_arrayArray(int n, int length, TRAPS) {
 133   if (length < 0) {
 134     THROW_MSG_0(vmSymbols::java_lang_NegativeArraySizeException(), err_msg("%d", length));
 135   }
 136   if (length > arrayOopDesc::max_array_length(T_ARRAY)) {


< prev index next >