src/share/vm/oops/instanceKlass.hpp
Index Unified diffs Context diffs Sdiffs Wdiffs Patch New Old Previous File Next File hotspot Sdiff src/share/vm/oops

src/share/vm/oops/instanceKlass.hpp

Print this page




  37 #include "oops/fieldInfo.hpp"
  38 #include "oops/instanceOop.hpp"
  39 #include "oops/klassVtable.hpp"
  40 #include "runtime/handles.hpp"
  41 #include "runtime/os.hpp"
  42 #include "trace/traceMacros.hpp"
  43 #include "utilities/accessFlags.hpp"
  44 #include "utilities/bitMap.inline.hpp"
  45 #include "utilities/macros.hpp"
  46 
  47 // An InstanceKlass is the VM level representation of a Java class.
  48 // It contains all information needed for at class at execution runtime.
  49 
  50 //  InstanceKlass embedded field layout (after declared fields):
  51 //    [EMBEDDED Java vtable             ] size in words = vtable_len
  52 //    [EMBEDDED nonstatic oop-map blocks] size in words = nonstatic_oop_map_size
  53 //      The embedded nonstatic oop-map blocks are short pairs (offset, length)
  54 //      indicating where oops are located in instances of this klass.
  55 //    [EMBEDDED implementor of the interface] only exist for interface
  56 //    [EMBEDDED host klass        ] only exist for an anonymous class (JSR 292 enabled)

  57 
  58 
  59 // forward declaration for class -- see below for definition
  60 #if INCLUDE_JVMTI
  61 class BreakpointInfo;
  62 #endif
  63 class ClassFileParser;
  64 class KlassDepChange;
  65 class DependencyContext;
  66 class fieldDescriptor;
  67 class jniIdMapBase;
  68 class JNIid;
  69 class JvmtiCachedClassFieldMap;
  70 class MemberNameTable;
  71 class SuperTypeClosure;
  72 
  73 // This is used in iterators below.
  74 class FieldClosure: public StackObj {
  75 public:
  76   virtual void do_field(fieldDescriptor* fd) = 0;


 198 
 199   static const unsigned _misc_kind_field_size = 2;
 200   static const unsigned _misc_kind_field_pos  = 0;
 201   static const unsigned _misc_kind_field_mask = (1u << _misc_kind_field_size) - 1u;
 202 
 203   static const unsigned _misc_kind_other        = 0; // concrete InstanceKlass
 204   static const unsigned _misc_kind_reference    = 1; // InstanceRefKlass
 205   static const unsigned _misc_kind_class_loader = 2; // InstanceClassLoaderKlass
 206   static const unsigned _misc_kind_mirror       = 3; // InstanceMirrorKlass
 207 
 208   // Start after _misc_kind field.
 209   enum {
 210     _misc_rewritten                           = 1 << 2,  // methods rewritten.
 211     _misc_has_nonstatic_fields                = 1 << 3,  // for sizing with UseCompressedOops
 212     _misc_should_verify_class                 = 1 << 4,  // allow caching of preverification
 213     _misc_is_anonymous                        = 1 << 5,  // has embedded _host_klass field
 214     _misc_is_contended                        = 1 << 6,  // marked with contended annotation
 215     _misc_has_nonstatic_concrete_methods      = 1 << 7,  // class/superclass/implemented interfaces has non-static, concrete methods
 216     _misc_declares_nonstatic_concrete_methods = 1 << 8,  // directly declares non-static, concrete methods
 217     _misc_has_been_redefined                  = 1 << 9,  // class has been redefined
 218     _misc_is_scratch_class                    = 1 << 10, // class is the redefined scratch class
 219     _misc_is_shared_boot_class                = 1 << 11, // defining class loader is boot class loader
 220     _misc_is_shared_platform_class            = 1 << 12, // defining class loader is platform class loader
 221     _misc_is_shared_app_class                 = 1 << 13  // defining class loader is app class loader


 222   };
 223   u2 loader_type_bits() {
 224     return _misc_is_shared_boot_class|_misc_is_shared_platform_class|_misc_is_shared_app_class;
 225   }
 226   u2              _misc_flags;
 227   u2              _minor_version;        // minor version number of class file
 228   u2              _major_version;        // major version number of class file
 229   Thread*         _init_thread;          // Pointer to current thread doing initialization (to handle recusive initialization)
 230   OopMapCache*    volatile _oop_map_cache;   // OopMapCache for all methods in the klass (allocated lazily)
 231   MemberNameTable* _member_names;        // Member names
 232   JNIid*          _jni_ids;              // First JNI identifier for static fields in this class
 233   jmethodID*      volatile _methods_jmethod_ids;  // jmethodIDs corresponding to method_idnum, or NULL if none
 234   intptr_t        _dep_context;          // packed DependencyContext structure
 235   nmethod*        _osr_nmethods_head;    // Head of list of on-stack replacement nmethods for this class
 236 #if INCLUDE_JVMTI
 237   BreakpointInfo* _breakpoints;          // bpt lists, managed by Method*
 238   // Linked instanceKlasses of previous versions
 239   InstanceKlass* _previous_versions;
 240   // JVMTI fields can be moved to their own structure - see 6315920
 241   // JVMTI: cached class file, before retransformable agent modified it in CFLH


 715 #else
 716   InstanceKlass* previous_versions() const { return NULL; }
 717 #endif
 718 
 719   InstanceKlass* get_klass_version(int version) {
 720     for (InstanceKlass* ik = this; ik != NULL; ik = ik->previous_versions()) {
 721       if (ik->constants()->version() == version) {
 722         return ik;
 723       }
 724     }
 725     return NULL;
 726   }
 727 
 728   bool has_been_redefined() const {
 729     return (_misc_flags & _misc_has_been_redefined) != 0;
 730   }
 731   void set_has_been_redefined() {
 732     _misc_flags |= _misc_has_been_redefined;
 733   }
 734 

















 735   bool is_scratch_class() const {
 736     return (_misc_flags & _misc_is_scratch_class) != 0;
 737   }
 738 
 739   void set_is_scratch_class() {
 740     _misc_flags |= _misc_is_scratch_class;
 741   }
 742 
 743 private:
 744 
 745   void set_kind(unsigned kind) {
 746     assert(kind <= _misc_kind_field_mask, "Invalid InstanceKlass kind");
 747     unsigned fmask = _misc_kind_field_mask << _misc_kind_field_pos;
 748     unsigned flags = _misc_flags & ~fmask;
 749     _misc_flags = (flags | (kind << _misc_kind_field_pos));
 750   }
 751 
 752   bool is_kind(unsigned desired) const {
 753     unsigned kind = (_misc_flags >> _misc_kind_field_pos) & _misc_kind_field_mask;
 754     return kind == desired;


1011 
1012   static InstanceKlass* cast(Klass* k) {
1013     return const_cast<InstanceKlass*>(cast(const_cast<const Klass*>(k)));
1014   }
1015 
1016   static const InstanceKlass* cast(const Klass* k) {
1017     assert(k != NULL, "k should not be null");
1018     assert(k->is_instance_klass(), "cast to InstanceKlass");
1019     return static_cast<const InstanceKlass*>(k);
1020   }
1021 
1022   InstanceKlass* java_super() const {
1023     return (super() == NULL) ? NULL : cast(super());
1024   }
1025 
1026   // Sizing (in words)
1027   static int header_size()            { return sizeof(InstanceKlass)/wordSize; }
1028 
1029   static int size(int vtable_length, int itable_length,
1030                   int nonstatic_oop_map_size,
1031                   bool is_interface, bool is_anonymous) {
1032     return align_metadata_size(header_size() +
1033            vtable_length +
1034            itable_length +
1035            nonstatic_oop_map_size +
1036            (is_interface ? (int)sizeof(Klass*)/wordSize : 0) +
1037            (is_anonymous ? (int)sizeof(Klass*)/wordSize : 0));

1038   }
1039   int size() const                    { return size(vtable_length(),
1040                                                itable_length(),
1041                                                nonstatic_oop_map_size(),
1042                                                is_interface(),
1043                                                is_anonymous());

1044   }
1045 #if INCLUDE_SERVICES
1046   virtual void collect_statistics(KlassSizeStats *sz) const;
1047 #endif
1048 
1049   intptr_t* start_of_itable()   const { return (intptr_t*)start_of_vtable() + vtable_length(); }
1050   intptr_t* end_of_itable()     const { return start_of_itable() + itable_length(); }
1051 
1052   int  itable_offset_in_words() const { return start_of_itable() - (intptr_t*)this; }
1053 
1054   address static_field_addr(int offset);
1055 
1056   OopMapBlock* start_of_nonstatic_oop_maps() const {
1057     return (OopMapBlock*)(start_of_itable() + itable_length());
1058   }
1059 
1060   Klass** end_of_nonstatic_oop_maps() const {
1061     return (Klass**)(start_of_nonstatic_oop_maps() +
1062                      nonstatic_oop_map_count());
1063   }


1066     if (is_interface()) {
1067       return (Klass**)end_of_nonstatic_oop_maps();
1068     } else {
1069       return NULL;
1070     }
1071   };
1072 
1073   InstanceKlass** adr_host_klass() const {
1074     if (is_anonymous()) {
1075       InstanceKlass** adr_impl = (InstanceKlass **)adr_implementor();
1076       if (adr_impl != NULL) {
1077         return adr_impl + 1;
1078       } else {
1079         return (InstanceKlass **)end_of_nonstatic_oop_maps();
1080       }
1081     } else {
1082       return NULL;
1083     }
1084   }
1085 


















1086   // Use this to return the size of an instance in heap words:
1087   int size_helper() const {
1088     return layout_helper_to_size_helper(layout_helper());
1089   }
1090 
1091   // This bit is initialized in classFileParser.cpp.
1092   // It is false under any of the following conditions:
1093   //  - the class is abstract (including any interface)
1094   //  - the class has a finalizer (if !RegisterFinalizersAtInit)
1095   //  - the class size is larger than FastAllocateSizeLimit
1096   //  - the class is java/lang/Class, which cannot be allocated directly
1097   bool can_be_fastpath_allocated() const {
1098     return !layout_helper_needs_slow_path(layout_helper());
1099   }
1100 
1101   // Java itable
1102   klassItable* itable() const;        // return new klassItable wrapper
1103   Method* method_at_itable(Klass* holder, int index, TRAPS);
1104 
1105 #if INCLUDE_JVMTI




  37 #include "oops/fieldInfo.hpp"
  38 #include "oops/instanceOop.hpp"
  39 #include "oops/klassVtable.hpp"
  40 #include "runtime/handles.hpp"
  41 #include "runtime/os.hpp"
  42 #include "trace/traceMacros.hpp"
  43 #include "utilities/accessFlags.hpp"
  44 #include "utilities/bitMap.inline.hpp"
  45 #include "utilities/macros.hpp"
  46 
  47 // An InstanceKlass is the VM level representation of a Java class.
  48 // It contains all information needed for at class at execution runtime.
  49 
  50 //  InstanceKlass embedded field layout (after declared fields):
  51 //    [EMBEDDED Java vtable             ] size in words = vtable_len
  52 //    [EMBEDDED nonstatic oop-map blocks] size in words = nonstatic_oop_map_size
  53 //      The embedded nonstatic oop-map blocks are short pairs (offset, length)
  54 //      indicating where oops are located in instances of this klass.
  55 //    [EMBEDDED implementor of the interface] only exist for interface
  56 //    [EMBEDDED host klass        ] only exist for an anonymous class (JSR 292 enabled)
  57 //    [EMBEDDED fingerprint       ] only if should_store_fingerprint()==true
  58 
  59 
  60 // forward declaration for class -- see below for definition
  61 #if INCLUDE_JVMTI
  62 class BreakpointInfo;
  63 #endif
  64 class ClassFileParser;
  65 class KlassDepChange;
  66 class DependencyContext;
  67 class fieldDescriptor;
  68 class jniIdMapBase;
  69 class JNIid;
  70 class JvmtiCachedClassFieldMap;
  71 class MemberNameTable;
  72 class SuperTypeClosure;
  73 
  74 // This is used in iterators below.
  75 class FieldClosure: public StackObj {
  76 public:
  77   virtual void do_field(fieldDescriptor* fd) = 0;


 199 
 200   static const unsigned _misc_kind_field_size = 2;
 201   static const unsigned _misc_kind_field_pos  = 0;
 202   static const unsigned _misc_kind_field_mask = (1u << _misc_kind_field_size) - 1u;
 203 
 204   static const unsigned _misc_kind_other        = 0; // concrete InstanceKlass
 205   static const unsigned _misc_kind_reference    = 1; // InstanceRefKlass
 206   static const unsigned _misc_kind_class_loader = 2; // InstanceClassLoaderKlass
 207   static const unsigned _misc_kind_mirror       = 3; // InstanceMirrorKlass
 208 
 209   // Start after _misc_kind field.
 210   enum {
 211     _misc_rewritten                           = 1 << 2,  // methods rewritten.
 212     _misc_has_nonstatic_fields                = 1 << 3,  // for sizing with UseCompressedOops
 213     _misc_should_verify_class                 = 1 << 4,  // allow caching of preverification
 214     _misc_is_anonymous                        = 1 << 5,  // has embedded _host_klass field
 215     _misc_is_contended                        = 1 << 6,  // marked with contended annotation
 216     _misc_has_nonstatic_concrete_methods      = 1 << 7,  // class/superclass/implemented interfaces has non-static, concrete methods
 217     _misc_declares_nonstatic_concrete_methods = 1 << 8,  // directly declares non-static, concrete methods
 218     _misc_has_been_redefined                  = 1 << 9,  // class has been redefined
 219     _misc_has_passed_fingerprint_check        = 1 << 10, // when this class was loaded, the fingerprint computed from its
 220                                                          // code source was found to be matching the value recorded by AOT.
 221     _misc_is_scratch_class                    = 1 << 11, // class is the redefined scratch class
 222     _misc_is_shared_boot_class                = 1 << 12, // defining class loader is boot class loader
 223     _misc_is_shared_platform_class            = 1 << 13, // defining class loader is platform class loader
 224     _misc_is_shared_app_class                 = 1 << 14  // defining class loader is app class loader
 225   };
 226   u2 loader_type_bits() {
 227     return _misc_is_shared_boot_class|_misc_is_shared_platform_class|_misc_is_shared_app_class;
 228   }
 229   u2              _misc_flags;
 230   u2              _minor_version;        // minor version number of class file
 231   u2              _major_version;        // major version number of class file
 232   Thread*         _init_thread;          // Pointer to current thread doing initialization (to handle recusive initialization)
 233   OopMapCache*    volatile _oop_map_cache;   // OopMapCache for all methods in the klass (allocated lazily)
 234   MemberNameTable* _member_names;        // Member names
 235   JNIid*          _jni_ids;              // First JNI identifier for static fields in this class
 236   jmethodID*      volatile _methods_jmethod_ids;  // jmethodIDs corresponding to method_idnum, or NULL if none
 237   intptr_t        _dep_context;          // packed DependencyContext structure
 238   nmethod*        _osr_nmethods_head;    // Head of list of on-stack replacement nmethods for this class
 239 #if INCLUDE_JVMTI
 240   BreakpointInfo* _breakpoints;          // bpt lists, managed by Method*
 241   // Linked instanceKlasses of previous versions
 242   InstanceKlass* _previous_versions;
 243   // JVMTI fields can be moved to their own structure - see 6315920
 244   // JVMTI: cached class file, before retransformable agent modified it in CFLH


 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() {
 735     _misc_flags |= _misc_has_been_redefined;
 736   }
 737 
 738   bool has_passed_fingerprint_check() const {
 739     return (_misc_flags & _misc_has_passed_fingerprint_check) != 0;
 740   }
 741   void set_has_passed_fingerprint_check(bool b) {
 742     if (b) {
 743       _misc_flags |= _misc_has_passed_fingerprint_check;
 744     } else {
 745       _misc_flags &= ~_misc_has_passed_fingerprint_check;
 746     }
 747   }
 748   bool supers_have_passed_fingerprint_checks();
 749 
 750   static bool should_store_fingerprint();
 751   bool has_stored_fingerprint() const;
 752   uint64_t get_stored_fingerprint() const;
 753   void store_fingerprint(uint64_t fingerprint);
 754 
 755   bool is_scratch_class() const {
 756     return (_misc_flags & _misc_is_scratch_class) != 0;
 757   }
 758 
 759   void set_is_scratch_class() {
 760     _misc_flags |= _misc_is_scratch_class;
 761   }
 762 
 763 private:
 764 
 765   void set_kind(unsigned kind) {
 766     assert(kind <= _misc_kind_field_mask, "Invalid InstanceKlass kind");
 767     unsigned fmask = _misc_kind_field_mask << _misc_kind_field_pos;
 768     unsigned flags = _misc_flags & ~fmask;
 769     _misc_flags = (flags | (kind << _misc_kind_field_pos));
 770   }
 771 
 772   bool is_kind(unsigned desired) const {
 773     unsigned kind = (_misc_flags >> _misc_kind_field_pos) & _misc_kind_field_mask;
 774     return kind == desired;


1031 
1032   static InstanceKlass* cast(Klass* k) {
1033     return const_cast<InstanceKlass*>(cast(const_cast<const Klass*>(k)));
1034   }
1035 
1036   static const InstanceKlass* cast(const Klass* k) {
1037     assert(k != NULL, "k should not be null");
1038     assert(k->is_instance_klass(), "cast to InstanceKlass");
1039     return static_cast<const InstanceKlass*>(k);
1040   }
1041 
1042   InstanceKlass* java_super() const {
1043     return (super() == NULL) ? NULL : cast(super());
1044   }
1045 
1046   // Sizing (in words)
1047   static int header_size()            { return sizeof(InstanceKlass)/wordSize; }
1048 
1049   static int size(int vtable_length, int itable_length,
1050                   int nonstatic_oop_map_size,
1051                   bool is_interface, bool is_anonymous, bool has_stored_fingerprint) {
1052     return align_metadata_size(header_size() +
1053            vtable_length +
1054            itable_length +
1055            nonstatic_oop_map_size +
1056            (is_interface ? (int)sizeof(Klass*)/wordSize : 0) +
1057            (is_anonymous ? (int)sizeof(Klass*)/wordSize : 0) +
1058            (has_stored_fingerprint ? (int)sizeof(uint64_t*)/wordSize : 0));
1059   }
1060   int size() const                    { return size(vtable_length(),
1061                                                itable_length(),
1062                                                nonstatic_oop_map_size(),
1063                                                is_interface(),
1064                                                is_anonymous(),
1065                                                has_stored_fingerprint());
1066   }
1067 #if INCLUDE_SERVICES
1068   virtual void collect_statistics(KlassSizeStats *sz) const;
1069 #endif
1070 
1071   intptr_t* start_of_itable()   const { return (intptr_t*)start_of_vtable() + vtable_length(); }
1072   intptr_t* end_of_itable()     const { return start_of_itable() + itable_length(); }
1073 
1074   int  itable_offset_in_words() const { return start_of_itable() - (intptr_t*)this; }
1075 
1076   address static_field_addr(int offset);
1077 
1078   OopMapBlock* start_of_nonstatic_oop_maps() const {
1079     return (OopMapBlock*)(start_of_itable() + itable_length());
1080   }
1081 
1082   Klass** end_of_nonstatic_oop_maps() const {
1083     return (Klass**)(start_of_nonstatic_oop_maps() +
1084                      nonstatic_oop_map_count());
1085   }


1088     if (is_interface()) {
1089       return (Klass**)end_of_nonstatic_oop_maps();
1090     } else {
1091       return NULL;
1092     }
1093   };
1094 
1095   InstanceKlass** adr_host_klass() const {
1096     if (is_anonymous()) {
1097       InstanceKlass** adr_impl = (InstanceKlass **)adr_implementor();
1098       if (adr_impl != NULL) {
1099         return adr_impl + 1;
1100       } else {
1101         return (InstanceKlass **)end_of_nonstatic_oop_maps();
1102       }
1103     } else {
1104       return NULL;
1105     }
1106   }
1107 
1108   address adr_fingerprint() const {
1109     if (has_stored_fingerprint()) {
1110       InstanceKlass** adr_host = adr_host_klass();
1111       if (adr_host != NULL) {
1112         return (address)(adr_host + 1);
1113       }
1114 
1115       Klass** adr_impl = adr_implementor();
1116       if (adr_impl != NULL) {
1117         return (address)(adr_impl + 1);
1118       }
1119 
1120       return (address)end_of_nonstatic_oop_maps();
1121     } else {
1122       return NULL;
1123     }
1124   }
1125 
1126   // Use this to return the size of an instance in heap words:
1127   int size_helper() const {
1128     return layout_helper_to_size_helper(layout_helper());
1129   }
1130 
1131   // This bit is initialized in classFileParser.cpp.
1132   // It is false under any of the following conditions:
1133   //  - the class is abstract (including any interface)
1134   //  - the class has a finalizer (if !RegisterFinalizersAtInit)
1135   //  - the class size is larger than FastAllocateSizeLimit
1136   //  - the class is java/lang/Class, which cannot be allocated directly
1137   bool can_be_fastpath_allocated() const {
1138     return !layout_helper_needs_slow_path(layout_helper());
1139   }
1140 
1141   // Java itable
1142   klassItable* itable() const;        // return new klassItable wrapper
1143   Method* method_at_itable(Klass* holder, int index, TRAPS);
1144 
1145 #if INCLUDE_JVMTI


src/share/vm/oops/instanceKlass.hpp
Index Unified diffs Context diffs Sdiffs Wdiffs Patch New Old Previous File Next File