48 // a vtbl and does the C++ dispatch depending on the object's
49 // actual type. (See oop.inline.hpp for some of the forwarding code.)
50 // ALL FUNCTIONS IMPLEMENTING THIS DISPATCH ARE PREFIXED WITH "oop_"!
51
52 // Forward declarations.
53 template <class T> class Array;
54 template <class T> class GrowableArray;
55 class ClassLoaderData;
56 class fieldDescriptor;
57 class klassVtable;
58 class ModuleEntry;
59 class PackageEntry;
60 class vtableEntry;
61
62 class Klass : public Metadata {
63
64 friend class VMStructs;
65 friend class JVMCIVMStructs;
66 public:
67 // Klass Kinds for all subclasses of Klass
68 enum KlassKind : u2 {
69 InstanceKlassKind,
70 InstanceRefKlassKind,
71 InstanceMirrorKlassKind,
72 InstanceClassLoaderKlassKind,
73 InstanceStackChunkKlassKind,
74 TypeArrayKlassKind,
75 ObjArrayKlassKind,
76 UnknownKlassKind
77 };
78
79 static const uint KLASS_KIND_COUNT = ObjArrayKlassKind + 1;
80 protected:
81
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 kind used to resolve the runtime type of the instance.
118 // - Used to implement devirtualized oop closure dispatching.
119 // - Various type checking in the JVM
120 const KlassKind _kind;
121
185 // no further need to call <clinit>
186 _has_aot_safe_initializer = 1 << 7, // has @AOTSafeClassInitializer annotation
187 _is_runtime_setup_required = 1 << 8, // has a runtimeSetup method to be called when
188 // this class is loaded from AOT cache
189 };
190 #endif
191
192 int _vtable_len; // vtable length. This field may be read very often when we
193 // have lots of itable dispatches (e.g., lambdas and streams).
194 // Keep it away from the beginning of a Klass to avoid cacheline
195 // contention that may happen when a nearby object is modified.
196
197 CDS_JAVA_HEAP_ONLY(int _archived_mirror_index;)
198
199 public:
200
201 JFR_ONLY(DEFINE_TRACE_ID_FIELD;)
202
203 protected:
204
205 Klass(KlassKind kind);
206 Klass();
207
208 void* operator new(size_t size, ClassLoaderData* loader_data, size_t word_size, TRAPS) throw();
209
210 public:
211 int kind() { return _kind; }
212
213 enum class DefaultsLookupMode { find, skip };
214 enum class OverpassLookupMode { find, skip };
215 enum class StaticLookupMode { find, skip };
216 enum class PrivateLookupMode { find, skip };
217
218 bool is_klass() const override { return true; }
219
220 // super() cannot be InstanceKlass* -- Java arrays are covariant, and _super is used
221 // to implement that. NB: the _super of "[Ljava/lang/Integer;" is "[Ljava/lang/Number;"
222 // If this is not what your code expects, you're probably looking for:
223 // - Klass::java_super() - if you have a Klass*
224 // - InstanceKlass::super() - if you have an InstanceKlass* ik, ik->super() returns InstanceKlass*.
225 Klass* super() const { return _super; }
452 static ByteSize class_loader_data_offset() { return byte_offset_of(Klass, _class_loader_data); }
453 static ByteSize layout_helper_offset() { return byte_offset_of(Klass, _layout_helper); }
454 #if INCLUDE_JVMCI
455 static ByteSize subklass_offset() { return byte_offset_of(Klass, _subklass); }
456 static ByteSize next_sibling_offset() { return byte_offset_of(Klass, _next_sibling); }
457 #endif
458 static ByteSize secondary_supers_bitmap_offset()
459 { return byte_offset_of(Klass, _secondary_supers_bitmap); }
460 static ByteSize hash_slot_offset() { return byte_offset_of(Klass, _hash_slot); }
461 static ByteSize misc_flags_offset() { return byte_offset_of(Klass, _misc_flags._flags); }
462
463 // Unpacking layout_helper:
464 static const int _lh_neutral_value = 0; // neutral non-array non-instance value
465 static const int _lh_instance_slow_path_bit = 0x01;
466 static const int _lh_log2_element_size_shift = BitsPerByte*0;
467 static const int _lh_log2_element_size_mask = BitsPerLong-1;
468 static const int _lh_element_type_shift = BitsPerByte*1;
469 static const int _lh_element_type_mask = right_n_bits(BitsPerByte); // shifted mask
470 static const int _lh_header_size_shift = BitsPerByte*2;
471 static const int _lh_header_size_mask = right_n_bits(BitsPerByte); // shifted mask
472 static const int _lh_array_tag_bits = 2;
473 static const int _lh_array_tag_shift = BitsPerInt - _lh_array_tag_bits;
474 static const int _lh_array_tag_obj_value = ~0x01; // 0x80000000 >> 30
475
476 static const unsigned int _lh_array_tag_type_value = 0Xffffffff; // ~0x00, // 0xC0000000 >> 30
477
478 static int layout_helper_size_in_bytes(jint lh) {
479 assert(lh > (jint)_lh_neutral_value, "must be instance");
480 return (int) lh & ~_lh_instance_slow_path_bit;
481 }
482 static bool layout_helper_needs_slow_path(jint lh) {
483 assert(lh > (jint)_lh_neutral_value, "must be instance");
484 return (lh & _lh_instance_slow_path_bit) != 0;
485 }
486 static bool layout_helper_is_instance(jint lh) {
487 return (jint)lh > (jint)_lh_neutral_value;
488 }
489 static bool layout_helper_is_array(jint lh) {
490 return (jint)lh < (jint)_lh_neutral_value;
491 }
492 static bool layout_helper_is_typeArray(jint lh) {
493 // _lh_array_tag_type_value == (lh >> _lh_array_tag_shift);
494 return (juint)lh >= (juint)(_lh_array_tag_type_value << _lh_array_tag_shift);
495 }
496 static bool layout_helper_is_objArray(jint lh) {
497 // _lh_array_tag_obj_value == (lh >> _lh_array_tag_shift);
498 return (jint)lh < (jint)(_lh_array_tag_type_value << _lh_array_tag_shift);
499 }
500 static int layout_helper_header_size(jint lh) {
501 assert(lh < (jint)_lh_neutral_value, "must be array");
502 int hsize = (lh >> _lh_header_size_shift) & _lh_header_size_mask;
503 assert(hsize > 0 && hsize < (int)sizeof(oopDesc)*3, "sanity");
504 return hsize;
505 }
506 static BasicType layout_helper_element_type(jint lh) {
507 assert(lh < (jint)_lh_neutral_value, "must be array");
508 int btvalue = (lh >> _lh_element_type_shift) & _lh_element_type_mask;
509 assert(btvalue >= T_BOOLEAN && btvalue <= T_OBJECT, "sanity");
510 return (BasicType) btvalue;
511 }
512
513 // Want a pattern to quickly diff against layout header in register
514 // find something less clever!
515 static int layout_helper_boolean_diffbit() {
516 jint zlh = array_layout_helper(T_BOOLEAN);
517 jint blh = array_layout_helper(T_BYTE);
518 assert(zlh != blh, "array layout helpers must differ");
519 int diffbit = 1;
520 while ((diffbit & (zlh ^ blh)) == 0 && (diffbit & zlh) == 0) {
521 diffbit <<= 1;
522 assert(diffbit != 0, "make sure T_BOOLEAN has a different bit than T_BYTE");
523 }
524 return diffbit;
525 }
526
527 static int layout_helper_log2_element_size(jint lh) {
528 assert(lh < (jint)_lh_neutral_value, "must be array");
529 int l2esz = (lh >> _lh_log2_element_size_shift) & _lh_log2_element_size_mask;
530 assert(l2esz <= LogBytesPerLong,
531 "sanity. l2esz: 0x%x for lh: 0x%x", (uint)l2esz, (uint)lh);
532 return l2esz;
533 }
534 static jint array_layout_helper(jint tag, int hsize, BasicType etype, int log2_esize) {
535 return (tag << _lh_array_tag_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
656 const char* external_name() const;
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 #endif // ASSERT
678 public:
679
680 // Fast non-virtual versions
681 #ifndef ASSERT
682 #define assert_same_query(xval, xcheck) xval
683 #else
684 private:
685 static bool assert_same_query(bool xval, bool xslow) {
686 assert(xval == xslow, "slow and fast queries agree");
687 return xval;
688 }
689 public:
690 #endif
691
692 bool is_instance_klass() const { return assert_same_query(_kind <= InstanceStackChunkKlassKind, is_instance_klass_slow()); }
693 // Other is anything that is not one of the more specialized kinds of InstanceKlass.
694 bool is_other_instance_klass() const { return _kind == InstanceKlassKind; }
695 bool is_reference_instance_klass() const { return _kind == InstanceRefKlassKind; }
696 bool is_mirror_instance_klass() const { return _kind == InstanceMirrorKlassKind; }
697 bool is_class_loader_instance_klass() const { return _kind == InstanceClassLoaderKlassKind; }
698 bool is_array_klass() const { return assert_same_query( _kind >= TypeArrayKlassKind, is_array_klass_slow()); }
699 bool is_stack_chunk_instance_klass() const { return _kind == InstanceStackChunkKlassKind; }
700 bool is_objArray_klass() const { return assert_same_query( _kind == ObjArrayKlassKind, is_objArray_klass_slow()); }
701 bool is_typeArray_klass() const { return assert_same_query( _kind == TypeArrayKlassKind, is_typeArray_klass_slow()); }
702 #undef assert_same_query
703
704
705 virtual bool is_interface() const { return false; }
706 virtual bool is_abstract() const { return false; }
707
708 bool has_finalizer() const { return _misc_flags.has_finalizer(); }
709 void set_has_finalizer() { _misc_flags.set_has_finalizer(true); }
710 bool is_hidden() const { return _misc_flags.is_hidden_class(); }
711 void set_is_hidden() { _misc_flags.set_is_hidden_class(true); }
712 bool is_value_based() const { return _misc_flags.is_value_based_class(); }
713 void set_is_value_based() { _misc_flags.set_is_value_based_class(true); }
714
715 klass_flags_t misc_flags() const { return _misc_flags.value(); }
716
717 inline bool is_non_strong_hidden() const;
718
719 bool is_cloneable() const;
720 void set_is_cloneable_fast() { _misc_flags.set_is_cloneable_fast(true); }
721
722 inline markWord prototype_header() const;
723 inline void set_prototype_header(markWord header);
724 static ByteSize prototype_header_offset() { return in_ByteSize(offset_of(Klass, _prototype_header)); }
725
726 JFR_ONLY(DEFINE_TRACE_ID_METHODS;)
727
728 void metaspace_pointers_do(MetaspaceClosure* iter) override;
729 MetaspaceObj::Type type() const override { return ClassType; }
730
731 inline bool is_loader_alive() const;
732 inline bool is_loader_present_and_alive() const;
733
734 Klass* clean_subklass(bool log = false);
735
736 // Clean out unnecessary weak klass links from the whole klass hierarchy.
737 static void clean_weak_klass_links(bool unloading_occurred, bool clean_alive_klasses = true);
738 // Clean out unnecessary weak klass links from the given InstanceKlass.
739 static void clean_weak_instanceklass_links(InstanceKlass* ik);
740
741 // Return self, except for abstract classes with exactly 1
742 // implementor. Then return the 1 concrete implementation.
743 Klass *up_cast_abstract();
744
|
48 // a vtbl and does the C++ dispatch depending on the object's
49 // actual type. (See oop.inline.hpp for some of the forwarding code.)
50 // ALL FUNCTIONS IMPLEMENTING THIS DISPATCH ARE PREFIXED WITH "oop_"!
51
52 // Forward declarations.
53 template <class T> class Array;
54 template <class T> class GrowableArray;
55 class ClassLoaderData;
56 class fieldDescriptor;
57 class klassVtable;
58 class ModuleEntry;
59 class PackageEntry;
60 class vtableEntry;
61
62 class Klass : public Metadata {
63
64 friend class VMStructs;
65 friend class JVMCIVMStructs;
66 public:
67 // Klass Kinds for all subclasses of Klass
68 enum KlassKind : u2
69 {
70 InstanceKlassKind,
71 InlineKlassKind,
72 InstanceRefKlassKind,
73 InstanceMirrorKlassKind,
74 InstanceClassLoaderKlassKind,
75 InstanceStackChunkKlassKind,
76 TypeArrayKlassKind,
77 ObjArrayKlassKind,
78 RefArrayKlassKind,
79 FlatArrayKlassKind,
80 UnknownKlassKind
81 };
82
83 static const uint KLASS_KIND_COUNT = FlatArrayKlassKind + 1;
84 protected:
85
86 // If you add a new field that points to any metaspace object, you
87 // must add this field to Klass::metaspace_pointers_do().
88
89 // note: put frequently-used fields together at start of klass structure
90 // for better cache behavior (may not make much of a difference but sure won't hurt)
91 enum { _primary_super_limit = 8 };
92
93 // The "layout helper" is a combined descriptor of object layout.
94 // For klasses which are neither instance nor array, the value is zero.
95 //
96 // For instances, layout helper is a positive number, the instance size.
97 // This size is already passed through align_object_size and scaled to bytes.
98 // The low order bit is set if instances of this class cannot be
99 // allocated using the fastpath.
100 //
101 // For arrays, layout helper is a negative number, containing four
102 // distinct bytes, as follows:
103 // MSB:[tag, hsz, ebt, log2(esz)]:LSB
104 // where:
105 // tag is 0x80 if the elements are oops, 0xC0 if non-oops, 0xA0 if value types
106 // hsz is array header size in bytes (i.e., offset of first element)
107 // ebt is the BasicType of the elements
108 // esz is the element size in bytes
109 // This packed word is arranged so as to be quickly unpacked by the
110 // various fast paths that use the various subfields.
111 //
112 // The esz bits can be used directly by a SLL instruction, without masking.
113 //
114 // Note that the array-kind tag looks like 0x00 for instance klasses,
115 // since their length in bytes is always less than 24Mb.
116 //
117 // Final note: This comes first, immediately after C++ vtable,
118 // because it is frequently queried.
119 jint _layout_helper;
120
121 // Klass kind used to resolve the runtime type of the instance.
122 // - Used to implement devirtualized oop closure dispatching.
123 // - Various type checking in the JVM
124 const KlassKind _kind;
125
189 // no further need to call <clinit>
190 _has_aot_safe_initializer = 1 << 7, // has @AOTSafeClassInitializer annotation
191 _is_runtime_setup_required = 1 << 8, // has a runtimeSetup method to be called when
192 // this class is loaded from AOT cache
193 };
194 #endif
195
196 int _vtable_len; // vtable length. This field may be read very often when we
197 // have lots of itable dispatches (e.g., lambdas and streams).
198 // Keep it away from the beginning of a Klass to avoid cacheline
199 // contention that may happen when a nearby object is modified.
200
201 CDS_JAVA_HEAP_ONLY(int _archived_mirror_index;)
202
203 public:
204
205 JFR_ONLY(DEFINE_TRACE_ID_FIELD;)
206
207 protected:
208
209 Klass(KlassKind kind, markWord prototype_header = markWord::prototype());
210 Klass();
211
212 void* operator new(size_t size, ClassLoaderData* loader_data, size_t word_size, TRAPS) throw();
213
214 public:
215 int kind() { return _kind; }
216
217 enum class DefaultsLookupMode { find, skip };
218 enum class OverpassLookupMode { find, skip };
219 enum class StaticLookupMode { find, skip };
220 enum class PrivateLookupMode { find, skip };
221
222 bool is_klass() const override { return true; }
223
224 // super() cannot be InstanceKlass* -- Java arrays are covariant, and _super is used
225 // to implement that. NB: the _super of "[Ljava/lang/Integer;" is "[Ljava/lang/Number;"
226 // If this is not what your code expects, you're probably looking for:
227 // - Klass::java_super() - if you have a Klass*
228 // - InstanceKlass::super() - if you have an InstanceKlass* ik, ik->super() returns InstanceKlass*.
229 Klass* super() const { return _super; }
456 static ByteSize class_loader_data_offset() { return byte_offset_of(Klass, _class_loader_data); }
457 static ByteSize layout_helper_offset() { return byte_offset_of(Klass, _layout_helper); }
458 #if INCLUDE_JVMCI
459 static ByteSize subklass_offset() { return byte_offset_of(Klass, _subklass); }
460 static ByteSize next_sibling_offset() { return byte_offset_of(Klass, _next_sibling); }
461 #endif
462 static ByteSize secondary_supers_bitmap_offset()
463 { return byte_offset_of(Klass, _secondary_supers_bitmap); }
464 static ByteSize hash_slot_offset() { return byte_offset_of(Klass, _hash_slot); }
465 static ByteSize misc_flags_offset() { return byte_offset_of(Klass, _misc_flags._flags); }
466
467 // Unpacking layout_helper:
468 static const int _lh_neutral_value = 0; // neutral non-array non-instance value
469 static const int _lh_instance_slow_path_bit = 0x01;
470 static const int _lh_log2_element_size_shift = BitsPerByte*0;
471 static const int _lh_log2_element_size_mask = BitsPerLong-1;
472 static const int _lh_element_type_shift = BitsPerByte*1;
473 static const int _lh_element_type_mask = right_n_bits(BitsPerByte); // shifted mask
474 static const int _lh_header_size_shift = BitsPerByte*2;
475 static const int _lh_header_size_mask = right_n_bits(BitsPerByte); // shifted mask
476 static const int _lh_array_tag_bits = 4;
477 static const int _lh_array_tag_shift = BitsPerInt - _lh_array_tag_bits;
478
479 static const unsigned int _lh_array_tag_type_value = 0Xfffffffc;
480 static const unsigned int _lh_array_tag_flat_value = 0Xfffffffa;
481 static const unsigned int _lh_array_tag_ref_value = 0Xfffffff8;
482
483 // null-free array flag bit under the array tag bits, shift one more to get array tag value
484 static const int _lh_null_free_shift = _lh_array_tag_shift - 1;
485 static const int _lh_null_free_mask = 1;
486
487 static const jint _lh_array_tag_flat_value_bit_inplace = (jint) (1 << (_lh_array_tag_shift + 1));
488
489 static int layout_helper_size_in_bytes(jint lh) {
490 assert(lh > (jint)_lh_neutral_value, "must be instance");
491 return (int) lh & ~_lh_instance_slow_path_bit;
492 }
493 static bool layout_helper_needs_slow_path(jint lh) {
494 assert(lh > (jint)_lh_neutral_value, "must be instance");
495 return (lh & _lh_instance_slow_path_bit) != 0;
496 }
497 static bool layout_helper_is_instance(jint lh) {
498 return (jint)lh > (jint)_lh_neutral_value;
499 }
500 static bool layout_helper_is_array(jint lh) {
501 return (jint)lh < (jint)_lh_neutral_value;
502 }
503 static bool layout_helper_is_typeArray(jint lh) {
504 return (juint) _lh_array_tag_type_value == (juint)(lh >> _lh_array_tag_shift);
505 }
506 static bool layout_helper_is_refArray(jint lh) {
507 return (juint)_lh_array_tag_ref_value == (juint)(lh >> _lh_array_tag_shift);
508 }
509 static bool layout_helper_is_flatArray(jint lh) {
510 return (juint)_lh_array_tag_flat_value == (juint)(lh >> _lh_array_tag_shift);
511 }
512 static bool layout_helper_is_null_free(jint lh) {
513 assert(layout_helper_is_flatArray(lh) || layout_helper_is_refArray(lh), "must be array of inline types");
514 return ((lh >> _lh_null_free_shift) & _lh_null_free_mask);
515 }
516 static jint layout_helper_set_null_free(jint lh) {
517 lh |= (_lh_null_free_mask << _lh_null_free_shift);
518 assert(layout_helper_is_null_free(lh), "Bad encoding");
519 return lh;
520 }
521 static int layout_helper_header_size(jint lh) {
522 assert(lh < (jint)_lh_neutral_value, "must be array");
523 int hsize = (lh >> _lh_header_size_shift) & _lh_header_size_mask;
524 assert(hsize > 0 && hsize < (int)sizeof(oopDesc)*3, "sanity");
525 return hsize;
526 }
527 static BasicType layout_helper_element_type(jint lh) {
528 assert(lh < (jint)_lh_neutral_value, "must be array");
529 int btvalue = (lh >> _lh_element_type_shift) & _lh_element_type_mask;
530 assert((btvalue >= T_BOOLEAN && btvalue <= T_OBJECT) || btvalue == T_FLAT_ELEMENT, "sanity");
531 return (BasicType) btvalue;
532 }
533
534 // Want a pattern to quickly diff against layout header in register
535 // find something less clever!
536 static int layout_helper_boolean_diffbit() {
537 jint zlh = array_layout_helper(T_BOOLEAN);
538 jint blh = array_layout_helper(T_BYTE);
539 assert(zlh != blh, "array layout helpers must differ");
540 int diffbit = 1;
541 while ((diffbit & (zlh ^ blh)) == 0 && (diffbit & zlh) == 0) {
542 diffbit <<= 1;
543 assert(diffbit != 0, "make sure T_BOOLEAN has a different bit than T_BYTE");
544 }
545 return diffbit;
546 }
547
548 static int layout_helper_log2_element_size(jint lh) {
549 assert(lh < (jint)_lh_neutral_value, "must be array");
550 int l2esz = (lh >> _lh_log2_element_size_shift) & _lh_log2_element_size_mask;
551 assert(layout_helper_element_type(lh) == T_FLAT_ELEMENT || l2esz <= LogBytesPerLong,
552 "sanity. l2esz: 0x%x for lh: 0x%x", (uint)l2esz, (uint)lh);
553 return l2esz;
554 }
555 static jint array_layout_helper(jint tag, bool null_free, int hsize, BasicType etype, int log2_esize) {
556 return (tag << _lh_array_tag_shift)
557 | ((null_free ? 1 : 0) << _lh_null_free_shift)
558 | (hsize << _lh_header_size_shift)
559 | ((int)etype << _lh_element_type_shift)
560 | (log2_esize << _lh_log2_element_size_shift);
561 }
562 static jint instance_layout_helper(jint size, bool slow_path_flag) {
563 return (size << LogBytesPerWord)
564 | (slow_path_flag ? _lh_instance_slow_path_bit : 0);
565 }
566 static int layout_helper_to_size_helper(jint lh) {
567 assert(lh > (jint)_lh_neutral_value, "must be instance");
568 // Note that the following expression discards _lh_instance_slow_path_bit.
569 return lh >> LogBytesPerWord;
570 }
571 // Out-of-line version computes everything based on the etype:
572 static jint array_layout_helper(BasicType etype);
573
574 // What is the maximum number of primary superclasses any klass can have?
575 static juint primary_super_limit() { return _primary_super_limit; }
576
577 // vtables
678 const char* external_name() const;
679 // Returns the name for a class (Resource allocated) as the class
680 // would appear in a signature.
681 // For arrays, this returns the name of the element with a leading '['.
682 // For classes, this returns the name with a leading 'L' and a trailing ';'
683 // and the package separators as '/'.
684 virtual const char* signature_name() const;
685
686 const char* joint_in_module_of_loader(const Klass* class2, bool include_parent_loader = false) const;
687 const char* class_in_module_of_loader(bool use_are = false, bool include_parent_loader = false) const;
688
689 // Returns "interface", "abstract class" or "class".
690 const char* external_kind() const;
691
692 // type testing operations
693 #ifdef ASSERT
694 protected:
695 virtual bool is_instance_klass_slow() const { return false; }
696 virtual bool is_array_klass_slow() const { return false; }
697 virtual bool is_objArray_klass_slow() const { return false; }
698 virtual bool is_refArray_klass_slow() const { return false; }
699 virtual bool is_typeArray_klass_slow() const { return false; }
700 virtual bool is_flatArray_klass_slow() const { return false; }
701 #endif // ASSERT
702 // current implementation uses this method even in non debug builds
703 virtual bool is_inline_klass_slow() const { return false; }
704 public:
705
706 // Fast non-virtual versions
707 #ifndef ASSERT
708 #define assert_same_query(xval, xcheck) xval
709 #else
710 private:
711 static bool assert_same_query(bool xval, bool xslow) {
712 assert(xval == xslow, "slow and fast queries agree");
713 return xval;
714 }
715 public:
716 #endif
717
718 bool is_instance_klass() const { return assert_same_query(_kind <= InstanceStackChunkKlassKind, is_instance_klass_slow()); }
719 bool is_inline_klass() const { return assert_same_query(_kind == InlineKlassKind, is_inline_klass_slow()); }
720 bool is_reference_instance_klass() const { return _kind == InstanceRefKlassKind; }
721 bool is_mirror_instance_klass() const { return _kind == InstanceMirrorKlassKind; }
722 bool is_class_loader_instance_klass() const { return _kind == InstanceClassLoaderKlassKind; }
723 bool is_array_klass() const { return assert_same_query( _kind >= TypeArrayKlassKind, is_array_klass_slow()); }
724 bool is_stack_chunk_instance_klass() const { return _kind == InstanceStackChunkKlassKind; }
725 bool is_flatArray_klass() const { return assert_same_query( _kind == FlatArrayKlassKind, is_flatArray_klass_slow()); }
726 bool is_objArray_klass() const { return assert_same_query( _kind == ObjArrayKlassKind || _kind == RefArrayKlassKind || _kind == FlatArrayKlassKind, is_objArray_klass_slow()); }
727 bool is_refArray_klass() const { return assert_same_query( _kind == RefArrayKlassKind, is_refArray_klass_slow()); }
728 bool is_typeArray_klass() const { return assert_same_query( _kind == TypeArrayKlassKind, is_typeArray_klass_slow()); }
729 bool is_refined_objArray_klass() const { return is_refArray_klass() || is_flatArray_klass(); }
730 #undef assert_same_query
731
732 inline bool is_null_free_array_klass() const { return !is_typeArray_klass() && layout_helper_is_null_free(layout_helper()); }
733
734
735 virtual bool is_interface() const { return false; }
736 virtual bool is_abstract() const { return false; }
737 virtual bool is_identity_class() const { return false; }
738
739 bool has_finalizer() const { return _misc_flags.has_finalizer(); }
740 void set_has_finalizer() { _misc_flags.set_has_finalizer(true); }
741 bool is_hidden() const { return _misc_flags.is_hidden_class(); }
742 void set_is_hidden() { _misc_flags.set_is_hidden_class(true); }
743 bool is_value_based() const { return _misc_flags.is_value_based_class(); }
744 void set_is_value_based() { _misc_flags.set_is_value_based_class(true); }
745
746 klass_flags_t misc_flags() const { return _misc_flags.value(); }
747
748 inline bool is_non_strong_hidden() const;
749
750 bool is_cloneable() const;
751 void set_is_cloneable_fast() { _misc_flags.set_is_cloneable_fast(true); }
752
753 static inline markWord make_prototype_header(const Klass* kls, markWord prototype = markWord::prototype());
754 inline markWord prototype_header() const;
755 inline void set_prototype_header(markWord header);
756 static ByteSize prototype_header_offset() { return in_ByteSize(offset_of(Klass, _prototype_header)); }
757 inline void set_prototype_header_klass(narrowKlass klass);
758
759 JFR_ONLY(DEFINE_TRACE_ID_METHODS;)
760
761 void metaspace_pointers_do(MetaspaceClosure* iter) override;
762 MetaspaceObj::Type type() const override { return ClassType; }
763
764 inline bool is_loader_alive() const;
765 inline bool is_loader_present_and_alive() const;
766
767 Klass* clean_subklass(bool log = false);
768
769 // Clean out unnecessary weak klass links from the whole klass hierarchy.
770 static void clean_weak_klass_links(bool unloading_occurred, bool clean_alive_klasses = true);
771 // Clean out unnecessary weak klass links from the given InstanceKlass.
772 static void clean_weak_instanceklass_links(InstanceKlass* ik);
773
774 // Return self, except for abstract classes with exactly 1
775 // implementor. Then return the 1 concrete implementation.
776 Klass *up_cast_abstract();
777
|