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