< prev index next >

src/hotspot/share/oops/klass.hpp

Print this page

 35 #include "jfr/support/jfrTraceIdExtension.hpp"
 36 #endif
 37 
 38 //
 39 // A Klass provides:
 40 //  1: language level class object (method dictionary etc.)
 41 //  2: provide vm dispatch behavior for the object
 42 // Both functions are combined into one C++ class.
 43 
 44 // One reason for the oop/klass dichotomy in the implementation is
 45 // that we don't want a C++ vtbl pointer in every object.  Thus,
 46 // normal oops don't have any virtual functions.  Instead, they
 47 // forward all "virtual" functions to their klass, which does have
 48 // a vtbl and does the C++ dispatch depending on the object's
 49 // actual type.  (See oop.inline.hpp for some of the forwarding code.)
 50 // ALL FUNCTIONS IMPLEMENTING THIS DISPATCH ARE PREFIXED WITH "oop_"!
 51 
 52 // Forward declarations.
 53 template <class T> class Array;
 54 template <class T> class GrowableArray;

 55 class ClassLoaderData;
 56 class fieldDescriptor;
 57 class klassVtable;
 58 class ModuleEntry;
 59 class PackageEntry;
 60 class vtableEntry;
 61 
 62 class Klass : public Metadata {
 63 
 64   friend class VMStructs;
 65  public:
 66   // Klass Kinds for all subclasses of Klass
 67   enum KlassKind : u2 {
 68     InstanceKlassKind,
 69     InstanceRefKlassKind,
 70     InstanceMirrorKlassKind,
 71     InstanceClassLoaderKlassKind,
 72     InstanceStackChunkKlassKind,
 73     TypeArrayKlassKind,
 74     ObjArrayKlassKind,
 75     UnknownKlassKind
 76   };
 77 
 78   static const uint KLASS_KIND_COUNT = ObjArrayKlassKind + 1;




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

184                                                      // no further need to call <clinit>
185     _has_aot_safe_initializer              = 1 << 7, // has @AOTSafeClassInitializer annotation
186     _is_runtime_setup_required             = 1 << 8, // has a runtimeSetup method to be called when
187                                                      // this class is loaded from AOT cache
188   };
189 #endif
190 
191   int _vtable_len;              // vtable length. This field may be read very often when we
192                                 // have lots of itable dispatches (e.g., lambdas and streams).
193                                 // Keep it away from the beginning of a Klass to avoid cacheline
194                                 // contention that may happen when a nearby object is modified.
195 
196   CDS_JAVA_HEAP_ONLY(int _archived_mirror_index;)
197 
198 public:
199 
200   JFR_ONLY(DEFINE_TRACE_ID_FIELD;)
201 
202 protected:
203 
204   Klass(KlassKind kind);
205   Klass();
206 
207   void* operator new(size_t size, ClassLoaderData* loader_data, size_t word_size, TRAPS) throw();
208 
209  public:
210   int kind() { return _kind; }
211 
212   enum class DefaultsLookupMode { find, skip };
213   enum class OverpassLookupMode { find, skip };
214   enum class StaticLookupMode   { find, skip };
215   enum class PrivateLookupMode  { find, skip };
216 
217   bool is_klass() const override { return true; }
218 
219   // super() cannot be InstanceKlass* -- Java arrays are covariant, and _super is used
220   // to implement that. NB: the _super of "[Ljava/lang/Integer;" is "[Ljava/lang/Number;"
221   // If this is not what your code expects, you're probably looking for:
222   // - Klass::java_super() - if you have a Klass*
223   // - InstanceKlass::super() - if you have an InstanceKlass* ik, ik->super() returns InstanceKlass*.
224   Klass* super() const               { return _super; }

