9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 *
23 */
24
25 #ifndef SHARE_VM_OOPS_KLASS_HPP
26 #define SHARE_VM_OOPS_KLASS_HPP
27
28 #include "classfile/classLoaderData.hpp"
29 #include "gc/shared/specialized_oop_closures.hpp"
30 #include "memory/iterator.hpp"
31 #include "memory/memRegion.hpp"
32 #include "oops/metadata.hpp"
33 #include "oops/oop.hpp"
34 #include "oops/oopHandle.hpp"
35 #include "utilities/accessFlags.hpp"
36 #include "utilities/macros.hpp"
37 #if INCLUDE_JFR
38 #include "jfr/support/jfrTraceIdExtension.hpp"
39 #endif
40
41 //
42 // A Klass provides:
43 // 1: language level class object (method dictionary etc.)
44 // 2: provide vm dispatch behavior for the object
45 // Both functions are combined into one C++ class.
46
47 // One reason for the oop/klass dichotomy in the implementation is
48 // that we don't want a C++ vtbl pointer in every object. Thus,
49 // normal oops don't have any virtual functions. Instead, they
86 // For arrays, layout helper is a negative number, containing four
87 // distinct bytes, as follows:
88 // MSB:[tag, hsz, ebt, log2(esz)]:LSB
89 // where:
90 // tag is 0x80 if the elements are oops, 0xC0 if non-oops
91 // hsz is array header size in bytes (i.e., offset of first element)
92 // ebt is the BasicType of the elements
93 // esz is the element size in bytes
94 // This packed word is arranged so as to be quickly unpacked by the
95 // various fast paths that use the various subfields.
96 //
97 // The esz bits can be used directly by a SLL instruction, without masking.
98 //
99 // Note that the array-kind tag looks like 0x00 for instance klasses,
100 // since their length in bytes is always less than 24Mb.
101 //
102 // Final note: This comes first, immediately after C++ vtable,
103 // because it is frequently queried.
104 jint _layout_helper;
105
106 // The fields _super_check_offset, _secondary_super_cache, _secondary_supers
107 // and _primary_supers all help make fast subtype checks. See big discussion
108 // in doc/server_compiler/checktype.txt
109 //
110 // Where to look to observe a supertype (it is &_secondary_super_cache for
111 // secondary supers, else is &_primary_supers[depth()].
112 juint _super_check_offset;
113
114 // Class name. Instance classes: java/lang/String, etc. Array classes: [I,
115 // [Ljava/lang/String;, etc. Set to zero for all other kinds of classes.
116 Symbol* _name;
117
118 // Cache of last observed secondary supertype
119 Klass* _secondary_super_cache;
120 // Array of all secondary supertypes
121 Array<Klass*>* _secondary_supers;
122 // Ordered list of all primary supertypes
123 Klass* _primary_supers[_primary_super_limit];
124 // java/lang/Class instance mirroring this class
125 OopHandle _java_mirror;
156 // associate this class with the JAR file where it's loaded from during
157 // dump time. If a class is not loaded from the shared archive, this field is
158 // -1.
159 jshort _shared_class_path_index;
160
161 #if INCLUDE_CDS
162 // Flags of the current shared class.
163 u2 _shared_class_flags;
164 enum {
165 _has_raw_archived_mirror = 1,
166 _has_signer_and_not_archived = 1 << 2
167 };
168 #endif
169 // The _archived_mirror is set at CDS dump time pointing to the cached mirror
170 // in the open archive heap region when archiving java object is supported.
171 CDS_JAVA_HEAP_ONLY(narrowOop _archived_mirror;)
172
173 protected:
174
175 // Constructor
176 Klass();
177
178 void* operator new(size_t size, ClassLoaderData* loader_data, size_t word_size, TRAPS) throw();
179
180 public:
181 enum DefaultsLookupMode { find_defaults, skip_defaults };
182 enum OverpassLookupMode { find_overpass, skip_overpass };
183 enum StaticLookupMode { find_static, skip_static };
184 enum PrivateLookupMode { find_private, skip_private };
185
186 bool is_klass() const volatile { return true; }
187
188 // super
189 Klass* super() const { return _super; }
190 void set_super(Klass* k) { _super = k; }
191
192 // initializes _super link, _primary_supers & _secondary_supers arrays
193 void initialize_supers(Klass* k, Array<Klass*>* transitive_interfaces, TRAPS);
194 void initialize_supers_impl1(Klass* k);
195 void initialize_supers_impl2(Klass* k);
196
197 // klass-specific helper for initializing _secondary_supers
198 virtual GrowableArray<Klass*>* compute_secondary_supers(int num_extra_slots,
199 Array<Klass*>* transitive_interfaces);
200
636
637 // Iff the class loader (or mirror for anonymous classes) is alive the
638 // Klass is considered alive. Has already been marked as unloading.
639 bool is_loader_alive() const { return !class_loader_data()->is_unloading(); }
640
641 static void clean_weak_klass_links(bool unloading_occurred, bool clean_alive_klasses = true);
642 static void clean_subklass_tree() {
643 clean_weak_klass_links(/*unloading_occurred*/ true , /* clean_alive_klasses */ false);
644 }
645
646 // GC specific object visitors
647 //
648 #if INCLUDE_PARALLELGC
649 // Parallel Scavenge
650 virtual void oop_ps_push_contents( oop obj, PSPromotionManager* pm) = 0;
651 // Parallel Compact
652 virtual void oop_pc_follow_contents(oop obj, ParCompactionManager* cm) = 0;
653 virtual void oop_pc_update_pointers(oop obj, ParCompactionManager* cm) = 0;
654 #endif
655
656 // Iterators specialized to particular subtypes
657 // of ExtendedOopClosure, to avoid closure virtual calls.
658 #define Klass_OOP_OOP_ITERATE_DECL(OopClosureType, nv_suffix) \
659 virtual void oop_oop_iterate##nv_suffix(oop obj, OopClosureType* closure) = 0; \
660 /* Iterates "closure" over all the oops in "obj" (of type "this") within "mr". */ \
661 virtual void oop_oop_iterate_bounded##nv_suffix(oop obj, OopClosureType* closure, MemRegion mr) = 0;
662
663 ALL_OOP_OOP_ITERATE_CLOSURES_1(Klass_OOP_OOP_ITERATE_DECL)
664 ALL_OOP_OOP_ITERATE_CLOSURES_2(Klass_OOP_OOP_ITERATE_DECL)
665
666 #if INCLUDE_OOP_OOP_ITERATE_BACKWARDS
667 #define Klass_OOP_OOP_ITERATE_DECL_BACKWARDS(OopClosureType, nv_suffix) \
668 virtual void oop_oop_iterate_backwards##nv_suffix(oop obj, OopClosureType* closure) = 0;
669
670 ALL_OOP_OOP_ITERATE_CLOSURES_1(Klass_OOP_OOP_ITERATE_DECL_BACKWARDS)
671 ALL_OOP_OOP_ITERATE_CLOSURES_2(Klass_OOP_OOP_ITERATE_DECL_BACKWARDS)
672 #endif
673
674 virtual void array_klasses_do(void f(Klass* k)) {}
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; }
682 void set_name(Symbol* n);
683
684 public:
685 // jvm support
686 virtual jint compute_modifier_flags(TRAPS) const;
687
688 // JVMTI support
689 virtual jint jvmti_class_status() const;
690
691 // Printing
692 virtual void print_on(outputStream* st) const;
693
701 void verify() { verify_on(tty); }
702
703 #ifndef PRODUCT
704 bool verify_vtable_index(int index);
705 bool verify_itable_index(int index);
706 #endif
707
708 virtual void oop_verify_on(oop obj, outputStream* st);
709
710 static bool is_null(narrowKlass obj);
711 static bool is_null(Klass* obj);
712
713 // klass encoding for klass pointer in objects.
714 static narrowKlass encode_klass_not_null(Klass* v);
715 static narrowKlass encode_klass(Klass* v);
716
717 static Klass* decode_klass_not_null(narrowKlass v);
718 static Klass* decode_klass(narrowKlass v);
719 };
720
721 // Helper to convert the oop iterate macro suffixes into bool values that can be used by template functions.
722 #define nvs_nv_to_bool true
723 #define nvs_v_to_bool false
724 #define nvs_to_bool(nv_suffix) nvs##nv_suffix##_to_bool
725
726 // Oop iteration macros for declarations.
727 // Used to generate declarations in the *Klass header files.
728
729 #define OOP_OOP_ITERATE_DECL(OopClosureType, nv_suffix) \
730 void oop_oop_iterate##nv_suffix(oop obj, OopClosureType* closure); \
731 void oop_oop_iterate_bounded##nv_suffix(oop obj, OopClosureType* closure, MemRegion mr);
732
733 #if INCLUDE_OOP_OOP_ITERATE_BACKWARDS
734 #define OOP_OOP_ITERATE_DECL_BACKWARDS(OopClosureType, nv_suffix) \
735 void oop_oop_iterate_backwards##nv_suffix(oop obj, OopClosureType* closure);
736 #endif
737
738
739 // Oop iteration macros for definitions.
740 // Used to generate definitions in the *Klass.inline.hpp files.
741
742 #define OOP_OOP_ITERATE_DEFN(KlassType, OopClosureType, nv_suffix) \
743 void KlassType::oop_oop_iterate##nv_suffix(oop obj, OopClosureType* closure) { \
744 oop_oop_iterate<nvs_to_bool(nv_suffix)>(obj, closure); \
745 }
746
747 #if INCLUDE_OOP_OOP_ITERATE_BACKWARDS
748 #define OOP_OOP_ITERATE_DEFN_BACKWARDS(KlassType, OopClosureType, nv_suffix) \
749 void KlassType::oop_oop_iterate_backwards##nv_suffix(oop obj, OopClosureType* closure) { \
750 oop_oop_iterate_reverse<nvs_to_bool(nv_suffix)>(obj, closure); \
751 }
752 #else
753 #define OOP_OOP_ITERATE_DEFN_BACKWARDS(KlassType, OopClosureType, nv_suffix)
754 #endif
755
756 #define OOP_OOP_ITERATE_DEFN_BOUNDED(KlassType, OopClosureType, nv_suffix) \
757 void KlassType::oop_oop_iterate_bounded##nv_suffix(oop obj, OopClosureType* closure, MemRegion mr) { \
758 oop_oop_iterate_bounded<nvs_to_bool(nv_suffix)>(obj, closure, mr); \
759 }
760
761 #endif // SHARE_VM_OOPS_KLASS_HPP
|
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 *
23 */
24
25 #ifndef SHARE_VM_OOPS_KLASS_HPP
26 #define SHARE_VM_OOPS_KLASS_HPP
27
28 #include "classfile/classLoaderData.hpp"
29 #include "memory/iterator.hpp"
30 #include "memory/memRegion.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 //
41 // A Klass provides:
42 // 1: language level class object (method dictionary etc.)
43 // 2: provide vm dispatch behavior for the object
44 // Both functions are combined into one C++ class.
45
46 // One reason for the oop/klass dichotomy in the implementation is
47 // that we don't want a C++ vtbl pointer in every object. Thus,
48 // normal oops don't have any virtual functions. Instead, they
85 // For arrays, layout helper is a negative number, containing four
86 // distinct bytes, as follows:
87 // MSB:[tag, hsz, ebt, log2(esz)]:LSB
88 // where:
89 // tag is 0x80 if the elements are oops, 0xC0 if non-oops
90 // hsz is array header size in bytes (i.e., offset of first element)
91 // ebt is the BasicType of the elements
92 // esz is the element size in bytes
93 // This packed word is arranged so as to be quickly unpacked by the
94 // various fast paths that use the various subfields.
95 //
96 // The esz bits can be used directly by a SLL instruction, without masking.
97 //
98 // Note that the array-kind tag looks like 0x00 for instance klasses,
99 // since their length in bytes is always less than 24Mb.
100 //
101 // Final note: This comes first, immediately after C++ vtable,
102 // because it is frequently queried.
103 jint _layout_helper;
104
105 // Klass identifier used to implement devirtualized oop closure dispatching.
106 const int _id;
107
108 // The fields _super_check_offset, _secondary_super_cache, _secondary_supers
109 // and _primary_supers all help make fast subtype checks. See big discussion
110 // in doc/server_compiler/checktype.txt
111 //
112 // Where to look to observe a supertype (it is &_secondary_super_cache for
113 // secondary supers, else is &_primary_supers[depth()].
114 juint _super_check_offset;
115
116 // Class name. Instance classes: java/lang/String, etc. Array classes: [I,
117 // [Ljava/lang/String;, etc. Set to zero for all other kinds of classes.
118 Symbol* _name;
119
120 // Cache of last observed secondary supertype
121 Klass* _secondary_super_cache;
122 // Array of all secondary supertypes
123 Array<Klass*>* _secondary_supers;
124 // Ordered list of all primary supertypes
125 Klass* _primary_supers[_primary_super_limit];
126 // java/lang/Class instance mirroring this class
127 OopHandle _java_mirror;
158 // associate this class with the JAR file where it's loaded from during
159 // dump time. If a class is not loaded from the shared archive, this field is
160 // -1.
161 jshort _shared_class_path_index;
162
163 #if INCLUDE_CDS
164 // Flags of the current shared class.
165 u2 _shared_class_flags;
166 enum {
167 _has_raw_archived_mirror = 1,
168 _has_signer_and_not_archived = 1 << 2
169 };
170 #endif
171 // The _archived_mirror is set at CDS dump time pointing to the cached mirror
172 // in the open archive heap region when archiving java object is supported.
173 CDS_JAVA_HEAP_ONLY(narrowOop _archived_mirror;)
174
175 protected:
176
177 // Constructor
178 Klass(int id);
179 Klass() : _id(-1) { assert(DumpSharedSpaces || UseSharedSpaces, "only for cds"); }
180
181 void* operator new(size_t size, ClassLoaderData* loader_data, size_t word_size, TRAPS) throw();
182
183 public:
184 int id() { return _id; }
185
186 enum DefaultsLookupMode { find_defaults, skip_defaults };
187 enum OverpassLookupMode { find_overpass, skip_overpass };
188 enum StaticLookupMode { find_static, skip_static };
189 enum PrivateLookupMode { find_private, skip_private };
190
191 bool is_klass() const volatile { return true; }
192
193 // super
194 Klass* super() const { return _super; }
195 void set_super(Klass* k) { _super = k; }
196
197 // initializes _super link, _primary_supers & _secondary_supers arrays
198 void initialize_supers(Klass* k, Array<Klass*>* transitive_interfaces, TRAPS);
199 void initialize_supers_impl1(Klass* k);
200 void initialize_supers_impl2(Klass* k);
201
202 // klass-specific helper for initializing _secondary_supers
203 virtual GrowableArray<Klass*>* compute_secondary_supers(int num_extra_slots,
204 Array<Klass*>* transitive_interfaces);
205
641
642 // Iff the class loader (or mirror for anonymous classes) is alive the
643 // Klass is considered alive. Has already been marked as unloading.
644 bool is_loader_alive() const { return !class_loader_data()->is_unloading(); }
645
646 static void clean_weak_klass_links(bool unloading_occurred, bool clean_alive_klasses = true);
647 static void clean_subklass_tree() {
648 clean_weak_klass_links(/*unloading_occurred*/ true , /* clean_alive_klasses */ false);
649 }
650
651 // GC specific object visitors
652 //
653 #if INCLUDE_PARALLELGC
654 // Parallel Scavenge
655 virtual void oop_ps_push_contents( oop obj, PSPromotionManager* pm) = 0;
656 // Parallel Compact
657 virtual void oop_pc_follow_contents(oop obj, ParCompactionManager* cm) = 0;
658 virtual void oop_pc_update_pointers(oop obj, ParCompactionManager* cm) = 0;
659 #endif
660
661 virtual void array_klasses_do(void f(Klass* k)) {}
662
663 // Return self, except for abstract classes with exactly 1
664 // implementor. Then return the 1 concrete implementation.
665 Klass *up_cast_abstract();
666
667 // klass name
668 Symbol* name() const { return _name; }
669 void set_name(Symbol* n);
670
671 public:
672 // jvm support
673 virtual jint compute_modifier_flags(TRAPS) const;
674
675 // JVMTI support
676 virtual jint jvmti_class_status() const;
677
678 // Printing
679 virtual void print_on(outputStream* st) const;
680
688 void verify() { verify_on(tty); }
689
690 #ifndef PRODUCT
691 bool verify_vtable_index(int index);
692 bool verify_itable_index(int index);
693 #endif
694
695 virtual void oop_verify_on(oop obj, outputStream* st);
696
697 static bool is_null(narrowKlass obj);
698 static bool is_null(Klass* obj);
699
700 // klass encoding for klass pointer in objects.
701 static narrowKlass encode_klass_not_null(Klass* v);
702 static narrowKlass encode_klass(Klass* v);
703
704 static Klass* decode_klass_not_null(narrowKlass v);
705 static Klass* decode_klass(narrowKlass v);
706 };
707
708 enum KlassID {
709 InstanceKlassID,
710 InstanceRefKlassID,
711 InstanceMirrorKlassID,
712 InstanceClassLoaderKlassID,
713 TypeArrayKlassID,
714 ObjArrayKlassID
715 };
716
717 #endif // SHARE_VM_OOPS_KLASS_HPP
|