< prev index next >

src/hotspot/share/oops/klass.hpp

Print this page

 23  */
 24 
 25 #ifndef SHARE_OOPS_KLASS_HPP
 26 #define SHARE_OOPS_KLASS_HPP
 27 
 28 #include "memory/iterator.hpp"
 29 #include "memory/memRegion.hpp"
 30 #include "oops/markWord.hpp"
 31 #include "oops/metadata.hpp"
 32 #include "oops/oop.hpp"
 33 #include "oops/oopHandle.hpp"
 34 #include "utilities/accessFlags.hpp"
 35 #include "utilities/macros.hpp"
 36 #if INCLUDE_JFR
 37 #include "jfr/support/jfrTraceIdExtension.hpp"
 38 #endif
 39 
 40 // Klass Kinds for all subclasses of Klass
 41 enum KlassKind {
 42   InstanceKlassKind,

 43   InstanceRefKlassKind,
 44   InstanceMirrorKlassKind,
 45   InstanceClassLoaderKlassKind,
 46   InstanceStackChunkKlassKind,
 47   TypeArrayKlassKind,

 48   ObjArrayKlassKind
 49 };
 50 
 51 const uint KLASS_KIND_COUNT = ObjArrayKlassKind + 1;
 52 
 53 //
 54 // A Klass provides:
 55 //  1: language level class object (method dictionary etc.)
 56 //  2: provide vm dispatch behavior for the object
 57 // Both functions are combined into one C++ class.
 58 
 59 // One reason for the oop/klass dichotomy in the implementation is
 60 // that we don't want a C++ vtbl pointer in every object.  Thus,
 61 // normal oops don't have any virtual functions.  Instead, they
 62 // forward all "virtual" functions to their klass, which does have
 63 // a vtbl and does the C++ dispatch depending on the object's
 64 // actual type.  (See oop.inline.hpp for some of the forwarding code.)
 65 // ALL FUNCTIONS IMPLEMENTING THIS DISPATCH ARE PREFIXED WITH "oop_"!
 66 
 67 // Forward declarations.

 82  protected:
 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 

148   // First subclass (NULL if none); _subklass->next_sibling() is next one
149   Klass* volatile _subklass;
150   // Sibling link (or NULL); links all subklasses of a klass
151   Klass* volatile _next_sibling;
152 
153   // All klasses loaded by a class loader are chained through these links
154   Klass*      _next_link;
155 
156   // The VM's representation of the ClassLoader used to load this class.
157   // Provide access the corresponding instance java.lang.ClassLoader.
158   ClassLoaderData* _class_loader_data;
159 
160   int _vtable_len;              // vtable length. This field may be read very often when we
161                                 // have lots of itable dispatches (e.g., lambdas and streams).
162                                 // Keep it away from the beginning of a Klass to avoid cacheline
163                                 // contention that may happen when a nearby object is modified.
164   AccessFlags _access_flags;    // Access flags. The class/interface distinction is stored here.
165 
166   JFR_ONLY(DEFINE_TRACE_ID_FIELD;)
167 

168 private:
169   // This is an index into FileMapHeader::_shared_path_table[], to
170   // associate this class with the JAR file where it's loaded from during
171   // dump time. If a class is not loaded from the shared archive, this field is
172   // -1.
173   jshort _shared_class_path_index;
174 
175 #if INCLUDE_CDS
176   // Various attributes for shared classes. Should be zero for a non-shared class.
177   u2     _shared_class_flags;
178   enum CDSSharedClassFlags {
179     _archived_lambda_proxy_is_available    = 1 << 1,
180     _has_value_based_class_annotation      = 1 << 2,
181     _verified_at_dump_time                 = 1 << 3,
182     _has_archived_enum_objs                = 1 << 4,
183     // This class was not loaded from a classfile in the module image
184     // or classpath.
185     _is_generated_shared_class             = 1 << 5
186   };
187 #endif

