455 ModuleEntry* module() const;
456 bool in_unnamed_package() const { return (_package_entry == NULL); }
457 void set_package(PackageEntry* p) { _package_entry = p; }
458 void set_package(ClassLoaderData* loader_data, TRAPS);
459 bool is_same_class_package(const Klass* class2) const;
460 bool is_same_class_package(oop classloader2, const Symbol* classname2) const;
461 static bool is_same_class_package(oop class_loader1,
462 const Symbol* class_name1,
463 oop class_loader2,
464 const Symbol* class_name2);
465
466 // find an enclosing class
467 InstanceKlass* compute_enclosing_class(bool* inner_is_member, TRAPS) const {
468 return compute_enclosing_class_impl(this, inner_is_member, THREAD);
469 }
470 static InstanceKlass* compute_enclosing_class_impl(const InstanceKlass* self,
471 bool* inner_is_member,
472 TRAPS);
473
474 // Find InnerClasses attribute for k and return outer_class_info_index & inner_name_index.
475 static bool find_inner_classes_attr(instanceKlassHandle k,
476 int* ooff, int* noff, TRAPS);
477
478 private:
479 // Check prohibited package ("java/" only loadable by boot or platform loaders)
480 static void check_prohibited_package(Symbol* class_name,
481 Handle class_loader,
482 TRAPS);
483 public:
484 // tell if two classes have the same enclosing class (at package level)
485 bool is_same_package_member(const Klass* class2, TRAPS) const {
486 return is_same_package_member_impl(this, class2, THREAD);
487 }
488 static bool is_same_package_member_impl(const InstanceKlass* self,
489 const Klass* class2,
490 TRAPS);
491
492 // initialization state
493 bool is_loaded() const { return _init_state >= loaded; }
494 bool is_linked() const { return _init_state >= linked; }
495 bool is_initialized() const { return _init_state == fully_initialized; }
507 void set_should_verify_class(bool value) {
508 if (value) {
509 _misc_flags |= _misc_should_verify_class;
510 } else {
511 _misc_flags &= ~_misc_should_verify_class;
512 }
513 }
514
515 // marking
516 bool is_marked_dependent() const { return _is_marked_dependent; }
517 void set_is_marked_dependent(bool value) { _is_marked_dependent = value; }
518
519 // initialization (virtuals from Klass)
520 bool should_be_initialized() const; // means that initialize should be called
521 void initialize(TRAPS);
522 void link_class(TRAPS);
523 bool link_class_or_fail(TRAPS); // returns false on failure
524 void unlink_class();
525 void rewrite_class(TRAPS);
526 void link_methods(TRAPS);
527 Method* class_initializer();
528
529 // set the class to initialized if no static initializer is present
530 void eager_initialize(Thread *thread);
531
532 // reference type
533 ReferenceType reference_type() const { return (ReferenceType)_reference_type; }
534 void set_reference_type(ReferenceType t) {
535 assert(t == (u1)t, "overflow");
536 _reference_type = (u1)t;
537 }
538
539 static ByteSize reference_type_offset() { return in_ByteSize(offset_of(InstanceKlass, _reference_type)); }
540
541 // find local field, returns true if found
542 bool find_local_field(Symbol* name, Symbol* sig, fieldDescriptor* fd) const;
543 // find field in direct superinterfaces, returns the interface in which the field is defined
544 Klass* find_interface_field(Symbol* name, Symbol* sig, fieldDescriptor* fd) const;
545 // find field according to JVM spec 5.4.3.2, returns the klass in which the field is defined
546 Klass* find_field(Symbol* name, Symbol* sig, fieldDescriptor* fd) const;
547 // find instance or static fields according to JVM spec 5.4.3.2, returns the klass in which the field is defined
694 void set_array_name(Symbol* name) { assert(_array_name == NULL || name == NULL, "name already created"); _array_name = name; }
695
696 // nonstatic oop-map blocks
697 static int nonstatic_oop_map_size(unsigned int oop_map_count) {
698 return oop_map_count * OopMapBlock::size_in_words();
699 }
700 unsigned int nonstatic_oop_map_count() const {
701 return _nonstatic_oop_map_size / OopMapBlock::size_in_words();
702 }
703 int nonstatic_oop_map_size() const { return _nonstatic_oop_map_size; }
704 void set_nonstatic_oop_map_size(int words) {
705 _nonstatic_oop_map_size = words;
706 }
707
708 #if INCLUDE_JVMTI
709 // Redefinition locking. Class can only be redefined by one thread at a time.
710 bool is_being_redefined() const { return _is_being_redefined; }
711 void set_is_being_redefined(bool value) { _is_being_redefined = value; }
712
713 // RedefineClasses() support for previous versions:
714 void add_previous_version(instanceKlassHandle ikh, int emcp_method_count);
715 void purge_previous_version_list();
716
717 InstanceKlass* previous_versions() const { return _previous_versions; }
718 #else
719 InstanceKlass* previous_versions() const { return NULL; }
720 #endif
721
722 InstanceKlass* get_klass_version(int version) {
723 for (InstanceKlass* ik = this; ik != NULL; ik = ik->previous_versions()) {
724 if (ik->constants()->version() == version) {
725 return ik;
726 }
727 }
728 return NULL;
729 }
730
731 bool has_been_redefined() const {
732 return (_misc_flags & _misc_has_been_redefined) != 0;
733 }
734 void set_has_been_redefined() {
866 (Symbol*)NULL : _constants->symbol_at(_generic_signature_index);
867 }
868 u2 generic_signature_index() const {
869 return _generic_signature_index;
870 }
871 void set_generic_signature_index(u2 sig_index) {
872 _generic_signature_index = sig_index;
873 }
874
875 u2 enclosing_method_data(int offset) const;
876 u2 enclosing_method_class_index() const {
877 return enclosing_method_data(enclosing_method_class_index_offset);
878 }
879 u2 enclosing_method_method_index() {
880 return enclosing_method_data(enclosing_method_method_index_offset);
881 }
882 void set_enclosing_method_indices(u2 class_index,
883 u2 method_index);
884
885 // jmethodID support
886 static jmethodID get_jmethod_id(instanceKlassHandle ik_h,
887 const methodHandle& method_h);
888 static jmethodID get_jmethod_id_fetch_or_update(instanceKlassHandle ik_h,
889 size_t idnum, jmethodID new_id, jmethodID* new_jmeths,
890 jmethodID* to_dealloc_id_p,
891 jmethodID** to_dealloc_jmeths_p);
892 static void get_jmethod_id_length_value(jmethodID* cache, size_t idnum,
893 size_t *length_p, jmethodID* id_p);
894 void ensure_space_for_methodids(int start_offset = 0);
895 jmethodID jmethod_id_or_null(Method* method);
896
897 // annotations support
898 Annotations* annotations() const { return _annotations; }
899 void set_annotations(Annotations* anno) { _annotations = anno; }
900
901 AnnotationArray* class_annotations() const {
902 return (_annotations != NULL) ? _annotations->class_annotations() : NULL;
903 }
904 Array<AnnotationArray*>* fields_annotations() const {
905 return (_annotations != NULL) ? _annotations->fields_annotations() : NULL;
906 }
907 AnnotationArray* class_type_annotations() const {
908 return (_annotations != NULL) ? _annotations->class_type_annotations() : NULL;
1291 // The RedefineClasses() API can cause new method idnums to be needed
1292 // which will cause the caches to grow. Safety requires different
1293 // cache management logic if the caches can grow instead of just
1294 // going from NULL to non-NULL.
1295 bool idnum_can_increment() const { return has_been_redefined(); }
1296 inline jmethodID* methods_jmethod_ids_acquire() const;
1297 inline void release_set_methods_jmethod_ids(jmethodID* jmeths);
1298
1299 // Lock during initialization
1300 public:
1301 // Lock for (1) initialization; (2) access to the ConstantPool of this class.
1302 // Must be one per class and it has to be a VM internal object so java code
1303 // cannot lock it (like the mirror).
1304 // It has to be an object not a Mutex because it's held through java calls.
1305 oop init_lock() const;
1306 private:
1307 void fence_and_clear_init_lock();
1308
1309 // Static methods that are used to implement member methods where an exposed this pointer
1310 // is needed due to possible GCs
1311 static bool link_class_impl (instanceKlassHandle this_k, bool throw_verifyerror, TRAPS);
1312 static bool verify_code (instanceKlassHandle this_k, bool throw_verifyerror, TRAPS);
1313 static void initialize_impl (instanceKlassHandle this_k, TRAPS);
1314 static void initialize_super_interfaces (instanceKlassHandle this_k, TRAPS);
1315 static void eager_initialize_impl (instanceKlassHandle this_k);
1316 static void set_initialization_state_and_notify_impl (instanceKlassHandle this_k, ClassState state, TRAPS);
1317 static void call_class_initializer_impl (instanceKlassHandle this_k, TRAPS);
1318 static Klass* array_klass_impl (instanceKlassHandle this_k, bool or_null, int n, TRAPS);
1319 static void do_local_static_fields_impl (instanceKlassHandle this_k, void f(fieldDescriptor* fd, Handle, TRAPS), Handle, TRAPS);
1320 /* jni_id_for_impl for jfieldID only */
1321 static JNIid* jni_id_for_impl (instanceKlassHandle this_k, int offset);
1322
1323 // Returns the array class for the n'th dimension
1324 Klass* array_klass_impl(bool or_null, int n, TRAPS);
1325
1326 // Returns the array class with this class as element type
1327 Klass* array_klass_impl(bool or_null, TRAPS);
1328
1329 // find a local method (returns NULL if not found)
1330 Method* find_method_impl(const Symbol* name,
1331 const Symbol* signature,
1332 OverpassLookupMode overpass_mode,
1333 StaticLookupMode static_mode,
1334 PrivateLookupMode private_mode) const;
1335
1336 static Method* find_method_impl(const Array<Method*>* methods,
1337 const Symbol* name,
1338 const Symbol* signature,
1339 OverpassLookupMode overpass_mode,
1340 StaticLookupMode static_mode,
1341 PrivateLookupMode private_mode);
1430 }
1431
1432 static void deallocate(JNIid* id);
1433 // Debugging
1434 #ifdef ASSERT
1435 bool is_static_field_id() const { return _is_static_field_id; }
1436 void set_is_static_field_id() { _is_static_field_id = true; }
1437 #endif
1438 void verify(Klass* holder);
1439 };
1440
1441 // An iterator that's used to access the inner classes indices in the
1442 // InstanceKlass::_inner_classes array.
1443 class InnerClassesIterator : public StackObj {
1444 private:
1445 Array<jushort>* _inner_classes;
1446 int _length;
1447 int _idx;
1448 public:
1449
1450 InnerClassesIterator(instanceKlassHandle k) {
1451 _inner_classes = k->inner_classes();
1452 if (k->inner_classes() != NULL) {
1453 _length = _inner_classes->length();
1454 // The inner class array's length should be the multiple of
1455 // inner_class_next_offset if it only contains the InnerClasses
1456 // attribute data, or it should be
1457 // n*inner_class_next_offset+enclosing_method_attribute_size
1458 // if it also contains the EnclosingMethod data.
1459 assert((_length % InstanceKlass::inner_class_next_offset == 0 ||
1460 _length % InstanceKlass::inner_class_next_offset == InstanceKlass::enclosing_method_attribute_size),
1461 "just checking");
1462 // Remove the enclosing_method portion if exists.
1463 if (_length % InstanceKlass::inner_class_next_offset == InstanceKlass::enclosing_method_attribute_size) {
1464 _length -= InstanceKlass::enclosing_method_attribute_size;
1465 }
1466 } else {
1467 _length = 0;
1468 }
1469 _idx = 0;
1470 }
|
455 ModuleEntry* module() const;
456 bool in_unnamed_package() const { return (_package_entry == NULL); }
457 void set_package(PackageEntry* p) { _package_entry = p; }
458 void set_package(ClassLoaderData* loader_data, TRAPS);
459 bool is_same_class_package(const Klass* class2) const;
460 bool is_same_class_package(oop classloader2, const Symbol* classname2) const;
461 static bool is_same_class_package(oop class_loader1,
462 const Symbol* class_name1,
463 oop class_loader2,
464 const Symbol* class_name2);
465
466 // find an enclosing class
467 InstanceKlass* compute_enclosing_class(bool* inner_is_member, TRAPS) const {
468 return compute_enclosing_class_impl(this, inner_is_member, THREAD);
469 }
470 static InstanceKlass* compute_enclosing_class_impl(const InstanceKlass* self,
471 bool* inner_is_member,
472 TRAPS);
473
474 // Find InnerClasses attribute for k and return outer_class_info_index & inner_name_index.
475 static bool find_inner_classes_attr(const InstanceKlass* k,
476 int* ooff, int* noff, TRAPS);
477
478 private:
479 // Check prohibited package ("java/" only loadable by boot or platform loaders)
480 static void check_prohibited_package(Symbol* class_name,
481 Handle class_loader,
482 TRAPS);
483 public:
484 // tell if two classes have the same enclosing class (at package level)
485 bool is_same_package_member(const Klass* class2, TRAPS) const {
486 return is_same_package_member_impl(this, class2, THREAD);
487 }
488 static bool is_same_package_member_impl(const InstanceKlass* self,
489 const Klass* class2,
490 TRAPS);
491
492 // initialization state
493 bool is_loaded() const { return _init_state >= loaded; }
494 bool is_linked() const { return _init_state >= linked; }
495 bool is_initialized() const { return _init_state == fully_initialized; }
507 void set_should_verify_class(bool value) {
508 if (value) {
509 _misc_flags |= _misc_should_verify_class;
510 } else {
511 _misc_flags &= ~_misc_should_verify_class;
512 }
513 }
514
515 // marking
516 bool is_marked_dependent() const { return _is_marked_dependent; }
517 void set_is_marked_dependent(bool value) { _is_marked_dependent = value; }
518
519 // initialization (virtuals from Klass)
520 bool should_be_initialized() const; // means that initialize should be called
521 void initialize(TRAPS);
522 void link_class(TRAPS);
523 bool link_class_or_fail(TRAPS); // returns false on failure
524 void unlink_class();
525 void rewrite_class(TRAPS);
526 void link_methods(TRAPS);
527 Method* class_initializer() const;
528
529 // set the class to initialized if no static initializer is present
530 void eager_initialize(Thread *thread);
531
532 // reference type
533 ReferenceType reference_type() const { return (ReferenceType)_reference_type; }
534 void set_reference_type(ReferenceType t) {
535 assert(t == (u1)t, "overflow");
536 _reference_type = (u1)t;
537 }
538
539 static ByteSize reference_type_offset() { return in_ByteSize(offset_of(InstanceKlass, _reference_type)); }
540
541 // find local field, returns true if found
542 bool find_local_field(Symbol* name, Symbol* sig, fieldDescriptor* fd) const;
543 // find field in direct superinterfaces, returns the interface in which the field is defined
544 Klass* find_interface_field(Symbol* name, Symbol* sig, fieldDescriptor* fd) const;
545 // find field according to JVM spec 5.4.3.2, returns the klass in which the field is defined
546 Klass* find_field(Symbol* name, Symbol* sig, fieldDescriptor* fd) const;
547 // find instance or static fields according to JVM spec 5.4.3.2, returns the klass in which the field is defined
694 void set_array_name(Symbol* name) { assert(_array_name == NULL || name == NULL, "name already created"); _array_name = name; }
695
696 // nonstatic oop-map blocks
697 static int nonstatic_oop_map_size(unsigned int oop_map_count) {
698 return oop_map_count * OopMapBlock::size_in_words();
699 }
700 unsigned int nonstatic_oop_map_count() const {
701 return _nonstatic_oop_map_size / OopMapBlock::size_in_words();
702 }
703 int nonstatic_oop_map_size() const { return _nonstatic_oop_map_size; }
704 void set_nonstatic_oop_map_size(int words) {
705 _nonstatic_oop_map_size = words;
706 }
707
708 #if INCLUDE_JVMTI
709 // Redefinition locking. Class can only be redefined by one thread at a time.
710 bool is_being_redefined() const { return _is_being_redefined; }
711 void set_is_being_redefined(bool value) { _is_being_redefined = value; }
712
713 // RedefineClasses() support for previous versions:
714 void add_previous_version(InstanceKlass* ik, int emcp_method_count);
715 void purge_previous_version_list();
716
717 InstanceKlass* previous_versions() const { return _previous_versions; }
718 #else
719 InstanceKlass* previous_versions() const { return NULL; }
720 #endif
721
722 InstanceKlass* get_klass_version(int version) {
723 for (InstanceKlass* ik = this; ik != NULL; ik = ik->previous_versions()) {
724 if (ik->constants()->version() == version) {
725 return ik;
726 }
727 }
728 return NULL;
729 }
730
731 bool has_been_redefined() const {
732 return (_misc_flags & _misc_has_been_redefined) != 0;
733 }
734 void set_has_been_redefined() {
866 (Symbol*)NULL : _constants->symbol_at(_generic_signature_index);
867 }
868 u2 generic_signature_index() const {
869 return _generic_signature_index;
870 }
871 void set_generic_signature_index(u2 sig_index) {
872 _generic_signature_index = sig_index;
873 }
874
875 u2 enclosing_method_data(int offset) const;
876 u2 enclosing_method_class_index() const {
877 return enclosing_method_data(enclosing_method_class_index_offset);
878 }
879 u2 enclosing_method_method_index() {
880 return enclosing_method_data(enclosing_method_method_index_offset);
881 }
882 void set_enclosing_method_indices(u2 class_index,
883 u2 method_index);
884
885 // jmethodID support
886 static jmethodID get_jmethod_id(InstanceKlass* ik,
887 const methodHandle& method_h);
888 static jmethodID get_jmethod_id_fetch_or_update(InstanceKlass* ik,
889 size_t idnum, jmethodID new_id, jmethodID* new_jmeths,
890 jmethodID* to_dealloc_id_p,
891 jmethodID** to_dealloc_jmeths_p);
892 static void get_jmethod_id_length_value(jmethodID* cache, size_t idnum,
893 size_t *length_p, jmethodID* id_p);
894 void ensure_space_for_methodids(int start_offset = 0);
895 jmethodID jmethod_id_or_null(Method* method);
896
897 // annotations support
898 Annotations* annotations() const { return _annotations; }
899 void set_annotations(Annotations* anno) { _annotations = anno; }
900
901 AnnotationArray* class_annotations() const {
902 return (_annotations != NULL) ? _annotations->class_annotations() : NULL;
903 }
904 Array<AnnotationArray*>* fields_annotations() const {
905 return (_annotations != NULL) ? _annotations->fields_annotations() : NULL;
906 }
907 AnnotationArray* class_type_annotations() const {
908 return (_annotations != NULL) ? _annotations->class_type_annotations() : NULL;
1291 // The RedefineClasses() API can cause new method idnums to be needed
1292 // which will cause the caches to grow. Safety requires different
1293 // cache management logic if the caches can grow instead of just
1294 // going from NULL to non-NULL.
1295 bool idnum_can_increment() const { return has_been_redefined(); }
1296 inline jmethodID* methods_jmethod_ids_acquire() const;
1297 inline void release_set_methods_jmethod_ids(jmethodID* jmeths);
1298
1299 // Lock during initialization
1300 public:
1301 // Lock for (1) initialization; (2) access to the ConstantPool of this class.
1302 // Must be one per class and it has to be a VM internal object so java code
1303 // cannot lock it (like the mirror).
1304 // It has to be an object not a Mutex because it's held through java calls.
1305 oop init_lock() const;
1306 private:
1307 void fence_and_clear_init_lock();
1308
1309 // Static methods that are used to implement member methods where an exposed this pointer
1310 // is needed due to possible GCs
1311 static bool link_class_impl (InstanceKlass* this_k, bool throw_verifyerror, TRAPS);
1312 static bool verify_code (InstanceKlass* this_k, bool throw_verifyerror, TRAPS);
1313 static void initialize_impl (InstanceKlass* this_k, TRAPS);
1314 static void initialize_super_interfaces (InstanceKlass* this_k, TRAPS);
1315 static void eager_initialize_impl (InstanceKlass* this_k);
1316 static void set_initialization_state_and_notify_impl (InstanceKlass* this_k, ClassState state, TRAPS);
1317 static void call_class_initializer_impl (InstanceKlass* this_k, TRAPS);
1318 static Klass* array_klass_impl (InstanceKlass* this_k, bool or_null, int n, TRAPS);
1319 static void do_local_static_fields_impl (InstanceKlass* this_k, void f(fieldDescriptor* fd, Handle, TRAPS), Handle, TRAPS);
1320 /* jni_id_for_impl for jfieldID only */
1321 static JNIid* jni_id_for_impl (InstanceKlass* this_k, int offset);
1322
1323 // Returns the array class for the n'th dimension
1324 Klass* array_klass_impl(bool or_null, int n, TRAPS);
1325
1326 // Returns the array class with this class as element type
1327 Klass* array_klass_impl(bool or_null, TRAPS);
1328
1329 // find a local method (returns NULL if not found)
1330 Method* find_method_impl(const Symbol* name,
1331 const Symbol* signature,
1332 OverpassLookupMode overpass_mode,
1333 StaticLookupMode static_mode,
1334 PrivateLookupMode private_mode) const;
1335
1336 static Method* find_method_impl(const Array<Method*>* methods,
1337 const Symbol* name,
1338 const Symbol* signature,
1339 OverpassLookupMode overpass_mode,
1340 StaticLookupMode static_mode,
1341 PrivateLookupMode private_mode);
1430 }
1431
1432 static void deallocate(JNIid* id);
1433 // Debugging
1434 #ifdef ASSERT
1435 bool is_static_field_id() const { return _is_static_field_id; }
1436 void set_is_static_field_id() { _is_static_field_id = true; }
1437 #endif
1438 void verify(Klass* holder);
1439 };
1440
1441 // An iterator that's used to access the inner classes indices in the
1442 // InstanceKlass::_inner_classes array.
1443 class InnerClassesIterator : public StackObj {
1444 private:
1445 Array<jushort>* _inner_classes;
1446 int _length;
1447 int _idx;
1448 public:
1449
1450 InnerClassesIterator(const InstanceKlass* k) {
1451 _inner_classes = k->inner_classes();
1452 if (k->inner_classes() != NULL) {
1453 _length = _inner_classes->length();
1454 // The inner class array's length should be the multiple of
1455 // inner_class_next_offset if it only contains the InnerClasses
1456 // attribute data, or it should be
1457 // n*inner_class_next_offset+enclosing_method_attribute_size
1458 // if it also contains the EnclosingMethod data.
1459 assert((_length % InstanceKlass::inner_class_next_offset == 0 ||
1460 _length % InstanceKlass::inner_class_next_offset == InstanceKlass::enclosing_method_attribute_size),
1461 "just checking");
1462 // Remove the enclosing_method portion if exists.
1463 if (_length % InstanceKlass::inner_class_next_offset == InstanceKlass::enclosing_method_attribute_size) {
1464 _length -= InstanceKlass::enclosing_method_attribute_size;
1465 }
1466 } else {
1467 _length = 0;
1468 }
1469 _idx = 0;
1470 }
|