< prev index next >

src/hotspot/share/oops/klass.hpp

Print this page

 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 IDs for all subclasses of Klass
 41 enum KlassID {
 42   InstanceKlassID,
 43   InstanceRefKlassID,
 44   InstanceMirrorKlassID,
 45   InstanceClassLoaderKlassID,
 46   TypeArrayKlassID,

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

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

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

165 private:
166   // This is an index into FileMapHeader::_shared_path_table[], to
167   // associate this class with the JAR file where it's loaded from during
168   // dump time. If a class is not loaded from the shared archive, this field is
169   // -1.
170   jshort _shared_class_path_index;
171 
172 #if INCLUDE_CDS
173   // Flags of the current shared class.
174   u2     _shared_class_flags;
175   enum {
176     _archived_lambda_proxy_is_available    = 1 << 1,
177     _has_value_based_class_annotation      = 1 << 2,
178     _verified_at_dump_time                 = 1 << 3,
179     _has_archived_enum_objs                = 1 << 4,
180     _regenerated                           = 1 << 5
181   };
182 #endif
183 
184   CDS_JAVA_HEAP_ONLY(int _archived_mirror_index;)

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









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











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

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

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

603 #endif // ASSERT


604  public:
605 
606   // Fast non-virtual versions
607   #ifndef ASSERT
608   #define assert_same_query(xval, xcheck) xval
609   #else
610  private:
611   static bool assert_same_query(bool xval, bool xslow) {
612     assert(xval == xslow, "slow and fast queries agree");
613     return xval;
614   }
615  public:
616   #endif
617   inline  bool is_instance_klass()            const { return assert_same_query(
618                                                       layout_helper_is_instance(layout_helper()),
619                                                       is_instance_klass_slow()); }
620   inline  bool is_array_klass()               const { return assert_same_query(
621                                                     layout_helper_is_array(layout_helper()),
622                                                     is_array_klass_slow()); }
623   inline  bool is_objArray_klass()            const { return assert_same_query(
624                                                     layout_helper_is_objArray(layout_helper()),
625                                                     is_objArray_klass_slow()); }
626   inline  bool is_typeArray_klass()           const { return assert_same_query(
627                                                     layout_helper_is_typeArray(layout_helper()),
628                                                     is_typeArray_klass_slow()); }





629   #undef assert_same_query
630 


631   // Access flags
632   AccessFlags access_flags() const         { return _access_flags;  }
633   void set_access_flags(AccessFlags flags) { _access_flags = flags; }
634 
635   bool is_public() const                { return _access_flags.is_public(); }
636   bool is_final() const                 { return _access_flags.is_final(); }
637   bool is_interface() const             { return _access_flags.is_interface(); }
638   bool is_abstract() const              { return _access_flags.is_abstract(); }
639   bool is_super() const                 { return _access_flags.is_super(); }
640   bool is_synthetic() const             { return _access_flags.is_synthetic(); }


641   void set_is_synthetic()               { _access_flags.set_is_synthetic(); }
642   bool has_finalizer() const            { return _access_flags.has_finalizer(); }
643   bool has_final_method() const         { return _access_flags.has_final_method(); }
644   void set_has_finalizer()              { _access_flags.set_has_finalizer(); }
645   void set_has_final_method()           { _access_flags.set_has_final_method(); }
646   bool has_vanilla_constructor() const  { return _access_flags.has_vanilla_constructor(); }
647   void set_has_vanilla_constructor()    { _access_flags.set_has_vanilla_constructor(); }
648   bool has_miranda_methods () const     { return access_flags().has_miranda_methods(); }
649   void set_has_miranda_methods()        { _access_flags.set_has_miranda_methods(); }
650   bool is_shared() const                { return access_flags().is_shared_class(); } // shadows MetaspaceObj::is_shared)()
651   void set_is_shared()                  { _access_flags.set_is_shared_class(); }
652   bool is_hidden() const                { return access_flags().is_hidden_class(); }
653   void set_is_hidden()                  { _access_flags.set_is_hidden_class(); }
654   bool is_value_based()                 { return _access_flags.is_value_based_class(); }
655   void set_is_value_based()             { _access_flags.set_is_value_based_class(); }
656 
657   inline bool is_non_strong_hidden() const;
658 
659   bool is_cloneable() const;
660   void set_is_cloneable();
661 











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

 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 IDs for all subclasses of Klass
 41 enum KlassID {
 42   InstanceKlassID,
 43   InstanceRefKlassID,
 44   InstanceMirrorKlassID,
 45   InstanceClassLoaderKlassID,
 46   TypeArrayKlassID,
 47   FlatArrayKlassID,
 48   ObjArrayKlassID
 49 };
 50 
 51 const uint KLASS_ID_COUNT = 7;
 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.
 68 template <class T> class Array;
 69 template <class T> class GrowableArray;
 70 class ClassLoaderData;
 71 class fieldDescriptor;

 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, 0xA0 if value types
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 identifier used to implement devirtualized oop closure dispatching.
119   const KlassID _id;
120 
121   // Processed access flags, for use by Class.getModifiers.
122   jint        _modifier_flags;

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

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

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

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

604   // Returns the name for a class (Resource allocated) as the class
605   // would appear in a signature.
606   // For arrays, this returns the name of the element with a leading '['.
607   // For classes, this returns the name with a leading 'L' and a trailing ';'
608   //     and the package separators as '/'.
609   virtual const char* signature_name() const;
610 
611   const char* joint_in_module_of_loader(const Klass* class2, bool include_parent_loader = false) const;
612   const char* class_in_module_of_loader(bool use_are = false, bool include_parent_loader = false) const;
613 
614   // Returns "interface", "abstract class" or "class".
615   const char* external_kind() const;
616 
617   // type testing operations
618 #ifdef ASSERT
619  protected:
620   virtual bool is_instance_klass_slow()     const { return false; }
621   virtual bool is_array_klass_slow()        const { return false; }
622   virtual bool is_objArray_klass_slow()     const { return false; }
623   virtual bool is_typeArray_klass_slow()    const { return false; }
624   virtual bool is_flatArray_klass_slow()    const { return false; }
625 #endif // ASSERT
626   // current implementation uses this method even in non debug builds
627   virtual bool is_inline_klass_slow()       const { return false; }
628  public:
629 
630   // Fast non-virtual versions
631   #ifndef ASSERT
632   #define assert_same_query(xval, xcheck) xval
633   #else
634  private:
635   static bool assert_same_query(bool xval, bool xslow) {
636     assert(xval == xslow, "slow and fast queries agree");
637     return xval;
638   }
639  public:
640   #endif
641   inline  bool is_instance_klass()            const { return assert_same_query(
642                                                       layout_helper_is_instance(layout_helper()),
643                                                       is_instance_klass_slow()); }
644   inline  bool is_array_klass()               const { return assert_same_query(
645                                                     layout_helper_is_array(layout_helper()),
646                                                     is_array_klass_slow()); }
647   inline  bool is_objArray_klass()            const { return assert_same_query(
648                                                     layout_helper_is_objArray(layout_helper()),
649                                                     is_objArray_klass_slow()); }
650   inline  bool is_typeArray_klass()           const { return assert_same_query(
651                                                     layout_helper_is_typeArray(layout_helper()),
652                                                     is_typeArray_klass_slow()); }
653   inline  bool is_inline_klass()              const { return is_inline_klass_slow(); } //temporary hack
654   inline  bool is_flatArray_klass()           const { return assert_same_query(
655                                                     layout_helper_is_flatArray(layout_helper()),
656                                                     is_flatArray_klass_slow()); }
657 
658   #undef assert_same_query
659 
660   inline bool is_null_free_array_klass()      const { return layout_helper_is_null_free(layout_helper()); }
661 
662   // Access flags
663   AccessFlags access_flags() const         { return _access_flags;  }
664   void set_access_flags(AccessFlags flags) { _access_flags = flags; }
665 
666   bool is_public() const                { return _access_flags.is_public(); }
667   bool is_final() const                 { return _access_flags.is_final(); }
668   bool is_interface() const             { return _access_flags.is_interface(); }
669   bool is_abstract() const              { return _access_flags.is_abstract(); }
670   bool is_super() const                 { return _access_flags.is_super(); }
671   bool is_synthetic() const             { return _access_flags.is_synthetic(); }
672   bool is_permits_value_class() const   { return _access_flags.is_permits_value_class(); }
673   bool is_identity_class() const        { return _access_flags.is_identity_class(); }
674   void set_is_synthetic()               { _access_flags.set_is_synthetic(); }
675   bool has_finalizer() const            { return _access_flags.has_finalizer(); }
676   bool has_final_method() const         { return _access_flags.has_final_method(); }
677   void set_has_finalizer()              { _access_flags.set_has_finalizer(); }
678   void set_has_final_method()           { _access_flags.set_has_final_method(); }
679   bool has_vanilla_constructor() const  { return _access_flags.has_vanilla_constructor(); }
680   void set_has_vanilla_constructor()    { _access_flags.set_has_vanilla_constructor(); }
681   bool has_miranda_methods () const     { return access_flags().has_miranda_methods(); }
682   void set_has_miranda_methods()        { _access_flags.set_has_miranda_methods(); }
683   bool is_shared() const                { return access_flags().is_shared_class(); } // shadows MetaspaceObj::is_shared)()
684   void set_is_shared()                  { _access_flags.set_is_shared_class(); }
685   bool is_hidden() const                { return access_flags().is_hidden_class(); }
686   void set_is_hidden()                  { _access_flags.set_is_hidden_class(); }
687   bool is_value_based()                 { return _access_flags.is_value_based_class(); }
688   void set_is_value_based()             { _access_flags.set_is_value_based_class(); }
689 
690   inline bool is_non_strong_hidden() const;
691 
692   bool is_cloneable() const;
693   void set_is_cloneable();
694 
695   // inline types and inline type array patterns
696   markWord prototype_header() const {
697     return _prototype_header;
698   }
699   static inline markWord default_prototype_header(Klass* k) {
700     return (k == NULL) ? markWord::prototype() : k->prototype_header();
701   }
702 
703   inline void set_prototype_header(markWord header);
704   static ByteSize prototype_header_offset() { return in_ByteSize(offset_of(Klass, _prototype_header)); }
705 
706   JFR_ONLY(DEFINE_TRACE_ID_METHODS;)
707 
708   virtual void metaspace_pointers_do(MetaspaceClosure* iter);
709   virtual MetaspaceObj::Type type() const { return ClassType; }
710 
711   inline bool is_loader_alive() const;
712 
713   void clean_subklass();
714 
715   static void clean_weak_klass_links(bool unloading_occurred, bool clean_alive_klasses = true);
716   static void clean_subklass_tree() {
717     clean_weak_klass_links(/*unloading_occurred*/ true , /* clean_alive_klasses */ false);
718   }
719 
720   // Return self, except for abstract classes with exactly 1
721   // implementor.  Then return the 1 concrete implementation.
722   Klass *up_cast_abstract();
723 
724   // klass name
725   Symbol* name() const                   { return _name; }
< prev index next >