376   static ByteSize super_offset()                 { return in_ByteSize(offset_of(Klass, _super)); }
377   static ByteSize super_check_offset_offset()    { return in_ByteSize(offset_of(Klass, _super_check_offset)); }
378   static ByteSize primary_supers_offset()        { return in_ByteSize(offset_of(Klass, _primary_supers)); }
379   static ByteSize secondary_super_cache_offset() { return in_ByteSize(offset_of(Klass, _secondary_super_cache)); }
380   static ByteSize secondary_supers_offset()      { return in_ByteSize(offset_of(Klass, _secondary_supers)); }
381   static ByteSize java_mirror_offset()           { return in_ByteSize(offset_of(Klass, _java_mirror)); }
382   static ByteSize class_loader_data_offset()     { return in_ByteSize(offset_of(Klass, _class_loader_data)); }
383   static ByteSize modifier_flags_offset()        { return in_ByteSize(offset_of(Klass, _modifier_flags)); }
384   static ByteSize layout_helper_offset()         { return in_ByteSize(offset_of(Klass, _layout_helper)); }
385   static ByteSize access_flags_offset()          { return in_ByteSize(offset_of(Klass, _access_flags)); }
386 
387   // Unpacking layout_helper:
388   static const int _lh_neutral_value           = 0;  // neutral non-array non-instance value
389   static const int _lh_instance_slow_path_bit  = 0x01;
390   static const int _lh_log2_element_size_shift = BitsPerByte*0;
391   static const int _lh_log2_element_size_mask  = BitsPerLong-1;
392   static const int _lh_element_type_shift      = BitsPerByte*1;
393   static const int _lh_element_type_mask       = right_n_bits(BitsPerByte);  // shifted mask
394   static const int _lh_header_size_shift       = BitsPerByte*2;
395   static const int _lh_header_size_mask        = right_n_bits(BitsPerByte);  // shifted mask
396   static const int _lh_array_tag_bits          = 2;
397   static const int _lh_array_tag_shift         = BitsPerInt - _lh_array_tag_bits;
398   static const int _lh_array_tag_obj_value     = ~0x01;   // 0x80000000 >> 30
399 
400   static const unsigned int _lh_array_tag_type_value = 0Xffffffff; // ~0x00,  // 0xC0000000 >> 30









401 
402   static int layout_helper_size_in_bytes(jint lh) {
403     assert(lh > (jint)_lh_neutral_value, "must be instance");
404     return (int) lh & ~_lh_instance_slow_path_bit;
405   }
406   static bool layout_helper_needs_slow_path(jint lh) {
407     assert(lh > (jint)_lh_neutral_value, "must be instance");
408     return (lh & _lh_instance_slow_path_bit) != 0;
409   }
410   static bool layout_helper_is_instance(jint lh) {
411     return (jint)lh > (jint)_lh_neutral_value;
412   }
413   static bool layout_helper_is_array(jint lh) {
414     return (jint)lh < (jint)_lh_neutral_value;
415   }
416   static bool layout_helper_is_typeArray(jint lh) {
417     // _lh_array_tag_type_value == (lh >> _lh_array_tag_shift);
418     return (juint)lh >= (juint)(_lh_array_tag_type_value << _lh_array_tag_shift);
419   }
420   static bool layout_helper_is_objArray(jint lh) {
421     // _lh_array_tag_obj_value == (lh >> _lh_array_tag_shift);
422     return (jint)lh < (jint)(_lh_array_tag_type_value << _lh_array_tag_shift);











423   }
424   static int layout_helper_header_size(jint lh) {
425     assert(lh < (jint)_lh_neutral_value, "must be array");
426     int hsize = (lh >> _lh_header_size_shift) & _lh_header_size_mask;
427     assert(hsize > 0 && hsize < (int)sizeof(oopDesc)*3, "sanity");
428     return hsize;
429   }
430   static BasicType layout_helper_element_type(jint lh) {
431     assert(lh < (jint)_lh_neutral_value, "must be array");
432     int btvalue = (lh >> _lh_element_type_shift) & _lh_element_type_mask;
433     assert(btvalue >= T_BOOLEAN && btvalue <= T_OBJECT, "sanity");
434     return (BasicType) btvalue;
435   }
436 
437   // Want a pattern to quickly diff against layout header in register
438   // find something less clever!
439   static int layout_helper_boolean_diffbit() {
440     jint zlh = array_layout_helper(T_BOOLEAN);
441     jint blh = array_layout_helper(T_BYTE);
442     assert(zlh != blh, "array layout helpers must differ");
443     int diffbit = 1;
444     while ((diffbit & (zlh ^ blh)) == 0 && (diffbit & zlh) == 0) {
445       diffbit <<= 1;
446       assert(diffbit != 0, "make sure T_BOOLEAN has a different bit than T_BYTE");
447     }
448     return diffbit;
449   }
450 
451   static int layout_helper_log2_element_size(jint lh) {
452     assert(lh < (jint)_lh_neutral_value, "must be array");
453     int l2esz = (lh >> _lh_log2_element_size_shift) & _lh_log2_element_size_mask;
454     assert(l2esz <= LogBytesPerLong,
455            "sanity. l2esz: 0x%x for lh: 0x%x", (uint)l2esz, (uint)lh);
456     return l2esz;
457   }
458   static jint array_layout_helper(jint tag, int hsize, BasicType etype, int log2_esize) {
459     return (tag        << _lh_array_tag_shift)

460       |    (hsize      << _lh_header_size_shift)
461       |    ((int)etype << _lh_element_type_shift)
462       |    (log2_esize << _lh_log2_element_size_shift);
463   }
464   static jint instance_layout_helper(jint size, bool slow_path_flag) {
465     return (size << LogBytesPerWord)
466       |    (slow_path_flag ? _lh_instance_slow_path_bit : 0);
467   }
468   static int layout_helper_to_size_helper(jint lh) {
469     assert(lh > (jint)_lh_neutral_value, "must be instance");
470     // Note that the following expression discards _lh_instance_slow_path_bit.
471     return lh >> LogBytesPerWord;
472   }
473   // Out-of-line version computes everything based on the etype:
474   static jint array_layout_helper(BasicType etype);
475 
476   // What is the maximum number of primary superclasses any klass can have?
477   static juint primary_super_limit()         { return _primary_super_limit; }
478 
479   // vtables

