< prev index next >

src/hotspot/share/oops/instanceKlass.hpp

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 #ifndef SHARE_OOPS_INSTANCEKLASS_HPP
  26 #define SHARE_OOPS_INSTANCEKLASS_HPP
  27 

  28 #include "memory/referenceType.hpp"
  29 #include "oops/annotations.hpp"
  30 #include "oops/constMethod.hpp"
  31 #include "oops/fieldInfo.hpp"
  32 #include "oops/instanceOop.hpp"
  33 #include "runtime/handles.hpp"
  34 #include "utilities/accessFlags.hpp"
  35 #include "utilities/align.hpp"
  36 #include "utilities/macros.hpp"
  37 #if INCLUDE_JFR
  38 #include "jfr/support/jfrKlassExtension.hpp"
  39 #endif
  40 
  41 class klassItable;
  42 class RecordComponent;
  43 
  44 // An InstanceKlass is the VM level representation of a Java class.
  45 // It contains all information needed for at class at execution runtime.
  46 
  47 //  InstanceKlass embedded field layout (after declared fields):
  48 //    [EMBEDDED Java vtable             ] size in words = vtable_len
  49 //    [EMBEDDED nonstatic oop-map blocks] size in words = nonstatic_oop_map_size
  50 //      The embedded nonstatic oop-map blocks are short pairs (offset, length)
  51 //      indicating where oops are located in instances of this klass.
  52 //    [EMBEDDED implementor of the interface] only exist for interface


  53 
  54 
  55 // forward declaration for class -- see below for definition
  56 #if INCLUDE_JVMTI
  57 class BreakpointInfo;
  58 #endif
  59 class ClassFileParser;
  60 class ClassFileStream;
  61 class KlassDepChange;
  62 class DependencyContext;
  63 class fieldDescriptor;
  64 class jniIdMapBase;
  65 class JNIid;
  66 class JvmtiCachedClassFieldMap;
  67 class nmethodBucket;
  68 class OopMapCache;

  69 class InterpreterOopMap;
  70 class PackageEntry;
  71 class ModuleEntry;
  72 
  73 // This is used in iterators below.
  74 class FieldClosure: public StackObj {
  75 public:
  76   virtual void do_field(fieldDescriptor* fd) = 0;
  77 };
  78 
  79 // Print fields.
  80 // If "obj" argument to constructor is NULL, prints static fields, otherwise prints non-static fields.
  81 class FieldPrinter: public FieldClosure {
  82    oop _obj;
  83    outputStream* _st;
  84  public:
  85    FieldPrinter(outputStream* st, oop obj = NULL) : _obj(obj), _st(st) {}
  86    void do_field(fieldDescriptor* fd);
  87 };
  88 

 109     return another_offset == end_offset();
 110   }
 111 
 112   // sizeof(OopMapBlock) in words.
 113   static const int size_in_words() {
 114     return align_up((int)sizeof(OopMapBlock), wordSize) >>
 115       LogBytesPerWord;
 116   }
 117 
 118   static int compare_offset(const OopMapBlock* a, const OopMapBlock* b) {
 119     return a->offset() - b->offset();
 120   }
 121 
 122  private:
 123   int  _offset;
 124   uint _count;
 125 };
 126 
 127 struct JvmtiCachedClassFileData;
 128 

















 129 class InstanceKlass: public Klass {
 130   friend class VMStructs;
 131   friend class JVMCIVMStructs;
 132   friend class ClassFileParser;
 133   friend class CompileReplay;

 134 
 135  public:
 136   static const KlassID ID = InstanceKlassID;
 137 
 138  protected:
 139   InstanceKlass(const ClassFileParser& parser, unsigned kind, KlassID id = ID);
 140 
 141  public:
 142   InstanceKlass() { assert(DumpSharedSpaces || UseSharedSpaces, "only for CDS"); }
 143 
 144   // See "The Java Virtual Machine Specification" section 2.16.2-5 for a detailed description
 145   // of the class loading & initialization procedure, and the use of the states.
 146   enum ClassState {
 147     allocated,                          // allocated (but not yet linked)
 148     loaded,                             // loaded and inserted in class hierarchy (but not linked yet)
 149     linked,                             // successfully linked/verified (but not initialized yet)
 150     being_initialized,                  // currently running class initializer
 151     fully_initialized,                  // initialized (successfull final state)
 152     initialization_error                // error happened during initialization
 153   };
 154 
 155  private:
 156   static InstanceKlass* allocate_instance_klass(const ClassFileParser& parser, TRAPS);
 157 
 158  protected:
 159   // If you add a new field that points to any metaspace object, you
 160   // must add this field to InstanceKlass::metaspace_pointers_do().
 161 
 162   // Annotations for this class
 163   Annotations*    _annotations;
 164   // Package this class is defined in
 165   PackageEntry*   _package_entry;
 166   // Array classes holding elements of this class.
 167   ObjArrayKlass* volatile _array_klasses;
 168   // Constant pool for this class.
 169   ConstantPool* _constants;
 170   // The InnerClasses attribute and EnclosingMethod attribute. The
 171   // _inner_classes is an array of shorts. If the class has InnerClasses
 172   // attribute, then the _inner_classes array begins with 4-tuples of shorts
 173   // [inner_class_info_index, outer_class_info_index,
 174   // inner_name_index, inner_class_access_flags] for the InnerClasses
 175   // attribute. If the EnclosingMethod attribute exists, it occupies the
 176   // last two shorts [class_index, method_index] of the array. If only
 177   // the InnerClasses attribute exists, the _inner_classes array length is
 178   // number_of_inner_classes * 4. If the class has both InnerClasses
 179   // and EnclosingMethod attributes the _inner_classes array length is
 180   // number_of_inner_classes * 4 + enclosing_method_attribute_size.
 181   Array<jushort>* _inner_classes;
 182 
 183   // The NestMembers attribute. An array of shorts, where each is a
 184   // class info index for the class that is a nest member. This data
 185   // has not been validated.
 186   Array<jushort>* _nest_members;
 187 

 212   int             _itable_len;              // length of Java itable (in words)
 213 
 214   // The NestHost attribute. The class info index for the class
 215   // that is the nest-host of this class. This data has not been validated.
 216   u2              _nest_host_index;
 217   u2              _this_class_index;        // constant pool entry
 218   u2              _static_oop_field_count;  // number of static oop fields in this klass
 219   u2              _java_fields_count;       // The number of declared Java fields
 220 
 221   volatile u2     _idnum_allocated_count;   // JNI/JVMTI: increments with the addition of methods, old ids don't change
 222 
 223   // _is_marked_dependent can be set concurrently, thus cannot be part of the
 224   // _misc_flags.
 225   bool            _is_marked_dependent;     // used for marking during flushing and deoptimization
 226 
 227   // Class states are defined as ClassState (see above).
 228   // Place the _init_state here to utilize the unused 2-byte after
 229   // _idnum_allocated_count.
 230   u1              _init_state;              // state of class
 231 
 232   // This can be used to quickly discriminate among the four kinds of
 233   // InstanceKlass. This should be an enum (?)
 234   static const unsigned _kind_other        = 0; // concrete InstanceKlass
 235   static const unsigned _kind_reference    = 1; // InstanceRefKlass
 236   static const unsigned _kind_class_loader = 2; // InstanceClassLoaderKlass
 237   static const unsigned _kind_mirror       = 3; // InstanceMirrorKlass

 238 
 239   u1              _reference_type;                // reference type
 240   u1              _kind;                          // kind of InstanceKlass
 241 
 242   enum {
 243     _misc_rewritten                           = 1 << 0,  // methods rewritten.
 244     _misc_has_nonstatic_fields                = 1 << 1,  // for sizing with UseCompressedOops
 245     _misc_should_verify_class                 = 1 << 2,  // allow caching of preverification
 246     _misc_unused                              = 1 << 3,  // not currently used
 247     _misc_is_contended                        = 1 << 4,  // marked with contended annotation
 248     _misc_has_nonstatic_concrete_methods      = 1 << 5,  // class/superclass/implemented interfaces has non-static, concrete methods
 249     _misc_declares_nonstatic_concrete_methods = 1 << 6,  // directly declares non-static, concrete methods
 250     _misc_has_been_redefined                  = 1 << 7,  // class has been redefined
 251     _misc_shared_loading_failed               = 1 << 8,  // class has been loaded from shared archive
 252     _misc_is_scratch_class                    = 1 << 9,  // class is the redefined scratch class
 253     _misc_is_shared_boot_class                = 1 << 10, // defining class loader is boot class loader
 254     _misc_is_shared_platform_class            = 1 << 11, // defining class loader is platform class loader
 255     _misc_is_shared_app_class                 = 1 << 12, // defining class loader is app class loader
 256     _misc_has_contended_annotations           = 1 << 13  // has @Contended annotation






 257   };






 258   u2 shared_loader_type_bits() const {
 259     return _misc_is_shared_boot_class|_misc_is_shared_platform_class|_misc_is_shared_app_class;
 260   }
 261   u2              _misc_flags;           // There is more space in access_flags for more flags.
 262 
 263   Thread*         _init_thread;          // Pointer to current thread doing initialization (to handle recursive initialization)
 264   OopMapCache*    volatile _oop_map_cache;   // OopMapCache for all methods in the klass (allocated lazily)
 265   JNIid*          _jni_ids;              // First JNI identifier for static fields in this class
 266   jmethodID*      volatile _methods_jmethod_ids;  // jmethodIDs corresponding to method_idnum, or NULL if none
 267   nmethodBucket*  volatile _dep_context;          // packed DependencyContext structure
 268   uint64_t        volatile _dep_context_last_cleaned;
 269   nmethod*        _osr_nmethods_head;    // Head of list of on-stack replacement nmethods for this class
 270 #if INCLUDE_JVMTI
 271   BreakpointInfo* _breakpoints;          // bpt lists, managed by Method*
 272   // Linked instanceKlasses of previous versions
 273   InstanceKlass* _previous_versions;
 274   // JVMTI fields can be moved to their own structure - see 6315920
 275   // JVMTI: cached class file, before retransformable agent modified it in CFLH
 276   JvmtiCachedClassFileData* _cached_class_file;
 277 #endif
 278 
 279 #if INCLUDE_JVMTI
 280   JvmtiCachedClassFieldMap* _jvmti_cached_class_field_map;  // JVMTI: used during heap iteration
 281 #endif

 293   // Int array containing the original order of method in the class file (for JVMTI).
 294   Array<int>*     _method_ordering;
 295   // Int array containing the vtable_indices for default_methods
 296   // offset matches _default_methods offset
 297   Array<int>*     _default_vtable_indices;
 298 
 299   // Instance and static variable information, starts with 6-tuples of shorts
 300   // [access, name index, sig index, initval index, low_offset, high_offset]
 301   // for all fields, followed by the generic signature data at the end of
 302   // the array. Only fields with generic signature attributes have the generic
 303   // signature data set in the array. The fields array looks like following:
 304   //
 305   // f1: [access, name index, sig index, initial value index, low_offset, high_offset]
 306   // f2: [access, name index, sig index, initial value index, low_offset, high_offset]
 307   //      ...
 308   // fn: [access, name index, sig index, initial value index, low_offset, high_offset]
 309   //     [generic signature index]
 310   //     [generic signature index]
 311   //     ...
 312   Array<u2>*      _fields;



 313 
 314   // embedded Java vtable follows here
 315   // embedded Java itables follows here
 316   // embedded static fields follows here
 317   // embedded nonstatic oop-map blocks follows here
 318   // embedded implementor of this interface follows here
 319   //   The embedded implementor only exists if the current klass is an
 320   //   interface. The possible values of the implementor fall into following
 321   //   three cases:
 322   //     NULL: no implementor.
 323   //     A Klass* that's not itself: one implementor.
 324   //     Itself: more than one implementors.
 325   //
 326 
 327   friend class SystemDictionary;
 328 
 329   static bool _disable_method_binary_search;
 330 
 331   // Controls finalizer registration
 332   static bool _finalization_enabled;

 362   }
 363 
 364   void set_shared_loading_failed() {
 365     _misc_flags |= _misc_shared_loading_failed;
 366   }
 367 
 368   void set_shared_class_loader_type(s2 loader_type);
 369 
 370   void assign_class_loader_type();
 371 
 372   bool has_nonstatic_fields() const        {
 373     return (_misc_flags & _misc_has_nonstatic_fields) != 0;
 374   }
 375   void set_has_nonstatic_fields(bool b)    {
 376     assert(!has_nonstatic_fields(), "set once");
 377     if (b) {
 378       _misc_flags |= _misc_has_nonstatic_fields;
 379     }
 380   }
 381 

























































 382   // field sizes
 383   int nonstatic_field_size() const         { return _nonstatic_field_size; }
 384   void set_nonstatic_field_size(int size)  { _nonstatic_field_size = size; }
 385 
 386   int static_field_size() const            { return _static_field_size; }
 387   void set_static_field_size(int size)     { _static_field_size = size; }
 388 
 389   int static_oop_field_count() const       { return (int)_static_oop_field_count; }
 390   void set_static_oop_field_count(u2 size) { _static_oop_field_count = size; }
 391 
 392   // Java itable
 393   int  itable_length() const               { return _itable_len; }
 394   void set_itable_length(int len)          { _itable_len = len; }
 395 
 396   // array klasses
 397   ObjArrayKlass* array_klasses() const     { return _array_klasses; }
 398   inline ObjArrayKlass* array_klasses_acquire() const; // load with acquire semantics
 399   inline void release_set_array_klasses(ObjArrayKlass* k); // store with release semantics
 400 
 401   // methods
 402   Array<Method*>* methods() const          { return _methods; }
 403   void set_methods(Array<Method*>* a)      { _methods = a; }
 404   Method* method_with_idnum(int idnum);
 405   Method* method_with_orig_idnum(int idnum);
 406   Method* method_with_orig_idnum(int idnum, int version);
 407 
 408   // method ordering
 409   Array<int>* method_ordering() const     { return _method_ordering; }
 410   void set_method_ordering(Array<int>* m) { _method_ordering = m; }
 411   void copy_method_ordering(const intArray* m, TRAPS);
 412 
 413   // default_methods
 414   Array<Method*>* default_methods() const  { return _default_methods; }
 415   void set_default_methods(Array<Method*>* a) { _default_methods = a; }
 416 
 417   // default method vtable_indices
 418   Array<int>* default_vtable_indices() const { return _default_vtable_indices; }
 419   void set_default_vtable_indices(Array<int>* v) { _default_vtable_indices = v; }

 423   Array<InstanceKlass*>* local_interfaces() const          { return _local_interfaces; }
 424   void set_local_interfaces(Array<InstanceKlass*>* a)      {
 425     guarantee(_local_interfaces == NULL || a == NULL, "Just checking");
 426     _local_interfaces = a; }
 427 
 428   Array<InstanceKlass*>* transitive_interfaces() const     { return _transitive_interfaces; }
 429   void set_transitive_interfaces(Array<InstanceKlass*>* a) {
 430     guarantee(_transitive_interfaces == NULL || a == NULL, "Just checking");
 431     _transitive_interfaces = a;
 432   }
 433 
 434  private:
 435   friend class fieldDescriptor;
 436   FieldInfo* field(int index) const { return FieldInfo::from_field_array(_fields, index); }
 437 
 438  public:
 439   int     field_offset      (int index) const { return field(index)->offset(); }
 440   int     field_access_flags(int index) const { return field(index)->access_flags(); }
 441   Symbol* field_name        (int index) const { return field(index)->name(constants()); }
 442   Symbol* field_signature   (int index) const { return field(index)->signature(constants()); }


 443 
 444   // Number of Java declared fields
 445   int java_fields_count() const           { return (int)_java_fields_count; }
 446 
 447   Array<u2>* fields() const            { return _fields; }
 448   void set_fields(Array<u2>* f, u2 java_fields_count) {
 449     guarantee(_fields == NULL || f == NULL, "Just checking");
 450     _fields = f;
 451     _java_fields_count = java_fields_count;
 452   }
 453 



 454   // inner classes
 455   Array<u2>* inner_classes() const       { return _inner_classes; }
 456   void set_inner_classes(Array<u2>* f)   { _inner_classes = f; }
 457 
 458   // nest members
 459   Array<u2>* nest_members() const     { return _nest_members; }
 460   void set_nest_members(Array<u2>* m) { _nest_members = m; }
 461 
 462   // nest-host index
 463   jushort nest_host_index() const { return _nest_host_index; }
 464   void set_nest_host_index(u2 i)  { _nest_host_index = i; }
 465   // dynamic nest member support
 466   void set_nest_host(InstanceKlass* host);
 467 
 468   // record components
 469   Array<RecordComponent*>* record_components() const { return _record_components; }
 470   void set_record_components(Array<RecordComponent*>* record_components) {
 471     _record_components = record_components;
 472   }
 473   bool is_record() const;

 551   bool is_rewritten() const                { return (_misc_flags & _misc_rewritten) != 0; }
 552 
 553   // is this a sealed class
 554   bool is_sealed() const;
 555 
 556   // defineClass specified verification
 557   bool should_verify_class() const         {
 558     return (_misc_flags & _misc_should_verify_class) != 0;
 559   }
 560   void set_should_verify_class(bool value) {
 561     assert(!should_verify_class(), "set once");
 562     if (value) {
 563       _misc_flags |= _misc_should_verify_class;
 564     }
 565   }
 566 
 567   // marking
 568   bool is_marked_dependent() const         { return _is_marked_dependent; }
 569   void set_is_marked_dependent(bool value) { _is_marked_dependent = value; }
 570 




 571   // initialization (virtuals from Klass)
 572   bool should_be_initialized() const;  // means that initialize should be called
 573   void initialize(TRAPS);
 574   void link_class(TRAPS);
 575   bool link_class_or_fail(TRAPS); // returns false on failure
 576   void rewrite_class(TRAPS);
 577   void link_methods(TRAPS);
 578   Method* class_initializer() const;
 579 
 580   // set the class to initialized if no static initializer is present
 581   void eager_initialize(Thread *thread);
 582 
 583   // reference type
 584   ReferenceType reference_type() const     { return (ReferenceType)_reference_type; }
 585   void set_reference_type(ReferenceType t) {
 586     assert(t == (u1)t, "overflow");
 587     _reference_type = (u1)t;
 588   }
 589 
 590   // this class cp index

 787   void set_has_resolved_methods() {
 788     _access_flags.set_has_resolved_methods();
 789   }
 790 private:
 791 
 792   void set_kind(unsigned kind) {
 793     _kind = (u1)kind;
 794   }
 795 
 796   bool is_kind(unsigned desired) const {
 797     return _kind == (u1)desired;
 798   }
 799 
 800 public:
 801 
 802   // Other is anything that is not one of the more specialized kinds of InstanceKlass.
 803   bool is_other_instance_klass() const        { return is_kind(_kind_other); }
 804   bool is_reference_instance_klass() const    { return is_kind(_kind_reference); }
 805   bool is_mirror_instance_klass() const       { return is_kind(_kind_mirror); }
 806   bool is_class_loader_instance_klass() const { return is_kind(_kind_class_loader); }

 807 
 808 #if INCLUDE_JVMTI
 809 
 810   void init_previous_versions() {
 811     _previous_versions = NULL;
 812   }
 813 
 814  private:
 815   static bool  _has_previous_versions;
 816  public:
 817   static void purge_previous_versions(InstanceKlass* ik) {
 818     if (ik->has_been_redefined()) {
 819       ik->purge_previous_version_list();
 820     }
 821   }
 822 
 823   static bool has_previous_versions_and_reset();
 824   static bool has_previous_versions() { return _has_previous_versions; }
 825 
 826   // JVMTI: Support for caching a class file before it is modified by an agent that can do retransformation

 954 
 955   // On-stack replacement support
 956   nmethod* osr_nmethods_head() const         { return _osr_nmethods_head; };
 957   void set_osr_nmethods_head(nmethod* h)     { _osr_nmethods_head = h; };
 958   void add_osr_nmethod(nmethod* n);
 959   bool remove_osr_nmethod(nmethod* n);
 960   int mark_osr_nmethods(const Method* m);
 961   nmethod* lookup_osr_nmethod(const Method* m, int bci, int level, bool match_level) const;
 962 
 963 #if INCLUDE_JVMTI
 964   // Breakpoint support (see methods on Method* for details)
 965   BreakpointInfo* breakpoints() const       { return _breakpoints; };
 966   void set_breakpoints(BreakpointInfo* bps) { _breakpoints = bps; };
 967 #endif
 968 
 969   // support for stub routines
 970   static ByteSize init_state_offset()  { return in_ByteSize(offset_of(InstanceKlass, _init_state)); }
 971   JFR_ONLY(DEFINE_KLASS_TRACE_ID_OFFSET;)
 972   static ByteSize init_thread_offset() { return in_ByteSize(offset_of(InstanceKlass, _init_thread)); }
 973 



 974   // subclass/subinterface checks
 975   bool implements_interface(Klass* k) const;
 976   bool is_same_or_direct_interface(Klass* k) const;
 977 
 978 #ifdef ASSERT
 979   // check whether this class or one of its superclasses was redefined
 980   bool has_redefined_this_or_super() const;
 981 #endif
 982 
 983   // Access to the implementor of an interface.
 984   InstanceKlass* implementor() const;
 985   void set_implementor(InstanceKlass* ik);
 986   int  nof_implementors() const;
 987   void add_implementor(InstanceKlass* ik);  // ik is a new class that implements this interface
 988   void init_implementor();           // initialize
 989 
 990   // link this class into the implementors list of every interface it implements
 991   void process_interfaces();
 992 
 993   // virtual operations from Klass

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

