< prev index next >

src/hotspot/share/oops/klass.hpp

Print this page

 51 // ALL FUNCTIONS IMPLEMENTING THIS DISPATCH ARE PREFIXED WITH "oop_"!
 52 
 53 // Forward declarations.
 54 template <class T> class Array;
 55 template <class T> class GrowableArray;
 56 class ClassLoaderData;
 57 class fieldDescriptor;
 58 class klassVtable;
 59 class ModuleEntry;
 60 class PackageEntry;
 61 class vtableEntry;
 62 
 63 class Klass : public Metadata {
 64 
 65   friend class VMStructs;
 66   friend class JVMCIVMStructs;
 67  public:
 68   // Klass Kinds for all subclasses of Klass
 69   enum KlassKind : u2 {
 70     InstanceKlassKind,

 71     InstanceRefKlassKind,
 72     InstanceMirrorKlassKind,
 73     InstanceClassLoaderKlassKind,
 74     InstanceStackChunkKlassKind,
 75     TypeArrayKlassKind,

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

188     _has_aot_initialized_mirror            = 1 << 6,
189     // If this class has been aot-inititalized, do we need to call its runtimeSetup()
190     // method during the production run?
191     _is_runtime_setup_required             = 1 << 7,
192   };
193 #endif
194 
195   int _vtable_len;              // vtable length. This field may be read very often when we
196                                 // have lots of itable dispatches (e.g., lambdas and streams).
197                                 // Keep it away from the beginning of a Klass to avoid cacheline
198                                 // contention that may happen when a nearby object is modified.
199 
200   CDS_JAVA_HEAP_ONLY(int _archived_mirror_index;)
201 
202 public:
203 
204   JFR_ONLY(DEFINE_TRACE_ID_FIELD;)
205 
206 protected:
207 
208   Klass(KlassKind kind);
209   Klass();
210 
211  public:
212   int kind() { return _kind; }
213 
214   enum class DefaultsLookupMode { find, skip };
215   enum class OverpassLookupMode { find, skip };
216   enum class StaticLookupMode   { find, skip };
217   enum class PrivateLookupMode  { find, skip };
218 
219   virtual bool is_klass() const { return true; }
220 
221   // super() cannot be InstanceKlass* -- Java arrays are covariant, and _super is used
222   // to implement that. NB: the _super of "[Ljava/lang/Integer;" is "[Ljava/lang/Number;"
223   // If this is not what your code expects, you're probably looking for Klass::java_super().
224   Klass* super() const               { return _super; }
225   void set_super(Klass* k)           { _super = k; }
226 
227   // initializes _super link, _primary_supers & _secondary_supers arrays
228   void initialize_supers(Klass* k, Array<InstanceKlass*>* transitive_interfaces, TRAPS);

444   static ByteSize layout_helper_offset()         { return byte_offset_of(Klass, _layout_helper); }
445   static ByteSize access_flags_offset()          { return byte_offset_of(Klass, _access_flags); }
446 #if INCLUDE_JVMCI
447   static ByteSize subklass_offset()              { return byte_offset_of(Klass, _subklass); }
448   static ByteSize next_sibling_offset()          { return byte_offset_of(Klass, _next_sibling); }
449 #endif
450   static ByteSize secondary_supers_bitmap_offset()
451                                                  { return byte_offset_of(Klass, _secondary_supers_bitmap); }
452   static ByteSize hash_slot_offset()             { return byte_offset_of(Klass, _hash_slot); }
453   static ByteSize misc_flags_offset()            { return byte_offset_of(Klass, _misc_flags._flags); }
454 
455   // Unpacking layout_helper:
456   static const int _lh_neutral_value           = 0;  // neutral non-array non-instance value
457   static const int _lh_instance_slow_path_bit  = 0x01;
458   static const int _lh_log2_element_size_shift = BitsPerByte*0;
459   static const int _lh_log2_element_size_mask  = BitsPerLong-1;
460   static const int _lh_element_type_shift      = BitsPerByte*1;
461   static const int _lh_element_type_mask       = right_n_bits(BitsPerByte);  // shifted mask
462   static const int _lh_header_size_shift       = BitsPerByte*2;
463   static const int _lh_header_size_mask        = right_n_bits(BitsPerByte);  // shifted mask
464   static const int _lh_array_tag_bits          = 2;
465   static const int _lh_array_tag_shift         = BitsPerInt - _lh_array_tag_bits;
466   static const int _lh_array_tag_obj_value     = ~0x01;   // 0x80000000 >> 30
467 
468   static const unsigned int _lh_array_tag_type_value = 0Xffffffff; // ~0x00,  // 0xC0000000 >> 30








469 
470   static int layout_helper_size_in_bytes(jint lh) {
471     assert(lh > (jint)_lh_neutral_value, "must be instance");
472     return (int) lh & ~_lh_instance_slow_path_bit;
473   }
474   static bool layout_helper_needs_slow_path(jint lh) {
475     assert(lh > (jint)_lh_neutral_value, "must be instance");
476     return (lh & _lh_instance_slow_path_bit) != 0;
477   }
478   static bool layout_helper_is_instance(jint lh) {
479     return (jint)lh > (jint)_lh_neutral_value;
480   }
481   static bool layout_helper_is_array(jint lh) {
482     return (jint)lh < (jint)_lh_neutral_value;
483   }
484   static bool layout_helper_is_typeArray(jint lh) {
485     // _lh_array_tag_type_value == (lh >> _lh_array_tag_shift);
486     return (juint)lh >= (juint)(_lh_array_tag_type_value << _lh_array_tag_shift);
487   }
488   static bool layout_helper_is_objArray(jint lh) {
489     // _lh_array_tag_obj_value == (lh >> _lh_array_tag_shift);
490     return (jint)lh < (jint)(_lh_array_tag_type_value << _lh_array_tag_shift);











491   }
492   static int layout_helper_header_size(jint lh) {
493     assert(lh < (jint)_lh_neutral_value, "must be array");
494     int hsize = (lh >> _lh_header_size_shift) & _lh_header_size_mask;
495     assert(hsize > 0 && hsize < (int)sizeof(oopDesc)*3, "sanity");
496     return hsize;
497   }
498   static BasicType layout_helper_element_type(jint lh) {
499     assert(lh < (jint)_lh_neutral_value, "must be array");
500     int btvalue = (lh >> _lh_element_type_shift) & _lh_element_type_mask;
501     assert(btvalue >= T_BOOLEAN && btvalue <= T_OBJECT, "sanity");
502     return (BasicType) btvalue;
503   }
504 
505   // Want a pattern to quickly diff against layout header in register
506   // find something less clever!
507   static int layout_helper_boolean_diffbit() {
508     jint zlh = array_layout_helper(T_BOOLEAN);
509     jint blh = array_layout_helper(T_BYTE);
510     assert(zlh != blh, "array layout helpers must differ");
511     int diffbit = 1;
512     while ((diffbit & (zlh ^ blh)) == 0 && (diffbit & zlh) == 0) {
513       diffbit <<= 1;
514       assert(diffbit != 0, "make sure T_BOOLEAN has a different bit than T_BYTE");
515     }
516     return diffbit;
517   }
518 
519   static int layout_helper_log2_element_size(jint lh) {
520     assert(lh < (jint)_lh_neutral_value, "must be array");
521     int l2esz = (lh >> _lh_log2_element_size_shift) & _lh_log2_element_size_mask;
522     assert(l2esz <= LogBytesPerLong,
523            "sanity. l2esz: 0x%x for lh: 0x%x", (uint)l2esz, (uint)lh);
524     return l2esz;
525   }
526   static jint array_layout_helper(jint tag, int hsize, BasicType etype, int log2_esize) {
527     return (tag        << _lh_array_tag_shift)

528       |    (hsize      << _lh_header_size_shift)
529       |    ((int)etype << _lh_element_type_shift)
530       |    (log2_esize << _lh_log2_element_size_shift);
531   }
532   static jint instance_layout_helper(jint size, bool slow_path_flag) {
533     return (size << LogBytesPerWord)
534       |    (slow_path_flag ? _lh_instance_slow_path_bit : 0);
535   }
536   static int layout_helper_to_size_helper(jint lh) {
537     assert(lh > (jint)_lh_neutral_value, "must be instance");
538     // Note that the following expression discards _lh_instance_slow_path_bit.
539     return lh >> LogBytesPerWord;
540   }
541   // Out-of-line version computes everything based on the etype:
542   static jint array_layout_helper(BasicType etype);
543 
544   // What is the maximum number of primary superclasses any klass can have?
545   static juint primary_super_limit()         { return _primary_super_limit; }
546 
547   // vtables

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

671 #endif // ASSERT


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

694   bool is_objArray_klass()              const { return assert_same_query( _kind == ObjArrayKlassKind,  is_objArray_klass_slow()); }
695   bool is_typeArray_klass()             const { return assert_same_query( _kind == TypeArrayKlassKind, is_typeArray_klass_slow()); }
696   #undef assert_same_query
697 


698   // Access flags
699   AccessFlags access_flags() const         { return _access_flags;  }
700   void set_access_flags(AccessFlags flags) { _access_flags = flags; }
701 
702   bool is_public() const                { return _access_flags.is_public(); }
703   bool is_final() const                 { return _access_flags.is_final(); }
704   bool is_interface() const             { return _access_flags.is_interface(); }
705   bool is_abstract() const              { return _access_flags.is_abstract(); }
706   bool is_super() const                 { return _access_flags.is_super(); }
707   bool is_synthetic() const             { return _access_flags.is_synthetic(); }

708   void set_is_synthetic()               { _access_flags.set_is_synthetic(); }
709   bool has_finalizer() const            { return _misc_flags.has_finalizer(); }
710   void set_has_finalizer()              { _misc_flags.set_has_finalizer(true); }
711   bool is_hidden() const                { return _misc_flags.is_hidden_class(); }
712   void set_is_hidden()                  { _misc_flags.set_is_hidden_class(true); }
713   bool is_value_based() const           { return _misc_flags.is_value_based_class(); }
714   void set_is_value_based()             { _misc_flags.set_is_value_based_class(true); }
715 
716   klass_flags_t misc_flags() const      { return _misc_flags.value(); }
717 
718   inline bool is_non_strong_hidden() const;
719 
720   bool is_cloneable() const;
721   void set_is_cloneable();
722 

723   inline markWord prototype_header() const;
724   inline void set_prototype_header(markWord header);
725   static ByteSize prototype_header_offset() { return in_ByteSize(offset_of(Klass, _prototype_header)); }

726 
727   JFR_ONLY(DEFINE_TRACE_ID_METHODS;)
728 
729   virtual void metaspace_pointers_do(MetaspaceClosure* iter);
730   virtual MetaspaceObj::Type type() const { return ClassType; }
731 
732   inline bool is_loader_alive() const;
733 
734   void clean_subklass();
735 
736   static void clean_weak_klass_links(bool unloading_occurred, bool clean_alive_klasses = true);
737   static void clean_subklass_tree() {
738     clean_weak_klass_links(/*unloading_occurred*/ true , /* clean_alive_klasses */ false);
739   }
740 
741   // Return self, except for abstract classes with exactly 1
742   // implementor.  Then return the 1 concrete implementation.
743   Klass *up_cast_abstract();
744 
745   // klass name

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

190     _has_aot_initialized_mirror            = 1 << 6,
191     // If this class has been aot-inititalized, do we need to call its runtimeSetup()
192     // method during the production run?
193     _is_runtime_setup_required             = 1 << 7,
194   };
195 #endif
196 
197   int _vtable_len;              // vtable length. This field may be read very often when we
198                                 // have lots of itable dispatches (e.g., lambdas and streams).
199                                 // Keep it away from the beginning of a Klass to avoid cacheline
200                                 // contention that may happen when a nearby object is modified.
201 
202   CDS_JAVA_HEAP_ONLY(int _archived_mirror_index;)
203 
204 public:
205 
206   JFR_ONLY(DEFINE_TRACE_ID_FIELD;)
207 
208 protected:
209 
210   Klass(KlassKind kind, markWord prototype_header = markWord::prototype());
211   Klass();
212 
213  public:
214   int kind() { return _kind; }
215 
216   enum class DefaultsLookupMode { find, skip };
217   enum class OverpassLookupMode { find, skip };
218   enum class StaticLookupMode   { find, skip };
219   enum class PrivateLookupMode  { find, skip };
220 
221   virtual bool is_klass() const { return true; }
222 
223   // super() cannot be InstanceKlass* -- Java arrays are covariant, and _super is used
224   // to implement that. NB: the _super of "[Ljava/lang/Integer;" is "[Ljava/lang/Number;"
225   // If this is not what your code expects, you're probably looking for Klass::java_super().
226   Klass* super() const               { return _super; }
227   void set_super(Klass* k)           { _super = k; }
228 
229   // initializes _super link, _primary_supers & _secondary_supers arrays
230   void initialize_supers(Klass* k, Array<InstanceKlass*>* transitive_interfaces, TRAPS);