592   // Returns the name for a class (Resource allocated) as the class
593   // would appear in a signature.
594   // For arrays, this returns the name of the element with a leading '['.
595   // For classes, this returns the name with a leading 'L' and a trailing ';'
596   //     and the package separators as '/'.
597   virtual const char* signature_name() const;
598 
599   const char* joint_in_module_of_loader(const Klass* class2, bool include_parent_loader = false) const;
600   const char* class_in_module_of_loader(bool use_are = false, bool include_parent_loader = false) const;
601 
602   // Returns "interface", "abstract class" or "class".
603   const char* external_kind() const;
604 
605   // type testing operations
606 #ifdef ASSERT
607  protected:
608   virtual bool is_instance_klass_slow()     const { return false; }
609   virtual bool is_array_klass_slow()        const { return false; }
610   virtual bool is_objArray_klass_slow()     const { return false; }
611   virtual bool is_typeArray_klass_slow()    const { return false; }

612 #endif // ASSERT


613  public:
614 
615   // Fast non-virtual versions
616   #ifndef ASSERT
617   #define assert_same_query(xval, xcheck) xval
618   #else
619  private:
620   static bool assert_same_query(bool xval, bool xslow) {
621     assert(xval == xslow, "slow and fast queries agree");
622     return xval;
623   }
624  public:
625   #endif
626 
627   bool is_instance_klass()              const { return assert_same_query(_kind <= InstanceStackChunkKlassKind, is_instance_klass_slow()); }

628   // Other is anything that is not one of the more specialized kinds of InstanceKlass.
629   bool is_other_instance_klass()        const { return _kind == InstanceKlassKind; }
630   bool is_reference_instance_klass()    const { return _kind == InstanceRefKlassKind; }
631   bool is_mirror_instance_klass()       const { return _kind == InstanceMirrorKlassKind; }
632   bool is_class_loader_instance_klass() const { return _kind == InstanceClassLoaderKlassKind; }
633   bool is_array_klass()                 const { return assert_same_query( _kind >= TypeArrayKlassKind, is_array_klass_slow()); }
634   bool is_stack_chunk_instance_klass()  const { return _kind == InstanceStackChunkKlassKind; }