1030     return align_metadata_size(header_size() +
1031            vtable_length +
1032            itable_length +
1033            nonstatic_oop_map_size +
1034            (is_interface ? (int)sizeof(Klass*)/wordSize : 0));


1035   }
1036 
1037   int size() const                    { return size(vtable_length(),
1038                                                itable_length(),
1039                                                nonstatic_oop_map_size(),
1040                                                is_interface());


1041   }
1042 
1043 
1044   inline intptr_t* start_of_itable() const;
1045   inline intptr_t* end_of_itable() const;
1046   inline int itable_offset_in_words() const;
1047   inline oop static_field_base_raw();

1048 
1049   inline OopMapBlock* start_of_nonstatic_oop_maps() const;
1050   inline Klass** end_of_nonstatic_oop_maps() const;
1051 
1052   inline InstanceKlass* volatile* adr_implementor() const;
1053 






1054   // Use this to return the size of an instance in heap words:
1055   int size_helper() const {
1056     return layout_helper_to_size_helper(layout_helper());
1057   }
1058 
1059   // This bit is initialized in classFileParser.cpp.
1060   // It is false under any of the following conditions:
1061   //  - the class is abstract (including any interface)
1062   //  - the class has a finalizer (if !RegisterFinalizersAtInit)
1063   //  - the class size is larger than FastAllocateSizeLimit
1064   //  - the class is java/lang/Class, which cannot be allocated directly
1065   bool can_be_fastpath_allocated() const {
1066     return !layout_helper_needs_slow_path(layout_helper());
1067   }
1068 
1069   // Java itable
1070   klassItable itable() const;        // return klassItable wrapper
1071   Method* method_at_itable(InstanceKlass* holder, int index, TRAPS);
1072   Method* method_at_itable_or_null(InstanceKlass* holder, int index, bool& itable_entry_found);
1073   int vtable_index_of_interface_method(Method* method);
1074 
1075 #if INCLUDE_JVMTI

