< prev index next >

src/hotspot/share/oops/klass.hpp

Print this page

 54 
 55 // Forward declarations.
 56 template <class T> class Array;
 57 template <class T> class GrowableArray;
 58 class ClassLoaderData;
 59 class fieldDescriptor;
 60 class klassVtable;
 61 class ModuleEntry;
 62 class PackageEntry;
 63 class ParCompactionManager;
 64 class PSPromotionManager;
 65 class vtableEntry;
 66 
 67 class Klass : public Metadata {
 68   friend class VMStructs;
 69   friend class JVMCIVMStructs;
 70  public:
 71   // Klass Kinds for all subclasses of Klass
 72   enum KlassKind {
 73     InstanceKlassKind,

 74     InstanceRefKlassKind,
 75     InstanceMirrorKlassKind,
 76     InstanceClassLoaderKlassKind,
 77     InstanceStackChunkKlassKind,
 78     TypeArrayKlassKind,

 79     ObjArrayKlassKind,
 80     UnknownKlassKind
 81   };
 82 
 83   static const uint KLASS_KIND_COUNT = ObjArrayKlassKind + 1;
 84  protected:
 85 
 86   // If you add a new field that points to any metaspace object, you
 87   // must add this field to Klass::metaspace_pointers_do().
 88 
 89   // note: put frequently-used fields together at start of klass structure
 90   // for better cache behavior (may not make much of a difference but sure won't hurt)
 91   enum { _primary_super_limit = 8 };
 92 
 93   // The "layout helper" is a combined descriptor of object layout.
 94   // For klasses which are neither instance nor array, the value is zero.
 95   //
 96   // For instances, layout helper is a positive number, the instance size.
 97   // This size is already passed through align_object_size and scaled to bytes.
 98   // The low order bit is set if instances of this class cannot be
 99   // allocated using the fastpath.
100   //
101   // For arrays, layout helper is a negative number, containing four
102   // distinct bytes, as follows:
103   //    MSB:[tag, hsz, ebt, log2(esz)]:LSB
104   // where:
105   //    tag is 0x80 if the elements are oops, 0xC0 if non-oops
106   //    hsz is array header size in bytes (i.e., offset of first element)
107   //    ebt is the BasicType of the elements
108   //    esz is the element size in bytes
109   // This packed word is arranged so as to be quickly unpacked by the
110   // various fast paths that use the various subfields.
111   //
112   // The esz bits can be used directly by a SLL instruction, without masking.
113   //
114   // Note that the array-kind tag looks like 0x00 for instance klasses,
115   // since their length in bytes is always less than 24Mb.
116   //
117   // Final note:  This comes first, immediately after C++ vtable,
118   // because it is frequently queried.
119   jint        _layout_helper;
120 
121   // Klass kind used to resolve the runtime type of the instance.
122   //  - Used to implement devirtualized oop closure dispatching.
123   //  - Various type checking in the JVM
124   const KlassKind _kind;
125 

154   Klass* volatile _next_sibling;
155 
156   // All klasses loaded by a class loader are chained through these links
157   Klass*      _next_link;
158 
159   // The VM's representation of the ClassLoader used to load this class.
160   // Provide access the corresponding instance java.lang.ClassLoader.
161   ClassLoaderData* _class_loader_data;
162 
163 
164   int _vtable_len;              // vtable length. This field may be read very often when we
165                                 // have lots of itable dispatches (e.g., lambdas and streams).
166                                 // Keep it away from the beginning of a Klass to avoid cacheline
167                                 // contention that may happen when a nearby object is modified.
168   AccessFlags _access_flags;    // Access flags. The class/interface distinction is stored here.
169                                 // Some flags created by the JVM, not in the class file itself,
170                                 // are in _misc_flags below.
171 
172   JFR_ONLY(DEFINE_TRACE_ID_FIELD;)
173 

174   // Bitmap and hash code used by hashed secondary supers.
175   uintx    _bitmap;
176   uint8_t  _hash_slot;
177 
178 private:
179   // This is an index into FileMapHeader::_shared_path_table[], to
180   // associate this class with the JAR file where it's loaded from during
181   // dump time. If a class is not loaded from the shared archive, this field is
182   // -1.
183   s2 _shared_class_path_index;
184 
185 #if INCLUDE_CDS
186   // Various attributes for shared classes. Should be zero for a non-shared class.
187   u2     _shared_class_flags;
188   enum CDSSharedClassFlags {
189     _is_shared_class                       = 1 << 0,  // shadows MetaspaceObj::is_shared
190     _archived_lambda_proxy_is_available    = 1 << 1,
191     _has_value_based_class_annotation      = 1 << 2,
192     _verified_at_dump_time                 = 1 << 3,
193     _has_archived_enum_objs                = 1 << 4,

425   static ByteSize class_loader_data_offset()     { return byte_offset_of(Klass, _class_loader_data); }
426   static ByteSize modifier_flags_offset()        { return byte_offset_of(Klass, _modifier_flags); }
427   static ByteSize layout_helper_offset()         { return byte_offset_of(Klass, _layout_helper); }
428   static ByteSize access_flags_offset()          { return byte_offset_of(Klass, _access_flags); }
429 #if INCLUDE_JVMCI
430   static ByteSize subklass_offset()              { return byte_offset_of(Klass, _subklass); }
431   static ByteSize next_sibling_offset()          { return byte_offset_of(Klass, _next_sibling); }
432 #endif
433   static ByteSize bitmap_offset()                { return byte_offset_of(Klass, _bitmap); }
434   static ByteSize misc_flags_offset()            { return byte_offset_of(Klass, _misc_flags._flags); }
435 
436   // Unpacking layout_helper:
437   static const int _lh_neutral_value           = 0;  // neutral non-array non-instance value
438   static const int _lh_instance_slow_path_bit  = 0x01;
439   static const int _lh_log2_element_size_shift = BitsPerByte*0;
440   static const int _lh_log2_element_size_mask  = BitsPerLong-1;
441   static const int _lh_element_type_shift      = BitsPerByte*1;
442   static const int _lh_element_type_mask       = right_n_bits(BitsPerByte);  // shifted mask
443   static const int _lh_header_size_shift       = BitsPerByte*2;
444   static const int _lh_header_size_mask        = right_n_bits(BitsPerByte);  // shifted mask
445   static const int _lh_array_tag_bits          = 2;
446   static const int _lh_array_tag_shift         = BitsPerInt - _lh_array_tag_bits;
447   static const int _lh_array_tag_obj_value     = ~0x01;   // 0x80000000 >> 30
448 
449   static const unsigned int _lh_array_tag_type_value = 0Xffffffff; // ~0x00,  // 0xC0000000 >> 30








450 
451   static int layout_helper_size_in_bytes(jint lh) {
452     assert(lh > (jint)_lh_neutral_value, "must be instance");
453     return (int) lh & ~_lh_instance_slow_path_bit;
454   }
455   static bool layout_helper_needs_slow_path(jint lh) {
456     assert(lh > (jint)_lh_neutral_value, "must be instance");
457     return (lh & _lh_instance_slow_path_bit) != 0;
458   }
459   static bool layout_helper_is_instance(jint lh) {
460     return (jint)lh > (jint)_lh_neutral_value;
461   }
462   static bool layout_helper_is_array(jint lh) {
463     return (jint)lh < (jint)_lh_neutral_value;
464   }
465   static bool layout_helper_is_typeArray(jint lh) {
466     // _lh_array_tag_type_value == (lh >> _lh_array_tag_shift);
467     return (juint)lh >= (juint)(_lh_array_tag_type_value << _lh_array_tag_shift);
468   }
469   static bool layout_helper_is_objArray(jint lh) {
470     // _lh_array_tag_obj_value == (lh >> _lh_array_tag_shift);
471     return (jint)lh < (jint)(_lh_array_tag_type_value << _lh_array_tag_shift);











472   }
473   static int layout_helper_header_size(jint lh) {
474     assert(lh < (jint)_lh_neutral_value, "must be array");
475     int hsize = (lh >> _lh_header_size_shift) & _lh_header_size_mask;
476     assert(hsize > 0 && hsize < (int)sizeof(oopDesc)*3, "sanity");
477     return hsize;
478   }
479   static BasicType layout_helper_element_type(jint lh) {
480     assert(lh < (jint)_lh_neutral_value, "must be array");
481     int btvalue = (lh >> _lh_element_type_shift) & _lh_element_type_mask;
482     assert(btvalue >= T_BOOLEAN && btvalue <= T_OBJECT, "sanity");
483     return (BasicType) btvalue;
484   }
485 
486   // Want a pattern to quickly diff against layout header in register
487   // find something less clever!
488   static int layout_helper_boolean_diffbit() {
489     jint zlh = array_layout_helper(T_BOOLEAN);
490     jint blh = array_layout_helper(T_BYTE);
491     assert(zlh != blh, "array layout helpers must differ");
492     int diffbit = 1;
493     while ((diffbit & (zlh ^ blh)) == 0 && (diffbit & zlh) == 0) {
494       diffbit <<= 1;
495       assert(diffbit != 0, "make sure T_BOOLEAN has a different bit than T_BYTE");
496     }
497     return diffbit;
498   }
499 
500   static int layout_helper_log2_element_size(jint lh) {
501     assert(lh < (jint)_lh_neutral_value, "must be array");
502     int l2esz = (lh >> _lh_log2_element_size_shift) & _lh_log2_element_size_mask;
503     assert(l2esz <= LogBytesPerLong,
504            "sanity. l2esz: 0x%x for lh: 0x%x", (uint)l2esz, (uint)lh);
505     return l2esz;
506   }
507   static jint array_layout_helper(jint tag, int hsize, BasicType etype, int log2_esize) {
508     return (tag        << _lh_array_tag_shift)

509       |    (hsize      << _lh_header_size_shift)
510       |    ((int)etype << _lh_element_type_shift)
511       |    (log2_esize << _lh_log2_element_size_shift);
512   }
513   static jint instance_layout_helper(jint size, bool slow_path_flag) {
514     return (size << LogBytesPerWord)
515       |    (slow_path_flag ? _lh_instance_slow_path_bit : 0);
516   }
517   static int layout_helper_to_size_helper(jint lh) {
518     assert(lh > (jint)_lh_neutral_value, "must be instance");
519     // Note that the following expression discards _lh_instance_slow_path_bit.
520     return lh >> LogBytesPerWord;
521   }
522   // Out-of-line version computes everything based on the etype:
523   static jint array_layout_helper(BasicType etype);
524 
525   // What is the maximum number of primary superclasses any klass can have?
526   static juint primary_super_limit()         { return _primary_super_limit; }
527 
528   // vtables

641   // Returns the name for a class (Resource allocated) as the class
642   // would appear in a signature.
643   // For arrays, this returns the name of the element with a leading '['.
644   // For classes, this returns the name with a leading 'L' and a trailing ';'
645   //     and the package separators as '/'.
646   virtual const char* signature_name() const;
647 
648   const char* joint_in_module_of_loader(const Klass* class2, bool include_parent_loader = false) const;
649   const char* class_in_module_of_loader(bool use_are = false, bool include_parent_loader = false) const;
650 
651   // Returns "interface", "abstract class" or "class".
652   const char* external_kind() const;
653 
654   // type testing operations
655 #ifdef ASSERT
656  protected:
657   virtual bool is_instance_klass_slow()     const { return false; }
658   virtual bool is_array_klass_slow()        const { return false; }
659   virtual bool is_objArray_klass_slow()     const { return false; }
660   virtual bool is_typeArray_klass_slow()    const { return false; }

661 #endif // ASSERT


662  public:
663 
664   // Fast non-virtual versions
665   #ifndef ASSERT
666   #define assert_same_query(xval, xcheck) xval
667   #else
668  private:
669   static bool assert_same_query(bool xval, bool xslow) {
670     assert(xval == xslow, "slow and fast queries agree");
671     return xval;
672   }
673  public:
674   #endif
675 
676   bool is_instance_klass()              const { return assert_same_query(_kind <= InstanceStackChunkKlassKind, is_instance_klass_slow()); }
677   // Other is anything that is not one of the more specialized kinds of InstanceKlass.
678   bool is_other_instance_klass()        const { return _kind == InstanceKlassKind; }
679   bool is_reference_instance_klass()    const { return _kind == InstanceRefKlassKind; }
680   bool is_mirror_instance_klass()       const { return _kind == InstanceMirrorKlassKind; }
681   bool is_class_loader_instance_klass() const { return _kind == InstanceClassLoaderKlassKind; }
682   bool is_array_klass()                 const { return assert_same_query( _kind >= TypeArrayKlassKind, is_array_klass_slow()); }
683   bool is_stack_chunk_instance_klass()  const { return _kind == InstanceStackChunkKlassKind; }

684   bool is_objArray_klass()              const { return assert_same_query( _kind == ObjArrayKlassKind,  is_objArray_klass_slow()); }
685   bool is_typeArray_klass()             const { return assert_same_query( _kind == TypeArrayKlassKind, is_typeArray_klass_slow()); }
686   #undef assert_same_query
687 


688   // Access flags
689   AccessFlags access_flags() const         { return _access_flags;  }
690   void set_access_flags(AccessFlags flags) { _access_flags = flags; }
691 
692   bool is_public() const                { return _access_flags.is_public(); }
693   bool is_final() const                 { return _access_flags.is_final(); }
694   bool is_interface() const             { return _access_flags.is_interface(); }
695   bool is_abstract() const              { return _access_flags.is_abstract(); }
696   bool is_super() const                 { return _access_flags.is_super(); }
697   bool is_synthetic() const             { return _access_flags.is_synthetic(); }

698   void set_is_synthetic()               { _access_flags.set_is_synthetic(); }
699   bool has_finalizer() const            { return _misc_flags.has_finalizer(); }
700   void set_has_finalizer()              { _misc_flags.set_has_finalizer(true); }
701   bool is_hidden() const                { return _misc_flags.is_hidden_class(); }
702   void set_is_hidden()                  { _misc_flags.set_is_hidden_class(true); }
703   bool is_value_based() const           { return _misc_flags.is_value_based_class(); }
704   void set_is_value_based()             { _misc_flags.set_is_value_based_class(true); }
705 
706   klass_flags_t misc_flags() const      { return _misc_flags.value(); }
707 
708   inline bool is_non_strong_hidden() const;
709 
710   bool is_cloneable() const;
711   void set_is_cloneable();
712 











713   JFR_ONLY(DEFINE_TRACE_ID_METHODS;)
714 
715   virtual void metaspace_pointers_do(MetaspaceClosure* iter);
716   virtual MetaspaceObj::Type type() const { return ClassType; }
717 
718   inline bool is_loader_alive() const;
719 
720   void clean_subklass();
721 
722   static void clean_weak_klass_links(bool unloading_occurred, bool clean_alive_klasses = true);
723   static void clean_subklass_tree() {
724     clean_weak_klass_links(/*unloading_occurred*/ true , /* clean_alive_klasses */ false);
725   }
726 
727   // Return self, except for abstract classes with exactly 1
728   // implementor.  Then return the 1 concrete implementation.
729   Klass *up_cast_abstract();
730 
731   // klass name
732   Symbol* name() const                   { return _name; }

 54 
 55 // Forward declarations.
 56 template <class T> class Array;
 57 template <class T> class GrowableArray;
 58 class ClassLoaderData;
 59 class fieldDescriptor;
 60 class klassVtable;
 61 class ModuleEntry;
 62 class PackageEntry;
 63 class ParCompactionManager;
 64 class PSPromotionManager;
 65 class vtableEntry;
 66 
 67 class Klass : public Metadata {
 68   friend class VMStructs;
 69   friend class JVMCIVMStructs;
 70  public:
 71   // Klass Kinds for all subclasses of Klass
 72   enum KlassKind {
 73     InstanceKlassKind,
 74     InlineKlassKind,
 75     InstanceRefKlassKind,
 76     InstanceMirrorKlassKind,
 77     InstanceClassLoaderKlassKind,
 78     InstanceStackChunkKlassKind,
 79     TypeArrayKlassKind,
 80     FlatArrayKlassKind,
 81     ObjArrayKlassKind,
 82     UnknownKlassKind
 83   };
 84 
 85   static const uint KLASS_KIND_COUNT = ObjArrayKlassKind + 1;
 86  protected:
 87 
 88   // If you add a new field that points to any metaspace object, you
 89   // must add this field to Klass::metaspace_pointers_do().
 90 
 91   // note: put frequently-used fields together at start of klass structure
 92   // for better cache behavior (may not make much of a difference but sure won't hurt)
 93   enum { _primary_super_limit = 8 };
 94 
 95   // The "layout helper" is a combined descriptor of object layout.
 96   // For klasses which are neither instance nor array, the value is zero.
 97   //
 98   // For instances, layout helper is a positive number, the instance size.
 99   // This size is already passed through align_object_size and scaled to bytes.
100   // The low order bit is set if instances of this class cannot be
101   // allocated using the fastpath.
102   //
103   // For arrays, layout helper is a negative number, containing four
104   // distinct bytes, as follows:
105   //    MSB:[tag, hsz, ebt, log2(esz)]:LSB
106   // where:
107   //    tag is 0x80 if the elements are oops, 0xC0 if non-oops, 0xA0 if value types
108   //    hsz is array header size in bytes (i.e., offset of first element)
109   //    ebt is the BasicType of the elements
110   //    esz is the element size in bytes
111   // This packed word is arranged so as to be quickly unpacked by the
112   // various fast paths that use the various subfields.
113   //
114   // The esz bits can be used directly by a SLL instruction, without masking.
115   //
116   // Note that the array-kind tag looks like 0x00 for instance klasses,
117   // since their length in bytes is always less than 24Mb.
118   //
119   // Final note:  This comes first, immediately after C++ vtable,
120   // because it is frequently queried.
121   jint        _layout_helper;
122 
123   // Klass kind used to resolve the runtime type of the instance.
124   //  - Used to implement devirtualized oop closure dispatching.
125   //  - Various type checking in the JVM
126   const KlassKind _kind;
127 

156   Klass* volatile _next_sibling;
157 
158   // All klasses loaded by a class loader are chained through these links
159   Klass*      _next_link;
160 
161   // The VM's representation of the ClassLoader used to load this class.
162   // Provide access the corresponding instance java.lang.ClassLoader.
163   ClassLoaderData* _class_loader_data;
164 
165 
166   int _vtable_len;              // vtable length. This field may be read very often when we
167                                 // have lots of itable dispatches (e.g., lambdas and streams).
168                                 // Keep it away from the beginning of a Klass to avoid cacheline
169                                 // contention that may happen when a nearby object is modified.
170   AccessFlags _access_flags;    // Access flags. The class/interface distinction is stored here.
171                                 // Some flags created by the JVM, not in the class file itself,
172                                 // are in _misc_flags below.
173 
174   JFR_ONLY(DEFINE_TRACE_ID_FIELD;)
175 
176   markWord _prototype_header;  // inline type and inline array mark patterns
177   // Bitmap and hash code used by hashed secondary supers.
178   uintx    _bitmap;
179   uint8_t  _hash_slot;
180 
181 private:
182   // This is an index into FileMapHeader::_shared_path_table[], to
183   // associate this class with the JAR file where it's loaded from during
184   // dump time. If a class is not loaded from the shared archive, this field is
185   // -1.
186   s2 _shared_class_path_index;
187 
188 #if INCLUDE_CDS
189   // Various attributes for shared classes. Should be zero for a non-shared class.
190   u2     _shared_class_flags;
191   enum CDSSharedClassFlags {
192     _is_shared_class                       = 1 << 0,  // shadows MetaspaceObj::is_shared
193     _archived_lambda_proxy_is_available    = 1 << 1,
194     _has_value_based_class_annotation      = 1 << 2,
195     _verified_at_dump_time                 = 1 << 3,
196     _has_archived_enum_objs                = 1 << 4,

428   static ByteSize class_loader_data_offset()     { return byte_offset_of(Klass, _class_loader_data); }
429   static ByteSize modifier_flags_offset()        { return byte_offset_of(Klass, _modifier_flags); }
430   static ByteSize layout_helper_offset()         { return byte_offset_of(Klass, _layout_helper); }
431   static ByteSize access_flags_offset()          { return byte_offset_of(Klass, _access_flags); }
432 #if INCLUDE_JVMCI
433   static ByteSize subklass_offset()              { return byte_offset_of(Klass, _subklass); }
434   static ByteSize next_sibling_offset()          { return byte_offset_of(Klass, _next_sibling); }
435 #endif
436   static ByteSize bitmap_offset()                { return byte_offset_of(Klass, _bitmap); }
437   static ByteSize misc_flags_offset()            { return byte_offset_of(Klass, _misc_flags._flags); }
438 
439   // Unpacking layout_helper:
440   static const int _lh_neutral_value           = 0;  // neutral non-array non-instance value
441   static const int _lh_instance_slow_path_bit  = 0x01;
442   static const int _lh_log2_element_size_shift = BitsPerByte*0;
443   static const int _lh_log2_element_size_mask  = BitsPerLong-1;
444   static const int _lh_element_type_shift      = BitsPerByte*1;
445   static const int _lh_element_type_mask       = right_n_bits(BitsPerByte);  // shifted mask
446   static const int _lh_header_size_shift       = BitsPerByte*2;
447   static const int _lh_header_size_mask        = right_n_bits(BitsPerByte);  // shifted mask
448   static const int _lh_array_tag_bits          = 3;
449   static const int _lh_array_tag_shift         = BitsPerInt - _lh_array_tag_bits;

450 
451   static const unsigned int _lh_array_tag_type_value = 0Xfffffffc;
452   static const unsigned int _lh_array_tag_vt_value   = 0Xfffffffd;
453   static const unsigned int _lh_array_tag_obj_value  = 0Xfffffffe;
454 
455   // null-free array flag bit under the array tag bits, shift one more to get array tag value
456   static const int _lh_null_free_shift = _lh_array_tag_shift - 1;
457   static const int _lh_null_free_mask  = 1;
458 
459   static const jint _lh_array_tag_flat_value_bit_inplace = (jint) (1 << _lh_array_tag_shift);
460 
461   static int layout_helper_size_in_bytes(jint lh) {
462     assert(lh > (jint)_lh_neutral_value, "must be instance");
463     return (int) lh & ~_lh_instance_slow_path_bit;
464   }
465   static bool layout_helper_needs_slow_path(jint lh) {
466     assert(lh > (jint)_lh_neutral_value, "must be instance");
467     return (lh & _lh_instance_slow_path_bit) != 0;
468   }
469   static bool layout_helper_is_instance(jint lh) {
470     return (jint)lh > (jint)_lh_neutral_value;
471   }
472   static bool layout_helper_is_array(jint lh) {
473     return (jint)lh < (jint)_lh_neutral_value;
474   }
475   static bool layout_helper_is_typeArray(jint lh) {
476     return (juint) _lh_array_tag_type_value == (juint)(lh >> _lh_array_tag_shift);

477   }
478   static bool layout_helper_is_objArray(jint lh) {
479     return (juint)_lh_array_tag_obj_value == (juint)(lh >> _lh_array_tag_shift);
480   }
481   static bool layout_helper_is_flatArray(jint lh) {
482     return (juint)_lh_array_tag_vt_value == (juint)(lh >> _lh_array_tag_shift);
483   }
484   static bool layout_helper_is_null_free(jint lh) {
485     assert(layout_helper_is_flatArray(lh) || layout_helper_is_objArray(lh), "must be array of inline types");
486     return ((lh >> _lh_null_free_shift) & _lh_null_free_mask);
487   }
488   static jint layout_helper_set_null_free(jint lh) {
489     lh |= (_lh_null_free_mask << _lh_null_free_shift);
490     assert(layout_helper_is_null_free(lh), "Bad encoding");
491     return lh;
492   }
493   static int layout_helper_header_size(jint lh) {
494     assert(lh < (jint)_lh_neutral_value, "must be array");
495     int hsize = (lh >> _lh_header_size_shift) & _lh_header_size_mask;
496     assert(hsize > 0 && hsize < (int)sizeof(oopDesc)*3, "sanity");
497     return hsize;
498   }
499   static BasicType layout_helper_element_type(jint lh) {
500     assert(lh < (jint)_lh_neutral_value, "must be array");
501     int btvalue = (lh >> _lh_element_type_shift) & _lh_element_type_mask;
502     assert((btvalue >= T_BOOLEAN && btvalue <= T_OBJECT) || btvalue == T_PRIMITIVE_OBJECT, "sanity");
503     return (BasicType) btvalue;
504   }
505 
506   // Want a pattern to quickly diff against layout header in register
507   // find something less clever!
508   static int layout_helper_boolean_diffbit() {
509     jint zlh = array_layout_helper(T_BOOLEAN);
510     jint blh = array_layout_helper(T_BYTE);
511     assert(zlh != blh, "array layout helpers must differ");
512     int diffbit = 1;
513     while ((diffbit & (zlh ^ blh)) == 0 && (diffbit & zlh) == 0) {
514       diffbit <<= 1;
515       assert(diffbit != 0, "make sure T_BOOLEAN has a different bit than T_BYTE");
516     }
517     return diffbit;
518   }
519 
520   static int layout_helper_log2_element_size(jint lh) {
521     assert(lh < (jint)_lh_neutral_value, "must be array");
522     int l2esz = (lh >> _lh_log2_element_size_shift) & _lh_log2_element_size_mask;
523     assert(layout_helper_element_type(lh) == T_PRIMITIVE_OBJECT || l2esz <= LogBytesPerLong,
524            "sanity. l2esz: 0x%x for lh: 0x%x", (uint)l2esz, (uint)lh);
525     return l2esz;
526   }
527   static jint array_layout_helper(jint tag, bool null_free, int hsize, BasicType etype, int log2_esize) {
528     return (tag        << _lh_array_tag_shift)
529       |    ((null_free ? 1 : 0) <<  _lh_null_free_shift)
530       |    (hsize      << _lh_header_size_shift)
531       |    ((int)etype << _lh_element_type_shift)
532       |    (log2_esize << _lh_log2_element_size_shift);
533   }
534   static jint instance_layout_helper(jint size, bool slow_path_flag) {
535     return (size << LogBytesPerWord)
536       |    (slow_path_flag ? _lh_instance_slow_path_bit : 0);
537   }
538   static int layout_helper_to_size_helper(jint lh) {
539     assert(lh > (jint)_lh_neutral_value, "must be instance");
540     // Note that the following expression discards _lh_instance_slow_path_bit.
541     return lh >> LogBytesPerWord;
542   }
543   // Out-of-line version computes everything based on the etype:
544   static jint array_layout_helper(BasicType etype);
545 
546   // What is the maximum number of primary superclasses any klass can have?
547   static juint primary_super_limit()         { return _primary_super_limit; }
548 
549   // vtables

662   // Returns the name for a class (Resource allocated) as the class
663   // would appear in a signature.
664   // For arrays, this returns the name of the element with a leading '['.
665   // For classes, this returns the name with a leading 'L' and a trailing ';'
666   //     and the package separators as '/'.
667   virtual const char* signature_name() const;
668 
669   const char* joint_in_module_of_loader(const Klass* class2, bool include_parent_loader = false) const;
670   const char* class_in_module_of_loader(bool use_are = false, bool include_parent_loader = false) const;
671 
672   // Returns "interface", "abstract class" or "class".
673   const char* external_kind() const;
674 
675   // type testing operations
676 #ifdef ASSERT
677  protected:
678   virtual bool is_instance_klass_slow()     const { return false; }
679   virtual bool is_array_klass_slow()        const { return false; }
680   virtual bool is_objArray_klass_slow()     const { return false; }
681   virtual bool is_typeArray_klass_slow()    const { return false; }
682   virtual bool is_flatArray_klass_slow()    const { return false; }
683 #endif // ASSERT
684   // current implementation uses this method even in non debug builds
685   virtual bool is_inline_klass_slow()       const { return false; }
686  public:
687 
688   // Fast non-virtual versions
689   #ifndef ASSERT
690   #define assert_same_query(xval, xcheck) xval
691   #else
692  private:
693   static bool assert_same_query(bool xval, bool xslow) {
694     assert(xval == xslow, "slow and fast queries agree");
695     return xval;
696   }
697  public:
698   #endif
699 
700   bool is_instance_klass()              const { return assert_same_query(_kind <= InstanceStackChunkKlassKind, is_instance_klass_slow()); }
701   bool is_inline_klass()                const { return assert_same_query(_kind == InlineKlassKind, is_inline_klass_slow()); }

702   bool is_reference_instance_klass()    const { return _kind == InstanceRefKlassKind; }
703   bool is_mirror_instance_klass()       const { return _kind == InstanceMirrorKlassKind; }
704   bool is_class_loader_instance_klass() const { return _kind == InstanceClassLoaderKlassKind; }
705   bool is_array_klass()                 const { return assert_same_query( _kind >= TypeArrayKlassKind, is_array_klass_slow()); }
706   bool is_stack_chunk_instance_klass()  const { return _kind == InstanceStackChunkKlassKind; }
707   bool is_flatArray_klass()             const { return assert_same_query( _kind == FlatArrayKlassKind, is_flatArray_klass_slow()); }
708   bool is_objArray_klass()              const { return assert_same_query( _kind == ObjArrayKlassKind,  is_objArray_klass_slow()); }
709   bool is_typeArray_klass()             const { return assert_same_query( _kind == TypeArrayKlassKind, is_typeArray_klass_slow()); }
710   #undef assert_same_query
711 
712   inline bool is_null_free_array_klass()      const { return layout_helper_is_null_free(layout_helper()); }
713 
714   // Access flags
715   AccessFlags access_flags() const         { return _access_flags;  }
716   void set_access_flags(AccessFlags flags) { _access_flags = flags; }
717 
718   bool is_public() const                { return _access_flags.is_public(); }
719   bool is_final() const                 { return _access_flags.is_final(); }
720   bool is_interface() const             { return _access_flags.is_interface(); }
721   bool is_abstract() const              { return _access_flags.is_abstract(); }

722   bool is_synthetic() const             { return _access_flags.is_synthetic(); }
723   bool is_identity_class() const        { return _access_flags.is_identity_class(); }
724   void set_is_synthetic()               { _access_flags.set_is_synthetic(); }
725   bool has_finalizer() const            { return _misc_flags.has_finalizer(); }
726   void set_has_finalizer()              { _misc_flags.set_has_finalizer(true); }
727   bool is_hidden() const                { return _misc_flags.is_hidden_class(); }
728   void set_is_hidden()                  { _misc_flags.set_is_hidden_class(true); }
729   bool is_value_based() const           { return _misc_flags.is_value_based_class(); }
730   void set_is_value_based()             { _misc_flags.set_is_value_based_class(true); }
731 
732   klass_flags_t misc_flags() const      { return _misc_flags.value(); }
733 
734   inline bool is_non_strong_hidden() const;
735 
736   bool is_cloneable() const;
737   void set_is_cloneable();
738 
739   // inline types and inline type array patterns
740   markWord prototype_header() const {
741     return _prototype_header;
742   }
743   static inline markWord default_prototype_header(Klass* k) {
744     return (k == nullptr) ? markWord::prototype() : k->prototype_header();
745   }
746 
747   inline void set_prototype_header(markWord header);
748   static ByteSize prototype_header_offset() { return in_ByteSize(offset_of(Klass, _prototype_header)); }
749 
750   JFR_ONLY(DEFINE_TRACE_ID_METHODS;)
751 
752   virtual void metaspace_pointers_do(MetaspaceClosure* iter);
753   virtual MetaspaceObj::Type type() const { return ClassType; }
754 
755   inline bool is_loader_alive() const;
756 
757   void clean_subklass();
758 
759   static void clean_weak_klass_links(bool unloading_occurred, bool clean_alive_klasses = true);
760   static void clean_subklass_tree() {
761     clean_weak_klass_links(/*unloading_occurred*/ true , /* clean_alive_klasses */ false);
762   }
763 
764   // Return self, except for abstract classes with exactly 1
765   // implementor.  Then return the 1 concrete implementation.
766   Klass *up_cast_abstract();
767 
768   // klass name
769   Symbol* name() const                   { return _name; }
< prev index next >