635   bool is_objArray_klass()              const { return assert_same_query( _kind == ObjArrayKlassKind,  is_objArray_klass_slow()); }
636   bool is_typeArray_klass()             const { return assert_same_query( _kind == TypeArrayKlassKind, is_typeArray_klass_slow()); }
637   #undef assert_same_query
638 


639   // Access flags
640   AccessFlags access_flags() const         { return _access_flags;  }
641   void set_access_flags(AccessFlags flags) { _access_flags = flags; }
642 
643   bool is_public() const                { return _access_flags.is_public(); }
644   bool is_final() const                 { return _access_flags.is_final(); }
645   bool is_interface() const             { return _access_flags.is_interface(); }
646   bool is_abstract() const              { return _access_flags.is_abstract(); }
647   bool is_super() const                 { return _access_flags.is_super(); }
648   bool is_synthetic() const             { return _access_flags.is_synthetic(); }


649   void set_is_synthetic()               { _access_flags.set_is_synthetic(); }
650   bool has_finalizer() const            { return _access_flags.has_finalizer(); }
651   bool has_final_method() const         { return _access_flags.has_final_method(); }
652   void set_has_finalizer()              { _access_flags.set_has_finalizer(); }
653   void set_has_final_method()           { _access_flags.set_has_final_method(); }
654   bool has_vanilla_constructor() const  { return _access_flags.has_vanilla_constructor(); }
655   void set_has_vanilla_constructor()    { _access_flags.set_has_vanilla_constructor(); }
656   bool has_miranda_methods () const     { return access_flags().has_miranda_methods(); }
657   void set_has_miranda_methods()        { _access_flags.set_has_miranda_methods(); }
658   bool is_shared() const                { return access_flags().is_shared_class(); } // shadows MetaspaceObj::is_shared)()
659   void set_is_shared()                  { _access_flags.set_is_shared_class(); }
660   bool is_hidden() const                { return access_flags().is_hidden_class(); }
661   void set_is_hidden()                  { _access_flags.set_is_hidden_class(); }
662   bool is_value_based()                 { return _access_flags.is_value_based_class(); }
663   void set_is_value_based()             { _access_flags.set_is_value_based_class(); }
664 
665   inline bool is_non_strong_hidden() const;
666 
667   bool is_cloneable() const;
668   void set_is_cloneable();
669 











670   JFR_ONLY(DEFINE_TRACE_ID_METHODS;)
671 
672   virtual void metaspace_pointers_do(MetaspaceClosure* iter);
673   virtual MetaspaceObj::Type type() const { return ClassType; }
674 
675   inline bool is_loader_alive() const;
676 
677   void clean_subklass();
678 
679   static void clean_weak_klass_links(bool unloading_occurred, bool clean_alive_klasses = true);
680   static void clean_subklass_tree() {
681     clean_weak_klass_links(/*unloading_occurred*/ true , /* clean_alive_klasses */ false);
682   }
683 
684   // Return self, except for abstract classes with exactly 1
685   // implementor.  Then return the 1 concrete implementation.
686   Klass *up_cast_abstract();
687 
688   // klass name
689   Symbol* name() const                   { return _name; }

 23  */
 24 
 25 #ifndef SHARE_OOPS_KLASS_HPP
 26 #define SHARE_OOPS_KLASS_HPP
 27 
 28 #include "memory/iterator.hpp"
 29 #include "memory/memRegion.hpp"
 30 #include "oops/markWord.hpp"
 31 #include "oops/metadata.hpp"
 32 #include "oops/oop.hpp"
 33 #include "oops/oopHandle.hpp"
 34 #include "utilities/accessFlags.hpp"
 35 #include "utilities/macros.hpp"
 36 #if INCLUDE_JFR
 37 #include "jfr/support/jfrTraceIdExtension.hpp"
 38 #endif
 39 
 40 // Klass Kinds for all subclasses of Klass
 41 enum KlassKind {
 42   InstanceKlassKind,
 43   InlineKlassKind,
 44   InstanceRefKlassKind,
 45   InstanceMirrorKlassKind,
 46   InstanceClassLoaderKlassKind,
 47   InstanceStackChunkKlassKind,
 48   TypeArrayKlassKind,
 49   FlatArrayKlassKind,
 50   ObjArrayKlassKind
 51 };
 52 
 53 const uint KLASS_KIND_COUNT = ObjArrayKlassKind + 1;
 54 
 55 //
 56 // A Klass provides:
 57 //  1: language level class object (method dictionary etc.)
 58 //  2: provide vm dispatch behavior for the object
 59 // Both functions are combined into one C++ class.
 60 
 61 // One reason for the oop/klass dichotomy in the implementation is
 62 // that we don't want a C++ vtbl pointer in every object.  Thus,
 63 // normal oops don't have any virtual functions.  Instead, they
 64 // forward all "virtual" functions to their klass, which does have
 65 // a vtbl and does the C++ dispatch depending on the object's
 66 // actual type.  (See oop.inline.hpp for some of the forwarding code.)
 67 // ALL FUNCTIONS IMPLEMENTING THIS DISPATCH ARE PREFIXED WITH "oop_"!
 68 
 69 // Forward declarations.

 84  protected:
 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 