1089   static void deallocate_methods(ClassLoaderData* loader_data,
1090                                  Array<Method*>* methods);
1091   void static deallocate_interfaces(ClassLoaderData* loader_data,
1092                                     const Klass* super_klass,
1093                                     Array<InstanceKlass*>* local_interfaces,
1094                                     Array<InstanceKlass*>* transitive_interfaces);
1095   void static deallocate_record_components(ClassLoaderData* loader_data,
1096                                            Array<RecordComponent*>* record_component);
1097 
1098   // The constant pool is on stack if any of the methods are executing or
1099   // referenced by handles.
1100   bool on_stack() const { return _constants->on_stack(); }
1101 
1102   // callbacks for actions during class unloading
1103   static void unload_class(InstanceKlass* ik);
1104 
1105   virtual void release_C_heap_structures(bool release_constant_pool = true);
1106 
1107   // Naming
1108   const char* signature_name() const;

1109 
1110   // Oop fields (and metadata) iterators
1111   //
1112   // The InstanceKlass iterators also visits the Object's klass.
1113 
1114   // Forward iteration
1115  public:
1116   // Iterate over all oop fields in the oop maps.
1117   template <typename T, class OopClosureType>
1118   inline void oop_oop_iterate_oop_maps(oop obj, OopClosureType* closure);
1119 
1120   // Iterate over all oop fields and metadata.
1121   template <typename T, class OopClosureType>
1122   inline void oop_oop_iterate(oop obj, OopClosureType* closure);
1123 
1124   // Iterate over all oop fields in one oop map.
1125   template <typename T, class OopClosureType>
1126   inline void oop_oop_iterate_oop_map(OopMapBlock* map, oop obj, OopClosureType* closure);
1127 
1128 

