< 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

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









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











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

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

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

613 #endif // ASSERT


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

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

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


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


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











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

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

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

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

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

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