25 #ifndef SHARE_OOPS_OOP_HPP
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 "runtime/atomic.hpp"
35 #include "utilities/globalDefinitions.hpp"
36 #include "utilities/macros.hpp"
37 #include <type_traits>
38
39 // oopDesc is the top baseclass for objects classes. The {name}Desc classes describe
40 // the format of Java objects so the fields can be accessed from C++.
41 // oopDesc is abstract.
42 // (see oopHierarchy for complete oop class hierarchy)
43 //
44 // no virtual functions allowed
45
46 // Forward declarations.
47 class OopClosure;
48 class PSPromotionManager;
49 class ParCompactionManager;
50
51 class oopDesc {
52 friend class VMStructs;
53 friend class JVMCIVMStructs;
54 private:
55 volatile markWord _mark;
56 union _metadata {
57 Klass* _klass;
58 narrowKlass _compressed_klass;
59 } _metadata;
60
61 // There may be ordering constraints on the initialization of fields that
62 // make use of the C++ copy/assign incorrect.
63 NONCOPYABLE(oopDesc);
64
92 inline void set_klass(Klass* k);
93 static inline void release_set_klass(HeapWord* mem, Klass* k);
94
95 // For klass field compression
96 static inline void set_klass_gap(HeapWord* mem, int z);
97
98 // size of object header, aligned to platform wordSize
99 static constexpr int header_size() { return sizeof(oopDesc)/HeapWordSize; }
100
101 // Returns whether this is an instance of k or an instance of a subclass of k
102 inline bool is_a(Klass* k) const;
103
104 // Returns the actual oop size of the object in machine words
105 inline size_t size();
106
107 // Sometimes (for complicated concurrency-related reasons), it is useful
108 // to be able to figure out the size of an object knowing its klass.
109 inline size_t size_given_klass(Klass* klass);
110
111 // type test operations (inlined in oop.inline.hpp)
112 inline bool is_instance() const;
113 inline bool is_instanceRef() const;
114 inline bool is_stackChunk() const;
115 inline bool is_array() const;
116 inline bool is_objArray() const;
117 inline bool is_typeArray() const;
118
119 // type test operations that don't require inclusion of oop.inline.hpp.
120 bool is_instance_noinline() const;
121 bool is_instanceRef_noinline() const;
122 bool is_stackChunk_noinline() const;
123 bool is_array_noinline() const;
124 bool is_objArray_noinline() const;
125 bool is_typeArray_noinline() const;
126
127 protected:
128 inline oop as_oop() const { return const_cast<oopDesc*>(this); }
129
130 public:
131 template<typename T>
132 inline T* field_addr(int offset) const;
133
134 template <typename T> inline size_t field_offset(T* p) const;
135
136 // Standard compare function returns negative value if o1 < o2
137 // 0 if o1 == o2
138 // positive value if o1 > o2
139 inline static int compare(oop o1, oop o2) {
140 void* o1_addr = (void*)o1;
141 void* o2_addr = (void*)o2;
142 if (o1_addr < o2_addr) {
143 return -1;
144 } else if (o1_addr > o2_addr) {
145 return 1;
|
25 #ifndef SHARE_OOPS_OOP_HPP
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 "runtime/atomic.hpp"
35 #include "utilities/globalDefinitions.hpp"
36 #include "utilities/macros.hpp"
37 #include <type_traits>
38
39 // oopDesc is the top baseclass for objects classes. The {name}Desc classes describe
40 // the format of Java objects so the fields can be accessed from C++.
41 // oopDesc is abstract.
42 // (see oopHierarchy for complete oop class hierarchy)
43 //
44 // no virtual functions allowed
45 //
46 // oopDesc::_mark - the "oop mark word" encoding to be found separately in markWord.hpp
47 //
48 // oopDesc::_metadata - encodes the object's klass pointer, as a raw pointer in "_klass"
49 // or compressed pointer in "_compressed_klass"
50 //
51 // The overall size of the _metadata field is dependent on "UseCompressedClassPointers",
52 // hence the terms "narrow" (32 bits) vs "wide" (64 bits).
53 //
54
55
56 // Forward declarations.
57 class OopClosure;
58 class PSPromotionManager;
59 class ParCompactionManager;
60
61 class oopDesc {
62 friend class VMStructs;
63 friend class JVMCIVMStructs;
64 private:
65 volatile markWord _mark;
66 union _metadata {
67 Klass* _klass;
68 narrowKlass _compressed_klass;
69 } _metadata;
70
71 // There may be ordering constraints on the initialization of fields that
72 // make use of the C++ copy/assign incorrect.
73 NONCOPYABLE(oopDesc);
74
102 inline void set_klass(Klass* k);
103 static inline void release_set_klass(HeapWord* mem, Klass* k);
104
105 // For klass field compression
106 static inline void set_klass_gap(HeapWord* mem, int z);
107
108 // size of object header, aligned to platform wordSize
109 static constexpr int header_size() { return sizeof(oopDesc)/HeapWordSize; }
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_inline_type() const;
124 inline bool is_instanceRef() const;
125 inline bool is_stackChunk() const;
126 inline bool is_array() const;
127 inline bool is_objArray() const;
128 inline bool is_typeArray() const;
129 inline bool is_flatArray() const;
130 inline bool is_null_free_array() const;
131
132 // type test operations that don't require inclusion of oop.inline.hpp.
133 bool is_instance_noinline() const;
134 bool is_instanceRef_noinline() const;
135 bool is_stackChunk_noinline() const;
136 bool is_array_noinline() const;
137 bool is_objArray_noinline() const;
138 bool is_typeArray_noinline() const;
139 bool is_flatArray_noinline() const;
140 bool is_null_free_array_noinline() const;
141
142 protected:
143 inline oop as_oop() const { return const_cast<oopDesc*>(this); }
144
145 public:
146 template<typename T>
147 inline T* field_addr(int offset) const;
148
149 template <typename T> inline size_t field_offset(T* p) const;
150
151 // Standard compare function returns negative value if o1 < o2
152 // 0 if o1 == o2
153 // positive value if o1 > o2
154 inline static int compare(oop o1, oop o2) {
155 void* o1_addr = (void*)o1;
156 void* o2_addr = (void*)o2;
157 if (o1_addr < o2_addr) {
158 return -1;
159 } else if (o1_addr > o2_addr) {
160 return 1;
|