1211                            PrivateLookupMode private_mode) const;
1212 
1213   static Method* find_method_impl(const Array<Method*>* methods,
1214                                   const Symbol* name,
1215                                   const Symbol* signature,
1216                                   OverpassLookupMode overpass_mode,
1217                                   StaticLookupMode static_mode,
1218                                   PrivateLookupMode private_mode);
1219 
1220 #if INCLUDE_JVMTI
1221   // RedefineClasses support
1222   void link_previous_versions(InstanceKlass* pv) { _previous_versions = pv; }
1223   void mark_newly_obsolete_methods(Array<Method*>* old_methods, int emcp_method_count);
1224 #endif
1225   // log class name to classlist
1226   void log_to_classlist() const;
1227 public:
1228   // CDS support - remove and restore oops from metadata. Oops are not shared.
1229   virtual void remove_unshareable_info();
1230   virtual void remove_java_mirror();
1231   void restore_unshareable_info(ClassLoaderData* loader_data, Handle protection_domain, PackageEntry* pkg_entry, TRAPS);
1232   void init_shared_package_entry();
1233   bool can_be_verified_at_dumptime() const;
1234 
1235   jint compute_modifier_flags() const;
1236 
1237 public:
1238   // JVMTI support
1239   jint jvmti_class_status() const;
1240 
1241   virtual void metaspace_pointers_do(MetaspaceClosure* iter);
1242 
1243  public:
1244   // Printing
1245   void print_on(outputStream* st) const;
1246   void print_value_on(outputStream* st) const;
1247 
1248   void oop_print_value_on(oop obj, outputStream* st);
1249 
1250   void oop_print_on      (oop obj, outputStream* st);
1251 

   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 #ifndef SHARE_OOPS_INSTANCEKLASS_HPP
  26 #define SHARE_OOPS_INSTANCEKLASS_HPP
  27 
  28 #include "code/vmreg.hpp"
  29 #include "memory/referenceType.hpp"
  30 #include "oops/annotations.hpp"
  31 #include "oops/constMethod.hpp"
  32 #include "oops/fieldInfo.hpp"
  33 #include "oops/instanceOop.hpp"
  34 #include "runtime/handles.hpp"
  35 #include "utilities/accessFlags.hpp"
  36 #include "utilities/align.hpp"
  37 #include "utilities/macros.hpp"
  38 #if INCLUDE_JFR
  39 #include "jfr/support/jfrKlassExtension.hpp"
  40 #endif
  41 
  42 class klassItable;
  43 class RecordComponent;
  44 
  45 // An InstanceKlass is the VM level representation of a Java class.
  46 // It contains all information needed for at class at execution runtime.
  47 
  48 //  InstanceKlass embedded field layout (after declared fields):
  49 //    [EMBEDDED Java vtable             ] size in words = vtable_len
  50 //    [EMBEDDED nonstatic oop-map blocks] size in words = nonstatic_oop_map_size
  51 //      The embedded nonstatic oop-map blocks are short pairs (offset, length)
  52 //      indicating where oops are located in instances of this klass.
  53 //    [EMBEDDED implementor of the interface] only exist for interface
  54 //    [EMBEDDED inline_type_field_klasses] only if has_inline_fields() == true
  55 //    [EMBEDDED InlineKlassFixedBlock] only if is an InlineKlass instance
  56 
  57 
  58 // forward declaration for class -- see below for definition
  59 #if INCLUDE_JVMTI
  60 class BreakpointInfo;
  61 #endif
  62 class ClassFileParser;
  63 class ClassFileStream;
  64 class KlassDepChange;
  65 class DependencyContext;
  66 class fieldDescriptor;
  67 class jniIdMapBase;
  68 class JNIid;
  69 class JvmtiCachedClassFieldMap;
  70 class nmethodBucket;
  71 class OopMapCache;
  72 class BufferedInlineTypeBlob;
  73 class InterpreterOopMap;
  74 class PackageEntry;
  75 class ModuleEntry;
  76 
  77 // This is used in iterators below.
  78 class FieldClosure: public StackObj {
  79 public:
  80   virtual void do_field(fieldDescriptor* fd) = 0;
  81 };
  82 
  83 // Print fields.
  84 // If "obj" argument to constructor is NULL, prints static fields, otherwise prints non-static fields.
  85 class FieldPrinter: public FieldClosure {
  86    oop _obj;
  87    outputStream* _st;
  88  public:
  89    FieldPrinter(outputStream* st, oop obj = NULL) : _obj(obj), _st(st) {}
  90    void do_field(fieldDescriptor* fd);
  91 };
  92 

 113     return another_offset == end_offset();
 114   }
 115 
 116   // sizeof(OopMapBlock) in words.
 117   static const int size_in_words() {
 118     return align_up((int)sizeof(OopMapBlock), wordSize) >>
 119       LogBytesPerWord;
 120   }
 121 
 122   static int compare_offset(const OopMapBlock* a, const OopMapBlock* b) {
 123     return a->offset() - b->offset();
 124   }
 125 
 126  private:
 127   int  _offset;
 128   uint _count;
 129 };
 130 
 131 struct JvmtiCachedClassFileData;
 132 
 133 class SigEntry;
 134 
 135 class InlineKlassFixedBlock {
 136   Array<SigEntry>** _extended_sig;
 137   Array<VMRegPair>** _return_regs;
 138   address* _pack_handler;
 139   address* _pack_handler_jobject;
 140   address* _unpack_handler;
 141   int* _default_value_offset;
 142   ArrayKlass** _null_free_inline_array_klasses;
 143   int _alignment;
 144   int _first_field_offset;
 145   int _exact_size_in_bytes;
 146 
 147   friend class InlineKlass;
 148 };
 149 
 150 class InstanceKlass: public Klass {
 151   friend class VMStructs;
 152   friend class JVMCIVMStructs;
 153   friend class ClassFileParser;
 154   friend class CompileReplay;
 155   friend class TemplateTable;
 156 
 157  public:
 158   static const KlassID ID = InstanceKlassID;
 159 
 160  protected:
 161   InstanceKlass(const ClassFileParser& parser, unsigned kind, KlassID id = ID);
 162 
 163  public:
 164   InstanceKlass() { assert(DumpSharedSpaces || UseSharedSpaces, "only for CDS"); }
 165 
 166   // See "The Java Virtual Machine Specification" section 2.16.2-5 for a detailed description
 167   // of the class loading & initialization procedure, and the use of the states.
 168   enum ClassState {
 169     allocated,                          // allocated (but not yet linked)
 170     loaded,                             // loaded and inserted in class hierarchy (but not linked yet)
 171     linked,                             // successfully linked/verified (but not initialized yet)
 172     being_initialized,                  // currently running class initializer
 173     fully_initialized,                  // initialized (successful final state)
 174     initialization_error                // error happened during initialization
 175   };
 176 
 177  private:
 178   static InstanceKlass* allocate_instance_klass(const ClassFileParser& parser, TRAPS);
 179 
 180  protected:
 181   // If you add a new field that points to any metaspace object, you
 182   // must add this field to InstanceKlass::metaspace_pointers_do().
 183 
 184   // Annotations for this class
 185   Annotations*    _annotations;
 186   // Package this class is defined in
 187   PackageEntry*   _package_entry;
 188   // Array classes holding elements of this class.
 189   ArrayKlass* volatile _array_klasses;
 190   // Constant pool for this class.
 191   ConstantPool* _constants;
 192   // The InnerClasses attribute and EnclosingMethod attribute. The
 193   // _inner_classes is an array of shorts. If the class has InnerClasses
 194   // attribute, then the _inner_classes array begins with 4-tuples of shorts
 195   // [inner_class_info_index, outer_class_info_index,
 196   // inner_name_index, inner_class_access_flags] for the InnerClasses
 197   // attribute. If the EnclosingMethod attribute exists, it occupies the
 198   // last two shorts [class_index, method_index] of the array. If only
 199   // the InnerClasses attribute exists, the _inner_classes array length is
 200   // number_of_inner_classes * 4. If the class has both InnerClasses
 201   // and EnclosingMethod attributes the _inner_classes array length is
 202   // number_of_inner_classes * 4 + enclosing_method_attribute_size.
 203   Array<jushort>* _inner_classes;
 204 
 205   // The NestMembers attribute. An array of shorts, where each is a
 206   // class info index for the class that is a nest member. This data
 207   // has not been validated.
 208   Array<jushort>* _nest_members;
 209 

 234   int             _itable_len;              // length of Java itable (in words)
 235 
 236   // The NestHost attribute. The class info index for the class
 237   // that is the nest-host of this class. This data has not been validated.
 238   u2              _nest_host_index;
 239   u2              _this_class_index;        // constant pool entry
 240   u2              _static_oop_field_count;  // number of static oop fields in this klass
 241   u2              _java_fields_count;       // The number of declared Java fields
 242 
 243   volatile u2     _idnum_allocated_count;   // JNI/JVMTI: increments with the addition of methods, old ids don't change
 244 
 245   // _is_marked_dependent can be set concurrently, thus cannot be part of the
 246   // _misc_flags.
 247   bool            _is_marked_dependent;     // used for marking during flushing and deoptimization
 248 
 249   // Class states are defined as ClassState (see above).
 250   // Place the _init_state here to utilize the unused 2-byte after
 251   // _idnum_allocated_count.
 252   u1              _init_state;              // state of class
 253 
 254   // This can be used to quickly discriminate among the five kinds of
 255   // InstanceKlass. This should be an enum (?)
 256   static const unsigned _kind_other        = 0; // concrete InstanceKlass
 257   static const unsigned _kind_reference    = 1; // InstanceRefKlass
 258   static const unsigned _kind_class_loader = 2; // InstanceClassLoaderKlass
 259   static const unsigned _kind_mirror       = 3; // InstanceMirrorKlass
 260   static const unsigned _kind_inline_type  = 4; // InlineKlass
 261 
 262   u1              _reference_type;                // reference type
 263   u1              _kind;                          // kind of InstanceKlass
 264 
 265   enum {
 266     _misc_rewritten                           = 1 << 0,  // methods rewritten.
 267     _misc_has_nonstatic_fields                = 1 << 1,  // for sizing with UseCompressedOops
 268     _misc_should_verify_class                 = 1 << 2,  // allow caching of preverification
 269     _misc_unused                              = 1 << 3,  // not currently used
 270     _misc_is_contended                        = 1 << 4,  // marked with contended annotation
 271     _misc_has_nonstatic_concrete_methods      = 1 << 5,  // class/superclass/implemented interfaces has non-static, concrete methods
 272     _misc_declares_nonstatic_concrete_methods = 1 << 6,  // directly declares non-static, concrete methods
 273     _misc_has_been_redefined                  = 1 << 7,  // class has been redefined
 274     _misc_shared_loading_failed               = 1 << 8,  // class has been loaded from shared archive
 275     _misc_is_scratch_class                    = 1 << 9,  // class is the redefined scratch class
 276     _misc_is_shared_boot_class                = 1 << 10, // defining class loader is boot class loader
 277     _misc_is_shared_platform_class            = 1 << 11, // defining class loader is platform class loader
 278     _misc_is_shared_app_class                 = 1 << 12, // defining class loader is app class loader
 279     _misc_has_contended_annotations           = 1 << 13, // has @Contended annotation
 280     _misc_has_inline_type_fields              = 1 << 14, // has inline fields and related embedded section is not empty
 281     _misc_is_empty_inline_type                = 1 << 15, // empty inline type (*)
 282     _misc_is_naturally_atomic                 = 1 << 16, // loaded/stored in one instruction
 283     _misc_is_declared_atomic                  = 1 << 17, // implements jl.NonTearable
 284     _misc_invalid_inline_super                = 1 << 18, // invalid super type for an inline type
 285     _misc_invalid_identity_super              = 1 << 19, // invalid super type for an identity type
 286   };
 287 
 288   // (*) An inline type is considered empty if it contains no non-static fields or
 289   // if it contains only empty inline fields. Note that JITs have a slightly different
 290   // definition: empty inline fields must be flattened otherwise the container won't
 291   // be considered empty
 292 
 293   u2 shared_loader_type_bits() const {
 294     return _misc_is_shared_boot_class|_misc_is_shared_platform_class|_misc_is_shared_app_class;
 295   }
 296   u4              _misc_flags;           // There is more space in access_flags for more flags.
 297 
 298   Thread*         _init_thread;          // Pointer to current thread doing initialization (to handle recursive initialization)
 299   OopMapCache*    volatile _oop_map_cache;   // OopMapCache for all methods in the klass (allocated lazily)
 300   JNIid*          _jni_ids;              // First JNI identifier for static fields in this class
 301   jmethodID*      volatile _methods_jmethod_ids;  // jmethodIDs corresponding to method_idnum, or NULL if none
 302   nmethodBucket*  volatile _dep_context;          // packed DependencyContext structure
 303   uint64_t        volatile _dep_context_last_cleaned;
 304   nmethod*        _osr_nmethods_head;    // Head of list of on-stack replacement nmethods for this class
 305 #if INCLUDE_JVMTI
 306   BreakpointInfo* _breakpoints;          // bpt lists, managed by Method*
 307   // Linked instanceKlasses of previous versions
 308   InstanceKlass* _previous_versions;
 309   // JVMTI fields can be moved to their own structure - see 6315920
 310   // JVMTI: cached class file, before retransformable agent modified it in CFLH
 311   JvmtiCachedClassFileData* _cached_class_file;
 312 #endif
 313 
 314 #if INCLUDE_JVMTI
 315   JvmtiCachedClassFieldMap* _jvmti_cached_class_field_map;  // JVMTI: used during heap iteration
 316 #endif

 328   // Int array containing the original order of method in the class file (for JVMTI).
 329   Array<int>*     _method_ordering;
 330   // Int array containing the vtable_indices for default_methods
 331   // offset matches _default_methods offset
 332   Array<int>*     _default_vtable_indices;
 333 
 334   // Instance and static variable information, starts with 6-tuples of shorts
 335   // [access, name index, sig index, initval index, low_offset, high_offset]
 336   // for all fields, followed by the generic signature data at the end of
 337   // the array. Only fields with generic signature attributes have the generic
 338   // signature data set in the array. The fields array looks like following:
 339   //
 340   // f1: [access, name index, sig index, initial value index, low_offset, high_offset]
 341   // f2: [access, name index, sig index, initial value index, low_offset, high_offset]
 342   //      ...
 343   // fn: [access, name index, sig index, initial value index, low_offset, high_offset]
 344   //     [generic signature index]
 345   //     [generic signature index]
 346   //     ...
 347   Array<u2>*      _fields;
 348   const Klass**   _inline_type_field_klasses; // For "inline class" fields, NULL if none present
 349   Array<u2>* _preload_classes;
 350   const InlineKlassFixedBlock* _adr_inlineklass_fixed_block;
 351 
 352   // embedded Java vtable follows here
 353   // embedded Java itables follows here
 354   // embedded static fields follows here
 355   // embedded nonstatic oop-map blocks follows here
 356   // embedded implementor of this interface follows here
 357   //   The embedded implementor only exists if the current klass is an
 358   //   interface. The possible values of the implementor fall into following
 359   //   three cases:
 360   //     NULL: no implementor.
 361   //     A Klass* that's not itself: one implementor.
 362   //     Itself: more than one implementors.
 363   //
 364 
 365   friend class SystemDictionary;
 366 
 367   static bool _disable_method_binary_search;
 368 
 369   // Controls finalizer registration
 370   static bool _finalization_enabled;

 400   }
 401 
 402   void set_shared_loading_failed() {
 403     _misc_flags |= _misc_shared_loading_failed;
 404   }
 405 
 406   void set_shared_class_loader_type(s2 loader_type);
 407 
 408   void assign_class_loader_type();
 409 
 410   bool has_nonstatic_fields() const        {
 411     return (_misc_flags & _misc_has_nonstatic_fields) != 0;
 412   }
 413   void set_has_nonstatic_fields(bool b)    {
 414     assert(!has_nonstatic_fields(), "set once");
 415     if (b) {
 416       _misc_flags |= _misc_has_nonstatic_fields;
 417     }
 418   }
 419 
 420   bool has_inline_type_fields() const          {
 421     return (_misc_flags & _misc_has_inline_type_fields) != 0;
 422   }
 423   void set_has_inline_type_fields()  {
 424     _misc_flags |= _misc_has_inline_type_fields;
 425   }
 426 
 427   bool is_empty_inline_type() const {
 428     return (_misc_flags & _misc_is_empty_inline_type) != 0;
 429   }
 430   void set_is_empty_inline_type() {
 431     _misc_flags |= _misc_is_empty_inline_type;
 432   }
 433 
 434   // Note:  The naturally_atomic property only applies to
 435   // inline classes; it is never true on identity classes.
 436   // The bit is placed on instanceKlass for convenience.
 437 
 438   // Query if h/w provides atomic load/store for instances.
 439   bool is_naturally_atomic() const {
 440     return (_misc_flags & _misc_is_naturally_atomic) != 0;
 441   }
 442   // Initialized in the class file parser, not changed later.
 443   void set_is_naturally_atomic() {
 444     _misc_flags |= _misc_is_naturally_atomic;
 445   }
 446 
 447   // Query if this class implements jl.NonTearable or was
 448   // mentioned in the JVM option ForceNonTearable.
 449   // This bit can occur anywhere, but is only significant
 450   // for inline classes *and* their super types.
 451   // It inherits from supers along with NonTearable.
 452   bool is_declared_atomic() const {
 453     return (_misc_flags & _misc_is_declared_atomic) != 0;
 454   }
 455   // Initialized in the class file parser, not changed later.
 456   void set_is_declared_atomic() {
 457     _misc_flags |= _misc_is_declared_atomic;
 458   }
 459 
 460   // Query if class is an invalid super class for an inline type.
 461   bool invalid_inline_super() const {
 462     return (_misc_flags & _misc_invalid_inline_super) != 0;
 463   }
 464   // Initialized in the class file parser, not changed later.
 465   void set_invalid_inline_super() {
 466     _misc_flags |= _misc_invalid_inline_super;
 467   }
 468   // Query if class is an invalid super class for an identity type.
 469   bool invalid_identity_super() const {
 470     return (_misc_flags & _misc_invalid_identity_super) != 0;
 471   }
 472   // Initialized in the class file parser, not changed later.
 473   void set_invalid_identity_super() {
 474     _misc_flags |= _misc_invalid_identity_super;
 475   }
 476 
 477   // field sizes
 478   int nonstatic_field_size() const         { return _nonstatic_field_size; }
 479   void set_nonstatic_field_size(int size)  { _nonstatic_field_size = size; }
 480 
 481   int static_field_size() const            { return _static_field_size; }
 482   void set_static_field_size(int size)     { _static_field_size = size; }
 483 
 484   int static_oop_field_count() const       { return (int)_static_oop_field_count; }
 485   void set_static_oop_field_count(u2 size) { _static_oop_field_count = size; }
 486 
 487   // Java itable
 488   int  itable_length() const               { return _itable_len; }
 489   void set_itable_length(int len)          { _itable_len = len; }
 490 
 491   // array klasses
 492   ArrayKlass* array_klasses() const     { return _array_klasses; }
 493   inline ArrayKlass* array_klasses_acquire() const; // load with acquire semantics
 494   inline void release_set_array_klasses(ArrayKlass* k); // store with release semantics
 495 
 496   // methods
 497   Array<Method*>* methods() const          { return _methods; }
 498   void set_methods(Array<Method*>* a)      { _methods = a; }
 499   Method* method_with_idnum(int idnum);
 500   Method* method_with_orig_idnum(int idnum);
 501   Method* method_with_orig_idnum(int idnum, int version);
 502 
 503   // method ordering
 504   Array<int>* method_ordering() const     { return _method_ordering; }
 505   void set_method_ordering(Array<int>* m) { _method_ordering = m; }
 506   void copy_method_ordering(const intArray* m, TRAPS);
 507 
 508   // default_methods
 509   Array<Method*>* default_methods() const  { return _default_methods; }
 510   void set_default_methods(Array<Method*>* a) { _default_methods = a; }
 511 
 512   // default method vtable_indices
 513   Array<int>* default_vtable_indices() const { return _default_vtable_indices; }
 514   void set_default_vtable_indices(Array<int>* v) { _default_vtable_indices = v; }

 518   Array<InstanceKlass*>* local_interfaces() const          { return _local_interfaces; }
 519   void set_local_interfaces(Array<InstanceKlass*>* a)      {
 520     guarantee(_local_interfaces == NULL || a == NULL, "Just checking");
 521     _local_interfaces = a; }
 522 
 523   Array<InstanceKlass*>* transitive_interfaces() const     { return _transitive_interfaces; }
 524   void set_transitive_interfaces(Array<InstanceKlass*>* a) {
 525     guarantee(_transitive_interfaces == NULL || a == NULL, "Just checking");
 526     _transitive_interfaces = a;
 527   }
 528 
 529  private:
 530   friend class fieldDescriptor;
 531   FieldInfo* field(int index) const { return FieldInfo::from_field_array(_fields, index); }
 532 
 533  public:
 534   int     field_offset      (int index) const { return field(index)->offset(); }
 535   int     field_access_flags(int index) const { return field(index)->access_flags(); }
 536   Symbol* field_name        (int index) const { return field(index)->name(constants()); }
 537   Symbol* field_signature   (int index) const { return field(index)->signature(constants()); }
 538   bool    field_is_inlined(int index) const { return field(index)->is_inlined(); }
 539   bool    field_is_null_free_inline_type(int index) const;
 540 
 541   // Number of Java declared fields
 542   int java_fields_count() const           { return (int)_java_fields_count; }
 543 
 544   Array<u2>* fields() const            { return _fields; }
 545   void set_fields(Array<u2>* f, u2 java_fields_count) {
 546     guarantee(_fields == NULL || f == NULL, "Just checking");
 547     _fields = f;
 548     _java_fields_count = java_fields_count;
 549   }
 550 
 551   Array<u2>* preload_classes() const { return _preload_classes; }
 552   void set_preload_classes(Array<u2>* c) { _preload_classes = c; }
 553 
 554   // inner classes
 555   Array<u2>* inner_classes() const       { return _inner_classes; }
 556   void set_inner_classes(Array<u2>* f)   { _inner_classes = f; }
 557 
 558   // nest members
 559   Array<u2>* nest_members() const     { return _nest_members; }
 560   void set_nest_members(Array<u2>* m) { _nest_members = m; }
 561 
 562   // nest-host index
 563   jushort nest_host_index() const { return _nest_host_index; }
 564   void set_nest_host_index(u2 i)  { _nest_host_index = i; }
 565   // dynamic nest member support
 566   void set_nest_host(InstanceKlass* host);
 567 
 568   // record components
 569   Array<RecordComponent*>* record_components() const { return _record_components; }
 570   void set_record_components(Array<RecordComponent*>* record_components) {
 571     _record_components = record_components;
 572   }
 573   bool is_record() const;

 651   bool is_rewritten() const                { return (_misc_flags & _misc_rewritten) != 0; }
 652 
 653   // is this a sealed class
 654   bool is_sealed() const;
 655 
 656   // defineClass specified verification
 657   bool should_verify_class() const         {
 658     return (_misc_flags & _misc_should_verify_class) != 0;
 659   }
 660   void set_should_verify_class(bool value) {
 661     assert(!should_verify_class(), "set once");
 662     if (value) {
 663       _misc_flags |= _misc_should_verify_class;
 664     }
 665   }
 666 
 667   // marking
 668   bool is_marked_dependent() const         { return _is_marked_dependent; }
 669   void set_is_marked_dependent(bool value) { _is_marked_dependent = value; }
 670 
 671   static ByteSize kind_offset() { return in_ByteSize(offset_of(InstanceKlass, _kind)); }
 672   static ByteSize misc_flags_offset() { return in_ByteSize(offset_of(InstanceKlass, _misc_flags)); }
 673   static u4 misc_flag_is_empty_inline_type() { return _misc_is_empty_inline_type; }
 674 
 675   // initialization (virtuals from Klass)
 676   bool should_be_initialized() const;  // means that initialize should be called
 677   void initialize(TRAPS);
 678   void link_class(TRAPS);
 679   bool link_class_or_fail(TRAPS); // returns false on failure
 680   void rewrite_class(TRAPS);
 681   void link_methods(TRAPS);
 682   Method* class_initializer() const;
 683 
 684   // set the class to initialized if no static initializer is present
 685   void eager_initialize(Thread *thread);
 686 
 687   // reference type
 688   ReferenceType reference_type() const     { return (ReferenceType)_reference_type; }
 689   void set_reference_type(ReferenceType t) {
 690     assert(t == (u1)t, "overflow");
 691     _reference_type = (u1)t;
 692   }
 693 
 694   // this class cp index

 891   void set_has_resolved_methods() {
 892     _access_flags.set_has_resolved_methods();
 893   }
 894 private:
 895 
 896   void set_kind(unsigned kind) {
 897     _kind = (u1)kind;
 898   }
 899 
 900   bool is_kind(unsigned desired) const {
 901     return _kind == (u1)desired;
 902   }
 903 
 904 public:
 905 
 906   // Other is anything that is not one of the more specialized kinds of InstanceKlass.
 907   bool is_other_instance_klass() const        { return is_kind(_kind_other); }
 908   bool is_reference_instance_klass() const    { return is_kind(_kind_reference); }
 909   bool is_mirror_instance_klass() const       { return is_kind(_kind_mirror); }
 910   bool is_class_loader_instance_klass() const { return is_kind(_kind_class_loader); }
 911   bool is_inline_type_klass()           const { return is_kind(_kind_inline_type); }
 912 
 913 #if INCLUDE_JVMTI
 914 
 915   void init_previous_versions() {
 916     _previous_versions = NULL;
 917   }
 918 
 919  private:
 920   static bool  _has_previous_versions;
 921  public:
 922   static void purge_previous_versions(InstanceKlass* ik) {
 923     if (ik->has_been_redefined()) {
 924       ik->purge_previous_version_list();
 925     }
 926   }
 927 
 928   static bool has_previous_versions_and_reset();
 929   static bool has_previous_versions() { return _has_previous_versions; }
 930 
 931   // JVMTI: Support for caching a class file before it is modified by an agent that can do retransformation

