26 #define SHARE_OOPS_OOP_HPP
27
28 #include "cppstdlib/type_traits.hpp"
29 #include "memory/iterator.hpp"
30 #include "memory/memRegion.hpp"
31 #include "oops/accessDecorators.hpp"
32 #include "oops/compressedKlass.hpp"
33 #include "oops/markWord.hpp"
34 #include "oops/metadata.hpp"
35 #include "oops/objLayout.hpp"
36 #include "runtime/atomicAccess.hpp"
37 #include "utilities/globalDefinitions.hpp"
38 #include "utilities/macros.hpp"
39
40 // oopDesc is the top baseclass for objects classes. The {name}Desc classes describe
41 // the format of Java objects so the fields can be accessed from C++.
42 // oopDesc is abstract.
43 // (see oopHierarchy for complete oop class hierarchy)
44 //
45 // no virtual functions allowed
46
47 class oopDesc {
48 friend class VMStructs;
49 friend class JVMCIVMStructs;
50 private:
51 volatile markWord _mark;
52 union _metadata {
53 Klass* _klass;
54 narrowKlass _compressed_klass;
55 } _metadata;
56
57 // There may be ordering constraints on the initialization of fields that
58 // make use of the C++ copy/assign incorrect.
59 NONCOPYABLE(oopDesc);
60
61 inline oop cas_set_forwardee(markWord new_mark, markWord old_mark, atomic_memory_order order);
62
63 public:
64 // Must be trivial; see verifying static assert after the class.
65 oopDesc() = default;
102 // Size of object header, aligned to platform wordSize
103 static int header_size() {
104 if (UseCompactObjectHeaders) {
105 return sizeof(markWord) / HeapWordSize;
106 } else {
107 return sizeof(oopDesc) / HeapWordSize;
108 }
109 }
110
111 // Returns whether this is an instance of k or an instance of a subclass of k
112 inline bool is_a(Klass* k) const;
113
114 // Returns the actual oop size of the object in machine words
115 inline size_t size();
116
117 // Sometimes (for complicated concurrency-related reasons), it is useful
118 // to be able to figure out the size of an object knowing its klass.
119 inline size_t size_given_klass(Klass* klass);
120
121 // type test operations (inlined in oop.inline.hpp)
122 inline bool is_instance() const;
123 inline bool is_instanceRef() const;
124 inline bool is_stackChunk() const;
125 inline bool is_array() const;
126 inline bool is_objArray() const;
127 inline bool is_typeArray() const;
128
129 // type test operations that don't require inclusion of oop.inline.hpp.
130 bool is_instance_noinline() const;
131 bool is_instanceRef_noinline() const;
132 bool is_stackChunk_noinline() const;
133 bool is_array_noinline() const;
134 bool is_objArray_noinline() const;
135 bool is_typeArray_noinline() const;
136
137 protected:
138 inline oop as_oop() const { return const_cast<oopDesc*>(this); }
139
140 public:
141 template<typename T>
142 inline T* field_addr(int offset) const;
143
144 template <typename T> inline size_t field_offset(T* p) const;
145
146 // Standard compare function returns negative value if o1 < o2
147 // 0 if o1 == o2
148 // positive value if o1 > o2
149 inline static int compare(oop o1, oop o2) {
150 void* o1_addr = (void*)o1;
151 void* o2_addr = (void*)o2;
152 if (o1_addr < o2_addr) {
153 return -1;
154 } else if (o1_addr > o2_addr) {
155 return 1;
|
26 #define SHARE_OOPS_OOP_HPP
27
28 #include "cppstdlib/type_traits.hpp"
29 #include "memory/iterator.hpp"
30 #include "memory/memRegion.hpp"
31 #include "oops/accessDecorators.hpp"
32 #include "oops/compressedKlass.hpp"
33 #include "oops/markWord.hpp"
34 #include "oops/metadata.hpp"
35 #include "oops/objLayout.hpp"
36 #include "runtime/atomicAccess.hpp"
37 #include "utilities/globalDefinitions.hpp"
38 #include "utilities/macros.hpp"
39
40 // oopDesc is the top baseclass for objects classes. The {name}Desc classes describe
41 // the format of Java objects so the fields can be accessed from C++.
42 // oopDesc is abstract.
43 // (see oopHierarchy for complete oop class hierarchy)
44 //
45 // no virtual functions allowed
46 //
47 // oopDesc::_mark - the "oop mark word" encoding to be found separately in markWord.hpp
48 //
49 // oopDesc::_metadata - encodes the object's klass pointer, as a raw pointer in "_klass"
50 // or compressed pointer in "_compressed_klass"
51 //
52 // The overall size of the _metadata field is dependent on "UseCompressedClassPointers",
53 // hence the terms "narrow" (32 bits) vs "wide" (64 bits).
54 //
55
56
57 class oopDesc {
58 friend class VMStructs;
59 friend class JVMCIVMStructs;
60 private:
61 volatile markWord _mark;
62 union _metadata {
63 Klass* _klass;
64 narrowKlass _compressed_klass;
65 } _metadata;
66
67 // There may be ordering constraints on the initialization of fields that
68 // make use of the C++ copy/assign incorrect.
69 NONCOPYABLE(oopDesc);
70
71 inline oop cas_set_forwardee(markWord new_mark, markWord old_mark, atomic_memory_order order);
72
73 public:
74 // Must be trivial; see verifying static assert after the class.
75 oopDesc() = default;
112 // Size of object header, aligned to platform wordSize
113 static int header_size() {
114 if (UseCompactObjectHeaders) {
115 return sizeof(markWord) / HeapWordSize;
116 } else {
117 return sizeof(oopDesc) / HeapWordSize;
118 }
119 }
120
121 // Returns whether this is an instance of k or an instance of a subclass of k
122 inline bool is_a(Klass* k) const;
123
124 // Returns the actual oop size of the object in machine words
125 inline size_t size();
126
127 // Sometimes (for complicated concurrency-related reasons), it is useful
128 // to be able to figure out the size of an object knowing its klass.
129 inline size_t size_given_klass(Klass* klass);
130
131 // type test operations (inlined in oop.inline.hpp)
132 inline bool is_instance() const;
133 inline bool is_inline_type() const;
134 inline bool is_instanceRef() const;
135 inline bool is_stackChunk() const;
136 inline bool is_array() const;
137 inline bool is_objArray() const;
138 inline bool is_typeArray() const;
139 inline bool is_flatArray() const;
140 inline bool is_refArray() const;
141 inline bool is_null_free_array() const;
142 inline bool is_refined_objArray() const;
143
144 // type test operations that don't require inclusion of oop.inline.hpp.
145 bool is_instance_noinline() const;
146 bool is_instanceRef_noinline() const;
147 bool is_stackChunk_noinline() const;
148 bool is_array_noinline() const;
149 bool is_objArray_noinline() const;
150 bool is_refArray_noinline() const;
151 bool is_typeArray_noinline() const;
152 bool is_flatArray_noinline() const;
153 bool is_null_free_array_noinline() const;
154
155 protected:
156 inline oop as_oop() const { return const_cast<oopDesc*>(this); }
157
158 public:
159 template<typename T>
160 inline T* field_addr(int offset) const;
161
162 template <typename T> inline size_t field_offset(T* p) const;
163
164 // Standard compare function returns negative value if o1 < o2
165 // 0 if o1 == o2
166 // positive value if o1 > o2
167 inline static int compare(oop o1, oop o2) {
168 void* o1_addr = (void*)o1;
169 void* o2_addr = (void*)o2;
170 if (o1_addr < o2_addr) {
171 return -1;
172 } else if (o1_addr > o2_addr) {
173 return 1;
|