< prev index next >

src/hotspot/share/oops/arrayKlass.cpp

Print this page

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

 29 #include "classfile/vmClasses.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.inline.hpp"
 37 #include "oops/arrayOop.hpp"
 38 #include "oops/instanceKlass.hpp"
 39 #include "oops/klass.inline.hpp"

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

 75 
 76 // find field according to JVM spec 5.4.3.2, returns the klass in which the field is defined
 77 Klass* ArrayKlass::find_field(Symbol* name, Symbol* sig, fieldDescriptor* fd) const {
 78   // There are no fields in an array klass but look to the super class (Object)
 79   assert(super(), "super klass must be present");
 80   return super()->find_field(name, sig, fd);
 81 }
 82 
 83 Method* ArrayKlass::uncached_lookup_method(const Symbol* name,
 84                                            const Symbol* signature,
 85                                            OverpassLookupMode overpass_mode,
 86                                            PrivateLookupMode private_mode) const {
 87   // There are no methods in an array klass but the super class (Object) has some
 88   assert(super(), "super klass must be present");
 89   // Always ignore overpass methods in superclasses, although technically the
 90   // super klass of an array, (j.l.Object) should not have
 91   // any overpass methods present.
 92   return super()->uncached_lookup_method(name, signature, OverpassLookupMode::skip, private_mode);
 93 }
 94 
 95 ArrayKlass::ArrayKlass(Symbol* name, KlassKind kind) :
 96   Klass(kind),
 97   _dimension(1),
 98   _higher_dimension(nullptr),
 99   _lower_dimension(nullptr) {
100   // Arrays don't add any new methods, so their vtable is the same size as
101   // the vtable of klass Object.
102   set_vtable_length(Universe::base_vtable_size());
103   set_name(name);
104   set_super(Universe::is_bootstrapping() ? nullptr : vmClasses::Object_klass());
105   set_layout_helper(Klass::_lh_neutral_value);
106   set_is_cloneable(); // All arrays are considered to be cloneable (See JLS 20.1.5)
107   JFR_ONLY(INIT_ID(this);)
108   log_array_class_load(this);
109 }
110 



















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

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




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

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

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

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