1059 
1060   // On-stack replacement support
1061   nmethod* osr_nmethods_head() const         { return _osr_nmethods_head; };
1062   void set_osr_nmethods_head(nmethod* h)     { _osr_nmethods_head = h; };
1063   void add_osr_nmethod(nmethod* n);
1064   bool remove_osr_nmethod(nmethod* n);
1065   int mark_osr_nmethods(const Method* m);
1066   nmethod* lookup_osr_nmethod(const Method* m, int bci, int level, bool match_level) const;
1067 
1068 #if INCLUDE_JVMTI
1069   // Breakpoint support (see methods on Method* for details)
1070   BreakpointInfo* breakpoints() const       { return _breakpoints; };
1071   void set_breakpoints(BreakpointInfo* bps) { _breakpoints = bps; };
1072 #endif
1073 
1074   // support for stub routines
1075   static ByteSize init_state_offset()  { return in_ByteSize(offset_of(InstanceKlass, _init_state)); }
1076   JFR_ONLY(DEFINE_KLASS_TRACE_ID_OFFSET;)
1077   static ByteSize init_thread_offset() { return in_ByteSize(offset_of(InstanceKlass, _init_thread)); }
1078 
1079   static ByteSize inline_type_field_klasses_offset() { return in_ByteSize(offset_of(InstanceKlass, _inline_type_field_klasses)); }
1080   static ByteSize adr_inlineklass_fixed_block_offset() { return in_ByteSize(offset_of(InstanceKlass, _adr_inlineklass_fixed_block)); }
1081 
1082   // subclass/subinterface checks
1083   bool implements_interface(Klass* k) const;
1084   bool is_same_or_direct_interface(Klass* k) const;
1085 
1086 #ifdef ASSERT
1087   // check whether this class or one of its superclasses was redefined
1088   bool has_redefined_this_or_super() const;
1089 #endif
1090 
1091   // Access to the implementor of an interface.
1092   InstanceKlass* implementor() const;
1093   void set_implementor(InstanceKlass* ik);
1094   int  nof_implementors() const;
1095   void add_implementor(InstanceKlass* ik);  // ik is a new class that implements this interface
1096   void init_implementor();           // initialize
1097 
1098   // link this class into the implementors list of every interface it implements
1099   void process_interfaces();
1100 
1101   // virtual operations from Klass