150   // First subclass (NULL if none); _subklass->next_sibling() is next one
151   Klass* volatile _subklass;
152   // Sibling link (or NULL); links all subklasses of a klass
153   Klass* volatile _next_sibling;
154 
155   // All klasses loaded by a class loader are chained through these links
156   Klass*      _next_link;
157 
158   // The VM's representation of the ClassLoader used to load this class.
159   // Provide access the corresponding instance java.lang.ClassLoader.
160   ClassLoaderData* _class_loader_data;
161 
162   int _vtable_len;              // vtable length. This field may be read very often when we
163                                 // have lots of itable dispatches (e.g., lambdas and streams).
164                                 // Keep it away from the beginning of a Klass to avoid cacheline
165                                 // contention that may happen when a nearby object is modified.
166   AccessFlags _access_flags;    // Access flags. The class/interface distinction is stored here.
167 
168   JFR_ONLY(DEFINE_TRACE_ID_FIELD;)
169 
170   markWord _prototype_header;  // inline type and inline array mark patterns
171 private:
172   // This is an index into FileMapHeader::_shared_path_table[], to
173   // associate this class with the JAR file where it's loaded from during
174   // dump time. If a class is not loaded from the shared archive, this field is
175   // -1.
176   jshort _shared_class_path_index;
177 
178 #if INCLUDE_CDS
179   // Various attributes for shared classes. Should be zero for a non-shared class.
180   u2     _shared_class_flags;
181   enum CDSSharedClassFlags {
182     _archived_lambda_proxy_is_available    = 1 << 1,
183     _has_value_based_class_annotation      = 1 << 2,
184     _verified_at_dump_time                 = 1 << 3,
185     _has_archived_enum_objs                = 1 << 4,
186     // This class was not loaded from a classfile in the module image
187     // or classpath.
188     _is_generated_shared_class             = 1 << 5
189   };
190 #endif

379   static ByteSize super_offset()                 { return in_ByteSize(offset_of(Klass, _super)); }
380   static ByteSize super_check_offset_offset()    { return in_ByteSize(offset_of(Klass, _super_check_offset)); }
381   static ByteSize primary_supers_offset()        { return in_ByteSize(offset_of(Klass, _primary_supers)); }
382   static ByteSize secondary_super_cache_offset() { return in_ByteSize(offset_of(Klass, _secondary_super_cache)); }
383   static ByteSize secondary_supers_offset()      { return in_ByteSize(offset_of(Klass, _secondary_supers)); }
384   static ByteSize java_mirror_offset()           { return in_ByteSize(offset_of(Klass, _java_mirror)); }
385   static ByteSize class_loader_data_offset()     { return in_ByteSize(offset_of(Klass, _class_loader_data)); }
386   static ByteSize modifier_flags_offset()        { return in_ByteSize(offset_of(Klass, _modifier_flags)); }
387   static ByteSize layout_helper_offset()         { return in_ByteSize(offset_of(Klass, _layout_helper)); }
388   static ByteSize access_flags_offset()          { return in_ByteSize(offset_of(Klass, _access_flags)); }
389 
390   // Unpacking layout_helper:
391   static const int _lh_neutral_value           = 0;  // neutral non-array non-instance value
392   static const int _lh_instance_slow_path_bit  = 0x01;
393   static const int _lh_log2_element_size_shift = BitsPerByte*0;
394   static const int _lh_log2_element_size_mask  = BitsPerLong-1;
395   static const int _lh_element_type_shift      = BitsPerByte*1;
396   static const int _lh_element_type_mask       = right_n_bits(BitsPerByte);  // shifted mask
397   static const int _lh_header_size_shift       = BitsPerByte*2;
398   static const int _lh_header_size_mask        = right_n_bits(BitsPerByte);  // shifted mask
399   static const int _lh_array_tag_bits          = 3;
400   static const int _lh_array_tag_shift         = BitsPerInt - _lh_array_tag_bits;

