< 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 ArrayKlass::ArrayKlass() {
 46   assert(CDSConfig::is_dumping_static_archive() || UseSharedSpaces, "only for CDS");
 47 }
 48 
 49 int ArrayKlass::static_size(int header_size) {
 50   // size of an array klass object
 51   assert(header_size <= InstanceKlass::header_size(), "bad header size");
 52   // If this assert fails, see comments in base_create_array_klass.
 53   header_size = InstanceKlass::header_size();
 54   int vtable_len = Universe::base_vtable_size();
 55   int size = header_size + vtable_len;
 56   return align_metadata_size(size);
 57 }
 58 
 59 
 60 InstanceKlass* ArrayKlass::java_super() const {

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



















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

181 GrowableArray<Klass*>* ArrayKlass::compute_secondary_supers(int num_extra_slots,
182                                                             Array<InstanceKlass*>* transitive_interfaces) {
183   // interfaces = { cloneable_klass, serializable_klass };
184   assert(num_extra_slots == 0, "sanity of primitive array type");
185   assert(transitive_interfaces == nullptr, "sanity");
186   // Must share this for correct bootstrapping!
187   set_secondary_supers(Universe::the_array_interfaces_array());
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 }

 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 ArrayKlass::ArrayKlass() {
 48   assert(CDSConfig::is_dumping_static_archive() || UseSharedSpaces, "only for CDS");
 49 }
 50 
 51 int ArrayKlass::static_size(int header_size) {
 52   // size of an array klass object
 53   assert(header_size <= InstanceKlass::header_size(), "bad header size");
 54   // If this assert fails, see comments in base_create_array_klass.
 55   header_size = InstanceKlass::header_size();
 56   int vtable_len = Universe::base_vtable_size();
 57   int size = header_size + vtable_len;
 58   return align_metadata_size(size);
 59 }
 60 
 61 
 62 InstanceKlass* ArrayKlass::java_super() const {

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

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