262
263 volatile u2 _idnum_allocated_count; // JNI/JVMTI: increments with the addition of methods, old ids don't change
264
265 // Class states are defined as ClassState (see above).
266 // Place the _init_state here to utilize the unused 2-byte after
267 // _idnum_allocated_count.
268 u1 _init_state; // state of class
269 u1 _reference_type; // reference type
270
271 u2 _this_class_index; // constant pool entry
272 #if INCLUDE_JVMTI
273 JvmtiCachedClassFieldMap* _jvmti_cached_class_field_map; // JVMTI: used during heap iteration
274 #endif
275
276 NOT_PRODUCT(int _verify_count;) // to avoid redundant verifies
277
278 // Method array.
279 Array<Method*>* _methods;
280 // Default Method Array, concrete methods inherited from interfaces
281 Array<Method*>* _default_methods;
282 // Interface (Klass*s) this class declares locally to implement.
283 Array<Klass*>* _local_interfaces;
284 // Interface (Klass*s) this class implements transitively.
285 Array<Klass*>* _transitive_interfaces;
286 // Int array containing the original order of method in the class file (for JVMTI).
287 Array<int>* _method_ordering;
288 // Int array containing the vtable_indices for default_methods
289 // offset matches _default_methods offset
290 Array<int>* _default_vtable_indices;
291
292 // Instance and static variable information, starts with 6-tuples of shorts
293 // [access, name index, sig index, initval index, low_offset, high_offset]
294 // for all fields, followed by the generic signature data at the end of
295 // the array. Only fields with generic signature attributes have the generic
296 // signature data set in the array. The fields array looks like following:
297 //
298 // f1: [access, name index, sig index, initial value index, low_offset, high_offset]
299 // f2: [access, name index, sig index, initial value index, low_offset, high_offset]
300 // ...
301 // fn: [access, name index, sig index, initial value index, low_offset, high_offset]
302 // [generic signature index]
303 // [generic signature index]
304 // ...
305 Array<u2>* _fields;
398 void set_methods(Array<Method*>* a) { _methods = a; }
399 Method* method_with_idnum(int idnum);
400 Method* method_with_orig_idnum(int idnum);
401 Method* method_with_orig_idnum(int idnum, int version);
402
403 // method ordering
404 Array<int>* method_ordering() const { return _method_ordering; }
405 void set_method_ordering(Array<int>* m) { _method_ordering = m; }
406 void copy_method_ordering(const intArray* m, TRAPS);
407
408 // default_methods
409 Array<Method*>* default_methods() const { return _default_methods; }
410 void set_default_methods(Array<Method*>* a) { _default_methods = a; }
411
412 // default method vtable_indices
413 Array<int>* default_vtable_indices() const { return _default_vtable_indices; }
414 void set_default_vtable_indices(Array<int>* v) { _default_vtable_indices = v; }
415 Array<int>* create_new_default_vtable_indices(int len, TRAPS);
416
417 // interfaces
418 Array<Klass*>* local_interfaces() const { return _local_interfaces; }
419 void set_local_interfaces(Array<Klass*>* a) {
420 guarantee(_local_interfaces == NULL || a == NULL, "Just checking");
421 _local_interfaces = a; }
422
423 Array<Klass*>* transitive_interfaces() const { return _transitive_interfaces; }
424 void set_transitive_interfaces(Array<Klass*>* a) {
425 guarantee(_transitive_interfaces == NULL || a == NULL, "Just checking");
426 _transitive_interfaces = a;
427 }
428
429 private:
430 friend class fieldDescriptor;
431 FieldInfo* field(int index) const { return FieldInfo::from_field_array(_fields, index); }
432
433 public:
434 int field_offset (int index) const { return field(index)->offset(); }
435 int field_access_flags(int index) const { return field(index)->access_flags(); }
436 Symbol* field_name (int index) const { return field(index)->name(constants()); }
437 Symbol* field_signature (int index) const { return field(index)->signature(constants()); }
438
439 // Number of Java declared fields
440 int java_fields_count() const { return (int)_java_fields_count; }
441
442 Array<u2>* fields() const { return _fields; }
443 void set_fields(Array<u2>* f, u2 java_fields_count) {
444 guarantee(_fields == NULL || f == NULL, "Just checking");
1035 int nof_implementors() const {
1036 Klass* k = implementor();
1037 if (k == NULL) {
1038 return 0;
1039 } else if (k != this) {
1040 return 1;
1041 } else {
1042 return 2;
1043 }
1044 }
1045
1046 void add_implementor(Klass* k); // k is a new class that implements this interface
1047 void init_implementor(); // initialize
1048
1049 // link this class into the implementors list of every interface it implements
1050 void process_interfaces(Thread *thread);
1051
1052 // virtual operations from Klass
1053 bool is_leaf_class() const { return _subklass == NULL; }
1054 GrowableArray<Klass*>* compute_secondary_supers(int num_extra_slots,
1055 Array<Klass*>* transitive_interfaces);
1056 bool compute_is_subtype_of(Klass* k);
1057 bool can_be_primary_super_slow() const;
1058 int oop_size(oop obj) const { return size_helper(); }
1059 // slow because it's a virtual call and used for verifying the layout_helper.
1060 // Using the layout_helper bits, we can call is_instance_klass without a virtual call.
1061 DEBUG_ONLY(bool is_instance_klass_slow() const { return true; })
1062
1063 // Iterators
1064 void do_local_static_fields(FieldClosure* cl);
1065 void do_nonstatic_fields(FieldClosure* cl); // including inherited fields
1066 void do_local_static_fields(void f(fieldDescriptor*, Handle, TRAPS), Handle, TRAPS);
1067
1068 void methods_do(void f(Method* method));
1069 void array_klasses_do(void f(Klass* k));
1070 void array_klasses_do(void f(Klass* k, TRAPS), TRAPS);
1071 bool super_types_do(SuperTypeClosure* blk);
1072
1073 static InstanceKlass* cast(Klass* k) {
1074 return const_cast<InstanceKlass*>(cast(const_cast<const Klass*>(k)));
1075 }
1076
1077 static const InstanceKlass* cast(const Klass* k) {
1078 assert(k != NULL, "k should not be null");
1079 assert(k->is_instance_klass(), "cast to InstanceKlass");
1080 return static_cast<const InstanceKlass*>(k);
1081 }
1082
1083 InstanceKlass* java_super() const {
1084 return (super() == NULL) ? NULL : cast(super());
1085 }
1086
1087 // Sizing (in words)
1088 static int header_size() { return sizeof(InstanceKlass)/wordSize; }
1089
1090 static int size(int vtable_length, int itable_length,
1091 int nonstatic_oop_map_size,
1092 bool is_interface, bool is_anonymous, bool has_stored_fingerprint) {
1093 return align_metadata_size(header_size() +
1094 vtable_length +
1095 itable_length +
1096 nonstatic_oop_map_size +
1097 (is_interface ? (int)sizeof(Klass*)/wordSize : 0) +
1098 (is_anonymous ? (int)sizeof(Klass*)/wordSize : 0) +
1099 (has_stored_fingerprint ? (int)sizeof(uint64_t*)/wordSize : 0));
1100 }
1101 int size() const { return size(vtable_length(),
1102 itable_length(),
1103 nonstatic_oop_map_size(),
1184 Method* method_at_itable(Klass* holder, int index, TRAPS);
1185
1186 #if INCLUDE_JVMTI
1187 void adjust_default_methods(InstanceKlass* holder, bool* trace_name_printed);
1188 #endif // INCLUDE_JVMTI
1189
1190 void clean_weak_instanceklass_links();
1191 private:
1192 void clean_implementors_list();
1193 void clean_method_data();
1194
1195 public:
1196 // Explicit metaspace deallocation of fields
1197 // For RedefineClasses and class file parsing errors, we need to deallocate
1198 // instanceKlasses and the metadata they point to.
1199 void deallocate_contents(ClassLoaderData* loader_data);
1200 static void deallocate_methods(ClassLoaderData* loader_data,
1201 Array<Method*>* methods);
1202 void static deallocate_interfaces(ClassLoaderData* loader_data,
1203 const Klass* super_klass,
1204 Array<Klass*>* local_interfaces,
1205 Array<Klass*>* transitive_interfaces);
1206
1207 // The constant pool is on stack if any of the methods are executing or
1208 // referenced by handles.
1209 bool on_stack() const { return _constants->on_stack(); }
1210
1211 // callbacks for actions during class unloading
1212 static void notify_unload_class(InstanceKlass* ik);
1213 static void release_C_heap_structures(InstanceKlass* ik);
1214
1215 // Naming
1216 const char* signature_name() const;
1217 static Symbol* package_from_name(const Symbol* name, TRAPS);
1218
1219 // GC specific object visitors
1220 //
1221 #if INCLUDE_PARALLELGC
1222 // Parallel Scavenge
1223 void oop_ps_push_contents( oop obj, PSPromotionManager* pm);
1224 // Parallel Compact
1225 void oop_pc_follow_contents(oop obj, ParCompactionManager* cm);
1362 public:
1363 // JVMTI support
1364 jint jvmti_class_status() const;
1365
1366 virtual void metaspace_pointers_do(MetaspaceClosure* iter);
1367
1368 public:
1369 // Printing
1370 #ifndef PRODUCT
1371 void print_on(outputStream* st) const;
1372 #endif
1373 void print_value_on(outputStream* st) const;
1374
1375 void oop_print_value_on(oop obj, outputStream* st);
1376
1377 #ifndef PRODUCT
1378 void oop_print_on (oop obj, outputStream* st);
1379
1380 void print_dependent_nmethods(bool verbose = false);
1381 bool is_dependent_nmethod(nmethod* nm);
1382 #endif
1383
1384 const char* internal_name() const;
1385
1386 // Verification
1387 void verify_on(outputStream* st);
1388
1389 void oop_verify_on(oop obj, outputStream* st);
1390
1391 // Logging
1392 void print_class_load_logging(ClassLoaderData* loader_data,
1393 const char* module_name,
1394 const ClassFileStream* cfs) const;
1395 };
1396
1397 // for adding methods
1398 // UNSET_IDNUM return means no more ids available
1399 inline u2 InstanceKlass::next_method_idnum() {
1400 if (_idnum_allocated_count == ConstMethod::MAX_IDNUM) {
1401 return ConstMethod::UNSET_IDNUM; // no more ids available
|
262
263 volatile u2 _idnum_allocated_count; // JNI/JVMTI: increments with the addition of methods, old ids don't change
264
265 // Class states are defined as ClassState (see above).
266 // Place the _init_state here to utilize the unused 2-byte after
267 // _idnum_allocated_count.
268 u1 _init_state; // state of class
269 u1 _reference_type; // reference type
270
271 u2 _this_class_index; // constant pool entry
272 #if INCLUDE_JVMTI
273 JvmtiCachedClassFieldMap* _jvmti_cached_class_field_map; // JVMTI: used during heap iteration
274 #endif
275
276 NOT_PRODUCT(int _verify_count;) // to avoid redundant verifies
277
278 // Method array.
279 Array<Method*>* _methods;
280 // Default Method Array, concrete methods inherited from interfaces
281 Array<Method*>* _default_methods;
282 // Interfaces (InstanceKlass*s) this class declares locally to implement.
283 Array<InstanceKlass*>* _local_interfaces;
284 // Interfaces (InstanceKlass*s) this class implements transitively.
285 Array<InstanceKlass*>* _transitive_interfaces;
286 // Int array containing the original order of method in the class file (for JVMTI).
287 Array<int>* _method_ordering;
288 // Int array containing the vtable_indices for default_methods
289 // offset matches _default_methods offset
290 Array<int>* _default_vtable_indices;
291
292 // Instance and static variable information, starts with 6-tuples of shorts
293 // [access, name index, sig index, initval index, low_offset, high_offset]
294 // for all fields, followed by the generic signature data at the end of
295 // the array. Only fields with generic signature attributes have the generic
296 // signature data set in the array. The fields array looks like following:
297 //
298 // f1: [access, name index, sig index, initial value index, low_offset, high_offset]
299 // f2: [access, name index, sig index, initial value index, low_offset, high_offset]
300 // ...
301 // fn: [access, name index, sig index, initial value index, low_offset, high_offset]
302 // [generic signature index]
303 // [generic signature index]
304 // ...
305 Array<u2>* _fields;
398 void set_methods(Array<Method*>* a) { _methods = a; }
399 Method* method_with_idnum(int idnum);
400 Method* method_with_orig_idnum(int idnum);
401 Method* method_with_orig_idnum(int idnum, int version);
402
403 // method ordering
404 Array<int>* method_ordering() const { return _method_ordering; }
405 void set_method_ordering(Array<int>* m) { _method_ordering = m; }
406 void copy_method_ordering(const intArray* m, TRAPS);
407
408 // default_methods
409 Array<Method*>* default_methods() const { return _default_methods; }
410 void set_default_methods(Array<Method*>* a) { _default_methods = a; }
411
412 // default method vtable_indices
413 Array<int>* default_vtable_indices() const { return _default_vtable_indices; }
414 void set_default_vtable_indices(Array<int>* v) { _default_vtable_indices = v; }
415 Array<int>* create_new_default_vtable_indices(int len, TRAPS);
416
417 // interfaces
418 Array<InstanceKlass*>* local_interfaces() const { return _local_interfaces; }
419 void set_local_interfaces(Array<InstanceKlass*>* a) {
420 guarantee(_local_interfaces == NULL || a == NULL, "Just checking");
421 _local_interfaces = a; }
422
423 Array<InstanceKlass*>* transitive_interfaces() const { return _transitive_interfaces; }
424 void set_transitive_interfaces(Array<InstanceKlass*>* a) {
425 guarantee(_transitive_interfaces == NULL || a == NULL, "Just checking");
426 _transitive_interfaces = a;
427 }
428
429 private:
430 friend class fieldDescriptor;
431 FieldInfo* field(int index) const { return FieldInfo::from_field_array(_fields, index); }
432
433 public:
434 int field_offset (int index) const { return field(index)->offset(); }
435 int field_access_flags(int index) const { return field(index)->access_flags(); }
436 Symbol* field_name (int index) const { return field(index)->name(constants()); }
437 Symbol* field_signature (int index) const { return field(index)->signature(constants()); }
438
439 // Number of Java declared fields
440 int java_fields_count() const { return (int)_java_fields_count; }
441
442 Array<u2>* fields() const { return _fields; }
443 void set_fields(Array<u2>* f, u2 java_fields_count) {
444 guarantee(_fields == NULL || f == NULL, "Just checking");
1035 int nof_implementors() const {
1036 Klass* k = implementor();
1037 if (k == NULL) {
1038 return 0;
1039 } else if (k != this) {
1040 return 1;
1041 } else {
1042 return 2;
1043 }
1044 }
1045
1046 void add_implementor(Klass* k); // k is a new class that implements this interface
1047 void init_implementor(); // initialize
1048
1049 // link this class into the implementors list of every interface it implements
1050 void process_interfaces(Thread *thread);
1051
1052 // virtual operations from Klass
1053 bool is_leaf_class() const { return _subklass == NULL; }
1054 GrowableArray<Klass*>* compute_secondary_supers(int num_extra_slots,
1055 Array<InstanceKlass*>* transitive_interfaces);
1056 bool compute_is_subtype_of(Klass* k);
1057 bool can_be_primary_super_slow() const;
1058 int oop_size(oop obj) const { return size_helper(); }
1059 // slow because it's a virtual call and used for verifying the layout_helper.
1060 // Using the layout_helper bits, we can call is_instance_klass without a virtual call.
1061 DEBUG_ONLY(bool is_instance_klass_slow() const { return true; })
1062
1063 // Iterators
1064 void do_local_static_fields(FieldClosure* cl);
1065 void do_nonstatic_fields(FieldClosure* cl); // including inherited fields
1066 void do_local_static_fields(void f(fieldDescriptor*, Handle, TRAPS), Handle, TRAPS);
1067
1068 void methods_do(void f(Method* method));
1069 void array_klasses_do(void f(Klass* k));
1070 void array_klasses_do(void f(Klass* k, TRAPS), TRAPS);
1071 bool super_types_do(SuperTypeClosure* blk);
1072
1073 static InstanceKlass* cast(Klass* k) {
1074 return const_cast<InstanceKlass*>(cast(const_cast<const Klass*>(k)));
1075 }
1076
1077 static const InstanceKlass* cast(const Klass* k) {
1078 assert(k != NULL, "k should not be null");
1079 assert(k->is_instance_klass(), "cast to InstanceKlass");
1080 return static_cast<const InstanceKlass*>(k);
1081 }
1082
1083 virtual InstanceKlass* java_super() const {
1084 return (super() == NULL) ? NULL : cast(super());
1085 }
1086
1087 // Sizing (in words)
1088 static int header_size() { return sizeof(InstanceKlass)/wordSize; }
1089
1090 static int size(int vtable_length, int itable_length,
1091 int nonstatic_oop_map_size,
1092 bool is_interface, bool is_anonymous, bool has_stored_fingerprint) {
1093 return align_metadata_size(header_size() +
1094 vtable_length +
1095 itable_length +
1096 nonstatic_oop_map_size +
1097 (is_interface ? (int)sizeof(Klass*)/wordSize : 0) +
1098 (is_anonymous ? (int)sizeof(Klass*)/wordSize : 0) +
1099 (has_stored_fingerprint ? (int)sizeof(uint64_t*)/wordSize : 0));
1100 }
1101 int size() const { return size(vtable_length(),
1102 itable_length(),
1103 nonstatic_oop_map_size(),
1184 Method* method_at_itable(Klass* holder, int index, TRAPS);
1185
1186 #if INCLUDE_JVMTI
1187 void adjust_default_methods(InstanceKlass* holder, bool* trace_name_printed);
1188 #endif // INCLUDE_JVMTI
1189
1190 void clean_weak_instanceklass_links();
1191 private:
1192 void clean_implementors_list();
1193 void clean_method_data();
1194
1195 public:
1196 // Explicit metaspace deallocation of fields
1197 // For RedefineClasses and class file parsing errors, we need to deallocate
1198 // instanceKlasses and the metadata they point to.
1199 void deallocate_contents(ClassLoaderData* loader_data);
1200 static void deallocate_methods(ClassLoaderData* loader_data,
1201 Array<Method*>* methods);
1202 void static deallocate_interfaces(ClassLoaderData* loader_data,
1203 const Klass* super_klass,
1204 Array<InstanceKlass*>* local_interfaces,
1205 Array<InstanceKlass*>* transitive_interfaces);
1206
1207 // The constant pool is on stack if any of the methods are executing or
1208 // referenced by handles.
1209 bool on_stack() const { return _constants->on_stack(); }
1210
1211 // callbacks for actions during class unloading
1212 static void notify_unload_class(InstanceKlass* ik);
1213 static void release_C_heap_structures(InstanceKlass* ik);
1214
1215 // Naming
1216 const char* signature_name() const;
1217 static Symbol* package_from_name(const Symbol* name, TRAPS);
1218
1219 // GC specific object visitors
1220 //
1221 #if INCLUDE_PARALLELGC
1222 // Parallel Scavenge
1223 void oop_ps_push_contents( oop obj, PSPromotionManager* pm);
1224 // Parallel Compact
1225 void oop_pc_follow_contents(oop obj, ParCompactionManager* cm);
1362 public:
1363 // JVMTI support
1364 jint jvmti_class_status() const;
1365
1366 virtual void metaspace_pointers_do(MetaspaceClosure* iter);
1367
1368 public:
1369 // Printing
1370 #ifndef PRODUCT
1371 void print_on(outputStream* st) const;
1372 #endif
1373 void print_value_on(outputStream* st) const;
1374
1375 void oop_print_value_on(oop obj, outputStream* st);
1376
1377 #ifndef PRODUCT
1378 void oop_print_on (oop obj, outputStream* st);
1379
1380 void print_dependent_nmethods(bool verbose = false);
1381 bool is_dependent_nmethod(nmethod* nm);
1382 bool verify_itable_index(int index);
1383 #endif
1384
1385 const char* internal_name() const;
1386
1387 // Verification
1388 void verify_on(outputStream* st);
1389
1390 void oop_verify_on(oop obj, outputStream* st);
1391
1392 // Logging
1393 void print_class_load_logging(ClassLoaderData* loader_data,
1394 const char* module_name,
1395 const ClassFileStream* cfs) const;
1396 };
1397
1398 // for adding methods
1399 // UNSET_IDNUM return means no more ids available
1400 inline u2 InstanceKlass::next_method_idnum() {
1401 if (_idnum_allocated_count == ConstMethod::MAX_IDNUM) {
1402 return ConstMethod::UNSET_IDNUM; // no more ids available
|