401 
402   static const unsigned int _lh_array_tag_type_value = 0Xfffffffc;
403   static const unsigned int _lh_array_tag_vt_value   = 0Xfffffffd;
404   static const unsigned int _lh_array_tag_obj_value  = 0Xfffffffe;
405 
406   // null-free array flag bit under the array tag bits, shift one more to get array tag value
407   static const int _lh_null_free_shift = _lh_array_tag_shift - 1;
408   static const int _lh_null_free_mask  = 1;
409 
410   static const jint _lh_array_tag_flat_value_bit_inplace = (jint) (1 << _lh_array_tag_shift);
411   static const jint _lh_null_free_array_bit_inplace = (jint) (_lh_null_free_mask << _lh_null_free_shift);
412 
413   static int layout_helper_size_in_bytes(jint lh) {
414     assert(lh > (jint)_lh_neutral_value, "must be instance");
415     return (int) lh & ~_lh_instance_slow_path_bit;
416   }
417   static bool layout_helper_needs_slow_path(jint lh) {
418     assert(lh > (jint)_lh_neutral_value, "must be instance");
419     return (lh & _lh_instance_slow_path_bit) != 0;
420   }
421   static bool layout_helper_is_instance(jint lh) {
422     return (jint)lh > (jint)_lh_neutral_value;
423   }
424   static bool layout_helper_is_array(jint lh) {
425     return (jint)lh < (jint)_lh_neutral_value;
426   }
427   static bool layout_helper_is_typeArray(jint lh) {
428     return (juint) _lh_array_tag_type_value == (juint)(lh >> _lh_array_tag_shift);

429   }
430   static bool layout_helper_is_objArray(jint lh) {
431     return (juint)_lh_array_tag_obj_value == (juint)(lh >> _lh_array_tag_shift);
432   }
433   static bool layout_helper_is_flatArray(jint lh) {
434     return (juint)_lh_array_tag_vt_value == (juint)(lh >> _lh_array_tag_shift);
435   }
436   static bool layout_helper_is_null_free(jint lh) {
437     assert(layout_helper_is_flatArray(lh) || layout_helper_is_objArray(lh), "must be array of inline types");
438     return ((lh >> _lh_null_free_shift) & _lh_null_free_mask);
439   }
440   static jint layout_helper_set_null_free(jint lh) {
441     lh |= (_lh_null_free_mask << _lh_null_free_shift);
442     assert(layout_helper_is_null_free(lh), "Bad encoding");
443     return lh;
444   }
445   static int layout_helper_header_size(jint lh) {
446     assert(lh < (jint)_lh_neutral_value, "must be array");
447     int hsize = (lh >> _lh_header_size_shift) & _lh_header_size_mask;
448     assert(hsize > 0 && hsize < (int)sizeof(oopDesc)*3, "sanity");
449     return hsize;
450   }
451   static BasicType layout_helper_element_type(jint lh) {
452     assert(lh < (jint)_lh_neutral_value, "must be array");
453     int btvalue = (lh >> _lh_element_type_shift) & _lh_element_type_mask;
454     assert((btvalue >= T_BOOLEAN && btvalue <= T_OBJECT) || btvalue == T_PRIMITIVE_OBJECT, "sanity");
455     return (BasicType) btvalue;
456   }
457 
458   // Want a pattern to quickly diff against layout header in register
459   // find something less clever!
460   static int layout_helper_boolean_diffbit() {
461     jint zlh = array_layout_helper(T_BOOLEAN);
462     jint blh = array_layout_helper(T_BYTE);
463     assert(zlh != blh, "array layout helpers must differ");
464     int diffbit = 1;
465     while ((diffbit & (zlh ^ blh)) == 0 && (diffbit & zlh) == 0) {
466       diffbit <<= 1;
467       assert(diffbit != 0, "make sure T_BOOLEAN has a different bit than T_BYTE");
468     }
469     return diffbit;
470   }
471 
472   static int layout_helper_log2_element_size(jint lh) {
473     assert(lh < (jint)_lh_neutral_value, "must be array");
474     int l2esz = (lh >> _lh_log2_element_size_shift) & _lh_log2_element_size_mask;
475     assert(layout_helper_element_type(lh) == T_PRIMITIVE_OBJECT || l2esz <= LogBytesPerLong,
476            "sanity. l2esz: 0x%x for lh: 0x%x", (uint)l2esz, (uint)lh);
477     return l2esz;
478   }
479   static jint array_layout_helper(jint tag, bool null_free, int hsize, BasicType etype, int log2_esize) {
480     return (tag        << _lh_array_tag_shift)
481       |    ((null_free ? 1 : 0) <<  _lh_null_free_shift)
482       |    (hsize      << _lh_header_size_shift)
483       |    ((int)etype << _lh_element_type_shift)
484       |    (log2_esize << _lh_log2_element_size_shift);
485   }
486   static jint instance_layout_helper(jint size, bool slow_path_flag) {
487     return (size << LogBytesPerWord)
488       |    (slow_path_flag ? _lh_instance_slow_path_bit : 0);
489   }
490   static int layout_helper_to_size_helper(jint lh) {
491     assert(lh > (jint)_lh_neutral_value, "must be instance");
492     // Note that the following expression discards _lh_instance_slow_path_bit.
493     return lh >> LogBytesPerWord;
494   }
495   // Out-of-line version computes everything based on the etype:
496   static jint array_layout_helper(BasicType etype);
497 
498   // What is the maximum number of primary superclasses any klass can have?
499   static juint primary_super_limit()         { return _primary_super_limit; }
500 
501   // vtables

