< 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 KlassKind Kind = InstanceKlassKind;
 137 
 138  protected:
 139   InstanceKlass(const ClassFileParser& parser, KlassKind kind = Kind, ReferenceType reference_type = REF_NONE);
 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 : u1 {
 147     allocated,                          // allocated (but not yet linked)
 148     loaded,                             // loaded and inserted in class hierarchy (but not linked yet)
 149     being_linked,                       // currently running verifier and rewriter
 150     linked,                             // successfully linked/verified (but not initialized yet)
 151     being_initialized,                  // currently running class initializer
 152     fully_initialized,                  // initialized (successful final state)
 153     initialization_error                // error happened during initialization
 154   };
 155 
 156  private:
 157   static InstanceKlass* allocate_instance_klass(const ClassFileParser& parser, TRAPS);
 158 
 159  protected:
 160   // If you add a new field that points to any metaspace object, you
 161   // must add this field to InstanceKlass::metaspace_pointers_do().
 162 
 163   // Annotations for this class
 164   Annotations*    _annotations;
 165   // Package this class is defined in
 166   PackageEntry*   _package_entry;
 167   // Array classes holding elements of this class.
 168   ObjArrayKlass* volatile _array_klasses;
 169   // Constant pool for this class.
 170   ConstantPool* _constants;
 171   // The InnerClasses attribute and EnclosingMethod attribute. The
 172   // _inner_classes is an array of shorts. If the class has InnerClasses
 173   // attribute, then the _inner_classes array begins with 4-tuples of shorts
 174   // [inner_class_info_index, outer_class_info_index,
 175   // inner_name_index, inner_class_access_flags] for the InnerClasses
 176   // attribute. If the EnclosingMethod attribute exists, it occupies the
 177   // last two shorts [class_index, method_index] of the array. If only
 178   // the InnerClasses attribute exists, the _inner_classes array length is
 179   // number_of_inner_classes * 4. If the class has both InnerClasses
 180   // and EnclosingMethod attributes the _inner_classes array length is
 181   // number_of_inner_classes * 4 + enclosing_method_attribute_size.
 182   Array<jushort>* _inner_classes;
 183 
 184   // The NestMembers attribute. An array of shorts, where each is a
 185   // class info index for the class that is a nest member. This data
 186   // has not been validated.
 187   Array<jushort>* _nest_members;
 188 

 226   bool            _is_marked_dependent;     // used for marking during flushing and deoptimization
 227 
 228   ClassState      _init_state;              // state of class
 229 
 230   u1              _reference_type;          // reference type
 231 
 232   enum {
 233     _misc_rewritten                           = 1 << 0,  // methods rewritten.
 234     _misc_has_nonstatic_fields                = 1 << 1,  // for sizing with UseCompressedOops
 235     _misc_should_verify_class                 = 1 << 2,  // allow caching of preverification
 236     _misc_unused                              = 1 << 3,  // not currently used
 237     _misc_is_contended                        = 1 << 4,  // marked with contended annotation
 238     _misc_has_nonstatic_concrete_methods      = 1 << 5,  // class/superclass/implemented interfaces has non-static, concrete methods
 239     _misc_declares_nonstatic_concrete_methods = 1 << 6,  // directly declares non-static, concrete methods
 240     _misc_has_been_redefined                  = 1 << 7,  // class has been redefined
 241     _misc_shared_loading_failed               = 1 << 8,  // class has been loaded from shared archive
 242     _misc_is_scratch_class                    = 1 << 9,  // class is the redefined scratch class
 243     _misc_is_shared_boot_class                = 1 << 10, // defining class loader is boot class loader
 244     _misc_is_shared_platform_class            = 1 << 11, // defining class loader is platform class loader
 245     _misc_is_shared_app_class                 = 1 << 12, // defining class loader is app class loader
 246     _misc_has_contended_annotations           = 1 << 13  // has @Contended annotation








 247   };






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

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



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

 354   }
 355 
 356   void set_shared_loading_failed() {
 357     _misc_flags |= _misc_shared_loading_failed;
 358   }
 359 
 360   void set_shared_class_loader_type(s2 loader_type);
 361 
 362   void assign_class_loader_type();
 363 
 364   bool has_nonstatic_fields() const        {
 365     return (_misc_flags & _misc_has_nonstatic_fields) != 0;
 366   }
 367   void set_has_nonstatic_fields(bool b)    {
 368     assert(!has_nonstatic_fields(), "set once");
 369     if (b) {
 370       _misc_flags |= _misc_has_nonstatic_fields;
 371     }
 372   }
 373 


























































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

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


 435 
 436   // Number of Java declared fields
 437   int java_fields_count() const           { return (int)_java_fields_count; }
 438 
 439   Array<u2>* fields() const            { return _fields; }
 440   void set_fields(Array<u2>* f, u2 java_fields_count) {
 441     guarantee(_fields == NULL || f == NULL, "Just checking");
 442     _fields = f;
 443     _java_fields_count = java_fields_count;
 444   }
 445 



 446   // inner classes
 447   Array<u2>* inner_classes() const       { return _inner_classes; }
 448   void set_inner_classes(Array<u2>* f)   { _inner_classes = f; }
 449 
 450   // nest members
 451   Array<u2>* nest_members() const     { return _nest_members; }
 452   void set_nest_members(Array<u2>* m) { _nest_members = m; }
 453 
 454   // nest-host index
 455   jushort nest_host_index() const { return _nest_host_index; }
 456   void set_nest_host_index(u2 i)  { _nest_host_index = i; }
 457   // dynamic nest member support
 458   void set_nest_host(InstanceKlass* host);
 459 
 460   // record components
 461   Array<RecordComponent*>* record_components() const { return _record_components; }
 462   void set_record_components(Array<RecordComponent*>* record_components) {
 463     _record_components = record_components;
 464   }
 465   bool is_record() const;

 564   };
 565 
 566   // is this a sealed class
 567   bool is_sealed() const;
 568 
 569   // defineClass specified verification
 570   bool should_verify_class() const         {
 571     return (_misc_flags & _misc_should_verify_class) != 0;
 572   }
 573   void set_should_verify_class(bool value) {
 574     assert(!should_verify_class(), "set once");
 575     if (value) {
 576       _misc_flags |= _misc_should_verify_class;
 577     }
 578   }
 579 
 580   // marking
 581   bool is_marked_dependent() const         { return _is_marked_dependent; }
 582   void set_is_marked_dependent(bool value) { _is_marked_dependent = value; }
 583 




 584   // initialization (virtuals from Klass)
 585   bool should_be_initialized() const;  // means that initialize should be called
 586   void initialize(TRAPS);
 587   void link_class(TRAPS);
 588   bool link_class_or_fail(TRAPS); // returns false on failure
 589   void rewrite_class(TRAPS);
 590   void link_methods(TRAPS);
 591   Method* class_initializer() const;
 592 
 593   // reference type
 594   ReferenceType reference_type() const     { return (ReferenceType)_reference_type; }
 595 
 596   // this class cp index
 597   u2 this_class_index() const             { return _this_class_index; }
 598   void set_this_class_index(u2 index)     { _this_class_index = index; }
 599 
 600   static ByteSize reference_type_offset() { return in_ByteSize(offset_of(InstanceKlass, _reference_type)); }
 601 
 602   // find local field, returns true if found
 603   bool find_local_field(Symbol* name, Symbol* sig, fieldDescriptor* fd) const;

 943 
 944   // On-stack replacement support
 945   nmethod* osr_nmethods_head() const         { return _osr_nmethods_head; };
 946   void set_osr_nmethods_head(nmethod* h)     { _osr_nmethods_head = h; };
 947   void add_osr_nmethod(nmethod* n);
 948   bool remove_osr_nmethod(nmethod* n);
 949   int mark_osr_nmethods(const Method* m);
 950   nmethod* lookup_osr_nmethod(const Method* m, int bci, int level, bool match_level) const;
 951 
 952 #if INCLUDE_JVMTI
 953   // Breakpoint support (see methods on Method* for details)
 954   BreakpointInfo* breakpoints() const       { return _breakpoints; };
 955   void set_breakpoints(BreakpointInfo* bps) { _breakpoints = bps; };
 956 #endif
 957 
 958   // support for stub routines
 959   static ByteSize init_state_offset()  { return in_ByteSize(offset_of(InstanceKlass, _init_state)); }
 960   JFR_ONLY(DEFINE_KLASS_TRACE_ID_OFFSET;)
 961   static ByteSize init_thread_offset() { return in_ByteSize(offset_of(InstanceKlass, _init_thread)); }
 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   // link this class into the implementors list of every interface it implements
 980   void process_interfaces();
 981 
 982   // virtual operations from Klass

 998 
 999   static InstanceKlass* cast(Klass* k) {
1000     return const_cast<InstanceKlass*>(cast(const_cast<const Klass*>(k)));
1001   }
1002 
1003   static const InstanceKlass* cast(const Klass* k) {
1004     assert(k != NULL, "k should not be null");
1005     assert(k->is_instance_klass(), "cast to InstanceKlass");
1006     return static_cast<const InstanceKlass*>(k);
1007   }
1008 
1009   virtual InstanceKlass* java_super() const {
1010     return (super() == NULL) ? NULL : cast(super());
1011   }
1012 
1013   // Sizing (in words)
1014   static int header_size()            { return sizeof(InstanceKlass)/wordSize; }
1015 
1016   static int size(int vtable_length, int itable_length,
1017                   int nonstatic_oop_map_size,
1018                   bool is_interface) {

1019     return align_metadata_size(header_size() +
1020            vtable_length +
1021            itable_length +
1022            nonstatic_oop_map_size +
1023            (is_interface ? (int)sizeof(Klass*)/wordSize : 0));


1024   }
1025 
1026   int size() const                    { return size(vtable_length(),
1027                                                itable_length(),
1028                                                nonstatic_oop_map_size(),
1029                                                is_interface());


1030   }
1031 
1032 
1033   inline intptr_t* start_of_itable() const;
1034   inline intptr_t* end_of_itable() const;
1035   inline int itable_offset_in_words() const;
1036   inline oop static_field_base_raw();

