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_INSTANCEMIRRORKLASS_HPP
26 #define SHARE_VM_OOPS_INSTANCEMIRRORKLASS_HPP
27
28 #include "classfile/systemDictionary.hpp"
29 #include "oops/instanceKlass.hpp"
30 #include "runtime/handles.hpp"
31 #include "utilities/macros.hpp"
32
33 // An InstanceMirrorKlass is a specialized InstanceKlass for
34 // java.lang.Class instances. These instances are special because
35 // they contain the static fields of the class in addition to the
36 // normal fields of Class. This means they are variable sized
37 // instances and need special logic for computing their size and for
38 // iteration of their oops.
39
40
41 class InstanceMirrorKlass: public InstanceKlass {
42 friend class VMStructs;
43 friend class InstanceKlass;
44
45 private:
46 static int _offset_of_static_fields;
47
48 // Constructor
49 InstanceMirrorKlass(int vtable_len, int itable_len, int static_field_size, int nonstatic_oop_map_size, ReferenceType rt, AccessFlags access_flags, bool is_anonymous)
50 : InstanceKlass(vtable_len, itable_len, static_field_size, nonstatic_oop_map_size, rt, access_flags, is_anonymous) {}
51
52 public:
53 InstanceMirrorKlass() { assert(DumpSharedSpaces || UseSharedSpaces, "only for CDS"); }
54 // Type testing
55 bool oop_is_instanceMirror() const { return true; }
56
57 // Casting from Klass*
58 static InstanceMirrorKlass* cast(Klass* k) {
59 assert(k->oop_is_instanceMirror(), "cast to InstanceMirrorKlass");
60 return (InstanceMirrorKlass*) k;
61 }
62
63 // Returns the size of the instance including the extra static fields.
64 virtual int oop_size(oop obj) const;
65
66 // Static field offset is an offset into the Heap, should be converted by
67 // based on UseCompressedOop for traversal
68 static HeapWord* start_of_static_fields(oop obj) {
69 return (HeapWord*)(cast_from_oop<intptr_t>(obj) + offset_of_static_fields());
70 }
71
72 static void init_offset_of_static_fields() {
73 // Cache the offset of the static fields in the Class instance
74 assert(_offset_of_static_fields == 0, "once");
75 _offset_of_static_fields = InstanceMirrorKlass::cast(SystemDictionary::Class_klass())->size_helper() << LogHeapWordSize;
76 }
77
78 static int offset_of_static_fields() {
79 return _offset_of_static_fields;
80 }
81
82 int compute_static_oop_field_count(oop obj);
83
84 // Given a Klass return the size of the instance
85 int instance_size(KlassHandle k);
86
87 // allocation
88 instanceOop allocate_instance(KlassHandle k, TRAPS);
89
90 // Garbage collection
91 int oop_adjust_pointers(oop obj);
92 void oop_follow_contents(oop obj);
93
94 // Parallel Scavenge and Parallel Old
95 PARALLEL_GC_DECLS
96
97 int oop_oop_iterate(oop obj, ExtendedOopClosure* blk) {
98 return oop_oop_iterate_v(obj, blk);
99 }
100 int oop_oop_iterate_m(oop obj, ExtendedOopClosure* blk, MemRegion mr) {
101 return oop_oop_iterate_v_m(obj, blk, mr);
102 }
103
104 #define InstanceMirrorKlass_OOP_OOP_ITERATE_DECL(OopClosureType, nv_suffix) \
105 int oop_oop_iterate##nv_suffix(oop obj, OopClosureType* blk); \
106 int oop_oop_iterate##nv_suffix##_m(oop obj, OopClosureType* blk, MemRegion mr);
107
108 ALL_OOP_OOP_ITERATE_CLOSURES_1(InstanceMirrorKlass_OOP_OOP_ITERATE_DECL)
109 ALL_OOP_OOP_ITERATE_CLOSURES_2(InstanceMirrorKlass_OOP_OOP_ITERATE_DECL)
110
111 #if INCLUDE_ALL_GCS
112 #define InstanceMirrorKlass_OOP_OOP_ITERATE_BACKWARDS_DECL(OopClosureType, nv_suffix) \
|
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_INSTANCEMIRRORKLASS_HPP
26 #define SHARE_VM_OOPS_INSTANCEMIRRORKLASS_HPP
27
28 #include "classfile/systemDictionary.hpp"
29 #include "oops/instanceKlass.hpp"
30 #include "runtime/handles.hpp"
31 #include "utilities/macros.hpp"
32 #include "utilities/templateIdioms.hpp"
33
34 // An InstanceMirrorKlass is a specialized InstanceKlass for
35 // java.lang.Class instances. These instances are special because
36 // they contain the static fields of the class in addition to the
37 // normal fields of Class. This means they are variable sized
38 // instances and need special logic for computing their size and for
39 // iteration of their oops.
40
41
42 class InstanceMirrorKlass: public InstanceKlass {
43 friend class VMStructs;
44 friend class InstanceKlass;
45
46 private:
47 static int _offset_of_static_fields;
48
49 // Constructor
50 InstanceMirrorKlass(int vtable_len, int itable_len, int static_field_size, int nonstatic_oop_map_size, ReferenceType rt, AccessFlags access_flags, bool is_anonymous)
51 : InstanceKlass(vtable_len, itable_len, static_field_size, nonstatic_oop_map_size, rt, access_flags, is_anonymous) {}
52
53 public:
54 InstanceMirrorKlass() { assert(DumpSharedSpaces || UseSharedSpaces, "only for CDS"); }
55 // Type testing
56 bool oop_is_instanceMirror() const { return true; }
57
58 // Casting from Klass*
59 static InstanceMirrorKlass* cast(Klass* k) {
60 assert(k->oop_is_instanceMirror(), "cast to InstanceMirrorKlass");
61 return (InstanceMirrorKlass*) k;
62 }
63
64 // Returns the size of the instance including the extra static fields.
65 virtual int oop_size(oop obj) const;
66
67 // Static field offset is an offset into the Heap, should be converted by
68 // based on UseCompressedOop for traversal
69 static HeapWord* start_of_static_fields(oop obj) {
70 return (HeapWord*)(cast_from_oop<intptr_t>(obj) + offset_of_static_fields());
71 }
72
73 static void init_offset_of_static_fields();
74
75 static int offset_of_static_fields() {
76 return _offset_of_static_fields;
77 }
78
79 int compute_static_oop_field_count(oop obj);
80
81 // Given a Klass return the size of the instance
82 int instance_size(KlassHandle k);
83
84 // allocation
85 instanceOop allocate_instance(KlassHandle k, TRAPS);
86
87 // Garbage collection
88 int oop_adjust_pointers(oop obj);
89 void oop_follow_contents(oop obj);
90
91 private:
92 // Some dispatch functions for auto dispatching
93 template<class OopType, class OopClosureType>
94 void oop_iterate_and_dispatch_helper(oop obj, OopClosureType *closure);
95
96 // Make sure metadata only gets dispatched for ExtendedOopClosure using SFINAE
97 template <class OopClosureType>
98 typename enable_if<is_kind_of<ExtendedOopClosure, OopClosureType>::value, void>::type
99 do_metadata_if_applicable(oop obj, OopClosureType *cl);
100
101 template <class OopClosureType>
102 typename enable_if<!is_kind_of<ExtendedOopClosure, OopClosureType>::value, void>::type
103 do_metadata_if_applicable(oop obj, OopClosureType *cl) {}
104
105 public:
106 template<class OopClosureType>
107 int oop_iterate_and_dispatch(oop obj, OopClosureType *cl);
108
109 int get_linear_oop_intervals(oop obj, OopInterval* &start, int &size) { return _instance_mirror_klass; }
110
111 // Parallel Scavenge and Parallel Old
112 PARALLEL_GC_DECLS
113
114 int oop_oop_iterate(oop obj, ExtendedOopClosure* blk) {
115 return oop_oop_iterate_v(obj, blk);
116 }
117 int oop_oop_iterate_m(oop obj, ExtendedOopClosure* blk, MemRegion mr) {
118 return oop_oop_iterate_v_m(obj, blk, mr);
119 }
120
121 #define InstanceMirrorKlass_OOP_OOP_ITERATE_DECL(OopClosureType, nv_suffix) \
122 int oop_oop_iterate##nv_suffix(oop obj, OopClosureType* blk); \
123 int oop_oop_iterate##nv_suffix##_m(oop obj, OopClosureType* blk, MemRegion mr);
124
125 ALL_OOP_OOP_ITERATE_CLOSURES_1(InstanceMirrorKlass_OOP_OOP_ITERATE_DECL)
126 ALL_OOP_OOP_ITERATE_CLOSURES_2(InstanceMirrorKlass_OOP_OOP_ITERATE_DECL)
127
128 #if INCLUDE_ALL_GCS
129 #define InstanceMirrorKlass_OOP_OOP_ITERATE_BACKWARDS_DECL(OopClosureType, nv_suffix) \
|