614   // Returns the name for a class (Resource allocated) as the class
615   // would appear in a signature.
616   // For arrays, this returns the name of the element with a leading '['.
617   // For classes, this returns the name with a leading 'L' and a trailing ';'
618   //     and the package separators as '/'.
619   virtual const char* signature_name() const;
620 
621   const char* joint_in_module_of_loader(const Klass* class2, bool include_parent_loader = false) const;
622   const char* class_in_module_of_loader(bool use_are = false, bool include_parent_loader = false) const;
623 
624   // Returns "interface", "abstract class" or "class".
625   const char* external_kind() const;
626 
627   // type testing operations
628 #ifdef ASSERT
629  protected:
630   virtual bool is_instance_klass_slow()     const { return false; }
631   virtual bool is_array_klass_slow()        const { return false; }
632   virtual bool is_objArray_klass_slow()     const { return false; }
633   virtual bool is_typeArray_klass_slow()    const { return false; }
634   virtual bool is_flatArray_klass_slow()    const { return false; }
635 #endif // ASSERT
636   // current implementation uses this method even in non debug builds
637   virtual bool is_inline_klass_slow()       const { return false; }
638  public:
639 
640   // Fast non-virtual versions
641   #ifndef ASSERT
642   #define assert_same_query(xval, xcheck) xval
643   #else
644  private:
645   static bool assert_same_query(bool xval, bool xslow) {
646     assert(xval == xslow, "slow and fast queries agree");
647     return xval;
648   }
649  public:
650   #endif
651 
652   bool is_instance_klass()              const { return assert_same_query(_kind <= InstanceStackChunkKlassKind, is_instance_klass_slow()); }
653   bool is_inline_klass()                const { return is_inline_klass_slow(); } //temporary hack
654   // Other is anything that is not one of the more specialized kinds of InstanceKlass.
655   bool is_other_instance_klass()        const { return _kind <= InlineKlassKind; }
656   bool is_reference_instance_klass()    const { return _kind == InstanceRefKlassKind; }
657   bool is_mirror_instance_klass()       const { return _kind == InstanceMirrorKlassKind; }
658   bool is_class_loader_instance_klass() const { return _kind == InstanceClassLoaderKlassKind; }
659   bool is_array_klass()                 const { return assert_same_query( _kind >= TypeArrayKlassKind, is_array_klass_slow()); }
660   bool is_stack_chunk_instance_klass()  const { return _kind == InstanceStackChunkKlassKind; }
661   bool is_flatArray_klass()             const { return assert_same_query( _kind == FlatArrayKlassKind, is_flatArray_klass_slow()); }
662   bool is_objArray_klass()              const { return assert_same_query( _kind == ObjArrayKlassKind,  is_objArray_klass_slow()); }
663   bool is_typeArray_klass()             const { return assert_same_query( _kind == TypeArrayKlassKind, is_typeArray_klass_slow()); }
664   #undef assert_same_query
665 
666   inline bool is_null_free_array_klass()      const { return layout_helper_is_null_free(layout_helper()); }
667 
668   // Access flags
669   AccessFlags access_flags() const         { return _access_flags;  }
670   void set_access_flags(AccessFlags flags) { _access_flags = flags; }
671 
672   bool is_public() const                { return _access_flags.is_public(); }
673   bool is_final() const                 { return _access_flags.is_final(); }
674   bool is_interface() const             { return _access_flags.is_interface(); }
675   bool is_abstract() const              { return _access_flags.is_abstract(); }

