< prev index next >

src/hotspot/share/oops/arrayKlass.cpp

Print this page

 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 "cds/cdsConfig.hpp"
 27 #include "cds/metaspaceShared.hpp"
 28 #include "classfile/javaClasses.hpp"
 29 #include "classfile/moduleEntry.hpp"

 30 #include "classfile/vmClasses.hpp"
 31 #include "classfile/vmSymbols.hpp"
 32 #include "gc/shared/collectedHeap.inline.hpp"
 33 #include "jvmtifiles/jvmti.h"
 34 #include "memory/metaspaceClosure.hpp"
 35 #include "memory/resourceArea.hpp"
 36 #include "memory/universe.hpp"
 37 #include "oops/arrayKlass.inline.hpp"
 38 #include "oops/arrayOop.hpp"
 39 #include "oops/instanceKlass.hpp"
 40 #include "oops/klass.inline.hpp"

 41 #include "oops/objArrayOop.hpp"
 42 #include "oops/oop.inline.hpp"
 43 #include "runtime/handles.inline.hpp"
 44 
 45 void* ArrayKlass::operator new(size_t size, ClassLoaderData* loader_data, size_t word_size, TRAPS) throw() {
 46   return Metaspace::allocate(loader_data, word_size, MetaspaceObj::ClassType, true, THREAD);
 47 }
 48 
 49 ArrayKlass::ArrayKlass() {
 50   assert(CDSConfig::is_dumping_static_archive() || CDSConfig::is_using_archive(), "only for CDS");
 51 }
 52 
 53 int ArrayKlass::static_size(int header_size) {
 54   // size of an array klass object
 55   assert(header_size <= InstanceKlass::header_size(), "bad header size");
 56   // If this assert fails, see comments in base_create_array_klass.
 57   header_size = InstanceKlass::header_size();
 58   int vtable_len = Universe::base_vtable_size();
 59   int size = header_size + vtable_len;
 60   return align_metadata_size(size);

 92   // any overpass methods present.
 93   return super()->uncached_lookup_method(name, signature, OverpassLookupMode::skip, private_mode);
 94 }
 95 
 96 ArrayKlass::ArrayKlass(Symbol* name, KlassKind kind) :
 97   Klass(kind),
 98   _dimension(1),
 99   _higher_dimension(nullptr),
100   _lower_dimension(nullptr) {
101   // Arrays don't add any new methods, so their vtable is the same size as
102   // the vtable of klass Object.
103   set_vtable_length(Universe::base_vtable_size());
104   set_name(name);
105   set_super(Universe::is_bootstrapping() ? nullptr : vmClasses::Object_klass());
106   set_layout_helper(Klass::_lh_neutral_value);
107   set_is_cloneable(); // All arrays are considered to be cloneable (See JLS 20.1.5)
108   JFR_ONLY(INIT_ID(this);)
109   log_array_class_load(this);
110 }
111 



















