24 |
24 |
25 #ifndef SHARE_VM_OOPS_KLASS_HPP |
25 #ifndef SHARE_VM_OOPS_KLASS_HPP |
26 #define SHARE_VM_OOPS_KLASS_HPP |
26 #define SHARE_VM_OOPS_KLASS_HPP |
27 |
27 |
28 #include "classfile/classLoaderData.hpp" |
28 #include "classfile/classLoaderData.hpp" |
29 #include "gc/shared/specialized_oop_closures.hpp" |
|
30 #include "memory/iterator.hpp" |
29 #include "memory/iterator.hpp" |
31 #include "memory/memRegion.hpp" |
30 #include "memory/memRegion.hpp" |
32 #include "oops/metadata.hpp" |
31 #include "oops/metadata.hpp" |
33 #include "oops/oop.hpp" |
32 #include "oops/oop.hpp" |
34 #include "oops/oopHandle.hpp" |
33 #include "oops/oopHandle.hpp" |
35 #include "utilities/accessFlags.hpp" |
34 #include "utilities/accessFlags.hpp" |
36 #include "utilities/macros.hpp" |
35 #include "utilities/macros.hpp" |
37 #if INCLUDE_JFR |
36 #if INCLUDE_JFR |
38 #include "jfr/support/jfrTraceIdExtension.hpp" |
37 #include "jfr/support/jfrTraceIdExtension.hpp" |
39 #endif |
38 #endif |
|
39 |
|
40 // Klass IDs for all subclasses of Klass |
|
41 enum KlassID { |
|
42 InstanceKlassID, |
|
43 InstanceRefKlassID, |
|
44 InstanceMirrorKlassID, |
|
45 InstanceClassLoaderKlassID, |
|
46 TypeArrayKlassID, |
|
47 ObjArrayKlassID |
|
48 }; |
|
49 |
|
50 const uint KLASS_ID_COUNT = 6; |
40 |
51 |
41 // |
52 // |
42 // A Klass provides: |
53 // A Klass provides: |
43 // 1: language level class object (method dictionary etc.) |
54 // 1: language level class object (method dictionary etc.) |
44 // 2: provide vm dispatch behavior for the object |
55 // 2: provide vm dispatch behavior for the object |
101 // |
112 // |
102 // Final note: This comes first, immediately after C++ vtable, |
113 // Final note: This comes first, immediately after C++ vtable, |
103 // because it is frequently queried. |
114 // because it is frequently queried. |
104 jint _layout_helper; |
115 jint _layout_helper; |
105 |
116 |
|
117 // Klass identifier used to implement devirtualized oop closure dispatching. |
|
118 const KlassID _id; |
|
119 |
106 // The fields _super_check_offset, _secondary_super_cache, _secondary_supers |
120 // The fields _super_check_offset, _secondary_super_cache, _secondary_supers |
107 // and _primary_supers all help make fast subtype checks. See big discussion |
121 // and _primary_supers all help make fast subtype checks. See big discussion |
108 // in doc/server_compiler/checktype.txt |
122 // in doc/server_compiler/checktype.txt |
109 // |
123 // |
110 // Where to look to observe a supertype (it is &_secondary_super_cache for |
124 // Where to look to observe a supertype (it is &_secondary_super_cache for |
171 CDS_JAVA_HEAP_ONLY(narrowOop _archived_mirror;) |
185 CDS_JAVA_HEAP_ONLY(narrowOop _archived_mirror;) |
172 |
186 |
173 protected: |
187 protected: |
174 |
188 |
175 // Constructor |
189 // Constructor |
176 Klass(); |
190 Klass(KlassID id); |
|
191 Klass() : _id(KlassID(-1)) { assert(DumpSharedSpaces || UseSharedSpaces, "only for cds"); } |
177 |
192 |
178 void* operator new(size_t size, ClassLoaderData* loader_data, size_t word_size, TRAPS) throw(); |
193 void* operator new(size_t size, ClassLoaderData* loader_data, size_t word_size, TRAPS) throw(); |
179 |
194 |
180 public: |
195 public: |
|
196 int id() { return _id; } |
|
197 |
181 enum DefaultsLookupMode { find_defaults, skip_defaults }; |
198 enum DefaultsLookupMode { find_defaults, skip_defaults }; |
182 enum OverpassLookupMode { find_overpass, skip_overpass }; |
199 enum OverpassLookupMode { find_overpass, skip_overpass }; |
183 enum StaticLookupMode { find_static, skip_static }; |
200 enum StaticLookupMode { find_static, skip_static }; |
184 enum PrivateLookupMode { find_private, skip_private }; |
201 enum PrivateLookupMode { find_private, skip_private }; |
185 |
202 |
658 // Parallel Compact |
675 // Parallel Compact |
659 virtual void oop_pc_follow_contents(oop obj, ParCompactionManager* cm) = 0; |
676 virtual void oop_pc_follow_contents(oop obj, ParCompactionManager* cm) = 0; |
660 virtual void oop_pc_update_pointers(oop obj, ParCompactionManager* cm) = 0; |
677 virtual void oop_pc_update_pointers(oop obj, ParCompactionManager* cm) = 0; |
661 #endif |
678 #endif |
662 |
679 |
663 // Iterators specialized to particular subtypes |
|
664 // of ExtendedOopClosure, to avoid closure virtual calls. |
|
665 #define Klass_OOP_OOP_ITERATE_DECL(OopClosureType, nv_suffix) \ |
|
666 virtual void oop_oop_iterate##nv_suffix(oop obj, OopClosureType* closure) = 0; \ |
|
667 /* Iterates "closure" over all the oops in "obj" (of type "this") within "mr". */ \ |
|
668 virtual void oop_oop_iterate_bounded##nv_suffix(oop obj, OopClosureType* closure, MemRegion mr) = 0; |
|
669 |
|
670 ALL_OOP_OOP_ITERATE_CLOSURES_1(Klass_OOP_OOP_ITERATE_DECL) |
|
671 ALL_OOP_OOP_ITERATE_CLOSURES_2(Klass_OOP_OOP_ITERATE_DECL) |
|
672 |
|
673 #if INCLUDE_OOP_OOP_ITERATE_BACKWARDS |
|
674 #define Klass_OOP_OOP_ITERATE_DECL_BACKWARDS(OopClosureType, nv_suffix) \ |
|
675 virtual void oop_oop_iterate_backwards##nv_suffix(oop obj, OopClosureType* closure) = 0; |
|
676 |
|
677 ALL_OOP_OOP_ITERATE_CLOSURES_1(Klass_OOP_OOP_ITERATE_DECL_BACKWARDS) |
|
678 ALL_OOP_OOP_ITERATE_CLOSURES_2(Klass_OOP_OOP_ITERATE_DECL_BACKWARDS) |
|
679 #endif |
|
680 |
|
681 virtual void array_klasses_do(void f(Klass* k)) {} |
680 virtual void array_klasses_do(void f(Klass* k)) {} |
682 |
681 |
683 // Return self, except for abstract classes with exactly 1 |
682 // Return self, except for abstract classes with exactly 1 |
684 // implementor. Then return the 1 concrete implementation. |
683 // implementor. Then return the 1 concrete implementation. |
685 Klass *up_cast_abstract(); |
684 Klass *up_cast_abstract(); |
723 |
722 |
724 static Klass* decode_klass_not_null(narrowKlass v); |
723 static Klass* decode_klass_not_null(narrowKlass v); |
725 static Klass* decode_klass(narrowKlass v); |
724 static Klass* decode_klass(narrowKlass v); |
726 }; |
725 }; |
727 |
726 |
728 // Helper to convert the oop iterate macro suffixes into bool values that can be used by template functions. |
|
729 #define nvs_nv_to_bool true |
|
730 #define nvs_v_to_bool false |
|
731 #define nvs_to_bool(nv_suffix) nvs##nv_suffix##_to_bool |
|
732 |
|
733 // Oop iteration macros for declarations. |
|
734 // Used to generate declarations in the *Klass header files. |
|
735 |
|
736 #define OOP_OOP_ITERATE_DECL(OopClosureType, nv_suffix) \ |
|
737 void oop_oop_iterate##nv_suffix(oop obj, OopClosureType* closure); \ |
|
738 void oop_oop_iterate_bounded##nv_suffix(oop obj, OopClosureType* closure, MemRegion mr); |
|
739 |
|
740 #if INCLUDE_OOP_OOP_ITERATE_BACKWARDS |
|
741 #define OOP_OOP_ITERATE_DECL_BACKWARDS(OopClosureType, nv_suffix) \ |
|
742 void oop_oop_iterate_backwards##nv_suffix(oop obj, OopClosureType* closure); |
|
743 #endif |
|
744 |
|
745 |
|
746 // Oop iteration macros for definitions. |
|
747 // Used to generate definitions in the *Klass.inline.hpp files. |
|
748 |
|
749 #define OOP_OOP_ITERATE_DEFN(KlassType, OopClosureType, nv_suffix) \ |
|
750 void KlassType::oop_oop_iterate##nv_suffix(oop obj, OopClosureType* closure) { \ |
|
751 oop_oop_iterate<nvs_to_bool(nv_suffix)>(obj, closure); \ |
|
752 } |
|
753 |
|
754 #if INCLUDE_OOP_OOP_ITERATE_BACKWARDS |
|
755 #define OOP_OOP_ITERATE_DEFN_BACKWARDS(KlassType, OopClosureType, nv_suffix) \ |
|
756 void KlassType::oop_oop_iterate_backwards##nv_suffix(oop obj, OopClosureType* closure) { \ |
|
757 oop_oop_iterate_reverse<nvs_to_bool(nv_suffix)>(obj, closure); \ |
|
758 } |
|
759 #else |
|
760 #define OOP_OOP_ITERATE_DEFN_BACKWARDS(KlassType, OopClosureType, nv_suffix) |
|
761 #endif |
|
762 |
|
763 #define OOP_OOP_ITERATE_DEFN_BOUNDED(KlassType, OopClosureType, nv_suffix) \ |
|
764 void KlassType::oop_oop_iterate_bounded##nv_suffix(oop obj, OopClosureType* closure, MemRegion mr) { \ |
|
765 oop_oop_iterate_bounded<nvs_to_bool(nv_suffix)>(obj, closure, mr); \ |
|
766 } |
|
767 |
|
768 #endif // SHARE_VM_OOPS_KLASS_HPP |
727 #endif // SHARE_VM_OOPS_KLASS_HPP |