1117 
1118   static InstanceKlass* cast(Klass* k) {
1119     return const_cast<InstanceKlass*>(cast(const_cast<const Klass*>(k)));
1120   }
1121 
1122   static const InstanceKlass* cast(const Klass* k) {
1123     assert(k != NULL, "k should not be null");
1124     assert(k->is_instance_klass(), "cast to InstanceKlass");
1125     return static_cast<const InstanceKlass*>(k);
1126   }
1127 
1128   virtual InstanceKlass* java_super() const {
1129     return (super() == NULL) ? NULL : cast(super());
1130   }
1131 
1132   // Sizing (in words)
1133   static int header_size()            { return sizeof(InstanceKlass)/wordSize; }
1134 
1135   static int size(int vtable_length, int itable_length,
1136                   int nonstatic_oop_map_size,
1137                   bool is_interface,
1138                   int java_fields, bool is_inline_type) {
1139     return align_metadata_size(header_size() +
1140            vtable_length +
1141            itable_length +
1142            nonstatic_oop_map_size +
1143            (is_interface ? (int)sizeof(Klass*)/wordSize : 0) +
1144            (java_fields * (int)sizeof(Klass*)/wordSize) +
1145            (is_inline_type ? (int)sizeof(InlineKlassFixedBlock) : 0));
1146   }
1147 
1148   int size() const                    { return size(vtable_length(),
1149                                                itable_length(),
1150                                                nonstatic_oop_map_size(),
1151                                                is_interface(),
1152                                                has_inline_type_fields() ? java_fields_count() : 0,
1153                                                is_inline_klass());
1154   }
1155 
1156 
1157   inline intptr_t* start_of_itable() const;
1158   inline intptr_t* end_of_itable() const;
1159   inline int itable_offset_in_words() const;
1160   inline oop static_field_base_raw();
1161   bool bounds_check(address addr, bool edge_ok = false, intptr_t size_in_bytes = -1) const PRODUCT_RETURN0;
1162 
1163   inline OopMapBlock* start_of_nonstatic_oop_maps() const;
1164   inline Klass** end_of_nonstatic_oop_maps() const;
1165 
1166   inline InstanceKlass* volatile* adr_implementor() const;
1167 
1168   inline address adr_inline_type_field_klasses() const;
1169   inline Klass* get_inline_type_field_klass(int idx) const;
1170   inline Klass* get_inline_type_field_klass_or_null(int idx) const;
1171   inline void set_inline_type_field_klass(int idx, Klass* k);
1172   inline void reset_inline_type_field_klass(int idx);
1173 
1174   // Use this to return the size of an instance in heap words:
1175   virtual int size_helper() const {
1176     return layout_helper_to_size_helper(layout_helper());
1177   }
1178 
1179   // This bit is initialized in classFileParser.cpp.
1180   // It is false under any of the following conditions:
1181   //  - the class is abstract (including any interface)
1182   //  - the class has a finalizer (if !RegisterFinalizersAtInit)
1183   //  - the class size is larger than FastAllocateSizeLimit
1184   //  - the class is java/lang/Class, which cannot be allocated directly
1185   bool can_be_fastpath_allocated() const {
1186     return !layout_helper_needs_slow_path(layout_helper());
1187   }
1188 
1189   // Java itable
1190   klassItable itable() const;        // return klassItable wrapper
1191   Method* method_at_itable(InstanceKlass* holder, int index, TRAPS);
1192   Method* method_at_itable_or_null(InstanceKlass* holder, int index, bool& itable_entry_found);
1193   int vtable_index_of_interface_method(Method* method);
1194 
1195 #if INCLUDE_JVMTI