447   static ByteSize primary_supers_offset()        { return byte_offset_of(Klass, _primary_supers); }
448   static ByteSize secondary_super_cache_offset() { return byte_offset_of(Klass, _secondary_super_cache); }
449   static ByteSize secondary_supers_offset()      { return byte_offset_of(Klass, _secondary_supers); }
450   static ByteSize java_mirror_offset()           { return byte_offset_of(Klass, _java_mirror); }
451   static ByteSize class_loader_data_offset()     { return byte_offset_of(Klass, _class_loader_data); }
452   static ByteSize layout_helper_offset()         { return byte_offset_of(Klass, _layout_helper); }
453   static ByteSize secondary_supers_bitmap_offset()
454                                                  { return byte_offset_of(Klass, _secondary_supers_bitmap); }
455   static ByteSize hash_slot_offset()             { return byte_offset_of(Klass, _hash_slot); }
456   static ByteSize misc_flags_offset()            { return byte_offset_of(Klass, _misc_flags._flags); }
457 
458   // Unpacking layout_helper:
459   static const int _lh_neutral_value           = 0;  // neutral non-array non-instance value
460   static const int _lh_instance_slow_path_bit  = 0x01;
461   static const int _lh_log2_element_size_shift = BitsPerByte*0;
462   static const int _lh_log2_element_size_mask  = BitsPerLong-1;
463   static const int _lh_element_type_shift      = BitsPerByte*1;
464   static const int _lh_element_type_mask       = right_n_bits<int>(BitsPerByte);  // shifted mask
465   static const int _lh_header_size_shift       = BitsPerByte*2;
466   static const int _lh_header_size_mask        = right_n_bits<int>(BitsPerByte);  // shifted mask
467   static const int _lh_array_tag_bits          = 2;
468   static const int _lh_array_tag_shift         = BitsPerInt - _lh_array_tag_bits;
469   static const int _lh_array_tag_obj_value     = ~0x01;   // 0x80000000 >> 30
470 
471   static const unsigned int _lh_array_tag_type_value = 0Xffffffff; // ~0x00,  // 0xC0000000 >> 30








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











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, "sanity");
505     return (BasicType) btvalue;
506   }
507 
508   // Return a value containing a single set bit that is in the bitset difference between the
509   // layout helpers for array-of-boolean and array-of-byte.
510   static int layout_helper_boolean_diffbit() {
511     uint zlh = static_cast<uint>(array_layout_helper(T_BOOLEAN));
512     uint blh = static_cast<uint>(array_layout_helper(T_BYTE));
513     // get all the bits that are set in zlh and clear in blh
514     uint candidates = (zlh & ~blh);
515     assert(candidates != 0, "must be"); // must be some if there is a solution.
516     // Use well known bit hack to isolate the low bit of candidates.
517     uint result = candidates & (-candidates);
518     assert(is_power_of_2(result), "must be power of 2");
519     assert((result & zlh) != 0, "must be set in alh of T_BOOLEAN");
520     assert((result & blh) == 0, "must be clear in alh of T_BYTE");
521     return static_cast<int>(result);
522   }
523 
524   static int layout_helper_log2_element_size(jint lh) {
525     assert(lh < (jint)_lh_neutral_value, "must be array");
526     int l2esz = (lh >> _lh_log2_element_size_shift) & _lh_log2_element_size_mask;
527     assert(l2esz <= LogBytesPerLong,
528            "sanity. l2esz: 0x%x for lh: 0x%x", (uint)l2esz, (uint)lh);
529     return l2esz;
530   }
531   static jint array_layout_helper(jint tag, int hsize, BasicType etype, int log2_esize) {
532     return (tag        << _lh_array_tag_shift)

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

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

673   virtual bool is_typeArray_klass_slow()    const { return false; }

674 #endif // ASSERT


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


698   bool is_typeArray_klass()             const { return assert_same_query( _kind == TypeArrayKlassKind, is_typeArray_klass_slow()); }


699   #undef assert_same_query
700 

701 
702   virtual bool is_interface() const     { return false; }
703   virtual bool is_abstract() const      { return false; }

704 
705   bool has_finalizer() const            { return _misc_flags.has_finalizer(); }
706   void set_has_finalizer()              { _misc_flags.set_has_finalizer(true); }
707   bool is_hidden() const                { return _misc_flags.is_hidden_class(); }
708   void set_is_hidden()                  { _misc_flags.set_is_hidden_class(true); }
709   bool is_value_based() const           { return _misc_flags.is_value_based_class(); }
710   void set_is_value_based()             { _misc_flags.set_is_value_based_class(true); }
711 
712   klass_flags_t misc_flags() const      { return _misc_flags.value(); }
713 
714   inline bool is_non_strong_hidden() const;
715 
716   bool is_cloneable() const;
717   void set_is_cloneable_fast() { _misc_flags.set_is_cloneable_fast(true); }
718 

719   inline markWord prototype_header() const;
720   inline void set_prototype_header(markWord header);
721   static ByteSize prototype_header_offset() { return in_ByteSize(offset_of(Klass, _prototype_header)); }

722 
723   JFR_ONLY(DEFINE_TRACE_ID_METHODS;)
724 
725   void metaspace_pointers_do(MetaspaceClosure* iter) override;
726   MetaspaceObj::Type type() const override { return ClassType; }
727 
728   inline bool is_loader_alive() const;
729   inline bool is_loader_present_and_alive() const;
730 
731   Klass* clean_subklass(bool log = false);
732 
733   // Clean out unnecessary weak klass links from the whole klass hierarchy.
734   static void clean_weak_klass_links(bool unloading_occurred, bool clean_alive_klasses = true);
735   // Clean out unnecessary weak klass links from the given InstanceKlass.
736   static void clean_weak_instanceklass_links(InstanceKlass* ik);
737 
738   // Return self, except for abstract classes with exactly 1
739   // implementor.  Then return the 1 concrete implementation.
740   Klass *up_cast_abstract();
741 

758   virtual jint jvmti_class_status() const;
759 
760   // Printing
761   void print_on(outputStream* st) const override;
762 
763   virtual void oop_print_value_on(oop obj, outputStream* st);
764   virtual void oop_print_on      (oop obj, outputStream* st);
765 
766   void print_secondary_supers_on(outputStream* st) const;
767 
768   // Verification
769   virtual void verify_on(outputStream* st);
770   void verify() { verify_on(tty); }
771 
772 #ifndef PRODUCT
773   bool verify_vtable_index(int index);
774 #endif
775 
776   virtual void oop_verify_on(oop obj, outputStream* st);
777 


778   // for error reporting
779   static bool is_valid(Klass* k);
780 
781   static void on_secondary_supers_verification_failure(Klass* super, Klass* sub, bool linear_result, bool table_result, const char* msg);
782 };
783 
784 #endif // SHARE_OOPS_KLASS_HPP

 35 #include "jfr/support/jfrTraceIdExtension.hpp"
 36 #endif
 37 
 38 //
 39 // A Klass provides:
 40 //  1: language level class object (method dictionary etc.)
 41 //  2: provide vm dispatch behavior for the object
 42 // Both functions are combined into one C++ class.
 43 
 44 // One reason for the oop/klass dichotomy in the implementation is
 45 // that we don't want a C++ vtbl pointer in every object.  Thus,
 46 // normal oops don't have any virtual functions.  Instead, they
 47 // forward all "virtual" functions to their klass, which does have
 48 // a vtbl and does the C++ dispatch depending on the object's
 49 // actual type.  (See oop.inline.hpp for some of the forwarding code.)
 50 // ALL FUNCTIONS IMPLEMENTING THIS DISPATCH ARE PREFIXED WITH "oop_"!
 51 
 52 // Forward declarations.
 53 template <class T> class Array;
 54 template <class T> class GrowableArray;
 55 class ArrayDescription;
 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  public:
 67   // Klass Kinds for all subclasses of Klass
 68    enum KlassKind : u2
 69    {
 70      InstanceKlassKind,
 71      InlineKlassKind,
 72      InstanceRefKlassKind,
 73      InstanceMirrorKlassKind,
 74      InstanceClassLoaderKlassKind,
 75      InstanceStackChunkKlassKind,
 76      TypeArrayKlassKind,
 77      ObjArrayKlassKind,
 78      RefArrayKlassKind,
 79      FlatArrayKlassKind,
 80      UnknownKlassKind
 81    };
 82 
 83    static const uint KLASS_KIND_COUNT = FlatArrayKlassKind + 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, 0xA0 if value types
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 