1037 
1038   inline OopMapBlock* start_of_nonstatic_oop_maps() const;
1039   inline Klass** end_of_nonstatic_oop_maps() const;
1040 
1041   inline InstanceKlass* volatile* adr_implementor() const;
1042 






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

1078   static void deallocate_methods(ClassLoaderData* loader_data,
1079                                  Array<Method*>* methods);
1080   void static deallocate_interfaces(ClassLoaderData* loader_data,
1081                                     const Klass* super_klass,
1082                                     Array<InstanceKlass*>* local_interfaces,
1083                                     Array<InstanceKlass*>* transitive_interfaces);
1084   void static deallocate_record_components(ClassLoaderData* loader_data,
1085                                            Array<RecordComponent*>* record_component);
1086 
1087   // The constant pool is on stack if any of the methods are executing or
1088   // referenced by handles.
1089   bool on_stack() const { return _constants->on_stack(); }
1090 
1091   // callbacks for actions during class unloading
1092   static void unload_class(InstanceKlass* ik);
1093 
1094   virtual void release_C_heap_structures(bool release_constant_pool = true);
1095 
1096   // Naming
1097   const char* signature_name() const;

1098 
1099   // Oop fields (and metadata) iterators
1100   //
1101   // The InstanceKlass iterators also visits the Object's klass.
1102 
1103   // Forward iteration
1104  public:
1105   // Iterate over all oop fields in the oop maps.
1106   template <typename T, class OopClosureType>
1107   inline void oop_oop_iterate_oop_maps(oop obj, OopClosureType* closure);
1108 
1109   // Iterate over all oop fields and metadata.
1110   template <typename T, class OopClosureType>
1111   inline void oop_oop_iterate(oop obj, OopClosureType* closure);
1112 
1113   // Iterate over all oop fields in one oop map.
1114   template <typename T, class OopClosureType>
1115   inline void oop_oop_iterate_oop_map(OopMapBlock* map, oop obj, OopClosureType* closure);
1116 
1117 

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

   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 KlassKind Kind = InstanceKlassKind;
 159 
 160  protected:
 161   InstanceKlass(const ClassFileParser& parser, KlassKind kind = Kind, ReferenceType reference_type = REF_NONE);
 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 : u1 {
 169     allocated,                          // allocated (but not yet linked)
 170     loaded,                             // loaded and inserted in class hierarchy (but not linked yet)
 171     being_linked,                       // currently running verifier and rewriter
 172     linked,                             // successfully linked/verified (but not initialized yet)
 173     being_initialized,                  // currently running class initializer
 174     fully_initialized,                  // initialized (successful final state)
 175     initialization_error                // error happened during initialization
 176   };
 177 
 178  private:
 179   static InstanceKlass* allocate_instance_klass(const ClassFileParser& parser, TRAPS);
 180 
 181  protected:
 182   // If you add a new field that points to any metaspace object, you
 183   // must add this field to InstanceKlass::metaspace_pointers_do().
 184 
 185   // Annotations for this class
 186   Annotations*    _annotations;
 187   // Package this class is defined in
 188   PackageEntry*   _package_entry;
 189   // Array classes holding elements of this class.
 190   ArrayKlass* volatile _array_klasses;
 191   // Constant pool for this class.
 192   ConstantPool* _constants;
 193   // The InnerClasses attribute and EnclosingMethod attribute. The
 194   // _inner_classes is an array of shorts. If the class has InnerClasses
 195   // attribute, then the _inner_classes array begins with 4-tuples of shorts
 196   // [inner_class_info_index, outer_class_info_index,
 197   // inner_name_index, inner_class_access_flags] for the InnerClasses
 198   // attribute. If the EnclosingMethod attribute exists, it occupies the
 199   // last two shorts [class_index, method_index] of the array. If only
 200   // the InnerClasses attribute exists, the _inner_classes array length is
 201   // number_of_inner_classes * 4. If the class has both InnerClasses
 202   // and EnclosingMethod attributes the _inner_classes array length is
 203   // number_of_inner_classes * 4 + enclosing_method_attribute_size.
 204   Array<jushort>* _inner_classes;
 205 
 206   // The NestMembers attribute. An array of shorts, where each is a
 207   // class info index for the class that is a nest member. This data
 208   // has not been validated.
 209   Array<jushort>* _nest_members;
 210 

 248   bool            _is_marked_dependent;     // used for marking during flushing and deoptimization
 249 
 250   ClassState      _init_state;              // state of class
 251 
 252   u1              _reference_type;          // reference type
 253 
 254   enum {
 255     _misc_rewritten                           = 1 << 0,  // methods rewritten.
 256     _misc_has_nonstatic_fields                = 1 << 1,  // for sizing with UseCompressedOops
 257     _misc_should_verify_class                 = 1 << 2,  // allow caching of preverification
 258     _misc_unused                              = 1 << 3,  // not currently used
 259     _misc_is_contended                        = 1 << 4,  // marked with contended annotation
 260     _misc_has_nonstatic_concrete_methods      = 1 << 5,  // class/superclass/implemented interfaces has non-static, concrete methods
 261     _misc_declares_nonstatic_concrete_methods = 1 << 6,  // directly declares non-static, concrete methods
 262     _misc_has_been_redefined                  = 1 << 7,  // class has been redefined
 263     _misc_shared_loading_failed               = 1 << 8,  // class has been loaded from shared archive
 264     _misc_is_scratch_class                    = 1 << 9,  // class is the redefined scratch class
 265     _misc_is_shared_boot_class                = 1 << 10, // defining class loader is boot class loader
 266     _misc_is_shared_platform_class            = 1 << 11, // defining class loader is platform class loader
 267     _misc_is_shared_app_class                 = 1 << 12, // defining class loader is app class loader
 268     _misc_has_contended_annotations           = 1 << 13, // has @Contended annotation
 269     _misc_has_inline_type_fields              = 1 << 14, // has inline fields and related embedded section is not empty
 270     _misc_is_empty_inline_type                = 1 << 15, // empty inline type (*)
 271     _misc_is_naturally_atomic                 = 1 << 16, // loaded/stored in one instruction
 272     _misc_is_declared_atomic                  = 1 << 17, // implements jl.NonTearable
 273     // _misc_invalid_value_super                 = 1 << 18, // invalid super type for an value type
 274     // _misc_invalid_identity_super              = 1 << 19, // invalid super type for an identity type
 275     _misc_carries_value_modifier              = 1 << 20, // the class or one of its super types has the ACC_VALUE modifier
 276     _misc_carries_identity_modifier           = 1 << 21, // the class or one of its super types has the ACC_IDENTITY modifier
 277   };
 278 
 279   // (*) An inline type is considered empty if it contains no non-static fields or
 280   // if it contains only empty inline fields. Note that JITs have a slightly different
 281   // definition: empty inline fields must be flattened otherwise the container won't
 282   // be considered empty
 283 
 284   u2 shared_loader_type_bits() const {
 285     return _misc_is_shared_boot_class|_misc_is_shared_platform_class|_misc_is_shared_app_class;
 286   }
 287   u4              _misc_flags;           // There is more space in access_flags for more flags.
 288 
 289   Monitor*        _init_monitor;         // mutual exclusion to _init_state and _init_thread.
 290   Thread*         _init_thread;          // Pointer to current thread doing initialization (to handle recursive initialization)
 291 
 292   OopMapCache*    volatile _oop_map_cache;   // OopMapCache for all methods in the klass (allocated lazily)
 293   JNIid*          _jni_ids;              // First JNI identifier for static fields in this class
 294   jmethodID*      volatile _methods_jmethod_ids;  // jmethodIDs corresponding to method_idnum, or NULL if none
 295   nmethodBucket*  volatile _dep_context;          // packed DependencyContext structure
 296   uint64_t        volatile _dep_context_last_cleaned;
 297   nmethod*        _osr_nmethods_head;    // Head of list of on-stack replacement nmethods for this class
 298 #if INCLUDE_JVMTI
 299   BreakpointInfo* _breakpoints;          // bpt lists, managed by Method*
 300   // Linked instanceKlasses of previous versions
 301   InstanceKlass* _previous_versions;
 302   // JVMTI fields can be moved to their own structure - see 6315920
 303   // JVMTI: cached class file, before retransformable agent modified it in CFLH
 304   JvmtiCachedClassFileData* _cached_class_file;
 305 #endif
 306 
 307 #if INCLUDE_JVMTI

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

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

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

 666   };
 667 
 668   // is this a sealed class
 669   bool is_sealed() const;
 670 
 671   // defineClass specified verification
 672   bool should_verify_class() const         {
 673     return (_misc_flags & _misc_should_verify_class) != 0;
 674   }
 675   void set_should_verify_class(bool value) {
 676     assert(!should_verify_class(), "set once");
 677     if (value) {
 678       _misc_flags |= _misc_should_verify_class;
 679     }
 680   }
 681 
 682   // marking
 683   bool is_marked_dependent() const         { return _is_marked_dependent; }
 684   void set_is_marked_dependent(bool value) { _is_marked_dependent = value; }
 685 
 686   static ByteSize kind_offset() { return in_ByteSize(offset_of(InstanceKlass, _kind)); }
 687   static ByteSize misc_flags_offset() { return in_ByteSize(offset_of(InstanceKlass, _misc_flags)); }
 688   static u4 misc_flag_is_empty_inline_type() { return _misc_is_empty_inline_type; }
 689 
 690   // initialization (virtuals from Klass)
 691   bool should_be_initialized() const;  // means that initialize should be called
 692   void initialize(TRAPS);
 693   void link_class(TRAPS);
 694   bool link_class_or_fail(TRAPS); // returns false on failure
 695   void rewrite_class(TRAPS);
 696   void link_methods(TRAPS);
 697   Method* class_initializer() const;
 698 
 699   // reference type
 700   ReferenceType reference_type() const     { return (ReferenceType)_reference_type; }
 701 
 702   // this class cp index
 703   u2 this_class_index() const             { return _this_class_index; }
 704   void set_this_class_index(u2 index)     { _this_class_index = index; }
 705 
 706   static ByteSize reference_type_offset() { return in_ByteSize(offset_of(InstanceKlass, _reference_type)); }
 707 
 708   // find local field, returns true if found
 709   bool find_local_field(Symbol* name, Symbol* sig, fieldDescriptor* fd) const;

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

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

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

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