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

  59 
  60 
  61 // forward declaration for class -- see below for definition
  62 #if INCLUDE_JVMTI
  63 class BreakpointInfo;
  64 #endif
  65 class ClassFileParser;
  66 class ClassFileStream;
  67 class KlassDepChange;
  68 class DependencyContext;
  69 class fieldDescriptor;
  70 class JNIid;
  71 class JvmtiCachedClassFieldMap;
  72 class nmethodBucket;
  73 class OopMapCache;

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


  89  public:
  90    FieldPrinter(outputStream* st, oop obj = nullptr) : _obj(obj), _st(st) {}

  91    void do_field(fieldDescriptor* fd);
  92 };
  93 
  94 // Describes where oops are located in instances of this klass.
  95 class OopMapBlock {
  96  public:
  97   // Byte offset of the first oop mapped by this block.
  98   int offset() const          { return _offset; }
  99   void set_offset(int offset) { _offset = offset; }
 100 
 101   // Number of oops in this block.
 102   uint count() const         { return _count; }
 103   void set_count(uint count) { _count = count; }
 104 
 105   void increment_count(int diff) { _count += diff; }
 106 
 107   int offset_span() const { return _count * heapOopSize; }
 108 
 109   int end_offset() const {
 110     return offset() + offset_span();

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


























































 134 class InstanceKlass: public Klass {
 135   friend class VMStructs;
 136   friend class JVMCIVMStructs;
 137   friend class ClassFileParser;
 138   friend class CompileReplay;

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

 261   NOT_PRODUCT(volatile int _shared_class_load_count;) // ensure a shared class is loaded only once
 262 
 263   // Method array.
 264   Array<Method*>* _methods;
 265   // Default Method Array, concrete methods inherited from interfaces
 266   Array<Method*>* _default_methods;
 267   // Interfaces (InstanceKlass*s) this class declares locally to implement.
 268   Array<InstanceKlass*>* _local_interfaces;
 269   // Interfaces (InstanceKlass*s) this class implements transitively.
 270   Array<InstanceKlass*>* _transitive_interfaces;
 271   // Int array containing the original order of method in the class file (for JVMTI).
 272   Array<int>*     _method_ordering;
 273   // Int array containing the vtable_indices for default_methods
 274   // offset matches _default_methods offset
 275   Array<int>*     _default_vtable_indices;
 276 
 277   // Fields information is stored in an UNSIGNED5 encoded stream (see fieldInfo.hpp)
 278   Array<u1>*          _fieldinfo_stream;
 279   Array<FieldStatus>* _fields_status;
 280 




 281   // embedded Java vtable follows here
 282   // embedded Java itables follows here
 283   // embedded static fields follows here
 284   // embedded nonstatic oop-map blocks follows here
 285   // embedded implementor of this interface follows here
 286   //   The embedded implementor only exists if the current klass is an
 287   //   interface. The possible values of the implementor fall into following
 288   //   three cases:
 289   //     null: no implementor.
 290   //     A Klass* that's not itself: one implementor.
 291   //     Itself: more than one implementors.
 292   //
 293 
 294   friend class SystemDictionary;
 295 
 296   static bool _disable_method_binary_search;
 297 
 298   // Controls finalizer registration
 299   static bool _finalization_enabled;
 300 

 315 
 316   // Check if the class can be shared in CDS
 317   bool is_shareable() const;
 318 
 319   bool shared_loading_failed() const { return _misc_flags.shared_loading_failed(); }
 320 
 321   void set_shared_loading_failed() { _misc_flags.set_shared_loading_failed(true); }
 322 
 323 #if INCLUDE_CDS
 324   int  shared_class_loader_type() const;
 325   void set_shared_class_loader_type(s2 loader_type) { _misc_flags.set_shared_class_loader_type(loader_type); }
 326   void assign_class_loader_type() { _misc_flags.assign_class_loader_type(_class_loader_data); }
 327 #endif
 328 
 329   bool has_nonstatic_fields() const        { return _misc_flags.has_nonstatic_fields(); }
 330   void set_has_nonstatic_fields(bool b)    { _misc_flags.set_has_nonstatic_fields(b); }
 331 
 332   bool has_localvariable_table() const     { return _misc_flags.has_localvariable_table(); }
 333   void set_has_localvariable_table(bool b) { _misc_flags.set_has_localvariable_table(b); }
 334 















 335   // field sizes
 336   int nonstatic_field_size() const         { return _nonstatic_field_size; }
 337   void set_nonstatic_field_size(int size)  { _nonstatic_field_size = size; }
 338 
 339   int static_field_size() const            { return _static_field_size; }
 340   void set_static_field_size(int size)     { _static_field_size = size; }
 341 
 342   int static_oop_field_count() const       { return (int)_static_oop_field_count; }
 343   void set_static_oop_field_count(u2 size) { _static_oop_field_count = size; }
 344 
 345   // Java itable
 346   int  itable_length() const               { return _itable_len; }
 347   void set_itable_length(int len)          { _itable_len = len; }
 348 
 349   // array klasses
 350   ObjArrayKlass* array_klasses() const     { return _array_klasses; }
 351   inline ObjArrayKlass* array_klasses_acquire() const; // load with acquire semantics
 352   inline void release_set_array_klasses(ObjArrayKlass* k); // store with release semantics
 353   void set_array_klasses(ObjArrayKlass* k) { _array_klasses = k; }
 354 
 355   // methods
 356   Array<Method*>* methods() const          { return _methods; }
 357   void set_methods(Array<Method*>* a)      { _methods = a; }
 358   Method* method_with_idnum(int idnum);
 359   Method* method_with_orig_idnum(int idnum);
 360   Method* method_with_orig_idnum(int idnum, int version);
 361 
 362   // method ordering
 363   Array<int>* method_ordering() const     { return _method_ordering; }
 364   void set_method_ordering(Array<int>* m) { _method_ordering = m; }
 365   void copy_method_ordering(const intArray* m, TRAPS);
 366 
 367   // default_methods
 368   Array<Method*>* default_methods() const  { return _default_methods; }
 369   void set_default_methods(Array<Method*>* a) { _default_methods = a; }
 370 
 371   // default method vtable_indices
 372   Array<int>* default_vtable_indices() const { return _default_vtable_indices; }
 373   void set_default_vtable_indices(Array<int>* v) { _default_vtable_indices = v; }

 379     guarantee(_local_interfaces == nullptr || a == nullptr, "Just checking");
 380     _local_interfaces = a; }
 381 
 382   Array<InstanceKlass*>* transitive_interfaces() const     { return _transitive_interfaces; }
 383   void set_transitive_interfaces(Array<InstanceKlass*>* a) {
 384     guarantee(_transitive_interfaces == nullptr || a == nullptr, "Just checking");
 385     _transitive_interfaces = a;
 386   }
 387 
 388  private:
 389   friend class fieldDescriptor;
 390   FieldInfo field(int index) const;
 391 
 392  public:
 393   int     field_offset      (int index) const { return field(index).offset(); }
 394   int     field_access_flags(int index) const { return field(index).access_flags().as_field_flags(); }
 395   FieldInfo::FieldFlags field_flags(int index) const { return field(index).field_flags(); }
 396   FieldStatus field_status(int index)   const { return fields_status()->at(index); }
 397   inline Symbol* field_name        (int index) const;
 398   inline Symbol* field_signature   (int index) const;






 399 
 400   // Number of Java declared fields
 401   int java_fields_count() const;
 402   int total_fields_count() const;
 403 
 404   Array<u1>* fieldinfo_stream() const { return _fieldinfo_stream; }
 405   void set_fieldinfo_stream(Array<u1>* fis) { _fieldinfo_stream = fis; }
 406 
 407   Array<FieldStatus>* fields_status() const {return _fields_status; }
 408   void set_fields_status(Array<FieldStatus>* array) { _fields_status = array; }
 409 



 410   // inner classes
 411   Array<u2>* inner_classes() const       { return _inner_classes; }
 412   void set_inner_classes(Array<u2>* f)   { _inner_classes = f; }
 413 
 414   // nest members
 415   Array<u2>* nest_members() const     { return _nest_members; }
 416   void set_nest_members(Array<u2>* m) { _nest_members = m; }
 417 
 418   // nest-host index
 419   jushort nest_host_index() const { return _nest_host_index; }
 420   void set_nest_host_index(u2 i)  { _nest_host_index = i; }
 421   // dynamic nest member support
 422   void set_nest_host(InstanceKlass* host);
 423 
 424   // record components
 425   Array<RecordComponent*>* record_components() const { return _record_components; }
 426   void set_record_components(Array<RecordComponent*>* record_components) {
 427     _record_components = record_components;
 428   }
 429   bool is_record() const;

 517   bool is_initialized() const              { return init_state() == fully_initialized; }
 518   bool is_not_initialized() const          { return init_state() <  being_initialized; }
 519   bool is_being_initialized() const        { return init_state() == being_initialized; }
 520   bool is_in_error_state() const           { return init_state() == initialization_error; }
 521   bool is_reentrant_initialization(Thread *thread)  { return thread == _init_thread; }
 522   ClassState  init_state() const           { return Atomic::load_acquire(&_init_state); }
 523   const char* init_state_name() const;
 524   bool is_rewritten() const                { return _misc_flags.rewritten(); }
 525 
 526   // is this a sealed class
 527   bool is_sealed() const;
 528 
 529   // defineClass specified verification
 530   bool should_verify_class() const         { return _misc_flags.should_verify_class(); }
 531   void set_should_verify_class(bool value) { _misc_flags.set_should_verify_class(value); }
 532 
 533   // marking
 534   bool is_marked_dependent() const         { return _misc_flags.is_marked_dependent(); }
 535   void set_is_marked_dependent(bool value) { _misc_flags.set_is_marked_dependent(value); }
 536 



 537   // initialization (virtuals from Klass)
 538   bool should_be_initialized() const;  // means that initialize should be called
 539   void initialize_with_aot_initialized_mirror(TRAPS);
 540   void assert_no_clinit_will_run_for_aot_initialized_class() const NOT_DEBUG_RETURN;
 541   void initialize(TRAPS);
 542   void link_class(TRAPS);
 543   bool link_class_or_fail(TRAPS); // returns false on failure
 544   void rewrite_class(TRAPS);
 545   void link_methods(TRAPS);
 546   Method* class_initializer() const;
 547   bool interface_needs_clinit_execution_as_super(bool also_check_supers=true) const;
 548 
 549   // reference type
 550   ReferenceType reference_type() const     { return (ReferenceType)_reference_type; }
 551 
 552   // this class cp index
 553   u2 this_class_index() const             { return _this_class_index; }
 554   void set_this_class_index(u2 index)     { _this_class_index = index; }
 555 
 556   static ByteSize reference_type_offset() { return byte_offset_of(InstanceKlass, _reference_type); }

 844 
 845   // On-stack replacement support
 846   nmethod* osr_nmethods_head() const         { return _osr_nmethods_head; };
 847   void set_osr_nmethods_head(nmethod* h)     { _osr_nmethods_head = h; };
 848   void add_osr_nmethod(nmethod* n);
 849   bool remove_osr_nmethod(nmethod* n);
 850   int mark_osr_nmethods(DeoptimizationScope* deopt_scope, const Method* m);
 851   nmethod* lookup_osr_nmethod(const Method* m, int bci, int level, bool match_level) const;
 852 
 853 #if INCLUDE_JVMTI
 854   // Breakpoint support (see methods on Method* for details)
 855   BreakpointInfo* breakpoints() const       { return _breakpoints; };
 856   void set_breakpoints(BreakpointInfo* bps) { _breakpoints = bps; };
 857 #endif
 858 
 859   // support for stub routines
 860   static ByteSize init_state_offset()  { return byte_offset_of(InstanceKlass, _init_state); }
 861   JFR_ONLY(DEFINE_KLASS_TRACE_ID_OFFSET;)
 862   static ByteSize init_thread_offset() { return byte_offset_of(InstanceKlass, _init_thread); }
 863 



 864   // subclass/subinterface checks
 865   bool implements_interface(Klass* k) const;
 866   bool is_same_or_direct_interface(Klass* k) const;
 867 
 868 #ifdef ASSERT
 869   // check whether this class or one of its superclasses was redefined
 870   bool has_redefined_this_or_super() const;
 871 #endif
 872 
 873   // Access to the implementor of an interface.
 874   InstanceKlass* implementor() const;
 875   void set_implementor(InstanceKlass* ik);
 876   int  nof_implementors() const;
 877   void add_implementor(InstanceKlass* ik);  // ik is a new class that implements this interface
 878   void init_implementor();           // initialize
 879 
 880  private:
 881   // link this class into the implementors list of every interface it implements
 882   void process_interfaces();
 883 

 901 
 902   static InstanceKlass* cast(Klass* k) {
 903     return const_cast<InstanceKlass*>(cast(const_cast<const Klass*>(k)));
 904   }
 905 
 906   static const InstanceKlass* cast(const Klass* k) {
 907     assert(k != nullptr, "k should not be null");
 908     assert(k->is_instance_klass(), "cast to InstanceKlass");
 909     return static_cast<const InstanceKlass*>(k);
 910   }
 911 
 912   virtual InstanceKlass* java_super() const {
 913     return (super() == nullptr) ? nullptr : cast(super());
 914   }
 915 
 916   // Sizing (in words)
 917   static int header_size()            { return sizeof(InstanceKlass)/wordSize; }
 918 
 919   static int size(int vtable_length, int itable_length,
 920                   int nonstatic_oop_map_size,
 921                   bool is_interface) {

 922     return align_metadata_size(header_size() +
 923            vtable_length +
 924            itable_length +
 925            nonstatic_oop_map_size +
 926            (is_interface ? (int)sizeof(Klass*)/wordSize : 0));

 927   }
 928 
 929   int size() const                    { return size(vtable_length(),
 930                                                itable_length(),
 931                                                nonstatic_oop_map_size(),
 932                                                is_interface());

 933   }
 934 
 935 
 936   inline intptr_t* start_of_itable() const;
 937   inline intptr_t* end_of_itable() const;
 938   inline oop static_field_base_raw();

 939 
 940   inline OopMapBlock* start_of_nonstatic_oop_maps() const;
 941   inline Klass** end_of_nonstatic_oop_maps() const;
 942 
 943   inline InstanceKlass* volatile* adr_implementor() const;
 944 


















 945   // Use this to return the size of an instance in heap words:
 946   int size_helper() const {
 947     return layout_helper_to_size_helper(layout_helper());
 948   }
 949 
 950   // This bit is initialized in classFileParser.cpp.
 951   // It is false under any of the following conditions:
 952   //  - the class is abstract (including any interface)
 953   //  - the class size is larger than FastAllocateSizeLimit
 954   //  - the class is java/lang/Class, which cannot be allocated directly
 955   bool can_be_fastpath_allocated() const {
 956     return !layout_helper_needs_slow_path(layout_helper());
 957   }
 958 
 959   // Java itable
 960   klassItable itable() const;        // return klassItable wrapper
 961   Method* method_at_itable(InstanceKlass* holder, int index, TRAPS);
 962   Method* method_at_itable_or_null(InstanceKlass* holder, int index, bool& itable_entry_found);
 963   int vtable_index_of_interface_method(Method* method);
 964 
 965 #if INCLUDE_JVMTI
 966   void adjust_default_methods(bool* trace_name_printed);

 977   // instanceKlasses and the metadata they point to.
 978   void deallocate_contents(ClassLoaderData* loader_data);
 979   static void deallocate_methods(ClassLoaderData* loader_data,
 980                                  Array<Method*>* methods);
 981   void static deallocate_interfaces(ClassLoaderData* loader_data,
 982                                     const Klass* super_klass,
 983                                     Array<InstanceKlass*>* local_interfaces,
 984                                     Array<InstanceKlass*>* transitive_interfaces);
 985   void static deallocate_record_components(ClassLoaderData* loader_data,
 986                                            Array<RecordComponent*>* record_component);
 987 
 988   virtual bool on_stack() const;
 989 
 990   // callbacks for actions during class unloading
 991   static void unload_class(InstanceKlass* ik);
 992 
 993   virtual void release_C_heap_structures(bool release_sub_metadata = true);
 994 
 995   // Naming
 996   const char* signature_name() const;

 997 
 998   // Oop fields (and metadata) iterators
 999   //
1000   // The InstanceKlass iterators also visits the Object's klass.
1001 
1002   // Forward iteration
1003  public:
1004   // Iterate over all oop fields in the oop maps.
1005   template <typename T, class OopClosureType>
1006   inline void oop_oop_iterate_oop_maps(oop obj, OopClosureType* closure);
1007 
1008   // Iterate over all oop fields and metadata.
1009   template <typename T, class OopClosureType>
1010   inline void oop_oop_iterate(oop obj, OopClosureType* closure);
1011 
1012   // Iterate over all oop fields in one oop map.
1013   template <typename T, class OopClosureType>
1014   inline void oop_oop_iterate_oop_map(OopMapBlock* map, oop obj, OopClosureType* closure);
1015 
1016 

1102                                   const Symbol* name,
1103                                   const Symbol* signature,
1104                                   OverpassLookupMode overpass_mode,
1105                                   StaticLookupMode static_mode,
1106                                   PrivateLookupMode private_mode);
1107 
1108 #if INCLUDE_JVMTI
1109   // RedefineClasses support
1110   void link_previous_versions(InstanceKlass* pv) { _previous_versions = pv; }
1111   void mark_newly_obsolete_methods(Array<Method*>* old_methods, int emcp_method_count);
1112 #endif
1113   // log class name to classlist
1114   void log_to_classlist() const;
1115 public:
1116 
1117 #if INCLUDE_CDS
1118   // CDS support - remove and restore oops from metadata. Oops are not shared.
1119   virtual void remove_unshareable_info();
1120   void remove_unshareable_flags();
1121   virtual void remove_java_mirror();
1122   void restore_unshareable_info(ClassLoaderData* loader_data, Handle protection_domain, PackageEntry* pkg_entry, TRAPS);
1123   void init_shared_package_entry();
1124   bool can_be_verified_at_dumptime() const;
1125   void compute_has_loops_flag_for_methods();
1126 #endif
1127 
1128   u2 compute_modifier_flags() const;
1129 
1130 public:
1131   // JVMTI support
1132   jint jvmti_class_status() const;
1133 
1134   virtual void metaspace_pointers_do(MetaspaceClosure* iter);
1135 
1136  public:
1137   // Printing
1138   void print_on(outputStream* st) const;
1139   void print_value_on(outputStream* st) const;
1140 
1141   void oop_print_value_on(oop obj, outputStream* st);
1142 
1143   void oop_print_on      (oop obj, outputStream* st);

1144 
1145 #ifndef PRODUCT
1146   void print_dependent_nmethods(bool verbose = false);
1147   bool is_dependent_nmethod(nmethod* nm);
1148   bool verify_itable_index(int index);
1149 #endif
1150 
1151   const char* internal_name() const;
1152 
1153   // Verification
1154   void verify_on(outputStream* st);
1155 
1156   void oop_verify_on(oop obj, outputStream* st);
1157 
1158   // Logging
1159   void print_class_load_logging(ClassLoaderData* loader_data,
1160                                 const ModuleEntry* module_entry,
1161                                 const ClassFileStream* cfs) const;
1162  private:
1163   void print_class_load_cause_logging() const;

   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/allocation.hpp"
  30 #include "memory/referenceType.hpp"
  31 #include "oops/annotations.hpp"
  32 #include "oops/constMethod.hpp"
  33 #include "oops/fieldInfo.hpp"
  34 #include "oops/instanceKlassFlags.hpp"
  35 #include "oops/instanceOop.hpp"
  36 #include "runtime/handles.hpp"
  37 #include "runtime/javaThread.hpp"
  38 #include "utilities/accessFlags.hpp"
  39 #include "utilities/align.hpp"
  40 #include "utilities/growableArray.hpp"
  41 #include "utilities/macros.hpp"
  42 #if INCLUDE_JFR
  43 #include "jfr/support/jfrKlassExtension.hpp"
  44 #endif
  45 
  46 class ConstantPool;
  47 class DeoptimizationScope;
  48 class klassItable;
  49 class RecordComponent;
  50 
  51 // An InstanceKlass is the VM level representation of a Java class.
  52 // It contains all information needed for at class at execution runtime.
  53 
  54 //  InstanceKlass embedded field layout (after declared fields):
  55 //    [EMBEDDED Java vtable             ] size in words = vtable_len
  56 //    [EMBEDDED nonstatic oop-map blocks] size in words = nonstatic_oop_map_size
  57 //      The embedded nonstatic oop-map blocks are short pairs (offset, length)
  58 //      indicating where oops are located in instances of this klass.
  59 //    [EMBEDDED implementor of the interface] only exist for interface
  60 //    [EMBEDDED InlineKlassFixedBlock] only if is an InlineKlass instance
  61 
  62 
  63 // forward declaration for class -- see below for definition
  64 #if INCLUDE_JVMTI
  65 class BreakpointInfo;
  66 #endif
  67 class ClassFileParser;
  68 class ClassFileStream;
  69 class KlassDepChange;
  70 class DependencyContext;
  71 class fieldDescriptor;
  72 class JNIid;
  73 class JvmtiCachedClassFieldMap;
  74 class nmethodBucket;
  75 class OopMapCache;
  76 class BufferedInlineTypeBlob;
  77 class InterpreterOopMap;
  78 class PackageEntry;
  79 class ModuleEntry;
  80 
  81 // This is used in iterators below.
  82 class FieldClosure: public StackObj {
  83 public:
  84   virtual void do_field(fieldDescriptor* fd) = 0;
  85 };
  86 
  87 // Print fields.
  88 // If "obj" argument to constructor is null, prints static fields, otherwise prints non-static fields.
  89 class FieldPrinter: public FieldClosure {
  90    oop _obj;
  91    outputStream* _st;
  92    int _indent;
  93    int _base_offset;
  94  public:
  95    FieldPrinter(outputStream* st, oop obj = nullptr, int indent = 0, int base_offset = 0) :
  96                  _obj(obj), _st(st), _indent(indent), _base_offset(base_offset) {}
  97    void do_field(fieldDescriptor* fd);
  98 };
  99 
 100 // Describes where oops are located in instances of this klass.
 101 class OopMapBlock {
 102  public:
 103   // Byte offset of the first oop mapped by this block.
 104   int offset() const          { return _offset; }
 105   void set_offset(int offset) { _offset = offset; }
 106 
 107   // Number of oops in this block.
 108   uint count() const         { return _count; }
 109   void set_count(uint count) { _count = count; }
 110 
 111   void increment_count(int diff) { _count += diff; }
 112 
 113   int offset_span() const { return _count * heapOopSize; }
 114 
 115   int end_offset() const {
 116     return offset() + offset_span();

 120     return another_offset == end_offset();
 121   }
 122 
 123   // sizeof(OopMapBlock) in words.
 124   static int size_in_words() {
 125     return align_up((int)sizeof(OopMapBlock), wordSize) >>
 126       LogBytesPerWord;
 127   }
 128 
 129   static int compare_offset(const OopMapBlock* a, const OopMapBlock* b) {
 130     return a->offset() - b->offset();
 131   }
 132 
 133  private:
 134   int  _offset;
 135   uint _count;
 136 };
 137 
 138 struct JvmtiCachedClassFileData;
 139 
 140 class SigEntry;
 141 
 142 class InlineKlassFixedBlock {
 143   Array<SigEntry>** _extended_sig;
 144   Array<VMRegPair>** _return_regs;
 145   address* _pack_handler;
 146   address* _pack_handler_jobject;
 147   address* _unpack_handler;
 148   int* _null_reset_value_offset;
 149   FlatArrayKlass* _non_atomic_flat_array_klass;
 150   FlatArrayKlass* _atomic_flat_array_klass;
 151   FlatArrayKlass* _nullable_atomic_flat_array_klass;
 152   ObjArrayKlass* _null_free_reference_array_klass;
 153   int _payload_offset;          // offset of the begining of the payload in a heap buffered instance
 154   int _payload_size_in_bytes;   // size of payload layout
 155   int _payload_alignment;       // alignment required for payload
 156   int _non_atomic_size_in_bytes; // size of null-free non-atomic flat layout
 157   int _non_atomic_alignment;    // alignment requirement for null-free non-atomic layout
 158   int _atomic_size_in_bytes;    // size and alignment requirement for a null-free atomic layout, -1 if no atomic flat layout is possible
 159   int _nullable_size_in_bytes;  // size and alignment requirement for a nullable layout (always atomic), -1 if no nullable flat layout is possible
 160   int _null_marker_offset;      // expressed as an offset from the beginning of the object for a heap buffered value
 161                                 // payload_offset must be subtracted to get the offset from the beginning of the payload
 162 
 163   friend class InlineKlass;
 164 };
 165 
 166 class InlineLayoutInfo : public MetaspaceObj {
 167   InlineKlass* _klass;
 168   LayoutKind _kind;
 169   int _null_marker_offset; // null marker offset for this field, relative to the beginning of the current container
 170 
 171  public:
 172   InlineLayoutInfo(): _klass(nullptr), _kind(LayoutKind::UNKNOWN), _null_marker_offset(-1)  {}
 173   InlineLayoutInfo(InlineKlass* ik, LayoutKind kind, int size, int nm_offset):
 174     _klass(ik), _kind(kind), _null_marker_offset(nm_offset) {}
 175 
 176   InlineKlass* klass() const { return _klass; }
 177   void set_klass(InlineKlass* k) { _klass = k; }
 178 
 179   LayoutKind kind() const {
 180     assert(_kind != LayoutKind::UNKNOWN, "Not set");
 181     return _kind;
 182   }
 183   void set_kind(LayoutKind lk) { _kind = lk; }
 184 
 185   int null_marker_offset() const {
 186     assert(_null_marker_offset != -1, "Not set");
 187     return _null_marker_offset;
 188   }
 189   void set_null_marker_offset(int o) { _null_marker_offset = o; }
 190 
 191   void metaspace_pointers_do(MetaspaceClosure* it);
 192   MetaspaceObj::Type type() const { return InlineLayoutInfoType; }
 193 
 194   static ByteSize klass_offset() { return in_ByteSize(offset_of(InlineLayoutInfo, _klass)); }
 195   static ByteSize null_marker_offset_offset() { return in_ByteSize(offset_of(InlineLayoutInfo, _null_marker_offset)); }
 196 };
 197 
 198 class InstanceKlass: public Klass {
 199   friend class VMStructs;
 200   friend class JVMCIVMStructs;
 201   friend class ClassFileParser;
 202   friend class CompileReplay;
 203   friend class TemplateTable;
 204 
 205  public:
 206   static const KlassKind Kind = InstanceKlassKind;
 207 
 208  protected:
 209   InstanceKlass(const ClassFileParser& parser, KlassKind kind = Kind, markWord prototype = markWord::prototype(), ReferenceType reference_type = REF_NONE);
 210 
 211   void* operator new(size_t size, ClassLoaderData* loader_data, size_t word_size, bool use_class_space, TRAPS) throw();
 212 
 213  public:
 214   InstanceKlass();
 215 
 216   // See "The Java Virtual Machine Specification" section 2.16.2-5 for a detailed description
 217   // of the class loading & initialization procedure, and the use of the states.
 218   enum ClassState : u1 {
 219     allocated,                          // allocated (but not yet linked)
 220     loaded,                             // loaded and inserted in class hierarchy (but not linked yet)
 221     linked,                             // successfully linked/verified (but not initialized yet)
 222     being_initialized,                  // currently running class initializer
 223     fully_initialized,                  // initialized (successful final state)
 224     initialization_error                // error happened during initialization
 225   };
 226 
 227  private:
 228   static InstanceKlass* allocate_instance_klass(const ClassFileParser& parser, TRAPS);
 229 
 230  protected:
 231   // If you add a new field that points to any metaspace object, you
 232   // must add this field to InstanceKlass::metaspace_pointers_do().
 233 
 234   // Annotations for this class
 235   Annotations*    _annotations;
 236   // Package this class is defined in
 237   PackageEntry*   _package_entry;
 238   // Array classes holding elements of this class.
 239   ArrayKlass* volatile _array_klasses;
 240   // Constant pool for this class.
 241   ConstantPool* _constants;
 242   // The InnerClasses attribute and EnclosingMethod attribute. The
 243   // _inner_classes is an array of shorts. If the class has InnerClasses
 244   // attribute, then the _inner_classes array begins with 4-tuples of shorts
 245   // [inner_class_info_index, outer_class_info_index,
 246   // inner_name_index, inner_class_access_flags] for the InnerClasses
 247   // attribute. If the EnclosingMethod attribute exists, it occupies the
 248   // last two shorts [class_index, method_index] of the array. If only
 249   // the InnerClasses attribute exists, the _inner_classes array length is
 250   // number_of_inner_classes * 4. If the class has both InnerClasses
 251   // and EnclosingMethod attributes the _inner_classes array length is
 252   // number_of_inner_classes * 4 + enclosing_method_attribute_size.
 253   Array<jushort>* _inner_classes;
 254 
 255   // The NestMembers attribute. An array of shorts, where each is a
 256   // class info index for the class that is a nest member. This data
 257   // has not been validated.
 258   Array<jushort>* _nest_members;
 259 

 326   NOT_PRODUCT(volatile int _shared_class_load_count;) // ensure a shared class is loaded only once
 327 
 328   // Method array.
 329   Array<Method*>* _methods;
 330   // Default Method Array, concrete methods inherited from interfaces
 331   Array<Method*>* _default_methods;
 332   // Interfaces (InstanceKlass*s) this class declares locally to implement.
 333   Array<InstanceKlass*>* _local_interfaces;
 334   // Interfaces (InstanceKlass*s) this class implements transitively.
 335   Array<InstanceKlass*>* _transitive_interfaces;
 336   // Int array containing the original order of method in the class file (for JVMTI).
 337   Array<int>*     _method_ordering;
 338   // Int array containing the vtable_indices for default_methods
 339   // offset matches _default_methods offset
 340   Array<int>*     _default_vtable_indices;
 341 
 342   // Fields information is stored in an UNSIGNED5 encoded stream (see fieldInfo.hpp)
 343   Array<u1>*          _fieldinfo_stream;
 344   Array<FieldStatus>* _fields_status;
 345 
 346   Array<InlineLayoutInfo>* _inline_layout_info_array;
 347   Array<u2>* _loadable_descriptors;
 348   const InlineKlassFixedBlock* _adr_inlineklass_fixed_block;
 349 
 350   // embedded Java vtable follows here
 351   // embedded Java itables follows here
 352   // embedded static fields follows here
 353   // embedded nonstatic oop-map blocks follows here
 354   // embedded implementor of this interface follows here
 355   //   The embedded implementor only exists if the current klass is an
 356   //   interface. The possible values of the implementor fall into following
 357   //   three cases:
 358   //     null: no implementor.
 359   //     A Klass* that's not itself: one implementor.
 360   //     Itself: more than one implementors.
 361   //
 362 
 363   friend class SystemDictionary;
 364 
 365   static bool _disable_method_binary_search;
 366 
 367   // Controls finalizer registration
 368   static bool _finalization_enabled;
 369 

 384 
 385   // Check if the class can be shared in CDS
 386   bool is_shareable() const;
 387 
 388   bool shared_loading_failed() const { return _misc_flags.shared_loading_failed(); }
 389 
 390   void set_shared_loading_failed() { _misc_flags.set_shared_loading_failed(true); }
 391 
 392 #if INCLUDE_CDS
 393   int  shared_class_loader_type() const;
 394   void set_shared_class_loader_type(s2 loader_type) { _misc_flags.set_shared_class_loader_type(loader_type); }
 395   void assign_class_loader_type() { _misc_flags.assign_class_loader_type(_class_loader_data); }
 396 #endif
 397 
 398   bool has_nonstatic_fields() const        { return _misc_flags.has_nonstatic_fields(); }
 399   void set_has_nonstatic_fields(bool b)    { _misc_flags.set_has_nonstatic_fields(b); }
 400 
 401   bool has_localvariable_table() const     { return _misc_flags.has_localvariable_table(); }
 402   void set_has_localvariable_table(bool b) { _misc_flags.set_has_localvariable_table(b); }
 403 
 404   bool has_inline_type_fields() const { return _misc_flags.has_inline_type_fields(); }
 405   void set_has_inline_type_fields()   { _misc_flags.set_has_inline_type_fields(true); }
 406 
 407   bool is_naturally_atomic() const  { return _misc_flags.is_naturally_atomic(); }
 408   void set_is_naturally_atomic()    { _misc_flags.set_is_naturally_atomic(true); }
 409 
 410   // Query if this class has atomicity requirements (default is yes)
 411   // This bit can occur anywhere, but is only significant
 412   // for inline classes *and* their super types.
 413   // It inherits from supers.
 414   // Its value depends on the ForceNonTearable VM option, the LooselyConsistentValue annotation
 415   // and the presence of flat fields with atomicity requirements
 416   bool must_be_atomic() const { return _misc_flags.must_be_atomic(); }
 417   void set_must_be_atomic()   { _misc_flags.set_must_be_atomic(true); }
 418 
 419   // field sizes
 420   int nonstatic_field_size() const         { return _nonstatic_field_size; }
 421   void set_nonstatic_field_size(int size)  { _nonstatic_field_size = size; }
 422 
 423   int static_field_size() const            { return _static_field_size; }
 424   void set_static_field_size(int size)     { _static_field_size = size; }
 425 
 426   int static_oop_field_count() const       { return (int)_static_oop_field_count; }
 427   void set_static_oop_field_count(u2 size) { _static_oop_field_count = size; }
 428 
 429   // Java itable
 430   int  itable_length() const               { return _itable_len; }
 431   void set_itable_length(int len)          { _itable_len = len; }
 432 
 433   // array klasses
 434   ArrayKlass* array_klasses() const     { return _array_klasses; }
 435   inline ArrayKlass* array_klasses_acquire() const; // load with acquire semantics
 436   inline void release_set_array_klasses(ArrayKlass* k); // store with release semantics
 437   void set_array_klasses(ArrayKlass* k) { _array_klasses = k; }
 438 
 439   // methods
 440   Array<Method*>* methods() const          { return _methods; }
 441   void set_methods(Array<Method*>* a)      { _methods = a; }
 442   Method* method_with_idnum(int idnum);
 443   Method* method_with_orig_idnum(int idnum);
 444   Method* method_with_orig_idnum(int idnum, int version);
 445 
 446   // method ordering
 447   Array<int>* method_ordering() const     { return _method_ordering; }
 448   void set_method_ordering(Array<int>* m) { _method_ordering = m; }
 449   void copy_method_ordering(const intArray* m, TRAPS);
 450 
 451   // default_methods
 452   Array<Method*>* default_methods() const  { return _default_methods; }
 453   void set_default_methods(Array<Method*>* a) { _default_methods = a; }
 454 
 455   // default method vtable_indices
 456   Array<int>* default_vtable_indices() const { return _default_vtable_indices; }
 457   void set_default_vtable_indices(Array<int>* v) { _default_vtable_indices = v; }

 463     guarantee(_local_interfaces == nullptr || a == nullptr, "Just checking");
 464     _local_interfaces = a; }
 465 
 466   Array<InstanceKlass*>* transitive_interfaces() const     { return _transitive_interfaces; }
 467   void set_transitive_interfaces(Array<InstanceKlass*>* a) {
 468     guarantee(_transitive_interfaces == nullptr || a == nullptr, "Just checking");
 469     _transitive_interfaces = a;
 470   }
 471 
 472  private:
 473   friend class fieldDescriptor;
 474   FieldInfo field(int index) const;
 475 
 476  public:
 477   int     field_offset      (int index) const { return field(index).offset(); }
 478   int     field_access_flags(int index) const { return field(index).access_flags().as_field_flags(); }
 479   FieldInfo::FieldFlags field_flags(int index) const { return field(index).field_flags(); }
 480   FieldStatus field_status(int index)   const { return fields_status()->at(index); }
 481   inline Symbol* field_name        (int index) const;
 482   inline Symbol* field_signature   (int index) const;
 483   bool field_is_flat(int index) const { return field_flags(index).is_flat(); }
 484   bool field_has_null_marker(int index) const { return field_flags(index).has_null_marker(); }
 485   bool field_is_null_free_inline_type(int index) const;
 486   bool is_class_in_loadable_descriptors_attribute(Symbol* name) const;
 487 
 488   int null_marker_offset(int index) const { return inline_layout_info(index).null_marker_offset(); }
 489 
 490   // Number of Java declared fields
 491   int java_fields_count() const;
 492   int total_fields_count() const;
 493 
 494   Array<u1>* fieldinfo_stream() const { return _fieldinfo_stream; }
 495   void set_fieldinfo_stream(Array<u1>* fis) { _fieldinfo_stream = fis; }
 496 
 497   Array<FieldStatus>* fields_status() const {return _fields_status; }
 498   void set_fields_status(Array<FieldStatus>* array) { _fields_status = array; }
 499 
 500   Array<u2>* loadable_descriptors() const { return _loadable_descriptors; }
 501   void set_loadable_descriptors(Array<u2>* c) { _loadable_descriptors = c; }
 502 
 503   // inner classes
 504   Array<u2>* inner_classes() const       { return _inner_classes; }
 505   void set_inner_classes(Array<u2>* f)   { _inner_classes = f; }
 506 
 507   // nest members
 508   Array<u2>* nest_members() const     { return _nest_members; }
 509   void set_nest_members(Array<u2>* m) { _nest_members = m; }
 510 
 511   // nest-host index
 512   jushort nest_host_index() const { return _nest_host_index; }
 513   void set_nest_host_index(u2 i)  { _nest_host_index = i; }
 514   // dynamic nest member support
 515   void set_nest_host(InstanceKlass* host);
 516 
 517   // record components
 518   Array<RecordComponent*>* record_components() const { return _record_components; }
 519   void set_record_components(Array<RecordComponent*>* record_components) {
 520     _record_components = record_components;
 521   }
 522   bool is_record() const;

 610   bool is_initialized() const              { return init_state() == fully_initialized; }
 611   bool is_not_initialized() const          { return init_state() <  being_initialized; }
 612   bool is_being_initialized() const        { return init_state() == being_initialized; }
 613   bool is_in_error_state() const           { return init_state() == initialization_error; }
 614   bool is_reentrant_initialization(Thread *thread)  { return thread == _init_thread; }
 615   ClassState  init_state() const           { return Atomic::load_acquire(&_init_state); }
 616   const char* init_state_name() const;
 617   bool is_rewritten() const                { return _misc_flags.rewritten(); }
 618 
 619   // is this a sealed class
 620   bool is_sealed() const;
 621 
 622   // defineClass specified verification
 623   bool should_verify_class() const         { return _misc_flags.should_verify_class(); }
 624   void set_should_verify_class(bool value) { _misc_flags.set_should_verify_class(value); }
 625 
 626   // marking
 627   bool is_marked_dependent() const         { return _misc_flags.is_marked_dependent(); }
 628   void set_is_marked_dependent(bool value) { _misc_flags.set_is_marked_dependent(value); }
 629 
 630   static ByteSize kind_offset() { return in_ByteSize(offset_of(InstanceKlass, _kind)); }
 631   static ByteSize misc_flags_offset() { return in_ByteSize(offset_of(InstanceKlass, _misc_flags)); }
 632 
 633   // initialization (virtuals from Klass)
 634   bool should_be_initialized() const;  // means that initialize should be called
 635   void initialize_with_aot_initialized_mirror(TRAPS);
 636   void assert_no_clinit_will_run_for_aot_initialized_class() const NOT_DEBUG_RETURN;
 637   void initialize(TRAPS);
 638   void link_class(TRAPS);
 639   bool link_class_or_fail(TRAPS); // returns false on failure
 640   void rewrite_class(TRAPS);
 641   void link_methods(TRAPS);
 642   Method* class_initializer() const;
 643   bool interface_needs_clinit_execution_as_super(bool also_check_supers=true) const;
 644 
 645   // reference type
 646   ReferenceType reference_type() const     { return (ReferenceType)_reference_type; }
 647 
 648   // this class cp index
 649   u2 this_class_index() const             { return _this_class_index; }
 650   void set_this_class_index(u2 index)     { _this_class_index = index; }
 651 
 652   static ByteSize reference_type_offset() { return byte_offset_of(InstanceKlass, _reference_type); }

 940 
 941   // On-stack replacement support
 942   nmethod* osr_nmethods_head() const         { return _osr_nmethods_head; };
 943   void set_osr_nmethods_head(nmethod* h)     { _osr_nmethods_head = h; };
 944   void add_osr_nmethod(nmethod* n);
 945   bool remove_osr_nmethod(nmethod* n);
 946   int mark_osr_nmethods(DeoptimizationScope* deopt_scope, const Method* m);
 947   nmethod* lookup_osr_nmethod(const Method* m, int bci, int level, bool match_level) const;
 948 
 949 #if INCLUDE_JVMTI
 950   // Breakpoint support (see methods on Method* for details)
 951   BreakpointInfo* breakpoints() const       { return _breakpoints; };
 952   void set_breakpoints(BreakpointInfo* bps) { _breakpoints = bps; };
 953 #endif
 954 
 955   // support for stub routines
 956   static ByteSize init_state_offset()  { return byte_offset_of(InstanceKlass, _init_state); }
 957   JFR_ONLY(DEFINE_KLASS_TRACE_ID_OFFSET;)
 958   static ByteSize init_thread_offset() { return byte_offset_of(InstanceKlass, _init_thread); }
 959 
 960   static ByteSize inline_layout_info_array_offset() { return in_ByteSize(offset_of(InstanceKlass, _inline_layout_info_array)); }
 961   static ByteSize adr_inlineklass_fixed_block_offset() { return in_ByteSize(offset_of(InstanceKlass, _adr_inlineklass_fixed_block)); }
 962 
 963   // subclass/subinterface checks
 964   bool implements_interface(Klass* k) const;
 965   bool is_same_or_direct_interface(Klass* k) const;
 966 
 967 #ifdef ASSERT
 968   // check whether this class or one of its superclasses was redefined
 969   bool has_redefined_this_or_super() const;
 970 #endif
 971 
 972   // Access to the implementor of an interface.
 973   InstanceKlass* implementor() const;
 974   void set_implementor(InstanceKlass* ik);
 975   int  nof_implementors() const;
 976   void add_implementor(InstanceKlass* ik);  // ik is a new class that implements this interface
 977   void init_implementor();           // initialize
 978 
 979  private:
 980   // link this class into the implementors list of every interface it implements
 981   void process_interfaces();
 982 

1000 
1001   static InstanceKlass* cast(Klass* k) {
1002     return const_cast<InstanceKlass*>(cast(const_cast<const Klass*>(k)));
1003   }
1004 
1005   static const InstanceKlass* cast(const Klass* k) {
1006     assert(k != nullptr, "k should not be null");
1007     assert(k->is_instance_klass(), "cast to InstanceKlass");
1008     return static_cast<const InstanceKlass*>(k);
1009   }
1010 
1011   virtual InstanceKlass* java_super() const {
1012     return (super() == nullptr) ? nullptr : cast(super());
1013   }
1014 
1015   // Sizing (in words)
1016   static int header_size()            { return sizeof(InstanceKlass)/wordSize; }
1017 
1018   static int size(int vtable_length, int itable_length,
1019                   int nonstatic_oop_map_size,
1020                   bool is_interface,
1021                   bool is_inline_type) {
1022     return align_metadata_size(header_size() +
1023            vtable_length +
1024            itable_length +
1025            nonstatic_oop_map_size +
1026            (is_interface ? (int)sizeof(Klass*)/wordSize : 0) +
1027            (is_inline_type ? (int)sizeof(InlineKlassFixedBlock) : 0));
1028   }
1029 
1030   int size() const                    { return size(vtable_length(),
1031                                                itable_length(),
1032                                                nonstatic_oop_map_size(),
1033                                                is_interface(),
1034                                                is_inline_klass());
1035   }
1036 
1037 
1038   inline intptr_t* start_of_itable() const;
1039   inline intptr_t* end_of_itable() const;
1040   inline oop static_field_base_raw();
1041   bool bounds_check(address addr, bool edge_ok = false, intptr_t size_in_bytes = -1) const PRODUCT_RETURN0;
1042 
1043   inline OopMapBlock* start_of_nonstatic_oop_maps() const;
1044   inline Klass** end_of_nonstatic_oop_maps() const;
1045 
1046   inline InstanceKlass* volatile* adr_implementor() const;
1047 
1048   void set_inline_layout_info_array(Array<InlineLayoutInfo>* array) { _inline_layout_info_array = array; }
1049   Array<InlineLayoutInfo>* inline_layout_info_array() const { return _inline_layout_info_array; }
1050   void set_inline_layout_info(int index, InlineLayoutInfo *info) {
1051     assert(_inline_layout_info_array != nullptr ,"Array not created");
1052     _inline_layout_info_array->at_put(index, *info);
1053   }
1054   InlineLayoutInfo inline_layout_info(int index) const {
1055     assert(_inline_layout_info_array != nullptr ,"Array not created");
1056     return _inline_layout_info_array->at(index);
1057   }
1058   InlineLayoutInfo* inline_layout_info_adr(int index) {
1059     assert(_inline_layout_info_array != nullptr ,"Array not created");
1060     return _inline_layout_info_array->adr_at(index);
1061   }
1062 
1063   inline InlineKlass* get_inline_type_field_klass(int idx) const ;
1064   inline InlineKlass* get_inline_type_field_klass_or_null(int idx) const;
1065 
1066   // Use this to return the size of an instance in heap words:
1067   virtual int size_helper() const {
1068     return layout_helper_to_size_helper(layout_helper());
1069   }
1070 
1071   // This bit is initialized in classFileParser.cpp.
1072   // It is false under any of the following conditions:
1073   //  - the class is abstract (including any interface)
1074   //  - the class size is larger than FastAllocateSizeLimit
1075   //  - the class is java/lang/Class, which cannot be allocated directly
1076   bool can_be_fastpath_allocated() const {
1077     return !layout_helper_needs_slow_path(layout_helper());
1078   }
1079 
1080   // Java itable
1081   klassItable itable() const;        // return klassItable wrapper
1082   Method* method_at_itable(InstanceKlass* holder, int index, TRAPS);
1083   Method* method_at_itable_or_null(InstanceKlass* holder, int index, bool& itable_entry_found);
1084   int vtable_index_of_interface_method(Method* method);
1085 
1086 #if INCLUDE_JVMTI
1087   void adjust_default_methods(bool* trace_name_printed);

1098   // instanceKlasses and the metadata they point to.
1099   void deallocate_contents(ClassLoaderData* loader_data);
1100   static void deallocate_methods(ClassLoaderData* loader_data,
1101                                  Array<Method*>* methods);
1102   void static deallocate_interfaces(ClassLoaderData* loader_data,
1103                                     const Klass* super_klass,
1104                                     Array<InstanceKlass*>* local_interfaces,
1105                                     Array<InstanceKlass*>* transitive_interfaces);
1106   void static deallocate_record_components(ClassLoaderData* loader_data,
1107                                            Array<RecordComponent*>* record_component);
1108 
1109   virtual bool on_stack() const;
1110 
1111   // callbacks for actions during class unloading
1112   static void unload_class(InstanceKlass* ik);
1113 
1114   virtual void release_C_heap_structures(bool release_sub_metadata = true);
1115 
1116   // Naming
1117   const char* signature_name() const;
1118   const char* signature_name_of_carrier(char c) const;
1119 
1120   // Oop fields (and metadata) iterators
1121   //
1122   // The InstanceKlass iterators also visits the Object's klass.
1123 
1124   // Forward iteration
1125  public:
1126   // Iterate over all oop fields in the oop maps.
1127   template <typename T, class OopClosureType>
1128   inline void oop_oop_iterate_oop_maps(oop obj, OopClosureType* closure);
1129 
1130   // Iterate over all oop fields and metadata.
1131   template <typename T, class OopClosureType>
1132   inline void oop_oop_iterate(oop obj, OopClosureType* closure);
1133 
1134   // Iterate over all oop fields in one oop map.
1135   template <typename T, class OopClosureType>
1136   inline void oop_oop_iterate_oop_map(OopMapBlock* map, oop obj, OopClosureType* closure);
1137 
1138 

1224                                   const Symbol* name,
1225                                   const Symbol* signature,
1226                                   OverpassLookupMode overpass_mode,
1227                                   StaticLookupMode static_mode,
1228                                   PrivateLookupMode private_mode);
1229 
1230 #if INCLUDE_JVMTI
1231   // RedefineClasses support
1232   void link_previous_versions(InstanceKlass* pv) { _previous_versions = pv; }
1233   void mark_newly_obsolete_methods(Array<Method*>* old_methods, int emcp_method_count);
1234 #endif
1235   // log class name to classlist
1236   void log_to_classlist() const;
1237 public:
1238 
1239 #if INCLUDE_CDS
1240   // CDS support - remove and restore oops from metadata. Oops are not shared.
1241   virtual void remove_unshareable_info();
1242   void remove_unshareable_flags();
1243   virtual void remove_java_mirror();
1244   virtual void restore_unshareable_info(ClassLoaderData* loader_data, Handle protection_domain, PackageEntry* pkg_entry, TRAPS);
1245   void init_shared_package_entry();
1246   bool can_be_verified_at_dumptime() const;
1247   void compute_has_loops_flag_for_methods();
1248 #endif
1249 
1250   u2 compute_modifier_flags() const;
1251 
1252 public:
1253   // JVMTI support
1254   jint jvmti_class_status() const;
1255 
1256   virtual void metaspace_pointers_do(MetaspaceClosure* iter);
1257 
1258  public:
1259   // Printing
1260   void print_on(outputStream* st) const;
1261   void print_value_on(outputStream* st) const;
1262 
1263   void oop_print_value_on(oop obj, outputStream* st);
1264 
1265   void oop_print_on      (oop obj, outputStream* st) { oop_print_on(obj, st, 0, 0); }
1266   void oop_print_on      (oop obj, outputStream* st, int indent = 0, int base_offset = 0);
1267 
1268 #ifndef PRODUCT
1269   void print_dependent_nmethods(bool verbose = false);
1270   bool is_dependent_nmethod(nmethod* nm);
1271   bool verify_itable_index(int index);
1272 #endif
1273 
1274   const char* internal_name() const;
1275 
1276   // Verification
1277   void verify_on(outputStream* st);
1278 
1279   void oop_verify_on(oop obj, outputStream* st);
1280 
1281   // Logging
1282   void print_class_load_logging(ClassLoaderData* loader_data,
1283                                 const ModuleEntry* module_entry,
1284                                 const ClassFileStream* cfs) const;
1285  private:
1286   void print_class_load_cause_logging() const;
< prev index next >