< 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_has_contended_annotations           = 1 << 14  // has @Contended annotation








 258   };






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

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



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

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









































































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

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


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

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




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

 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

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

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

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

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

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

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

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

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

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

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