189                                                      // no further need to call <clinit>
190     _has_aot_safe_initializer              = 1 << 7, // has @AOTSafeClassInitializer annotation
191     _is_runtime_setup_required             = 1 << 8, // has a runtimeSetup method to be called when
192                                                      // this class is loaded from AOT cache
193   };
194 #endif
195 
196   int _vtable_len;              // vtable length. This field may be read very often when we
197                                 // have lots of itable dispatches (e.g., lambdas and streams).
198                                 // Keep it away from the beginning of a Klass to avoid cacheline
199                                 // contention that may happen when a nearby object is modified.
200 
201   CDS_JAVA_HEAP_ONLY(int _archived_mirror_index;)
202 
203 public:
204 
205   JFR_ONLY(DEFINE_TRACE_ID_FIELD;)
206 
207 protected:
208 
209   Klass(KlassKind kind, markWord prototype_header = markWord::prototype());
210   Klass();
211 
212   void* operator new(size_t size, ClassLoaderData* loader_data, size_t word_size, TRAPS) throw();
213 
214  public:
215   int kind() { return _kind; }
216 
217   enum class DefaultsLookupMode { find, skip };
218   enum class OverpassLookupMode { find, skip };
219   enum class StaticLookupMode   { find, skip };
220   enum class PrivateLookupMode  { find, skip };
221 
222   bool is_klass() const override { return true; }
223 
224   // super() cannot be InstanceKlass* -- Java arrays are covariant, and _super is used
225   // to implement that. NB: the _super of "[Ljava/lang/Integer;" is "[Ljava/lang/Number;"
226   // If this is not what your code expects, you're probably looking for:
227   // - Klass::java_super() - if you have a Klass*
228   // - InstanceKlass::super() - if you have an InstanceKlass* ik, ik->super() returns InstanceKlass*.
229   Klass* super() const               { return _super; }

