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