112 
113 // Initialization of vtables and mirror object is done separately from base_create_array_klass,
114 // since a GC can happen. At this point all instance variables of the ArrayKlass must be setup.
115 void ArrayKlass::complete_create_array_klass(ArrayKlass* k, Klass* super_klass, ModuleEntry* module_entry, TRAPS) {
116   k->initialize_supers(super_klass, nullptr, CHECK);
117   k->vtable().initialize_vtable();
118 
119   // During bootstrapping, before java.base is defined, the module_entry may not be present yet.
120   // These classes will be put on a fixup list and their module fields will be patched once
121   // java.base is defined.
122   assert((module_entry != nullptr) || ((module_entry == nullptr) && !ModuleEntryTable::javabase_defined()),
123          "module entry not available post " JAVA_BASE_NAME " definition");
124   oop module = (module_entry != nullptr) ? module_entry->module() : (oop)nullptr;
125   java_lang_Class::create_mirror(k, Handle(THREAD, k->class_loader()), Handle(THREAD, module), Handle(), Handle(), CHECK);
126 }
127 
128 ArrayKlass* ArrayKlass::array_klass(int n, TRAPS) {
129 
130   assert(dimension() <= n, "check order of chain");
131   int dim = dimension();
132   if (dim == n) return this;
133 
134   // lock-free read needs acquire semantics
135   if (higher_dimension_acquire() == nullptr) {
136 
137     // Ensure atomic creation of higher dimensions
138     RecursiveLocker rl(MultiArray_lock, THREAD);
139 
140     if (higher_dimension() == nullptr) {
141       // Create multi-dim klass object and link them together
142       ObjArrayKlass* ak =
143           ObjArrayKlass::allocate_objArray_klass(class_loader_data(), dim + 1, this, CHECK_NULL);
144       // use 'release' to pair with lock-free load
145       release_set_higher_dimension(ak);
146       assert(ak->lower_dimension() == this, "lower dimension mismatch");
147     }
148   }
149 
150   ObjArrayKlass* ak = higher_dimension();
151   assert(ak != nullptr, "should be set");
152   THREAD->check_possible_safepoint();
153   return ak->array_klass(n, THREAD);
154 }
155 
156 ArrayKlass* ArrayKlass::array_klass_or_null(int n) {
157 
158   assert(dimension() <= n, "check order of chain");
159   int dim = dimension();
160   if (dim == n) return this;
161 
162   // lock-free read needs acquire semantics
163   if (higher_dimension_acquire() == nullptr) {

181                                                             Array<InstanceKlass*>* transitive_interfaces) {
182   // interfaces = { cloneable_klass, serializable_klass };
183   assert(num_extra_slots == 0, "sanity of primitive array type");
184   assert(transitive_interfaces == nullptr, "sanity");
185   // Must share this for correct bootstrapping!
186   set_secondary_supers(Universe::the_array_interfaces_array(),
187                        Universe::the_array_interfaces_bitmap());
188   return nullptr;
189 }
190 
191 objArrayOop ArrayKlass::allocate_arrayArray(int n, int length, TRAPS) {
192   check_array_allocation_length(length, arrayOopDesc::max_array_length(T_ARRAY), CHECK_NULL);
193   size_t size = objArrayOopDesc::object_size(length);
194   ArrayKlass* ak = array_klass(n + dimension(), CHECK_NULL);
195   objArrayOop o = (objArrayOop)Universe::heap()->array_allocate(ak, size, length,
196                                                                 /* do_zero */ true, CHECK_NULL);
197   // initialization to null not necessary, area already cleared
198   return o;
199 }
200 




201 jint ArrayKlass::compute_modifier_flags() const {
202   return JVM_ACC_ABSTRACT | JVM_ACC_FINAL | JVM_ACC_PUBLIC;



203 }
204 
205 // JVMTI support
206 
207 jint ArrayKlass::jvmti_class_status() const {
208   return JVMTI_CLASS_STATUS_ARRAY;
209 }
210 
211 void ArrayKlass::metaspace_pointers_do(MetaspaceClosure* it) {
212   Klass::metaspace_pointers_do(it);
213 
214   ResourceMark rm;
215   log_trace(cds)("Iter(ArrayKlass): %p (%s)", this, external_name());
216 
217   // need to cast away volatile
218   it->push((Klass**)&_higher_dimension);
219   it->push((Klass**)&_lower_dimension);
220 }
221 
222 #if INCLUDE_CDS

 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 "cds/cdsConfig.hpp"
 27 #include "cds/metaspaceShared.hpp"
 28 #include "classfile/javaClasses.hpp"
 29 #include "classfile/moduleEntry.hpp"
 30 #include "classfile/symbolTable.hpp"
 31 #include "classfile/vmClasses.hpp"
 32 #include "classfile/vmSymbols.hpp"
 33 #include "gc/shared/collectedHeap.inline.hpp"
 34 #include "jvmtifiles/jvmti.h"
 35 #include "memory/metaspaceClosure.hpp"
 36 #include "memory/resourceArea.hpp"
 37 #include "memory/universe.hpp"
 38 #include "oops/arrayKlass.inline.hpp"
 39 #include "oops/arrayOop.hpp"
 40 #include "oops/instanceKlass.hpp"
 41 #include "oops/klass.inline.hpp"
 42 #include "oops/objArrayKlass.hpp"
 43 #include "oops/objArrayOop.hpp"
 44 #include "oops/oop.inline.hpp"
 45 #include "runtime/handles.inline.hpp"
 46 
 47 void* ArrayKlass::operator new(size_t size, ClassLoaderData* loader_data, size_t word_size, TRAPS) throw() {
 48   return Metaspace::allocate(loader_data, word_size, MetaspaceObj::ClassType, true, THREAD);
 49 }
 50 
 51 ArrayKlass::ArrayKlass() {
 52   assert(CDSConfig::is_dumping_static_archive() || CDSConfig::is_using_archive(), "only for CDS");
 53 }
 54 
 55 int ArrayKlass::static_size(int header_size) {
 56   // size of an array klass object
 57   assert(header_size <= InstanceKlass::header_size(), "bad header size");
 58   // If this assert fails, see comments in base_create_array_klass.
 59   header_size = InstanceKlass::header_size();
 60   int vtable_len = Universe::base_vtable_size();
 61   int size = header_size + vtable_len;
 62   return align_metadata_size(size);

 94   // any overpass methods present.
 95   return super()->uncached_lookup_method(name, signature, OverpassLookupMode::skip, private_mode);
 96 }
 97 
 98 ArrayKlass::ArrayKlass(Symbol* name, KlassKind kind) :
 99   Klass(kind),
100   _dimension(1),
101   _higher_dimension(nullptr),
102   _lower_dimension(nullptr) {
103   // Arrays don't add any new methods, so their vtable is the same size as
104   // the vtable of klass Object.
105   set_vtable_length(Universe::base_vtable_size());
106   set_name(name);
107   set_super(Universe::is_bootstrapping() ? nullptr : vmClasses::Object_klass());
108   set_layout_helper(Klass::_lh_neutral_value);
109   set_is_cloneable(); // All arrays are considered to be cloneable (See JLS 20.1.5)
110   JFR_ONLY(INIT_ID(this);)
111   log_array_class_load(this);
112 }
113 
114 Symbol* ArrayKlass::create_element_klass_array_name(Klass* element_klass, TRAPS) {
115   ResourceMark rm(THREAD);
116   Symbol* name = nullptr;
117   char *name_str = element_klass->name()->as_C_string();
118   int len = element_klass->name()->utf8_length();
119   char *new_str = NEW_RESOURCE_ARRAY(char, len + 4);
120   int idx = 0;
121   new_str[idx++] = JVM_SIGNATURE_ARRAY;
122   if (element_klass->is_instance_klass()) { // it could be an array or simple type
123     new_str[idx++] = JVM_SIGNATURE_CLASS;
124   }
125   memcpy(&new_str[idx], name_str, len * sizeof(char));
126   idx += len;
127   if (element_klass->is_instance_klass()) {
128     new_str[idx++] = JVM_SIGNATURE_ENDCLASS;
129   }
130   new_str[idx++] = '\0';
131   return SymbolTable::new_symbol(new_str);
132 }
133 
134 // Initialization of vtables and mirror object is done separately from base_create_array_klass,
135 // since a GC can happen. At this point all instance variables of the ArrayKlass must be setup.
136 void ArrayKlass::complete_create_array_klass(ArrayKlass* k, Klass* super_klass, ModuleEntry* module_entry, TRAPS) {
137   k->initialize_supers(super_klass, nullptr, CHECK);
138   k->vtable().initialize_vtable();
139 
140   // During bootstrapping, before java.base is defined, the module_entry may not be present yet.
141   // These classes will be put on a fixup list and their module fields will be patched once
142   // java.base is defined.
143   assert((module_entry != nullptr) || ((module_entry == nullptr) && !ModuleEntryTable::javabase_defined()),
144          "module entry not available post " JAVA_BASE_NAME " definition");
145   oop module = (module_entry != nullptr) ? module_entry->module() : (oop)nullptr;
146   java_lang_Class::create_mirror(k, Handle(THREAD, k->class_loader()), Handle(THREAD, module), Handle(), Handle(), CHECK);
147 }
148 
149 ArrayKlass* ArrayKlass::array_klass(int n, TRAPS) {
150 
151   assert(dimension() <= n, "check order of chain");
152   int dim = dimension();
153   if (dim == n) return this;
154 
155   // lock-free read needs acquire semantics
156   if (higher_dimension_acquire() == nullptr) {
157 
158     // Ensure atomic creation of higher dimensions
159     RecursiveLocker rl(MultiArray_lock, THREAD);
160 
161     if (higher_dimension() == nullptr) {
162       // Create multi-dim klass object and link them together
163       ObjArrayKlass* ak =
164       ObjArrayKlass::allocate_objArray_klass(class_loader_data(), dim + 1, this, false, CHECK_NULL);
165       // use 'release' to pair with lock-free load
166       release_set_higher_dimension(ak);
167       assert(ak->lower_dimension() == this, "lower dimension mismatch");
168     }
169   }
170 
171   ObjArrayKlass* ak = higher_dimension();
172   assert(ak != nullptr, "should be set");
173   THREAD->check_possible_safepoint();
174   return ak->array_klass(n, THREAD);
175 }
176 
177 ArrayKlass* ArrayKlass::array_klass_or_null(int n) {
178 
179   assert(dimension() <= n, "check order of chain");
180   int dim = dimension();
181   if (dim == n) return this;
182 
183   // lock-free read needs acquire semantics
184   if (higher_dimension_acquire() == nullptr) {

202                                                             Array<InstanceKlass*>* transitive_interfaces) {
203   // interfaces = { cloneable_klass, serializable_klass };
204   assert(num_extra_slots == 0, "sanity of primitive array type");
205   assert(transitive_interfaces == nullptr, "sanity");
206   // Must share this for correct bootstrapping!
207   set_secondary_supers(Universe::the_array_interfaces_array(),
208                        Universe::the_array_interfaces_bitmap());
209   return nullptr;
210 }
211 
212 objArrayOop ArrayKlass::allocate_arrayArray(int n, int length, TRAPS) {
213   check_array_allocation_length(length, arrayOopDesc::max_array_length(T_ARRAY), CHECK_NULL);
214   size_t size = objArrayOopDesc::object_size(length);
215   ArrayKlass* ak = array_klass(n + dimension(), CHECK_NULL);
216   objArrayOop o = (objArrayOop)Universe::heap()->array_allocate(ak, size, length,
217                                                                 /* do_zero */ true, CHECK_NULL);
218   // initialization to null not necessary, area already cleared
219   return o;
220 }
221 
222 oop ArrayKlass::component_mirror() const {
223   return java_lang_Class::component_mirror(java_mirror());
224 }
225 
226 jint ArrayKlass::compute_modifier_flags() const {
227   int identity_flag = (Arguments::enable_preview()) ? JVM_ACC_IDENTITY : 0;
228 
229   return JVM_ACC_ABSTRACT | JVM_ACC_FINAL | JVM_ACC_PUBLIC
230                     | identity_flag;
231 }
232 
233 // JVMTI support
234 
235 jint ArrayKlass::jvmti_class_status() const {
236   return JVMTI_CLASS_STATUS_ARRAY;
237 }
238 
239 void ArrayKlass::metaspace_pointers_do(MetaspaceClosure* it) {
240   Klass::metaspace_pointers_do(it);
241 
242   ResourceMark rm;
243   log_trace(cds)("Iter(ArrayKlass): %p (%s)", this, external_name());
244 
245   // need to cast away volatile
246   it->push((Klass**)&_higher_dimension);
247   it->push((Klass**)&_lower_dimension);
248 }
249 
250 #if INCLUDE_CDS
< prev index next >