452   static ByteSize primary_supers_offset()        { return byte_offset_of(Klass, _primary_supers); }
453   static ByteSize secondary_super_cache_offset() { return byte_offset_of(Klass, _secondary_super_cache); }
454   static ByteSize secondary_supers_offset()      { return byte_offset_of(Klass, _secondary_supers); }
455   static ByteSize java_mirror_offset()           { return byte_offset_of(Klass, _java_mirror); }
456   static ByteSize class_loader_data_offset()     { return byte_offset_of(Klass, _class_loader_data); }
457   static ByteSize layout_helper_offset()         { return byte_offset_of(Klass, _layout_helper); }
458   static ByteSize secondary_supers_bitmap_offset()
459                                                  { return byte_offset_of(Klass, _secondary_supers_bitmap); }
460   static ByteSize hash_slot_offset()             { return byte_offset_of(Klass, _hash_slot); }
461   static ByteSize misc_flags_offset()            { return byte_offset_of(Klass, _misc_flags._flags); }
462 
463   // Unpacking layout_helper:
464   static const int _lh_neutral_value           = 0;  // neutral non-array non-instance value
465   static const int _lh_instance_slow_path_bit  = 0x01;
466   static const int _lh_log2_element_size_shift = BitsPerByte*0;
467   static const int _lh_log2_element_size_mask  = BitsPerLong-1;
468   static const int _lh_element_type_shift      = BitsPerByte*1;
469   static const int _lh_element_type_mask       = right_n_bits<int>(BitsPerByte);  // shifted mask
470   static const int _lh_header_size_shift       = BitsPerByte*2;
471   static const int _lh_header_size_mask        = right_n_bits<int>(BitsPerByte);  // shifted mask
472   static const int _lh_array_tag_bits          = 4;
473   static const int _lh_array_tag_shift         = BitsPerInt - _lh_array_tag_bits;

