< 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,

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








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











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

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

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

663 #endif // ASSERT


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

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


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

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











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

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

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

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

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

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

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