676   bool is_synthetic() const             { return _access_flags.is_synthetic(); }
677   bool is_value_class() const           { return _access_flags.is_value_class(); }
678   bool is_identity_class() const        { return _access_flags.is_identity_class(); }
679   void set_is_synthetic()               { _access_flags.set_is_synthetic(); }
680   bool has_finalizer() const            { return _access_flags.has_finalizer(); }
681   bool has_final_method() const         { return _access_flags.has_final_method(); }
682   void set_has_finalizer()              { _access_flags.set_has_finalizer(); }
683   void set_has_final_method()           { _access_flags.set_has_final_method(); }
684   bool has_vanilla_constructor() const  { return _access_flags.has_vanilla_constructor(); }
685   void set_has_vanilla_constructor()    { _access_flags.set_has_vanilla_constructor(); }
686   bool has_miranda_methods () const     { return access_flags().has_miranda_methods(); }
687   void set_has_miranda_methods()        { _access_flags.set_has_miranda_methods(); }
688   bool is_shared() const                { return access_flags().is_shared_class(); } // shadows MetaspaceObj::is_shared)()
689   void set_is_shared()                  { _access_flags.set_is_shared_class(); }
690   bool is_hidden() const                { return access_flags().is_hidden_class(); }
691   void set_is_hidden()                  { _access_flags.set_is_hidden_class(); }
692   bool is_value_based()                 { return _access_flags.is_value_based_class(); }
693   void set_is_value_based()             { _access_flags.set_is_value_based_class(); }
694 
695   inline bool is_non_strong_hidden() const;
696 
697   bool is_cloneable() const;
698   void set_is_cloneable();
699 
700   // inline types and inline type array patterns
701   markWord prototype_header() const {
702     return _prototype_header;
703   }
704   static inline markWord default_prototype_header(Klass* k) {
705     return (k == NULL) ? markWord::prototype() : k->prototype_header();
706   }
707 
708   inline void set_prototype_header(markWord header);
709   static ByteSize prototype_header_offset() { return in_ByteSize(offset_of(Klass, _prototype_header)); }
710 
711   JFR_ONLY(DEFINE_TRACE_ID_METHODS;)
712 
713   virtual void metaspace_pointers_do(MetaspaceClosure* iter);
714   virtual MetaspaceObj::Type type() const { return ClassType; }
715 
716   inline bool is_loader_alive() const;
717 
718   void clean_subklass();
719 
720   static void clean_weak_klass_links(bool unloading_occurred, bool clean_alive_klasses = true);
721   static void clean_subklass_tree() {
722     clean_weak_klass_links(/*unloading_occurred*/ true , /* clean_alive_klasses */ false);
723   }
724 
725   // Return self, except for abstract classes with exactly 1
726   // implementor.  Then return the 1 concrete implementation.
727   Klass *up_cast_abstract();
728 
729   // klass name
730   Symbol* name() const                   { return _name; }
< prev index next >