26 #define SHARE_OOPS_OOP_HPP
27
28 #include "memory/iterator.hpp"
29 #include "memory/memRegion.hpp"
30 #include "oops/compressedKlass.hpp"
31 #include "oops/accessDecorators.hpp"
32 #include "oops/markWord.hpp"
33 #include "oops/metadata.hpp"
34 #include "oops/objLayout.hpp"
35 #include "runtime/atomic.hpp"
36 #include "utilities/globalDefinitions.hpp"
37 #include "utilities/macros.hpp"
38 #include <type_traits>
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;
99 // Size of object header, aligned to platform wordSize
100 static int header_size() {
101 if (UseCompactObjectHeaders) {
102 return sizeof(markWord) / HeapWordSize;
103 } else {
104 return sizeof(oopDesc) / HeapWordSize;
105 }
106 }
107
108 // Returns whether this is an instance of k or an instance of a subclass of k
109 inline bool is_a(Klass* k) const;
110
111 // Returns the actual oop size of the object in machine words
112 inline size_t size();
113
114 // Sometimes (for complicated concurrency-related reasons), it is useful
115 // to be able to figure out the size of an object knowing its klass.
116 inline size_t size_given_klass(Klass* klass);
117
118 // type test operations (inlined in oop.inline.hpp)
119 inline bool is_instance() const;
120 inline bool is_instanceRef() const;
121 inline bool is_stackChunk() const;
122 inline bool is_array() const;
123 inline bool is_objArray() const;
124 inline bool is_typeArray() const;
125
126 // type test operations that don't require inclusion of oop.inline.hpp.
127 bool is_instance_noinline() const;
128 bool is_instanceRef_noinline() const;
129 bool is_stackChunk_noinline() const;
130 bool is_array_noinline() const;
131 bool is_objArray_noinline() const;
132 bool is_typeArray_noinline() const;
133
134 protected:
135 inline oop as_oop() const { return const_cast<oopDesc*>(this); }
136
137 public:
138 template<typename T>
139 inline T* field_addr(int offset) const;
140
141 template <typename T> inline size_t field_offset(T* p) const;
142
143 // Standard compare function returns negative value if o1 < o2
144 // 0 if o1 == o2
145 // positive value if o1 > o2
146 inline static int compare(oop o1, oop o2) {
147 void* o1_addr = (void*)o1;
148 void* o2_addr = (void*)o2;
149 if (o1_addr < o2_addr) {
150 return -1;
151 } else if (o1_addr > o2_addr) {
152 return 1;
|
26 #define SHARE_OOPS_OOP_HPP
27
28 #include "memory/iterator.hpp"
29 #include "memory/memRegion.hpp"
30 #include "oops/compressedKlass.hpp"
31 #include "oops/accessDecorators.hpp"
32 #include "oops/markWord.hpp"
33 #include "oops/metadata.hpp"
34 #include "oops/objLayout.hpp"
35 #include "runtime/atomic.hpp"
36 #include "utilities/globalDefinitions.hpp"
37 #include "utilities/macros.hpp"
38 #include <type_traits>
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;
109 // Size of object header, aligned to platform wordSize
110 static int header_size() {
111 if (UseCompactObjectHeaders) {
112 return sizeof(markWord) / HeapWordSize;
113 } else {
114 return sizeof(oopDesc) / HeapWordSize;
115 }
116 }
117
118 // Returns whether this is an instance of k or an instance of a subclass of k
119 inline bool is_a(Klass* k) const;
120
121 // Returns the actual oop size of the object in machine words
122 inline size_t size();
123
124 // Sometimes (for complicated concurrency-related reasons), it is useful
125 // to be able to figure out the size of an object knowing its klass.
126 inline size_t size_given_klass(Klass* klass);
127
128 // type test operations (inlined in oop.inline.hpp)
129 inline bool is_instance() const;
130 inline bool is_inline_type() const;
131 inline bool is_instanceRef() const;
132 inline bool is_stackChunk() const;
133 inline bool is_array() const;
134 inline bool is_objArray() const;
135 inline bool is_typeArray() const;
136 inline bool is_flatArray() const;
137 inline bool is_null_free_array() const;
138
139 // type test operations that don't require inclusion of oop.inline.hpp.
140 bool is_instance_noinline() const;
141 bool is_instanceRef_noinline() const;
142 bool is_stackChunk_noinline() const;
143 bool is_array_noinline() const;
144 bool is_objArray_noinline() const;
145 bool is_typeArray_noinline() const;
146 bool is_flatArray_noinline() const;
147 bool is_null_free_array_noinline() const;
148
149 protected:
150 inline oop as_oop() const { return const_cast<oopDesc*>(this); }
151
152 public:
153 template<typename T>
154 inline T* field_addr(int offset) const;
155
156 template <typename T> inline size_t field_offset(T* p) const;
157
158 // Standard compare function returns negative value if o1 < o2
159 // 0 if o1 == o2
160 // positive value if o1 > o2
161 inline static int compare(oop o1, oop o2) {
162 void* o1_addr = (void*)o1;
163 void* o2_addr = (void*)o2;
164 if (o1_addr < o2_addr) {
165 return -1;
166 } else if (o1_addr > o2_addr) {
167 return 1;
|