1209   static void deallocate_methods(ClassLoaderData* loader_data,
1210                                  Array<Method*>* methods);
1211   void static deallocate_interfaces(ClassLoaderData* loader_data,
1212                                     const Klass* super_klass,
1213                                     Array<InstanceKlass*>* local_interfaces,
1214                                     Array<InstanceKlass*>* transitive_interfaces);
1215   void static deallocate_record_components(ClassLoaderData* loader_data,
1216                                            Array<RecordComponent*>* record_component);
1217 
1218   // The constant pool is on stack if any of the methods are executing or
1219   // referenced by handles.
1220   bool on_stack() const { return _constants->on_stack(); }
1221 
1222   // callbacks for actions during class unloading
1223   static void unload_class(InstanceKlass* ik);
1224 
1225   virtual void release_C_heap_structures(bool release_constant_pool = true);
1226 
1227   // Naming
1228   const char* signature_name() const;
1229   const char* signature_name_of_carrier(char c) const;
1230 
1231   // Oop fields (and metadata) iterators
1232   //
1233   // The InstanceKlass iterators also visits the Object's klass.
1234 
1235   // Forward iteration
1236  public:
1237   // Iterate over all oop fields in the oop maps.
1238   template <typename T, class OopClosureType>
1239   inline void oop_oop_iterate_oop_maps(oop obj, OopClosureType* closure);
1240 
1241   // Iterate over all oop fields and metadata.
1242   template <typename T, class OopClosureType>
1243   inline void oop_oop_iterate(oop obj, OopClosureType* closure);
1244 
1245   // Iterate over all oop fields in one oop map.
1246   template <typename T, class OopClosureType>
1247   inline void oop_oop_iterate_oop_map(OopMapBlock* map, oop obj, OopClosureType* closure);
1248 
1249 

