55 // Forward declarations.
56 template <class T> class Array;
57 template <class T> class GrowableArray;
58 class ClassLoaderData;
59 class fieldDescriptor;
60 class klassVtable;
61 class ModuleEntry;
62 class PackageEntry;
63 class ParCompactionManager;
64 class PSPromotionManager;
65 class vtableEntry;
66
67 class Klass : public Metadata {
68
69 friend class VMStructs;
70 friend class JVMCIVMStructs;
71 public:
72 // Klass Kinds for all subclasses of Klass
73 enum KlassKind {
74 InstanceKlassKind,
75 InstanceRefKlassKind,
76 InstanceMirrorKlassKind,
77 InstanceClassLoaderKlassKind,
78 InstanceStackChunkKlassKind,
79 TypeArrayKlassKind,
80 ObjArrayKlassKind,
81 UnknownKlassKind
82 };
83
84 static const uint KLASS_KIND_COUNT = ObjArrayKlassKind + 1;
85 protected:
86
87 // If you add a new field that points to any metaspace object, you
88 // must add this field to Klass::metaspace_pointers_do().
89
90 // note: put frequently-used fields together at start of klass structure
91 // for better cache behavior (may not make much of a difference but sure won't hurt)
92 enum { _primary_super_limit = 8 };
93
94 // The "layout helper" is a combined descriptor of object layout.
95 // For klasses which are neither instance nor array, the value is zero.
96 //
97 // For instances, layout helper is a positive number, the instance size.
98 // This size is already passed through align_object_size and scaled to bytes.
99 // The low order bit is set if instances of this class cannot be
100 // allocated using the fastpath.
101 //
102 // For arrays, layout helper is a negative number, containing four
103 // distinct bytes, as follows:
104 // MSB:[tag, hsz, ebt, log2(esz)]:LSB
105 // where:
106 // tag is 0x80 if the elements are oops, 0xC0 if non-oops
107 // hsz is array header size in bytes (i.e., offset of first element)
108 // ebt is the BasicType of the elements
109 // esz is the element size in bytes
110 // This packed word is arranged so as to be quickly unpacked by the
111 // various fast paths that use the various subfields.
112 //
113 // The esz bits can be used directly by a SLL instruction, without masking.
114 //
115 // Note that the array-kind tag looks like 0x00 for instance klasses,
116 // since their length in bytes is always less than 24Mb.
117 //
118 // Final note: This comes first, immediately after C++ vtable,
119 // because it is frequently queried.
120 jint _layout_helper;
121
122 // Klass kind used to resolve the runtime type of the instance.
123 // - Used to implement devirtualized oop closure dispatching.
124 // - Various type checking in the JVM
125 const KlassKind _kind;
126
158 Klass* _next_link;
159
160 // The VM's representation of the ClassLoader used to load this class.
161 // Provide access the corresponding instance java.lang.ClassLoader.
162 ClassLoaderData* _class_loader_data;
163
164 // Bitmap and hash code used by hashed secondary supers.
165 uintx _secondary_supers_bitmap;
166 uint8_t _hash_slot;
167
168 int _vtable_len; // vtable length. This field may be read very often when we
169 // have lots of itable dispatches (e.g., lambdas and streams).
170 // Keep it away from the beginning of a Klass to avoid cacheline
171 // contention that may happen when a nearby object is modified.
172 AccessFlags _access_flags; // Access flags. The class/interface distinction is stored here.
173 // Some flags created by the JVM, not in the class file itself,
174 // are in _misc_flags below.
175
176 JFR_ONLY(DEFINE_TRACE_ID_FIELD;)
177
178 private:
179 // This is an index into FileMapHeader::_shared_path_table[], to
180 // associate this class with the JAR file where it's loaded from during
181 // dump time. If a class is not loaded from the shared archive, this field is
182 // -1.
183 s2 _shared_class_path_index;
184
185 #if INCLUDE_CDS
186 // Various attributes for shared classes. Should be zero for a non-shared class.
187 u2 _shared_class_flags;
188 enum CDSSharedClassFlags {
189 _is_shared_class = 1 << 0, // shadows MetaspaceObj::is_shared
190 _archived_lambda_proxy_is_available = 1 << 1,
191 _has_value_based_class_annotation = 1 << 2,
192 _verified_at_dump_time = 1 << 3,
193 _has_archived_enum_objs = 1 << 4,
194 // This class was not loaded from a classfile in the module image
195 // or classpath.
196 _is_generated_shared_class = 1 << 5
197 };
431 static ByteSize layout_helper_offset() { return byte_offset_of(Klass, _layout_helper); }
432 static ByteSize access_flags_offset() { return byte_offset_of(Klass, _access_flags); }
433 #if INCLUDE_JVMCI
434 static ByteSize subklass_offset() { return byte_offset_of(Klass, _subklass); }
435 static ByteSize next_sibling_offset() { return byte_offset_of(Klass, _next_sibling); }
436 #endif
437 static ByteSize secondary_supers_bitmap_offset()
438 { return byte_offset_of(Klass, _secondary_supers_bitmap); }
439 static ByteSize hash_slot_offset() { return byte_offset_of(Klass, _hash_slot); }
440 static ByteSize misc_flags_offset() { return byte_offset_of(Klass, _misc_flags._flags); }
441
442 // Unpacking layout_helper:
443 static const int _lh_neutral_value = 0; // neutral non-array non-instance value
444 static const int _lh_instance_slow_path_bit = 0x01;
445 static const int _lh_log2_element_size_shift = BitsPerByte*0;
446 static const int _lh_log2_element_size_mask = BitsPerLong-1;
447 static const int _lh_element_type_shift = BitsPerByte*1;
448 static const int _lh_element_type_mask = right_n_bits(BitsPerByte); // shifted mask
449 static const int _lh_header_size_shift = BitsPerByte*2;
450 static const int _lh_header_size_mask = right_n_bits(BitsPerByte); // shifted mask
451 static const int _lh_array_tag_bits = 2;
452 static const int _lh_array_tag_shift = BitsPerInt - _lh_array_tag_bits;
453 static const int _lh_array_tag_obj_value = ~0x01; // 0x80000000 >> 30
454
455 static const unsigned int _lh_array_tag_type_value = 0Xffffffff; // ~0x00, // 0xC0000000 >> 30
456
457 static int layout_helper_size_in_bytes(jint lh) {
458 assert(lh > (jint)_lh_neutral_value, "must be instance");
459 return (int) lh & ~_lh_instance_slow_path_bit;
460 }
461 static bool layout_helper_needs_slow_path(jint lh) {
462 assert(lh > (jint)_lh_neutral_value, "must be instance");
463 return (lh & _lh_instance_slow_path_bit) != 0;
464 }
465 static bool layout_helper_is_instance(jint lh) {
466 return (jint)lh > (jint)_lh_neutral_value;
467 }
468 static bool layout_helper_is_array(jint lh) {
469 return (jint)lh < (jint)_lh_neutral_value;
470 }
471 static bool layout_helper_is_typeArray(jint lh) {
472 // _lh_array_tag_type_value == (lh >> _lh_array_tag_shift);
473 return (juint)lh >= (juint)(_lh_array_tag_type_value << _lh_array_tag_shift);
474 }
475 static bool layout_helper_is_objArray(jint lh) {
476 // _lh_array_tag_obj_value == (lh >> _lh_array_tag_shift);
477 return (jint)lh < (jint)(_lh_array_tag_type_value << _lh_array_tag_shift);
478 }
479 static int layout_helper_header_size(jint lh) {
480 assert(lh < (jint)_lh_neutral_value, "must be array");
481 int hsize = (lh >> _lh_header_size_shift) & _lh_header_size_mask;
482 assert(hsize > 0 && hsize < (int)sizeof(oopDesc)*3, "sanity");
483 return hsize;
484 }
485 static BasicType layout_helper_element_type(jint lh) {
486 assert(lh < (jint)_lh_neutral_value, "must be array");
487 int btvalue = (lh >> _lh_element_type_shift) & _lh_element_type_mask;
488 assert(btvalue >= T_BOOLEAN && btvalue <= T_OBJECT, "sanity");
489 return (BasicType) btvalue;
490 }
491
492 // Want a pattern to quickly diff against layout header in register
493 // find something less clever!
494 static int layout_helper_boolean_diffbit() {
495 jint zlh = array_layout_helper(T_BOOLEAN);
496 jint blh = array_layout_helper(T_BYTE);
497 assert(zlh != blh, "array layout helpers must differ");
498 int diffbit = 1;
499 while ((diffbit & (zlh ^ blh)) == 0 && (diffbit & zlh) == 0) {
500 diffbit <<= 1;
501 assert(diffbit != 0, "make sure T_BOOLEAN has a different bit than T_BYTE");
502 }
503 return diffbit;
504 }
505
506 static int layout_helper_log2_element_size(jint lh) {
507 assert(lh < (jint)_lh_neutral_value, "must be array");
508 int l2esz = (lh >> _lh_log2_element_size_shift) & _lh_log2_element_size_mask;
509 assert(l2esz <= LogBytesPerLong,
510 "sanity. l2esz: 0x%x for lh: 0x%x", (uint)l2esz, (uint)lh);
511 return l2esz;
512 }
513 static jint array_layout_helper(jint tag, int hsize, BasicType etype, int log2_esize) {
514 return (tag << _lh_array_tag_shift)
515 | (hsize << _lh_header_size_shift)
516 | ((int)etype << _lh_element_type_shift)
517 | (log2_esize << _lh_log2_element_size_shift);
518 }
519 static jint instance_layout_helper(jint size, bool slow_path_flag) {
520 return (size << LogBytesPerWord)
521 | (slow_path_flag ? _lh_instance_slow_path_bit : 0);
522 }
523 static int layout_helper_to_size_helper(jint lh) {
524 assert(lh > (jint)_lh_neutral_value, "must be instance");
525 // Note that the following expression discards _lh_instance_slow_path_bit.
526 return lh >> LogBytesPerWord;
527 }
528 // Out-of-line version computes everything based on the etype:
529 static jint array_layout_helper(BasicType etype);
530
531 // What is the maximum number of primary superclasses any klass can have?
532 static juint primary_super_limit() { return _primary_super_limit; }
533
534 // vtables
636 // Returns the name for a class (Resource allocated) as the class
637 // would appear in a signature.
638 // For arrays, this returns the name of the element with a leading '['.
639 // For classes, this returns the name with a leading 'L' and a trailing ';'
640 // and the package separators as '/'.
641 virtual const char* signature_name() const;
642
643 const char* joint_in_module_of_loader(const Klass* class2, bool include_parent_loader = false) const;
644 const char* class_in_module_of_loader(bool use_are = false, bool include_parent_loader = false) const;
645
646 // Returns "interface", "abstract class" or "class".
647 const char* external_kind() const;
648
649 // type testing operations
650 #ifdef ASSERT
651 protected:
652 virtual bool is_instance_klass_slow() const { return false; }
653 virtual bool is_array_klass_slow() const { return false; }
654 virtual bool is_objArray_klass_slow() const { return false; }
655 virtual bool is_typeArray_klass_slow() const { return false; }
656 #endif // ASSERT
657 public:
658
659 // Fast non-virtual versions
660 #ifndef ASSERT
661 #define assert_same_query(xval, xcheck) xval
662 #else
663 private:
664 static bool assert_same_query(bool xval, bool xslow) {
665 assert(xval == xslow, "slow and fast queries agree");
666 return xval;
667 }
668 public:
669 #endif
670
671 bool is_instance_klass() const { return assert_same_query(_kind <= InstanceStackChunkKlassKind, is_instance_klass_slow()); }
672 // Other is anything that is not one of the more specialized kinds of InstanceKlass.
673 bool is_other_instance_klass() const { return _kind == InstanceKlassKind; }
674 bool is_reference_instance_klass() const { return _kind == InstanceRefKlassKind; }
675 bool is_mirror_instance_klass() const { return _kind == InstanceMirrorKlassKind; }
676 bool is_class_loader_instance_klass() const { return _kind == InstanceClassLoaderKlassKind; }
677 bool is_array_klass() const { return assert_same_query( _kind >= TypeArrayKlassKind, is_array_klass_slow()); }
678 bool is_stack_chunk_instance_klass() const { return _kind == InstanceStackChunkKlassKind; }
679 bool is_objArray_klass() const { return assert_same_query( _kind == ObjArrayKlassKind, is_objArray_klass_slow()); }
680 bool is_typeArray_klass() const { return assert_same_query( _kind == TypeArrayKlassKind, is_typeArray_klass_slow()); }
681 #undef assert_same_query
682
683 // Access flags
684 AccessFlags access_flags() const { return _access_flags; }
685 void set_access_flags(AccessFlags flags) { _access_flags = flags; }
686
687 bool is_public() const { return _access_flags.is_public(); }
688 bool is_final() const { return _access_flags.is_final(); }
689 bool is_interface() const { return _access_flags.is_interface(); }
690 bool is_abstract() const { return _access_flags.is_abstract(); }
691 bool is_super() const { return _access_flags.is_super(); }
692 bool is_synthetic() const { return _access_flags.is_synthetic(); }
693 void set_is_synthetic() { _access_flags.set_is_synthetic(); }
694 bool has_finalizer() const { return _misc_flags.has_finalizer(); }
695 void set_has_finalizer() { _misc_flags.set_has_finalizer(true); }
696 bool is_hidden() const { return _misc_flags.is_hidden_class(); }
697 void set_is_hidden() { _misc_flags.set_is_hidden_class(true); }
698 bool is_value_based() const { return _misc_flags.is_value_based_class(); }
699 void set_is_value_based() { _misc_flags.set_is_value_based_class(true); }
700
701 klass_flags_t misc_flags() const { return _misc_flags.value(); }
702
703 inline bool is_non_strong_hidden() const;
704
705 bool is_cloneable() const;
706 void set_is_cloneable();
707
708 JFR_ONLY(DEFINE_TRACE_ID_METHODS;)
709
710 virtual void metaspace_pointers_do(MetaspaceClosure* iter);
711 virtual MetaspaceObj::Type type() const { return ClassType; }
712
713 inline bool is_loader_alive() const;
714
715 void clean_subklass();
716
717 static void clean_weak_klass_links(bool unloading_occurred, bool clean_alive_klasses = true);
718 static void clean_subklass_tree() {
719 clean_weak_klass_links(/*unloading_occurred*/ true , /* clean_alive_klasses */ false);
720 }
721
722 // Return self, except for abstract classes with exactly 1
723 // implementor. Then return the 1 concrete implementation.
724 Klass *up_cast_abstract();
725
726 // klass name
727 Symbol* name() const { return _name; }
|
55 // Forward declarations.
56 template <class T> class Array;
57 template <class T> class GrowableArray;
58 class ClassLoaderData;
59 class fieldDescriptor;
60 class klassVtable;
61 class ModuleEntry;
62 class PackageEntry;
63 class ParCompactionManager;
64 class PSPromotionManager;
65 class vtableEntry;
66
67 class Klass : public Metadata {
68
69 friend class VMStructs;
70 friend class JVMCIVMStructs;
71 public:
72 // Klass Kinds for all subclasses of Klass
73 enum KlassKind {
74 InstanceKlassKind,
75 InlineKlassKind,
76 InstanceRefKlassKind,
77 InstanceMirrorKlassKind,
78 InstanceClassLoaderKlassKind,
79 InstanceStackChunkKlassKind,
80 TypeArrayKlassKind,
81 FlatArrayKlassKind,
82 ObjArrayKlassKind,
83 UnknownKlassKind
84 };
85
86 static const uint KLASS_KIND_COUNT = ObjArrayKlassKind + 1;
87 protected:
88
89 // If you add a new field that points to any metaspace object, you
90 // must add this field to Klass::metaspace_pointers_do().
91
92 // note: put frequently-used fields together at start of klass structure
93 // for better cache behavior (may not make much of a difference but sure won't hurt)
94 enum { _primary_super_limit = 8 };
95
96 // The "layout helper" is a combined descriptor of object layout.
97 // For klasses which are neither instance nor array, the value is zero.
98 //
99 // For instances, layout helper is a positive number, the instance size.
100 // This size is already passed through align_object_size and scaled to bytes.
101 // The low order bit is set if instances of this class cannot be
102 // allocated using the fastpath.
103 //
104 // For arrays, layout helper is a negative number, containing four
105 // distinct bytes, as follows:
106 // MSB:[tag, hsz, ebt, log2(esz)]:LSB
107 // where:
108 // tag is 0x80 if the elements are oops, 0xC0 if non-oops, 0xA0 if value types
109 // hsz is array header size in bytes (i.e., offset of first element)
110 // ebt is the BasicType of the elements
111 // esz is the element size in bytes
112 // This packed word is arranged so as to be quickly unpacked by the
113 // various fast paths that use the various subfields.
114 //
115 // The esz bits can be used directly by a SLL instruction, without masking.
116 //
117 // Note that the array-kind tag looks like 0x00 for instance klasses,
118 // since their length in bytes is always less than 24Mb.
119 //
120 // Final note: This comes first, immediately after C++ vtable,
121 // because it is frequently queried.
122 jint _layout_helper;
123
124 // Klass kind used to resolve the runtime type of the instance.
125 // - Used to implement devirtualized oop closure dispatching.
126 // - Various type checking in the JVM
127 const KlassKind _kind;
128
160 Klass* _next_link;
161
162 // The VM's representation of the ClassLoader used to load this class.
163 // Provide access the corresponding instance java.lang.ClassLoader.
164 ClassLoaderData* _class_loader_data;
165
166 // Bitmap and hash code used by hashed secondary supers.
167 uintx _secondary_supers_bitmap;
168 uint8_t _hash_slot;
169
170 int _vtable_len; // vtable length. This field may be read very often when we
171 // have lots of itable dispatches (e.g., lambdas and streams).
172 // Keep it away from the beginning of a Klass to avoid cacheline
173 // contention that may happen when a nearby object is modified.
174 AccessFlags _access_flags; // Access flags. The class/interface distinction is stored here.
175 // Some flags created by the JVM, not in the class file itself,
176 // are in _misc_flags below.
177
178 JFR_ONLY(DEFINE_TRACE_ID_FIELD;)
179
180 markWord _prototype_header; // inline type and inline array mark patterns
181 private:
182 // This is an index into FileMapHeader::_shared_path_table[], to
183 // associate this class with the JAR file where it's loaded from during
184 // dump time. If a class is not loaded from the shared archive, this field is
185 // -1.
186 s2 _shared_class_path_index;
187
188 #if INCLUDE_CDS
189 // Various attributes for shared classes. Should be zero for a non-shared class.
190 u2 _shared_class_flags;
191 enum CDSSharedClassFlags {
192 _is_shared_class = 1 << 0, // shadows MetaspaceObj::is_shared
193 _archived_lambda_proxy_is_available = 1 << 1,
194 _has_value_based_class_annotation = 1 << 2,
195 _verified_at_dump_time = 1 << 3,
196 _has_archived_enum_objs = 1 << 4,
197 // This class was not loaded from a classfile in the module image
198 // or classpath.
199 _is_generated_shared_class = 1 << 5
200 };
434 static ByteSize layout_helper_offset() { return byte_offset_of(Klass, _layout_helper); }
435 static ByteSize access_flags_offset() { return byte_offset_of(Klass, _access_flags); }
436 #if INCLUDE_JVMCI
437 static ByteSize subklass_offset() { return byte_offset_of(Klass, _subklass); }
438 static ByteSize next_sibling_offset() { return byte_offset_of(Klass, _next_sibling); }
439 #endif
440 static ByteSize secondary_supers_bitmap_offset()
441 { return byte_offset_of(Klass, _secondary_supers_bitmap); }
442 static ByteSize hash_slot_offset() { return byte_offset_of(Klass, _hash_slot); }
443 static ByteSize misc_flags_offset() { return byte_offset_of(Klass, _misc_flags._flags); }
444
445 // Unpacking layout_helper:
446 static const int _lh_neutral_value = 0; // neutral non-array non-instance value
447 static const int _lh_instance_slow_path_bit = 0x01;
448 static const int _lh_log2_element_size_shift = BitsPerByte*0;
449 static const int _lh_log2_element_size_mask = BitsPerLong-1;
450 static const int _lh_element_type_shift = BitsPerByte*1;
451 static const int _lh_element_type_mask = right_n_bits(BitsPerByte); // shifted mask
452 static const int _lh_header_size_shift = BitsPerByte*2;
453 static const int _lh_header_size_mask = right_n_bits(BitsPerByte); // shifted mask
454 static const int _lh_array_tag_bits = 3;
455 static const int _lh_array_tag_shift = BitsPerInt - _lh_array_tag_bits;
456
457 static const unsigned int _lh_array_tag_type_value = 0Xfffffffc;
458 static const unsigned int _lh_array_tag_vt_value = 0Xfffffffd;
459 static const unsigned int _lh_array_tag_obj_value = 0Xfffffffe;
460
461 // null-free array flag bit under the array tag bits, shift one more to get array tag value
462 static const int _lh_null_free_shift = _lh_array_tag_shift - 1;
463 static const int _lh_null_free_mask = 1;
464
465 static const jint _lh_array_tag_flat_value_bit_inplace = (jint) (1 << _lh_array_tag_shift);
466
467 static int layout_helper_size_in_bytes(jint lh) {
468 assert(lh > (jint)_lh_neutral_value, "must be instance");
469 return (int) lh & ~_lh_instance_slow_path_bit;
470 }
471 static bool layout_helper_needs_slow_path(jint lh) {
472 assert(lh > (jint)_lh_neutral_value, "must be instance");
473 return (lh & _lh_instance_slow_path_bit) != 0;
474 }
475 static bool layout_helper_is_instance(jint lh) {
476 return (jint)lh > (jint)_lh_neutral_value;
477 }
478 static bool layout_helper_is_array(jint lh) {
479 return (jint)lh < (jint)_lh_neutral_value;
480 }
481 static bool layout_helper_is_typeArray(jint lh) {
482 return (juint) _lh_array_tag_type_value == (juint)(lh >> _lh_array_tag_shift);
483 }
484 static bool layout_helper_is_objArray(jint lh) {
485 return (juint)_lh_array_tag_obj_value == (juint)(lh >> _lh_array_tag_shift);
486 }
487 static bool layout_helper_is_flatArray(jint lh) {
488 return (juint)_lh_array_tag_vt_value == (juint)(lh >> _lh_array_tag_shift);
489 }
490 static bool layout_helper_is_null_free(jint lh) {
491 assert(layout_helper_is_flatArray(lh) || layout_helper_is_objArray(lh), "must be array of inline types");
492 return ((lh >> _lh_null_free_shift) & _lh_null_free_mask);
493 }
494 static jint layout_helper_set_null_free(jint lh) {
495 lh |= (_lh_null_free_mask << _lh_null_free_shift);
496 assert(layout_helper_is_null_free(lh), "Bad encoding");
497 return lh;
498 }
499 static int layout_helper_header_size(jint lh) {
500 assert(lh < (jint)_lh_neutral_value, "must be array");
501 int hsize = (lh >> _lh_header_size_shift) & _lh_header_size_mask;
502 assert(hsize > 0 && hsize < (int)sizeof(oopDesc)*3, "sanity");
503 return hsize;
504 }
505 static BasicType layout_helper_element_type(jint lh) {
506 assert(lh < (jint)_lh_neutral_value, "must be array");
507 int btvalue = (lh >> _lh_element_type_shift) & _lh_element_type_mask;
508 assert((btvalue >= T_BOOLEAN && btvalue <= T_OBJECT) || btvalue == T_PRIMITIVE_OBJECT, "sanity");
509 return (BasicType) btvalue;
510 }
511
512 // Want a pattern to quickly diff against layout header in register
513 // find something less clever!
514 static int layout_helper_boolean_diffbit() {
515 jint zlh = array_layout_helper(T_BOOLEAN);
516 jint blh = array_layout_helper(T_BYTE);
517 assert(zlh != blh, "array layout helpers must differ");
518 int diffbit = 1;
519 while ((diffbit & (zlh ^ blh)) == 0 && (diffbit & zlh) == 0) {
520 diffbit <<= 1;
521 assert(diffbit != 0, "make sure T_BOOLEAN has a different bit than T_BYTE");
522 }
523 return diffbit;
524 }
525
526 static int layout_helper_log2_element_size(jint lh) {
527 assert(lh < (jint)_lh_neutral_value, "must be array");
528 int l2esz = (lh >> _lh_log2_element_size_shift) & _lh_log2_element_size_mask;
529 assert(layout_helper_element_type(lh) == T_PRIMITIVE_OBJECT || l2esz <= LogBytesPerLong,
530 "sanity. l2esz: 0x%x for lh: 0x%x", (uint)l2esz, (uint)lh);
531 return l2esz;
532 }
533 static jint array_layout_helper(jint tag, bool null_free, int hsize, BasicType etype, int log2_esize) {
534 return (tag << _lh_array_tag_shift)
535 | ((null_free ? 1 : 0) << _lh_null_free_shift)
536 | (hsize << _lh_header_size_shift)
537 | ((int)etype << _lh_element_type_shift)
538 | (log2_esize << _lh_log2_element_size_shift);
539 }
540 static jint instance_layout_helper(jint size, bool slow_path_flag) {
541 return (size << LogBytesPerWord)
542 | (slow_path_flag ? _lh_instance_slow_path_bit : 0);
543 }
544 static int layout_helper_to_size_helper(jint lh) {
545 assert(lh > (jint)_lh_neutral_value, "must be instance");
546 // Note that the following expression discards _lh_instance_slow_path_bit.
547 return lh >> LogBytesPerWord;
548 }
549 // Out-of-line version computes everything based on the etype:
550 static jint array_layout_helper(BasicType etype);
551
552 // What is the maximum number of primary superclasses any klass can have?
553 static juint primary_super_limit() { return _primary_super_limit; }
554
555 // vtables
657 // Returns the name for a class (Resource allocated) as the class
658 // would appear in a signature.
659 // For arrays, this returns the name of the element with a leading '['.
660 // For classes, this returns the name with a leading 'L' and a trailing ';'
661 // and the package separators as '/'.
662 virtual const char* signature_name() const;
663
664 const char* joint_in_module_of_loader(const Klass* class2, bool include_parent_loader = false) const;
665 const char* class_in_module_of_loader(bool use_are = false, bool include_parent_loader = false) const;
666
667 // Returns "interface", "abstract class" or "class".
668 const char* external_kind() const;
669
670 // type testing operations
671 #ifdef ASSERT
672 protected:
673 virtual bool is_instance_klass_slow() const { return false; }
674 virtual bool is_array_klass_slow() const { return false; }
675 virtual bool is_objArray_klass_slow() const { return false; }
676 virtual bool is_typeArray_klass_slow() const { return false; }
677 virtual bool is_flatArray_klass_slow() const { return false; }
678 #endif // ASSERT
679 // current implementation uses this method even in non debug builds
680 virtual bool is_inline_klass_slow() const { return false; }
681 public:
682
683 // Fast non-virtual versions
684 #ifndef ASSERT
685 #define assert_same_query(xval, xcheck) xval
686 #else
687 private:
688 static bool assert_same_query(bool xval, bool xslow) {
689 assert(xval == xslow, "slow and fast queries agree");
690 return xval;
691 }
692 public:
693 #endif
694
695 bool is_instance_klass() const { return assert_same_query(_kind <= InstanceStackChunkKlassKind, is_instance_klass_slow()); }
696 bool is_inline_klass() const { return assert_same_query(_kind == InlineKlassKind, is_inline_klass_slow()); }
697 bool is_reference_instance_klass() const { return _kind == InstanceRefKlassKind; }
698 bool is_mirror_instance_klass() const { return _kind == InstanceMirrorKlassKind; }
699 bool is_class_loader_instance_klass() const { return _kind == InstanceClassLoaderKlassKind; }
700 bool is_array_klass() const { return assert_same_query( _kind >= TypeArrayKlassKind, is_array_klass_slow()); }
701 bool is_stack_chunk_instance_klass() const { return _kind == InstanceStackChunkKlassKind; }
702 bool is_flatArray_klass() const { return assert_same_query( _kind == FlatArrayKlassKind, is_flatArray_klass_slow()); }
703 bool is_objArray_klass() const { return assert_same_query( _kind == ObjArrayKlassKind, is_objArray_klass_slow()); }
704 bool is_typeArray_klass() const { return assert_same_query( _kind == TypeArrayKlassKind, is_typeArray_klass_slow()); }
705 #undef assert_same_query
706
707 inline bool is_null_free_array_klass() const { return layout_helper_is_null_free(layout_helper()); }
708
709 // Access flags
710 AccessFlags access_flags() const { return _access_flags; }
711 void set_access_flags(AccessFlags flags) { _access_flags = flags; }
712
713 bool is_public() const { return _access_flags.is_public(); }
714 bool is_final() const { return _access_flags.is_final(); }
715 bool is_interface() const { return _access_flags.is_interface(); }
716 bool is_abstract() const { return _access_flags.is_abstract(); }
717 bool is_synthetic() const { return _access_flags.is_synthetic(); }
718 bool is_identity_class() const { return _access_flags.is_identity_class(); }
719 void set_is_synthetic() { _access_flags.set_is_synthetic(); }
720 bool has_finalizer() const { return _misc_flags.has_finalizer(); }
721 void set_has_finalizer() { _misc_flags.set_has_finalizer(true); }
722 bool is_hidden() const { return _misc_flags.is_hidden_class(); }
723 void set_is_hidden() { _misc_flags.set_is_hidden_class(true); }
724 bool is_value_based() const { return _misc_flags.is_value_based_class(); }
725 void set_is_value_based() { _misc_flags.set_is_value_based_class(true); }
726
727 klass_flags_t misc_flags() const { return _misc_flags.value(); }
728
729 inline bool is_non_strong_hidden() const;
730
731 bool is_cloneable() const;
732 void set_is_cloneable();
733
734 // inline types and inline type array patterns
735 markWord prototype_header() const {
736 return _prototype_header;
737 }
738 static inline markWord default_prototype_header(Klass* k) {
739 return (k == nullptr) ? markWord::prototype() : k->prototype_header();
740 }
741
742 inline void set_prototype_header(markWord header);
743 static ByteSize prototype_header_offset() { return in_ByteSize(offset_of(Klass, _prototype_header)); }
744
745 JFR_ONLY(DEFINE_TRACE_ID_METHODS;)
746
747 virtual void metaspace_pointers_do(MetaspaceClosure* iter);
748 virtual MetaspaceObj::Type type() const { return ClassType; }
749
750 inline bool is_loader_alive() const;
751
752 void clean_subklass();
753
754 static void clean_weak_klass_links(bool unloading_occurred, bool clean_alive_klasses = true);
755 static void clean_subklass_tree() {
756 clean_weak_klass_links(/*unloading_occurred*/ true , /* clean_alive_klasses */ false);
757 }
758
759 // Return self, except for abstract classes with exactly 1
760 // implementor. Then return the 1 concrete implementation.
761 Klass *up_cast_abstract();
762
763 // klass name
764 Symbol* name() const { return _name; }
|