474 
475   static const unsigned int _lh_array_tag_type_value = 0Xfffffffc;
476   static const unsigned int _lh_array_tag_flat_value = 0Xfffffffa;
477   static const unsigned int _lh_array_tag_ref_value  = 0Xfffffff8;
478 
479   // null-free array flag bit under the array tag bits, shift one more to get array tag value
480   static const int _lh_null_free_shift = _lh_array_tag_shift - 1;
481   static const int _lh_null_free_mask  = 1;
482 
483   static const jint _lh_array_tag_flat_value_bit_inplace = (jint) (1 << (_lh_array_tag_shift + 1));
484 
485   static int layout_helper_size_in_bytes(jint lh) {
486     assert(lh > (jint)_lh_neutral_value, "must be instance");
487     return (int) lh & ~_lh_instance_slow_path_bit;
488   }
489   static bool layout_helper_needs_slow_path(jint lh) {
490     assert(lh > (jint)_lh_neutral_value, "must be instance");
491     return (lh & _lh_instance_slow_path_bit) != 0;
492   }
493   static bool layout_helper_is_instance(jint lh) {
494     return (jint)lh > (jint)_lh_neutral_value;
495   }
496   static bool layout_helper_is_array(jint lh) {
497     return (jint)lh < (jint)_lh_neutral_value;
498   }
499   static bool layout_helper_is_typeArray(jint lh) {
500     return (juint) _lh_array_tag_type_value == (juint)(lh >> _lh_array_tag_shift);

501   }
502   static bool layout_helper_is_refArray(jint lh) {
503     return (juint)_lh_array_tag_ref_value == (juint)(lh >> _lh_array_tag_shift);
504   }
505   static bool layout_helper_is_flatArray(jint lh) {
506     return (juint)_lh_array_tag_flat_value == (juint)(lh >> _lh_array_tag_shift);
507   }
508   static bool layout_helper_is_null_free(jint lh) {
509     assert(layout_helper_is_flatArray(lh) || layout_helper_is_refArray(lh), "must be array of inline types");
510     return ((lh >> _lh_null_free_shift) & _lh_null_free_mask);
511   }
512   static jint layout_helper_set_null_free(jint lh) {
513     lh |= (_lh_null_free_mask << _lh_null_free_shift);
514     assert(layout_helper_is_null_free(lh), "Bad encoding");
515     return lh;
516   }
517   static int layout_helper_header_size(jint lh) {
518     assert(lh < (jint)_lh_neutral_value, "must be array");
519     int hsize = (lh >> _lh_header_size_shift) & _lh_header_size_mask;
520     assert(hsize > 0 && hsize < (int)sizeof(oopDesc)*3, "sanity");
521     return hsize;
522   }
523   static BasicType layout_helper_element_type(jint lh) {
524     assert(lh < (jint)_lh_neutral_value, "must be array");
525     int btvalue = (lh >> _lh_element_type_shift) & _lh_element_type_mask;
526     assert((btvalue >= T_BOOLEAN && btvalue <= T_OBJECT) || btvalue == T_FLAT_ELEMENT, "sanity");
527     return (BasicType) btvalue;
528   }
529 
530   // Return a value containing a single set bit that is in the bitset difference between the
531   // layout helpers for array-of-boolean and array-of-byte.
532   static int layout_helper_boolean_diffbit() {
533     uint zlh = static_cast<uint>(array_layout_helper(T_BOOLEAN));
534     uint blh = static_cast<uint>(array_layout_helper(T_BYTE));
535     // get all the bits that are set in zlh and clear in blh
536     uint candidates = (zlh & ~blh);
537     assert(candidates != 0, "must be"); // must be some if there is a solution.
538     // Use well known bit hack to isolate the low bit of candidates.
539     uint result = candidates & (-candidates);
540     assert(is_power_of_2(result), "must be power of 2");
541     assert((result & zlh) != 0, "must be set in alh of T_BOOLEAN");
542     assert((result & blh) == 0, "must be clear in alh of T_BYTE");
543     return static_cast<int>(result);
544   }
545 
546   static int layout_helper_log2_element_size(jint lh) {
547     assert(lh < (jint)_lh_neutral_value, "must be array");
548     int l2esz = (lh >> _lh_log2_element_size_shift) & _lh_log2_element_size_mask;
549     assert(layout_helper_element_type(lh) == T_FLAT_ELEMENT || l2esz <= LogBytesPerLong,
550            "sanity. l2esz: 0x%x for lh: 0x%x", (uint)l2esz, (uint)lh);
551     return l2esz;
552   }
553   static jint array_layout_helper(jint tag, bool null_free, int hsize, BasicType etype, int log2_esize) {
554     return (tag        << _lh_array_tag_shift)
555       |    ((null_free ? 1 : 0) <<  _lh_null_free_shift)
556       |    (hsize      << _lh_header_size_shift)
557       |    ((int)etype << _lh_element_type_shift)
558       |    (log2_esize << _lh_log2_element_size_shift);
559   }
560   static jint instance_layout_helper(jint size, bool slow_path_flag) {
561     return (size << LogBytesPerWord)
562       |    (slow_path_flag ? _lh_instance_slow_path_bit : 0);
563   }
564   static int layout_helper_to_size_helper(jint lh) {
565     assert(lh > (jint)_lh_neutral_value, "must be instance");
566     // Note that the following expression discards _lh_instance_slow_path_bit.
567     return lh >> LogBytesPerWord;
568   }
569   // Out-of-line version computes everything based on the etype:
570   static jint array_layout_helper(BasicType etype);
571 
572   // What is the maximum number of primary superclasses any klass can have?
573   static juint primary_super_limit()         { return _primary_super_limit; }
574 
575   // vtables

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