1332                            PrivateLookupMode private_mode) const;
1333 
1334   static Method* find_method_impl(const Array<Method*>* methods,
1335                                   const Symbol* name,
1336                                   const Symbol* signature,
1337                                   OverpassLookupMode overpass_mode,
1338                                   StaticLookupMode static_mode,
1339                                   PrivateLookupMode private_mode);
1340 
1341 #if INCLUDE_JVMTI
1342   // RedefineClasses support
1343   void link_previous_versions(InstanceKlass* pv) { _previous_versions = pv; }
1344   void mark_newly_obsolete_methods(Array<Method*>* old_methods, int emcp_method_count);
1345 #endif
1346   // log class name to classlist
1347   void log_to_classlist() const;
1348 public:
1349   // CDS support - remove and restore oops from metadata. Oops are not shared.
1350   virtual void remove_unshareable_info();
1351   virtual void remove_java_mirror();
1352   virtual void restore_unshareable_info(ClassLoaderData* loader_data, Handle protection_domain, PackageEntry* pkg_entry, TRAPS);
1353   void init_shared_package_entry();
1354   bool can_be_verified_at_dumptime() const;
1355 
1356   jint compute_modifier_flags() const;
1357 
1358 public:
1359   // JVMTI support
1360   jint jvmti_class_status() const;
1361 
1362   virtual void metaspace_pointers_do(MetaspaceClosure* iter);
1363 
1364  public:
1365   // Printing
1366   void print_on(outputStream* st) const;
1367   void print_value_on(outputStream* st) const;
1368 
1369   void oop_print_value_on(oop obj, outputStream* st);
1370 
1371   void oop_print_on      (oop obj, outputStream* st);
1372 
< prev index next >