< prev index next >

src/hotspot/share/oops/typeArrayKlass.cpp

Print this page

 21  * questions.
 22  *
 23  */
 24 
 25 #include "classfile/moduleEntry.hpp"
 26 #include "classfile/packageEntry.hpp"
 27 #include "classfile/symbolTable.hpp"
 28 #include "classfile/vmSymbols.hpp"
 29 #include "gc/shared/collectedHeap.hpp"
 30 #include "gc/shared/collectedHeap.inline.hpp"
 31 #include "memory/metadataFactory.hpp"
 32 #include "memory/resourceArea.hpp"
 33 #include "memory/universe.hpp"
 34 #include "oops/arrayKlass.hpp"
 35 #include "oops/instanceKlass.hpp"
 36 #include "oops/klass.inline.hpp"
 37 #include "oops/objArrayKlass.hpp"
 38 #include "oops/oop.inline.hpp"
 39 #include "oops/typeArrayKlass.inline.hpp"
 40 #include "oops/typeArrayOop.inline.hpp"

 41 #include "runtime/handles.inline.hpp"
 42 #include "utilities/macros.hpp"
 43 
 44 TypeArrayKlass* TypeArrayKlass::create_klass(BasicType type,
 45                                       const char* name_str, TRAPS) {
 46   Symbol* sym = nullptr;
 47   if (name_str != nullptr) {
 48     sym = SymbolTable::new_permanent_symbol(name_str);
 49   }
 50 
 51   ClassLoaderData* null_loader_data = ClassLoaderData::the_null_class_loader_data();
 52 
 53   TypeArrayKlass* ak = TypeArrayKlass::allocate_klass(null_loader_data, type, sym, CHECK_NULL);
 54 
 55   // Call complete_create_array_klass after all instance variables have been initialized.
 56   complete_create_array_klass(ak, ak->super(), ModuleEntryTable::javabase_moduleEntry(), CHECK_NULL);
 57 
 58   // Add all classes to our internal class loader list here,
 59   // including classes in the bootstrap (null) class loader.
 60   // Do this step after creating the mirror so that if the
 61   // mirror creation fails, loaded_classes_do() doesn't find
 62   // an array class without a mirror.
 63   null_loader_data->add_class(ak);
 64   JFR_ONLY(ASSIGN_PRIMITIVE_CLASS_ID(ak);)
 65   return ak;
 66 }
 67 
 68 TypeArrayKlass* TypeArrayKlass::allocate_klass(ClassLoaderData* loader_data, BasicType type, Symbol* name, TRAPS) {
 69   assert(TypeArrayKlass::header_size() <= InstanceKlass::header_size(),
 70       "array klasses must be same size as InstanceKlass");
 71 
 72   int size = ArrayKlass::static_size(TypeArrayKlass::header_size());
 73 
 74   return new (loader_data, size, THREAD) TypeArrayKlass(type, name);
 75 }
 76 
 77 u2 TypeArrayKlass::compute_modifier_flags() const {
 78   return JVM_ACC_ABSTRACT | JVM_ACC_FINAL | JVM_ACC_PUBLIC;



 79 }
 80 
 81 TypeArrayKlass::TypeArrayKlass(BasicType type, Symbol* name) : ArrayKlass(name, Kind) {
 82   set_layout_helper(array_layout_helper(type));
 83   assert(is_array_klass(), "sanity");
 84   assert(is_typeArray_klass(), "sanity");
 85 
 86   set_max_length(arrayOopDesc::max_array_length(type));
 87   assert(size() >= TypeArrayKlass::header_size(), "bad size");
 88 
 89   set_class_loader_data(ClassLoaderData::the_null_class_loader_data());
 90 }
 91 
 92 typeArrayOop TypeArrayKlass::allocate_common(int length, bool do_zero, TRAPS) {
 93   assert(log2_element_size() >= 0, "bad scale");
 94   check_array_allocation_length(length, max_length(), CHECK_NULL);
 95   size_t size = typeArrayOopDesc::object_size(layout_helper(), length);
 96   return (typeArrayOop)Universe::heap()->array_allocate(this, size, length,
 97                                                         do_zero, CHECK_NULL);
 98 }
 99 
