< prev index next >

src/hotspot/share/oops/arrayKlass.cpp

Print this page




   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  *
  23  */
  24 
  25 #include "precompiled.hpp"
  26 #include "classfile/javaClasses.hpp"
  27 #include "classfile/moduleEntry.hpp"

  28 #include "classfile/systemDictionary.hpp"
  29 #include "classfile/vmSymbols.hpp"
  30 #include "gc/shared/collectedHeap.inline.hpp"
  31 #include "jvmtifiles/jvmti.h"
  32 #include "memory/metaspaceClosure.hpp"
  33 #include "memory/resourceArea.hpp"
  34 #include "memory/universe.hpp"
  35 #include "oops/arrayKlass.hpp"

  36 #include "oops/arrayOop.hpp"
  37 #include "oops/instanceKlass.hpp"
  38 #include "oops/objArrayOop.hpp"
  39 #include "oops/oop.inline.hpp"
  40 #include "runtime/handles.inline.hpp"
  41 
  42 int ArrayKlass::static_size(int header_size) {
  43   // size of an array klass object
  44   assert(header_size <= InstanceKlass::header_size(), "bad header size");
  45   // If this assert fails, see comments in base_create_array_klass.
  46   header_size = InstanceKlass::header_size();
  47   int vtable_len = Universe::base_vtable_size();
  48   int size = header_size + vtable_len;
  49   return align_metadata_size(size);
  50 }
  51 
  52 
  53 InstanceKlass* ArrayKlass::java_super() const {
  54   if (super() == NULL)  return NULL;  // bootstrap case
  55   // Array klasses have primary supertypes which are not reported to Java.


  80   // super klass of an array, (j.l.Object) should not have
  81   // any overpass methods present.
  82   return super()->uncached_lookup_method(name, signature, Klass::skip_overpass, private_mode);
  83 }
  84 
  85 ArrayKlass::ArrayKlass(Symbol* name, KlassID id) :
  86   Klass(id),
  87   _dimension(1),
  88   _higher_dimension(NULL),
  89   _lower_dimension(NULL) {
  90     // Arrays don't add any new methods, so their vtable is the same size as
  91     // the vtable of klass Object.
  92     set_vtable_length(Universe::base_vtable_size());
  93     set_name(name);
  94     set_super(Universe::is_bootstrapping() ? NULL : SystemDictionary::Object_klass());
  95     set_layout_helper(Klass::_lh_neutral_value);
  96     set_is_cloneable(); // All arrays are considered to be cloneable (See JLS 20.1.5)
  97     JFR_ONLY(INIT_ID(this);)
  98 }
  99 

































 100 
 101 // Initialization of vtables and mirror object is done separatly from base_create_array_klass,
 102 // since a GC can happen. At this point all instance variables of the ArrayKlass must be setup.
 103 void ArrayKlass::complete_create_array_klass(ArrayKlass* k, Klass* super_klass, ModuleEntry* module_entry, TRAPS) {
 104   k->initialize_supers(super_klass, NULL, CHECK);
 105   k->vtable().initialize_vtable(false, CHECK);
 106 
 107   // During bootstrapping, before java.base is defined, the module_entry may not be present yet.
 108   // These classes will be put on a fixup list and their module fields will be patched once
 109   // java.base is defined.
 110   assert((module_entry != NULL) || ((module_entry == NULL) && !ModuleEntryTable::javabase_defined()),
 111          "module entry not available post " JAVA_BASE_NAME " definition");
 112   oop module = (module_entry != NULL) ? module_entry->module() : (oop)NULL;
 113   java_lang_Class::create_mirror(k, Handle(THREAD, k->class_loader()), Handle(THREAD, module), Handle(), CHECK);
 114 }
 115 
 116 GrowableArray<Klass*>* ArrayKlass::compute_secondary_supers(int num_extra_slots,
 117                                                             Array<InstanceKlass*>* transitive_interfaces) {
 118   // interfaces = { cloneable_klass, serializable_klass };
 119   assert(num_extra_slots == 0, "sanity of primitive array type");
 120   assert(transitive_interfaces == NULL, "sanity");
 121   // Must share this for correct bootstrapping!
 122   set_secondary_supers(Universe::the_array_interfaces_array());
 123   return NULL;
 124 }
 125 
 126 objArrayOop ArrayKlass::allocate_arrayArray(int n, int length, TRAPS) {
 127   check_array_allocation_length(length, arrayOopDesc::max_array_length(T_ARRAY), CHECK_0);
 128   int size = objArrayOopDesc::object_size(length);
 129   Klass* k = array_klass(n+dimension(), CHECK_0);
 130   ArrayKlass* ak = ArrayKlass::cast(k);
 131   objArrayOop o = (objArrayOop)Universe::heap()->array_allocate(ak, size, length,
 132                                                                 /* do_zero */ true, CHECK_0);
 133   // initialization to NULL not necessary, area already cleared
 134   return o;
 135 }
 136 
 137 void ArrayKlass::array_klasses_do(void f(Klass* k, TRAPS), TRAPS) {
 138   Klass* k = this;
 139   // Iterate over this array klass and all higher dimensions
 140   while (k != NULL) {
 141     f(k, CHECK);
 142     k = ArrayKlass::cast(k)->higher_dimension();
 143   }
 144 }
 145 
 146 void ArrayKlass::array_klasses_do(void f(Klass* k)) {
 147   Klass* k = this;
 148   // Iterate over this array klass and all higher dimensions
 149   while (k != NULL) {
 150     f(k);
 151     k = ArrayKlass::cast(k)->higher_dimension();
 152   }




 153 }
 154 
 155 // JVM support
 156 
 157 jint ArrayKlass::compute_modifier_flags(TRAPS) const {
 158   return JVM_ACC_ABSTRACT | JVM_ACC_FINAL | JVM_ACC_PUBLIC;
 159 }
 160 
 161 // JVMTI support
 162 
 163 jint ArrayKlass::jvmti_class_status() const {
 164   return JVMTI_CLASS_STATUS_ARRAY;
 165 }
 166 
 167 void ArrayKlass::metaspace_pointers_do(MetaspaceClosure* it) {
 168   Klass::metaspace_pointers_do(it);
 169 
 170   ResourceMark rm;
 171   log_trace(cds)("Iter(ArrayKlass): %p (%s)", this, external_name());
 172 




   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  *
  23  */
  24 
  25 #include "precompiled.hpp"
  26 #include "classfile/javaClasses.hpp"
  27 #include "classfile/moduleEntry.hpp"
  28 #include "classfile/symbolTable.hpp"
  29 #include "classfile/systemDictionary.hpp"
  30 #include "classfile/vmSymbols.hpp"
  31 #include "gc/shared/collectedHeap.inline.hpp"
  32 #include "jvmtifiles/jvmti.h"
  33 #include "memory/metaspaceClosure.hpp"
  34 #include "memory/resourceArea.hpp"
  35 #include "memory/universe.hpp"
  36 #include "oops/arrayKlass.hpp"
  37 #include "oops/objArrayKlass.hpp"
  38 #include "oops/arrayOop.hpp"
  39 #include "oops/instanceKlass.hpp"
  40 #include "oops/objArrayOop.hpp"
  41 #include "oops/oop.inline.hpp"
  42 #include "runtime/handles.inline.hpp"
  43 
  44 int ArrayKlass::static_size(int header_size) {
  45   // size of an array klass object
  46   assert(header_size <= InstanceKlass::header_size(), "bad header size");
  47   // If this assert fails, see comments in base_create_array_klass.
  48   header_size = InstanceKlass::header_size();
  49   int vtable_len = Universe::base_vtable_size();
  50   int size = header_size + vtable_len;
  51   return align_metadata_size(size);
  52 }
  53 
  54 
  55 InstanceKlass* ArrayKlass::java_super() const {
  56   if (super() == NULL)  return NULL;  // bootstrap case
  57   // Array klasses have primary supertypes which are not reported to Java.


  82   // super klass of an array, (j.l.Object) should not have
  83   // any overpass methods present.
  84   return super()->uncached_lookup_method(name, signature, Klass::skip_overpass, private_mode);
  85 }
  86 
  87 ArrayKlass::ArrayKlass(Symbol* name, KlassID id) :
  88   Klass(id),
  89   _dimension(1),
  90   _higher_dimension(NULL),
  91   _lower_dimension(NULL) {
  92     // Arrays don't add any new methods, so their vtable is the same size as
  93     // the vtable of klass Object.
  94     set_vtable_length(Universe::base_vtable_size());
  95     set_name(name);
  96     set_super(Universe::is_bootstrapping() ? NULL : SystemDictionary::Object_klass());
  97     set_layout_helper(Klass::_lh_neutral_value);
  98     set_is_cloneable(); // All arrays are considered to be cloneable (See JLS 20.1.5)
  99     JFR_ONLY(INIT_ID(this);)
 100 }
 101 
 102 Symbol* ArrayKlass::create_element_klass_array_name(bool is_qtype, Klass* element_klass, TRAPS) {
 103   Symbol* name = NULL;
 104   if (!element_klass->is_instance_klass() || is_qtype ||
 105       (name = InstanceKlass::cast(element_klass)->array_name()) == NULL) {
 106 
 107     ResourceMark rm(THREAD);
 108     char *name_str = element_klass->name()->as_C_string();
 109     int len = element_klass->name()->utf8_length();
 110     char *new_str = NEW_RESOURCE_ARRAY(char, len + 4);
 111     int idx = 0;
 112     new_str[idx++] = '[';
 113     if (element_klass->is_instance_klass()) { // it could be an array or simple type
 114       if (is_qtype) {
 115         new_str[idx++] = 'Q';
 116       } else {
 117         new_str[idx++] = 'L';
 118       }
 119     }
 120     memcpy(&new_str[idx], name_str, len * sizeof(char));
 121     idx += len;
 122     if (element_klass->is_instance_klass()) {
 123       new_str[idx++] = ';';
 124     }
 125     new_str[idx++] = '\0';
 126     name = SymbolTable::new_permanent_symbol(new_str);
 127     if (element_klass->is_instance_klass() && (!is_qtype)) {
 128       InstanceKlass* ik = InstanceKlass::cast(element_klass);
 129       ik->set_array_name(name); // CMH: only cache and deref array_name for L-type...missing for Q-type
 130     }
 131   }
 132 
 133   return name;
 134 }
 135 
 136 // Initialization of vtables and mirror object is done separatly from base_create_array_klass,
 137 // since a GC can happen. At this point all instance variables of the ArrayKlass must be setup.
 138 void ArrayKlass::complete_create_array_klass(ArrayKlass* k, Klass* super_klass, ModuleEntry* module_entry, TRAPS) {
 139   k->initialize_supers(super_klass, NULL, CHECK);
 140   k->vtable().initialize_vtable(false, CHECK);
 141 
 142   // During bootstrapping, before java.base is defined, the module_entry may not be present yet.
 143   // These classes will be put on a fixup list and their module fields will be patched once
 144   // java.base is defined.
 145   assert((module_entry != NULL) || ((module_entry == NULL) && !ModuleEntryTable::javabase_defined()),
 146          "module entry not available post " JAVA_BASE_NAME " definition");
 147   oop module = (module_entry != NULL) ? module_entry->module() : (oop)NULL;
 148   java_lang_Class::create_mirror(k, Handle(THREAD, k->class_loader()), Handle(THREAD, module), Handle(), CHECK);
 149 }
 150 
 151 GrowableArray<Klass*>* ArrayKlass::compute_secondary_supers(int num_extra_slots,
 152                                                             Array<InstanceKlass*>* transitive_interfaces) {
 153   // interfaces = { cloneable_klass, serializable_klass };
 154   assert(num_extra_slots == 0, "sanity of primitive array type");
 155   assert(transitive_interfaces == NULL, "sanity");
 156   // Must share this for correct bootstrapping!
 157   set_secondary_supers(Universe::the_array_interfaces_array());
 158   return NULL;
 159 }
 160 
 161 objArrayOop ArrayKlass::allocate_arrayArray(int n, int length, TRAPS) {
 162   check_array_allocation_length(length, arrayOopDesc::max_array_length(T_ARRAY), CHECK_0);
 163   int size = objArrayOopDesc::object_size(length);
 164   Klass* k = array_klass(FieldType::get_array_storage_properties(name()), n+dimension(), CHECK_0);
 165   ArrayKlass* ak = ArrayKlass::cast(k);
 166   objArrayOop o = (objArrayOop)Universe::heap()->array_allocate(ak, size, length,
 167                                                                 /* do_zero */ true, CHECK_0);
 168   // initialization to NULL not necessary, area already cleared
 169   return o;
 170 }
 171 









 172 void ArrayKlass::array_klasses_do(void f(Klass* k)) {
 173   Klass* k = this;
 174   // Iterate over this array klass and all higher dimensions
 175   while (k != NULL) {
 176     f(k);
 177     k = ArrayKlass::cast(k)->higher_dimension();
 178   }
 179 }
 180 
 181 oop ArrayKlass::component_mirror() const {
 182   return java_lang_Class::component_mirror(java_mirror());
 183 }
 184 
 185 // JVM support
 186 
 187 jint ArrayKlass::compute_modifier_flags(TRAPS) const {
 188   return JVM_ACC_ABSTRACT | JVM_ACC_FINAL | JVM_ACC_PUBLIC;
 189 }
 190 
 191 // JVMTI support
 192 
 193 jint ArrayKlass::jvmti_class_status() const {
 194   return JVMTI_CLASS_STATUS_ARRAY;
 195 }
 196 
 197 void ArrayKlass::metaspace_pointers_do(MetaspaceClosure* it) {
 198   Klass::metaspace_pointers_do(it);
 199 
 200   ResourceMark rm;
 201   log_trace(cds)("Iter(ArrayKlass): %p (%s)", this, external_name());
 202 


< prev index next >