446   static ByteSize layout_helper_offset()         { return byte_offset_of(Klass, _layout_helper); }
447   static ByteSize access_flags_offset()          { return byte_offset_of(Klass, _access_flags); }
448 #if INCLUDE_JVMCI
449   static ByteSize subklass_offset()              { return byte_offset_of(Klass, _subklass); }
450   static ByteSize next_sibling_offset()          { return byte_offset_of(Klass, _next_sibling); }
451 #endif
452   static ByteSize secondary_supers_bitmap_offset()
453                                                  { return byte_offset_of(Klass, _secondary_supers_bitmap); }
454   static ByteSize hash_slot_offset()             { return byte_offset_of(Klass, _hash_slot); }
455   static ByteSize misc_flags_offset()            { return byte_offset_of(Klass, _misc_flags._flags); }
456 
457   // Unpacking layout_helper:
458   static const int _lh_neutral_value           = 0;  // neutral non-array non-instance value
459   static const int _lh_instance_slow_path_bit  = 0x01;
460   static const int _lh_log2_element_size_shift = BitsPerByte*0;
461   static const int _lh_log2_element_size_mask  = BitsPerLong-1;
462   static const int _lh_element_type_shift      = BitsPerByte*1;
463   static const int _lh_element_type_mask       = right_n_bits(BitsPerByte);  // shifted mask
464   static const int _lh_header_size_shift       = BitsPerByte*2;
465   static const int _lh_header_size_mask        = right_n_bits(BitsPerByte);  // shifted mask
466   static const int _lh_array_tag_bits          = 3;
467   static const int _lh_array_tag_shift         = BitsPerInt - _lh_array_tag_bits;

