< 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_resolved_methods                = 1 << 13, // resolved methods table entries added for this class
 257     _misc_is_being_redefined                  = 1 << 14, // used for locking redefinition
 258     _misc_has_contended_annotations           = 1 << 15  // has @Contended annotation








 259   };






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

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



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

 359 
 360   void clear_shared_loading_failed() {
 361     _misc_flags &= ~_misc_shared_loading_failed;
 362   }
 363 
 364   void set_shared_class_loader_type(s2 loader_type);
 365 
 366   void assign_class_loader_type();
 367 
 368   bool has_nonstatic_fields() const        {
 369     return (_misc_flags & _misc_has_nonstatic_fields) != 0;
 370   }
 371   void set_has_nonstatic_fields(bool b)    {
 372     if (b) {
 373       _misc_flags |= _misc_has_nonstatic_fields;
 374     } else {
 375       _misc_flags &= ~_misc_has_nonstatic_fields;
 376     }
 377   }
 378 









































































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

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


 441 
 442   // Number of Java declared fields
 443   int java_fields_count() const           { return (int)_java_fields_count; }
 444 
 445   Array<u2>* fields() const            { return _fields; }
 446   void set_fields(Array<u2>* f, u2 java_fields_count) {
 447     guarantee(_fields == NULL || f == NULL, "Just checking");
 448     _fields = f;
 449     _java_fields_count = java_fields_count;
 450   }
 451 
 452   // inner classes
 453   Array<u2>* inner_classes() const       { return _inner_classes; }
 454   void set_inner_classes(Array<u2>* f)   { _inner_classes = f; }
 455 
 456   // nest members
 457   Array<u2>* nest_members() const     { return _nest_members; }
 458   void set_nest_members(Array<u2>* m) { _nest_members = m; }
 459 
 460   // nest-host index

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




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

 717     return _nonstatic_oop_map_size / OopMapBlock::size_in_words();
 718   }
 719   int nonstatic_oop_map_size() const { return _nonstatic_oop_map_size; }
 720   void set_nonstatic_oop_map_size(int words) {
 721     _nonstatic_oop_map_size = words;
 722   }
 723 
 724   bool has_contended_annotations() const {
 725     return ((_misc_flags & _misc_has_contended_annotations) != 0);
 726   }
 727   void set_has_contended_annotations(bool value)  {
 728     if (value) {
 729       _misc_flags |= _misc_has_contended_annotations;
 730     } else {
 731       _misc_flags &= ~_misc_has_contended_annotations;
 732     }
 733   }
 734 
 735 #if INCLUDE_JVMTI
 736   // Redefinition locking.  Class can only be redefined by one thread at a time.

 737   bool is_being_redefined() const          {
 738     return ((_misc_flags & _misc_is_being_redefined) != 0);
 739   }
 740   void set_is_being_redefined(bool value)  {
 741     if (value) {
 742       _misc_flags |= _misc_is_being_redefined;
 743     } else {
 744       _misc_flags &= ~_misc_is_being_redefined;
 745     }
 746   }
 747 
 748   // RedefineClasses() support for previous versions:
 749   void add_previous_version(InstanceKlass* ik, int emcp_method_count);
 750   void purge_previous_version_list();
 751 
 752   InstanceKlass* previous_versions() const { return _previous_versions; }
 753 #else
 754   InstanceKlass* previous_versions() const { return NULL; }
 755 #endif
 756 
 757   InstanceKlass* get_klass_version(int version) {
 758     for (InstanceKlass* ik = this; ik != NULL; ik = ik->previous_versions()) {

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

 805 
 806 #if INCLUDE_JVMTI
 807 
 808   void init_previous_versions() {
 809     _previous_versions = NULL;
 810   }
 811 
 812  private:
 813   static bool  _has_previous_versions;
 814  public:
 815   static void purge_previous_versions(InstanceKlass* ik) {
 816     if (ik->has_been_redefined()) {
 817       ik->purge_previous_version_list();
 818     }
 819   }
 820 
 821   static bool has_previous_versions_and_reset();
 822   static bool has_previous_versions() { return _has_previous_versions; }
 823 
 824   // 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
 994   GrowableArray<Klass*>* compute_secondary_supers(int num_extra_slots,
 995                                                   Array<InstanceKlass*>* transitive_interfaces);
 996   bool can_be_primary_super_slow() const;
 997   int oop_size(oop obj)  const             { return size_helper(); }
 998   // slow because it's a virtual call and used for verifying the layout_helper.
 999   // Using the layout_helper bits, we can call is_instance_klass without a virtual call.
1000   DEBUG_ONLY(bool is_instance_klass_slow() const      { return true; })
1001 
1002   // Iterators
1003   void do_local_static_fields(FieldClosure* cl);
1004   void do_nonstatic_fields(FieldClosure* cl); // including inherited fields
1005   void do_local_static_fields(void f(fieldDescriptor*, Handle, TRAPS), Handle, TRAPS);
1006   void print_nonstatic_fields(FieldClosure* cl); // including inherited and injected fields
1007 
1008   void methods_do(void f(Method* method));
1009   void array_klasses_do(void f(Klass* k));
1010   void array_klasses_do(void f(Klass* k, TRAPS), TRAPS);
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   virtual 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) {

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   }
1038 
1039   int size() const                    { return size(vtable_length(),
1040                                                itable_length(),
1041                                                nonstatic_oop_map_size(),
1042                                                is_interface());


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

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






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

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

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

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

   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_resolved_methods                = 1 << 13, // resolved methods table entries added for this class
 280     _misc_is_being_redefined                  = 1 << 14, // used for locking redefinition
 281     _misc_has_contended_annotations           = 1 << 15,  // has @Contended annotation
 282     _misc_has_inline_type_fields              = 1 << 16, // has inline fields and related embedded section is not empty
 283     _misc_is_empty_inline_type                = 1 << 17, // empty inline type (*)
 284     _misc_is_naturally_atomic                 = 1 << 18, // loaded/stored in one instruction
 285     _misc_is_declared_atomic                  = 1 << 19, // implements jl.NonTearable
 286     _misc_invalid_inline_super                = 1 << 20, // invalid super type for an inline type
 287     _misc_invalid_identity_super              = 1 << 21, // invalid super type for an identity type
 288     _misc_has_injected_identityObject         = 1 << 22, // IdentityObject has been injected by the JVM
 289     _misc_has_injected_primitiveObject        = 1 << 23  // PrimitiveObject has been injected by the JVM
 290   };
 291 
 292   // (*) An inline type is considered empty if it contains no non-static fields or
 293   // if it contains only empty inline fields. Note that JITs have a slightly different
 294   // definition: empty inline fields must be flattened otherwise the container won't
 295   // be considered empty
 296 
 297   u2 shared_loader_type_bits() const {
 298     return _misc_is_shared_boot_class|_misc_is_shared_platform_class|_misc_is_shared_app_class;
 299   }
 300   u4              _misc_flags;           // There is more space in access_flags for more flags.
 301 
 302   Thread*         _init_thread;          // Pointer to current thread doing initialization (to handle recursive initialization)
 303   OopMapCache*    volatile _oop_map_cache;   // OopMapCache for all methods in the klass (allocated lazily)
 304   JNIid*          _jni_ids;              // First JNI identifier for static fields in this class
 305   jmethodID*      volatile _methods_jmethod_ids;  // jmethodIDs corresponding to method_idnum, or NULL if none
 306   nmethodBucket*  volatile _dep_context;          // packed DependencyContext structure
 307   uint64_t        volatile _dep_context_last_cleaned;
 308   nmethod*        _osr_nmethods_head;    // Head of list of on-stack replacement nmethods for this class
 309 #if INCLUDE_JVMTI
 310   BreakpointInfo* _breakpoints;          // bpt lists, managed by Method*
 311   // Linked instanceKlasses of previous versions
 312   InstanceKlass* _previous_versions;
 313   // JVMTI fields can be moved to their own structure - see 6315920
 314   // JVMTI: cached class file, before retransformable agent modified it in CFLH
 315   JvmtiCachedClassFileData* _cached_class_file;
 316 #endif
 317 
 318 #if INCLUDE_JVMTI
 319   JvmtiCachedClassFieldMap* _jvmti_cached_class_field_map;  // JVMTI: used during heap iteration
 320 #endif

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

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

 534   Array<InstanceKlass*>* local_interfaces() const          { return _local_interfaces; }
 535   void set_local_interfaces(Array<InstanceKlass*>* a)      {
 536     guarantee(_local_interfaces == NULL || a == NULL, "Just checking");
 537     _local_interfaces = a; }
 538 
 539   Array<InstanceKlass*>* transitive_interfaces() const     { return _transitive_interfaces; }
 540   void set_transitive_interfaces(Array<InstanceKlass*>* a) {
 541     guarantee(_transitive_interfaces == NULL || a == NULL, "Just checking");
 542     _transitive_interfaces = a;
 543   }
 544 
 545  private:
 546   friend class fieldDescriptor;
 547   FieldInfo* field(int index) const { return FieldInfo::from_field_array(_fields, index); }
 548 
 549  public:
 550   int     field_offset      (int index) const { return field(index)->offset(); }
 551   int     field_access_flags(int index) const { return field(index)->access_flags(); }
 552   Symbol* field_name        (int index) const { return field(index)->name(constants()); }
 553   Symbol* field_signature   (int index) const { return field(index)->signature(constants()); }
 554   bool    field_is_inlined(int index) const { return field(index)->is_inlined(); }
 555   bool    field_is_null_free_inline_type(int index) const;
 556 
 557   // Number of Java declared fields
 558   int java_fields_count() const           { return (int)_java_fields_count; }
 559 
 560   Array<u2>* fields() const            { return _fields; }
 561   void set_fields(Array<u2>* f, u2 java_fields_count) {
 562     guarantee(_fields == NULL || f == NULL, "Just checking");
 563     _fields = f;
 564     _java_fields_count = java_fields_count;
 565   }
 566 
 567   // inner classes
 568   Array<u2>* inner_classes() const       { return _inner_classes; }
 569   void set_inner_classes(Array<u2>* f)   { _inner_classes = f; }
 570 
 571   // nest members
 572   Array<u2>* nest_members() const     { return _nest_members; }
 573   void set_nest_members(Array<u2>* m) { _nest_members = m; }
 574 
 575   // nest-host index

 664 
 665   // is this a sealed class
 666   bool is_sealed() const;
 667 
 668   // defineClass specified verification
 669   bool should_verify_class() const         {
 670     return (_misc_flags & _misc_should_verify_class) != 0;
 671   }
 672   void set_should_verify_class(bool value) {
 673     if (value) {
 674       _misc_flags |= _misc_should_verify_class;
 675     } else {
 676       _misc_flags &= ~_misc_should_verify_class;
 677     }
 678   }
 679 
 680   // marking
 681   bool is_marked_dependent() const         { return _is_marked_dependent; }
 682   void set_is_marked_dependent(bool value) { _is_marked_dependent = value; }
 683 
 684   static ByteSize kind_offset() { return in_ByteSize(offset_of(InstanceKlass, _kind)); }
 685   static ByteSize misc_flags_offset() { return in_ByteSize(offset_of(InstanceKlass, _misc_flags)); }
 686   static u4 misc_flags_is_empty_inline_type() { return _misc_is_empty_inline_type; }
 687 
 688   // initialization (virtuals from Klass)
 689   bool should_be_initialized() const;  // means that initialize should be called
 690   void initialize(TRAPS);
 691   void link_class(TRAPS);
 692   bool link_class_or_fail(TRAPS); // returns false on failure
 693   void rewrite_class(TRAPS);
 694   void link_methods(TRAPS);
 695   Method* class_initializer() const;
 696 
 697   // set the class to initialized if no static initializer is present
 698   void eager_initialize(Thread *thread);
 699 
 700   // reference type
 701   ReferenceType reference_type() const     { return (ReferenceType)_reference_type; }
 702   void set_reference_type(ReferenceType t) {
 703     assert(t == (u1)t, "overflow");
 704     _reference_type = (u1)t;
 705   }
 706 
 707   // this class cp index

 836     return _nonstatic_oop_map_size / OopMapBlock::size_in_words();
 837   }
 838   int nonstatic_oop_map_size() const { return _nonstatic_oop_map_size; }
 839   void set_nonstatic_oop_map_size(int words) {
 840     _nonstatic_oop_map_size = words;
 841   }
 842 
 843   bool has_contended_annotations() const {
 844     return ((_misc_flags & _misc_has_contended_annotations) != 0);
 845   }
 846   void set_has_contended_annotations(bool value)  {
 847     if (value) {
 848       _misc_flags |= _misc_has_contended_annotations;
 849     } else {
 850       _misc_flags &= ~_misc_has_contended_annotations;
 851     }
 852   }
 853 
 854 #if INCLUDE_JVMTI
 855   // Redefinition locking.  Class can only be redefined by one thread at a time.
 856 
 857   bool is_being_redefined() const          {
 858     return (_misc_flags & _misc_is_being_redefined);
 859   }
 860   void set_is_being_redefined(bool value)  {
 861     if (value) {
 862       _misc_flags |= _misc_is_being_redefined;
 863     } else {
 864       _misc_flags &= ~_misc_is_being_redefined;
 865     }
 866   }
 867 
 868   // RedefineClasses() support for previous versions:
 869   void add_previous_version(InstanceKlass* ik, int emcp_method_count);
 870   void purge_previous_version_list();
 871 
 872   InstanceKlass* previous_versions() const { return _previous_versions; }
 873 #else
 874   InstanceKlass* previous_versions() const { return NULL; }
 875 #endif
 876 
 877   InstanceKlass* get_klass_version(int version) {
 878     for (InstanceKlass* ik = this; ik != NULL; ik = ik->previous_versions()) {

 905   void set_has_resolved_methods() {
 906     _misc_flags |= _misc_has_resolved_methods;
 907   }
 908 private:
 909 
 910   void set_kind(unsigned kind) {
 911     _kind = (u1)kind;
 912   }
 913 
 914   bool is_kind(unsigned desired) const {
 915     return _kind == (u1)desired;
 916   }
 917 
 918 public:
 919 
 920   // Other is anything that is not one of the more specialized kinds of InstanceKlass.
 921   bool is_other_instance_klass() const        { return is_kind(_kind_other); }
 922   bool is_reference_instance_klass() const    { return is_kind(_kind_reference); }
 923   bool is_mirror_instance_klass() const       { return is_kind(_kind_mirror); }
 924   bool is_class_loader_instance_klass() const { return is_kind(_kind_class_loader); }
 925   bool is_inline_type_klass()           const { return is_kind(_kind_inline_type); }
 926 
 927 #if INCLUDE_JVMTI
 928 
 929   void init_previous_versions() {
 930     _previous_versions = NULL;
 931   }
 932 
 933  private:
 934   static bool  _has_previous_versions;
 935  public:
 936   static void purge_previous_versions(InstanceKlass* ik) {
 937     if (ik->has_been_redefined()) {
 938       ik->purge_previous_version_list();
 939     }
 940   }
 941 
 942   static bool has_previous_versions_and_reset();
 943   static bool has_previous_versions() { return _has_previous_versions; }
 944 
 945   // JVMTI: Support for caching a class file before it is modified by an agent that can do retransformation

1075 
1076   // On-stack replacement support
1077   nmethod* osr_nmethods_head() const         { return _osr_nmethods_head; };
1078   void set_osr_nmethods_head(nmethod* h)     { _osr_nmethods_head = h; };
1079   void add_osr_nmethod(nmethod* n);
1080   bool remove_osr_nmethod(nmethod* n);
1081   int mark_osr_nmethods(const Method* m);
1082   nmethod* lookup_osr_nmethod(const Method* m, int bci, int level, bool match_level) const;
1083 
1084 #if INCLUDE_JVMTI
1085   // Breakpoint support (see methods on Method* for details)
1086   BreakpointInfo* breakpoints() const       { return _breakpoints; };
1087   void set_breakpoints(BreakpointInfo* bps) { _breakpoints = bps; };
1088 #endif
1089 
1090   // support for stub routines
1091   static ByteSize init_state_offset()  { return in_ByteSize(offset_of(InstanceKlass, _init_state)); }
1092   JFR_ONLY(DEFINE_KLASS_TRACE_ID_OFFSET;)
1093   static ByteSize init_thread_offset() { return in_ByteSize(offset_of(InstanceKlass, _init_thread)); }
1094 
1095   static ByteSize inline_type_field_klasses_offset() { return in_ByteSize(offset_of(InstanceKlass, _inline_type_field_klasses)); }
1096   static ByteSize adr_inlineklass_fixed_block_offset() { return in_ByteSize(offset_of(InstanceKlass, _adr_inlineklass_fixed_block)); }
1097 
1098   // subclass/subinterface checks
1099   bool implements_interface(Klass* k) const;
1100   bool is_same_or_direct_interface(Klass* k) const;
1101 
1102 #ifdef ASSERT
1103   // check whether this class or one of its superclasses was redefined
1104   bool has_redefined_this_or_super() const;
1105 #endif
1106 
1107   // Access to the implementor of an interface.
1108   InstanceKlass* implementor() const;
1109   void set_implementor(InstanceKlass* ik);
1110   int  nof_implementors() const;
1111   void add_implementor(InstanceKlass* ik);  // ik is a new class that implements this interface
1112   void init_implementor();           // initialize
1113 
1114   // link this class into the implementors list of every interface it implements
1115   void process_interfaces();
1116 
1117   // virtual operations from Klass
1118   GrowableArray<Klass*>* compute_secondary_supers(int num_extra_slots,
1119                                                   Array<InstanceKlass*>* transitive_interfaces);
1120   bool can_be_primary_super_slow() const;
1121   int oop_size(oop obj)  const             { return size_helper(); }
1122   // slow because it's a virtual call and used for verifying the layout_helper.
1123   // Using the layout_helper bits, we can call is_instance_klass without a virtual call.
1124   DEBUG_ONLY(bool is_instance_klass_slow() const      { return true; })
1125 
1126   // Iterators
1127   void do_local_static_fields(FieldClosure* cl);
1128   void do_nonstatic_fields(FieldClosure* cl); // including inherited fields
1129   void do_local_static_fields(void f(fieldDescriptor*, Handle, TRAPS), Handle, TRAPS);
1130   void print_nonstatic_fields(FieldClosure* cl); // including inherited and injected fields
1131 
1132   void methods_do(void f(Method* method));
1133   virtual void array_klasses_do(void f(Klass* k));
1134   virtual void array_klasses_do(void f(Klass* k, TRAPS), TRAPS);
1135 
1136   static InstanceKlass* cast(Klass* k) {
1137     return const_cast<InstanceKlass*>(cast(const_cast<const Klass*>(k)));
1138   }
1139 
1140   static const InstanceKlass* cast(const Klass* k) {
1141     assert(k != NULL, "k should not be null");
1142     assert(k->is_instance_klass(), "cast to InstanceKlass");
1143     return static_cast<const InstanceKlass*>(k);
1144   }
1145 
1146   virtual InstanceKlass* java_super() const {
1147     return (super() == NULL) ? NULL : cast(super());
1148   }
1149 
1150   // Sizing (in words)
1151   static int header_size()            { return sizeof(InstanceKlass)/wordSize; }
1152 
1153   static int size(int vtable_length, int itable_length,
1154                   int nonstatic_oop_map_size,
1155                   bool is_interface,
1156                   int java_fields, bool is_inline_type) {
1157     return align_metadata_size(header_size() +
1158            vtable_length +
1159            itable_length +
1160            nonstatic_oop_map_size +
1161            (is_interface ? (int)sizeof(Klass*)/wordSize : 0) +
1162            (java_fields * (int)sizeof(Klass*)/wordSize) +
1163            (is_inline_type ? (int)sizeof(InlineKlassFixedBlock) : 0));
1164   }
1165 
1166   int size() const                    { return size(vtable_length(),
1167                                                itable_length(),
1168                                                nonstatic_oop_map_size(),
1169                                                is_interface(),
1170                                                has_inline_type_fields() ? java_fields_count() : 0,
1171                                                is_inline_klass());
1172   }
1173 
1174 
1175   inline intptr_t* start_of_itable() const;
1176   inline intptr_t* end_of_itable() const;
1177   inline int itable_offset_in_words() const;
1178   inline oop static_field_base_raw();
1179   bool bounds_check(address addr, bool edge_ok = false, intptr_t size_in_bytes = -1) const PRODUCT_RETURN0;
1180 
1181   inline OopMapBlock* start_of_nonstatic_oop_maps() const;
1182   inline Klass** end_of_nonstatic_oop_maps() const;
1183 
1184   inline InstanceKlass* volatile* adr_implementor() const;
1185 
1186   inline address adr_inline_type_field_klasses() const;
1187   inline Klass* get_inline_type_field_klass(int idx) const;
1188   inline Klass* get_inline_type_field_klass_or_null(int idx) const;
1189   inline void set_inline_type_field_klass(int idx, Klass* k);
1190   inline void reset_inline_type_field_klass(int idx);
1191 
1192   // Use this to return the size of an instance in heap words:
1193   virtual int size_helper() const {
1194     return layout_helper_to_size_helper(layout_helper());
1195   }
1196 
1197   // This bit is initialized in classFileParser.cpp.
1198   // It is false under any of the following conditions:
1199   //  - the class is abstract (including any interface)
1200   //  - the class has a finalizer (if !RegisterFinalizersAtInit)
1201   //  - the class size is larger than FastAllocateSizeLimit
1202   //  - the class is java/lang/Class, which cannot be allocated directly
1203   bool can_be_fastpath_allocated() const {
1204     return !layout_helper_needs_slow_path(layout_helper());
1205   }
1206 
1207   // Java itable
1208   klassItable itable() const;        // return klassItable wrapper
1209   Method* method_at_itable(InstanceKlass* holder, int index, TRAPS);
1210   Method* method_at_itable_or_null(InstanceKlass* holder, int index, bool& itable_entry_found);
1211   int vtable_index_of_interface_method(Method* method);
1212 
1213 #if INCLUDE_JVMTI

1227   static void deallocate_methods(ClassLoaderData* loader_data,
1228                                  Array<Method*>* methods);
1229   void static deallocate_interfaces(ClassLoaderData* loader_data,
1230                                     const Klass* super_klass,
1231                                     Array<InstanceKlass*>* local_interfaces,
1232                                     Array<InstanceKlass*>* transitive_interfaces);
1233   void static deallocate_record_components(ClassLoaderData* loader_data,
1234                                            Array<RecordComponent*>* record_component);
1235 
1236   // The constant pool is on stack if any of the methods are executing or
1237   // referenced by handles.
1238   bool on_stack() const { return _constants->on_stack(); }
1239 
1240   // callbacks for actions during class unloading
1241   static void unload_class(InstanceKlass* ik);
1242 
1243   virtual void release_C_heap_structures();
1244 
1245   // Naming
1246   const char* signature_name() const;
1247   const char* signature_name_of_carrier(char c) const;
1248 
1249   // Oop fields (and metadata) iterators
1250   //
1251   // The InstanceKlass iterators also visits the Object's klass.
1252 
1253   // Forward iteration
1254  public:
1255   // Iterate over all oop fields in the oop maps.
1256   template <typename T, class OopClosureType>
1257   inline void oop_oop_iterate_oop_maps(oop obj, OopClosureType* closure);
1258 
1259   // Iterate over all oop fields and metadata.
1260   template <typename T, class OopClosureType>
1261   inline void oop_oop_iterate(oop obj, OopClosureType* closure);
1262 
1263   // Iterate over all oop fields in one oop map.
1264   template <typename T, class OopClosureType>
1265   inline void oop_oop_iterate_oop_map(OopMapBlock* map, oop obj, OopClosureType* closure);
1266 
1267 

1355                                   const Symbol* name,
1356                                   const Symbol* signature,
1357                                   OverpassLookupMode overpass_mode,
1358                                   StaticLookupMode static_mode,
1359                                   PrivateLookupMode private_mode);
1360 
1361   // Free CHeap allocated fields.
1362   void release_C_heap_structures_internal();
1363 
1364 #if INCLUDE_JVMTI
1365   // RedefineClasses support
1366   void link_previous_versions(InstanceKlass* pv) { _previous_versions = pv; }
1367   void mark_newly_obsolete_methods(Array<Method*>* old_methods, int emcp_method_count);
1368 #endif
1369   // log class name to classlist
1370   void log_to_classlist() const;
1371 public:
1372   // CDS support - remove and restore oops from metadata. Oops are not shared.
1373   virtual void remove_unshareable_info();
1374   virtual void remove_java_mirror();
1375   virtual void restore_unshareable_info(ClassLoaderData* loader_data, Handle protection_domain, PackageEntry* pkg_entry, TRAPS);
1376   void init_shared_package_entry();
1377   bool can_be_verified_at_dumptime() const;
1378 
1379   jint compute_modifier_flags() const;
1380 
1381 public:
1382   // JVMTI support
1383   jint jvmti_class_status() const;
1384 
1385   virtual void metaspace_pointers_do(MetaspaceClosure* iter);
1386 
1387  public:
1388   // Printing
1389   void print_on(outputStream* st) const;
1390   void print_value_on(outputStream* st) const;
1391 
1392   void oop_print_value_on(oop obj, outputStream* st);
1393 
1394   void oop_print_on      (oop obj, outputStream* st);
1395 
< prev index next >