718   bool is_reference_instance_klass()    const { return _kind == InstanceRefKlassKind; }
719   bool is_mirror_instance_klass()       const { return _kind == InstanceMirrorKlassKind; }
720   bool is_class_loader_instance_klass() const { return _kind == InstanceClassLoaderKlassKind; }
721   bool is_array_klass()                 const { return assert_same_query( _kind >= TypeArrayKlassKind, is_array_klass_slow()); }
722   bool is_stack_chunk_instance_klass()  const { return _kind == InstanceStackChunkKlassKind; }
723   bool is_flatArray_klass()             const { return assert_same_query( _kind == FlatArrayKlassKind, is_flatArray_klass_slow()); }
724   bool is_objArray_klass()              const { return assert_same_query( _kind == ObjArrayKlassKind || _kind == RefArrayKlassKind || _kind == FlatArrayKlassKind,  is_objArray_klass_slow()); }
725   bool is_refArray_klass()              const { return assert_same_query( _kind == RefArrayKlassKind, is_refArray_klass_slow()); }
726   bool is_typeArray_klass()             const { return assert_same_query( _kind == TypeArrayKlassKind, is_typeArray_klass_slow()); }
727   bool is_refined_objArray_klass()      const { return is_refArray_klass() || is_flatArray_klass(); }
728   bool is_unrefined_objArray_klass()    const { return _kind == ObjArrayKlassKind; }
729   #undef assert_same_query
730 
731   inline bool is_null_free_array_klass() const { return !is_typeArray_klass() && layout_helper_is_null_free(layout_helper()); }
732 
733   virtual bool is_interface() const     { return false; }
734   virtual bool is_abstract() const      { return false; }
735   virtual bool is_identity_class() const { return false; }
736 
737   bool has_finalizer() const            { return _misc_flags.has_finalizer(); }
738   void set_has_finalizer()              { _misc_flags.set_has_finalizer(true); }
739   bool is_hidden() const                { return _misc_flags.is_hidden_class(); }
740   void set_is_hidden()                  { _misc_flags.set_is_hidden_class(true); }
741   bool is_value_based() const           { return _misc_flags.is_value_based_class(); }
742   void set_is_value_based()             { _misc_flags.set_is_value_based_class(true); }
743 
744   klass_flags_t misc_flags() const      { return _misc_flags.value(); }
745 
746   inline bool is_non_strong_hidden() const;
747 
748   bool is_cloneable() const;
749   void set_is_cloneable_fast() { _misc_flags.set_is_cloneable_fast(true); }
750 
751   static inline markWord make_prototype_header(const Klass* kls, markWord prototype = markWord::prototype());
752   inline markWord prototype_header() const;
753   inline void set_prototype_header(markWord header);
754   static ByteSize prototype_header_offset() { return in_ByteSize(offset_of(Klass, _prototype_header)); }
755   inline void set_prototype_header_klass(narrowKlass klass);
756 
757   JFR_ONLY(DEFINE_TRACE_ID_METHODS;)
758 
759   void metaspace_pointers_do(MetaspaceClosure* iter) override;
760   MetaspaceObj::Type type() const override { return ClassType; }
761 
762   inline bool is_loader_alive() const;
763   inline bool is_loader_present_and_alive() const;
764 
765   Klass* clean_subklass(bool log = false);
766 
767   // Clean out unnecessary weak klass links from the whole klass hierarchy.
768   static void clean_weak_klass_links(bool unloading_occurred, bool clean_alive_klasses = true);
769   // Clean out unnecessary weak klass links from the given InstanceKlass.
770   static void clean_weak_instanceklass_links(InstanceKlass* ik);
771 
772   // Return self, except for abstract classes with exactly 1
773   // implementor.  Then return the 1 concrete implementation.
774   Klass *up_cast_abstract();
775 

792   virtual jint jvmti_class_status() const;
793 
794   // Printing
795   void print_on(outputStream* st) const override;
796 
797   virtual void oop_print_value_on(oop obj, outputStream* st);
798   virtual void oop_print_on      (oop obj, outputStream* st);
799 
800   void print_secondary_supers_on(outputStream* st) const;
801 
802   // Verification
803   virtual void verify_on(outputStream* st);
804   void verify() { verify_on(tty); }
805 
806 #ifndef PRODUCT
807   bool verify_vtable_index(int index);
808 #endif
809 
810   virtual void oop_verify_on(oop obj, outputStream* st);
811 
812   void validate_array_description(const ArrayDescription& ad) NOT_DEBUG_RETURN;
813 
814   // for error reporting
815   static bool is_valid(Klass* k);
816 
817   static void on_secondary_supers_verification_failure(Klass* super, Klass* sub, bool linear_result, bool table_result, const char* msg);
818 };
819 
820 #endif // SHARE_OOPS_KLASS_HPP
< prev index next >