468 
469   static const unsigned int _lh_array_tag_type_value = 0Xfffffffc;
470   static const unsigned int _lh_array_tag_vt_value   = 0Xfffffffd;
471   static const unsigned int _lh_array_tag_obj_value  = 0Xfffffffe;
472 
473   // null-free array flag bit under the array tag bits, shift one more to get array tag value
474   static const int _lh_null_free_shift = _lh_array_tag_shift - 1;
475   static const int _lh_null_free_mask  = 1;
476 
477   static const jint _lh_array_tag_flat_value_bit_inplace = (jint) (1 << _lh_array_tag_shift);
478 
479   static int layout_helper_size_in_bytes(jint lh) {
480     assert(lh > (jint)_lh_neutral_value, "must be instance");
481     return (int) lh & ~_lh_instance_slow_path_bit;
482   }
483   static bool layout_helper_needs_slow_path(jint lh) {
484     assert(lh > (jint)_lh_neutral_value, "must be instance");
485     return (lh & _lh_instance_slow_path_bit) != 0;
486   }
487   static bool layout_helper_is_instance(jint lh) {
488     return (jint)lh > (jint)_lh_neutral_value;
489   }
490   static bool layout_helper_is_array(jint lh) {
491     return (jint)lh < (jint)_lh_neutral_value;
492   }
493   static bool layout_helper_is_typeArray(jint lh) {
494     return (juint) _lh_array_tag_type_value == (juint)(lh >> _lh_array_tag_shift);

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

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

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

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