100 oop TypeArrayKlass::multi_allocate(int rank, jint* last_size, TRAPS) {
101   // For typeArrays this is only called for the last dimension
102   assert(rank == 1, "just checking");
103   int length = *last_size;
104   return allocate_instance(length, THREAD);
105 }
106 
107 
108 void TypeArrayKlass::copy_array(arrayOop s, int src_pos, arrayOop d, int dst_pos, int length, TRAPS) {
109   assert(s->is_typeArray(), "must be type array");
110 
111   // Check destination type.
112   if (!d->is_typeArray()) {
113     ResourceMark rm(THREAD);
114     stringStream ss;
115     if (d->is_objArray()) {
116       ss.print("arraycopy: type mismatch: can not copy %s[] into object array[]",
117                type2name_tab[ArrayKlass::cast(s->klass())->element_type()]);
118     } else {
119       ss.print("arraycopy: destination type %s is not an array", d->klass()->external_name());
120     }
121     THROW_MSG(vmSymbols::java_lang_ArrayStoreException(), ss.as_string());

 21  * questions.
 22  *
 23  */
 24 
 25 #include "classfile/moduleEntry.hpp"
 26 #include "classfile/packageEntry.hpp"
 27 #include "classfile/symbolTable.hpp"
 28 #include "classfile/vmSymbols.hpp"
 29 #include "gc/shared/collectedHeap.hpp"
 30 #include "gc/shared/collectedHeap.inline.hpp"
 31 #include "memory/metadataFactory.hpp"
 32 #include "memory/resourceArea.hpp"
 33 #include "memory/universe.hpp"
 34 #include "oops/arrayKlass.hpp"
 35 #include "oops/instanceKlass.hpp"
 36 #include "oops/klass.inline.hpp"
 37 #include "oops/objArrayKlass.hpp"
 38 #include "oops/oop.inline.hpp"
 39 #include "oops/typeArrayKlass.inline.hpp"
 40 #include "oops/typeArrayOop.inline.hpp"
 41 #include "runtime/arguments.hpp"
 42 #include "runtime/handles.inline.hpp"
 43 #include "utilities/macros.hpp"
 44 
 45 TypeArrayKlass* TypeArrayKlass::create_klass(BasicType type,
 46                                       const char* name_str, TRAPS) {
 47   Symbol* sym = nullptr;
 48   if (name_str != nullptr) {
 49     sym = SymbolTable::new_permanent_symbol(name_str);
 50   }
 51 
 52   ClassLoaderData* null_loader_data = ClassLoaderData::the_null_class_loader_data();
 53 
 54   TypeArrayKlass* ak = TypeArrayKlass::allocate_klass(null_loader_data, type, sym, CHECK_NULL);
 55 
 56   // Call complete_create_array_klass after all instance variables have been initialized.
 57   complete_create_array_klass(ak, ak->super(), ModuleEntryTable::javabase_moduleEntry(), CHECK_NULL);
 58 
 59   // Add all classes to our internal class loader list here,
 60   // including classes in the bootstrap (null) class loader.
 61   // Do this step after creating the mirror so that if the
 62   // mirror creation fails, loaded_classes_do() doesn't find
 63   // an array class without a mirror.
 64   null_loader_data->add_class(ak);
 65   JFR_ONLY(ASSIGN_PRIMITIVE_CLASS_ID(ak);)
 66   return ak;
 67 }
 68 
 69 TypeArrayKlass* TypeArrayKlass::allocate_klass(ClassLoaderData* loader_data, BasicType type, Symbol* name, TRAPS) {
 70   assert(TypeArrayKlass::header_size() <= InstanceKlass::header_size(),
 71       "array klasses must be same size as InstanceKlass");
 72 
 73   int size = ArrayKlass::static_size(TypeArrayKlass::header_size());
 74 
 75   return new (loader_data, size, THREAD) TypeArrayKlass(type, name);
 76 }
 77 
 78 u2 TypeArrayKlass::compute_modifier_flags() const {
 79   u2 identity_flag = (Arguments::enable_preview()) ? JVM_ACC_IDENTITY : 0;
 80 
 81   return JVM_ACC_ABSTRACT | JVM_ACC_FINAL | JVM_ACC_PUBLIC
 82                     | identity_flag;
 83 }
 84 
 85 TypeArrayKlass::TypeArrayKlass(BasicType type, Symbol* name) : ArrayKlass(name, Kind, ArrayKlass::ArrayProperties::DEFAULT) {
 86   set_layout_helper(array_layout_helper(type));
 87   assert(is_array_klass(), "sanity");
 88   assert(is_typeArray_klass(), "sanity");
 89 
 90   set_max_length(arrayOopDesc::max_array_length(type));
 91   assert(size() >= TypeArrayKlass::header_size(), "bad size");
 92 
 93   set_class_loader_data(ClassLoaderData::the_null_class_loader_data());
 94 }
 95 
 96 typeArrayOop TypeArrayKlass::allocate_common(int length, bool do_zero, TRAPS) {
 97   assert(log2_element_size() >= 0, "bad scale");
 98   check_array_allocation_length(length, max_length(), CHECK_NULL);
 99   size_t size = typeArrayOopDesc::object_size(layout_helper(), length);
100   return (typeArrayOop)Universe::heap()->array_allocate(this, size, length,
101                                                         do_zero, CHECK_NULL);
102 }
103 
104 oop TypeArrayKlass::multi_allocate(int rank, jint* last_size, TRAPS) {

105   assert(rank == 1, "just checking");
106   int length = *last_size;
107   return allocate_instance(length, THREAD);
108 }
109 
110 
111 void TypeArrayKlass::copy_array(arrayOop s, int src_pos, arrayOop d, int dst_pos, int length, TRAPS) {
112   assert(s->is_typeArray(), "must be type array");
113 
114   // Check destination type.
115   if (!d->is_typeArray()) {
116     ResourceMark rm(THREAD);
117     stringStream ss;
118     if (d->is_objArray()) {
119       ss.print("arraycopy: type mismatch: can not copy %s[] into object array[]",
120                type2name_tab[ArrayKlass::cast(s->klass())->element_type()]);
121     } else {
122       ss.print("arraycopy: destination type %s is not an array", d->klass()->external_name());
123     }
124     THROW_MSG(vmSymbols::java_lang_ArrayStoreException(), ss.as_string());
< prev index next >