< 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/vmClasses.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/klass.inline.hpp"
 39 #include "oops/objArrayOop.hpp"
 40 #include "oops/oop.inline.hpp"
 41 #include "runtime/handles.inline.hpp"
 42 
 43 int ArrayKlass::static_size(int header_size) {
 44   // size of an array klass object
 45   assert(header_size <= InstanceKlass::header_size(), "bad header size");
 46   // If this assert fails, see comments in base_create_array_klass.
 47   header_size = InstanceKlass::header_size();
 48   int vtable_len = Universe::base_vtable_size();
 49   int size = header_size + vtable_len;
 50   return align_metadata_size(size);
 51 }
 52 
 53 
 54 InstanceKlass* ArrayKlass::java_super() const {
 55   if (super() == NULL)  return NULL;  // bootstrap case

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























101 
102 // Initialization of vtables and mirror object is done separatly from base_create_array_klass,
103 // since a GC can happen. At this point all instance variables of the ArrayKlass must be setup.
104 void ArrayKlass::complete_create_array_klass(ArrayKlass* k, Klass* super_klass, ModuleEntry* module_entry, TRAPS) {
105   k->initialize_supers(super_klass, NULL, CHECK);
106   k->vtable().initialize_vtable();
107 
108   // During bootstrapping, before java.base is defined, the module_entry may not be present yet.
109   // These classes will be put on a fixup list and their module fields will be patched once
110   // java.base is defined.
111   assert((module_entry != NULL) || ((module_entry == NULL) && !ModuleEntryTable::javabase_defined()),
112          "module entry not available post " JAVA_BASE_NAME " definition");
113   oop module = (module_entry != NULL) ? module_entry->module() : (oop)NULL;
114   java_lang_Class::create_mirror(k, Handle(THREAD, k->class_loader()), Handle(THREAD, module), Handle(), Handle(), CHECK);
115 }
116 
117 GrowableArray<Klass*>* ArrayKlass::compute_secondary_supers(int num_extra_slots,
118                                                             Array<InstanceKlass*>* transitive_interfaces) {
119   // interfaces = { cloneable_klass, serializable_klass };
120   assert(num_extra_slots == 0, "sanity of primitive array type");

136 }
137 
138 void ArrayKlass::array_klasses_do(void f(Klass* k, TRAPS), TRAPS) {
139   Klass* k = this;
140   // Iterate over this array klass and all higher dimensions
141   while (k != NULL) {
142     f(k, CHECK);
143     k = ArrayKlass::cast(k)->higher_dimension();
144   }
145 }
146 
147 void ArrayKlass::array_klasses_do(void f(Klass* k)) {
148   Klass* k = this;
149   // Iterate over this array klass and all higher dimensions
150   while (k != NULL) {
151     f(k);
152     k = ArrayKlass::cast(k)->higher_dimension();
153   }
154 }
155 




156 jint ArrayKlass::compute_modifier_flags() const {
157   return JVM_ACC_ABSTRACT | JVM_ACC_FINAL | JVM_ACC_PUBLIC;
158 }
159 
160 // JVMTI support
161 
162 jint ArrayKlass::jvmti_class_status() const {
163   return JVMTI_CLASS_STATUS_ARRAY;
164 }
165 
166 void ArrayKlass::metaspace_pointers_do(MetaspaceClosure* it) {
167   Klass::metaspace_pointers_do(it);
168 
169   ResourceMark rm;
170   log_trace(cds)("Iter(ArrayKlass): %p (%s)", this, external_name());
171 
172   // need to cast away volatile
173   it->push((Klass**)&_higher_dimension);
174   it->push((Klass**)&_lower_dimension);
175 }

  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/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.hpp"
 37 #include "oops/objArrayKlass.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 int ArrayKlass::static_size(int header_size) {
 46   // size of an array klass object
 47   assert(header_size <= InstanceKlass::header_size(), "bad header size");
 48   // If this assert fails, see comments in base_create_array_klass.
 49   header_size = InstanceKlass::header_size();
 50   int vtable_len = Universe::base_vtable_size();
 51   int size = header_size + vtable_len;
 52   return align_metadata_size(size);
 53 }
 54 
 55 
 56 InstanceKlass* ArrayKlass::java_super() const {
 57   if (super() == NULL)  return NULL;  // bootstrap case

 83   // super klass of an array, (j.l.Object) should not have
 84   // any overpass methods present.
 85   return super()->uncached_lookup_method(name, signature, OverpassLookupMode::skip, private_mode);
 86 }
 87 
 88 ArrayKlass::ArrayKlass(Symbol* name, KlassID id) :
 89   Klass(id),
 90   _dimension(1),
 91   _higher_dimension(NULL),
 92   _lower_dimension(NULL) {
 93   // Arrays don't add any new methods, so their vtable is the same size as
 94   // the vtable of klass Object.
 95   set_vtable_length(Universe::base_vtable_size());
 96   set_name(name);
 97   set_super(Universe::is_bootstrapping() ? NULL : vmClasses::Object_klass());
 98   set_layout_helper(Klass::_lh_neutral_value);
 99   set_is_cloneable(); // All arrays are considered to be cloneable (See JLS 20.1.5)
100   JFR_ONLY(INIT_ID(this);)
101 }
102 
103 Symbol* ArrayKlass::create_element_klass_array_name(Klass* element_klass, bool qdesc, TRAPS) {
104   ResourceMark rm(THREAD);
105   Symbol* name = NULL;
106   char *name_str = element_klass->name()->as_C_string();
107   int len = element_klass->name()->utf8_length();
108   char *new_str = NEW_RESOURCE_ARRAY(char, len + 4);
109   int idx = 0;
110   new_str[idx++] = JVM_SIGNATURE_ARRAY;
111   if (element_klass->is_instance_klass()) { // it could be an array or simple type
112     if (qdesc) {
113       new_str[idx++] = JVM_SIGNATURE_INLINE_TYPE;
114     } else {
115       new_str[idx++] = JVM_SIGNATURE_CLASS;
116     }
117   }
118   memcpy(&new_str[idx], name_str, len * sizeof(char));
119   idx += len;
120   if (element_klass->is_instance_klass()) {
121     new_str[idx++] = JVM_SIGNATURE_ENDCLASS;
122   }
123   new_str[idx++] = '\0';
124   return SymbolTable::new_symbol(new_str);
125 }
126 
127 // Initialization of vtables and mirror object is done separatly from base_create_array_klass,
128 // since a GC can happen. At this point all instance variables of the ArrayKlass must be setup.
129 void ArrayKlass::complete_create_array_klass(ArrayKlass* k, Klass* super_klass, ModuleEntry* module_entry, TRAPS) {
130   k->initialize_supers(super_klass, NULL, CHECK);
131   k->vtable().initialize_vtable();
132 
133   // During bootstrapping, before java.base is defined, the module_entry may not be present yet.
134   // These classes will be put on a fixup list and their module fields will be patched once
135   // java.base is defined.
136   assert((module_entry != NULL) || ((module_entry == NULL) && !ModuleEntryTable::javabase_defined()),
137          "module entry not available post " JAVA_BASE_NAME " definition");
138   oop module = (module_entry != NULL) ? module_entry->module() : (oop)NULL;
139   java_lang_Class::create_mirror(k, Handle(THREAD, k->class_loader()), Handle(THREAD, module), Handle(), Handle(), CHECK);
140 }
141 
142 GrowableArray<Klass*>* ArrayKlass::compute_secondary_supers(int num_extra_slots,
143                                                             Array<InstanceKlass*>* transitive_interfaces) {
144   // interfaces = { cloneable_klass, serializable_klass };
145   assert(num_extra_slots == 0, "sanity of primitive array type");

161 }
162 
163 void ArrayKlass::array_klasses_do(void f(Klass* k, TRAPS), TRAPS) {
164   Klass* k = this;
165   // Iterate over this array klass and all higher dimensions
166   while (k != NULL) {
167     f(k, CHECK);
168     k = ArrayKlass::cast(k)->higher_dimension();
169   }
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 jint ArrayKlass::compute_modifier_flags() const {
186   return JVM_ACC_ABSTRACT | JVM_ACC_FINAL | JVM_ACC_PUBLIC;
187 }
188 
189 // JVMTI support
190 
191 jint ArrayKlass::jvmti_class_status() const {
192   return JVMTI_CLASS_STATUS_ARRAY;
193 }
194 
195 void ArrayKlass::metaspace_pointers_do(MetaspaceClosure* it) {
196   Klass::metaspace_pointers_do(it);
197 
198   ResourceMark rm;
199   log_trace(cds)("Iter(ArrayKlass): %p (%s)", this, external_name());
200 
201   // need to cast away volatile
202   it->push((Klass**)&_higher_dimension);
203   it->push((Klass**)&_lower_dimension);
204 }
< prev index next >