11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 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_OOPS_OOP_HPP 26 #define SHARE_OOPS_OOP_HPP 27 28 #include "memory/iterator.hpp" 29 #include "memory/memRegion.hpp" 30 #include "oops/access.hpp" 31 #include "oops/metadata.hpp" 32 #include "runtime/atomic.hpp" 33 #include "utilities/macros.hpp" 34 35 // oopDesc is the top baseclass for objects classes. The {name}Desc classes describe 36 // the format of Java objects so the fields can be accessed from C++. 37 // oopDesc is abstract. 38 // (see oopHierarchy for complete oop class hierarchy) 39 // 40 // no virtual functions allowed 41 42 extern bool always_do_update_barrier; 43 44 // Forward declarations. 45 class OopClosure; 46 class ScanClosure; 47 class FastScanClosure; 48 class FilteringClosure; 49 class CMSIsAliveClosure; 50 51 class PSPromotionManager; 52 class ParCompactionManager; 53 54 class oopDesc { 55 friend class VMStructs; 56 friend class JVMCIVMStructs; 57 private: 58 volatile markOop _mark; 59 union _metadata { 60 Klass* _klass; 61 narrowKlass _compressed_klass; 62 } _metadata; 63 64 public: 65 inline markOop mark() const; 66 inline markOop mark_raw() const; 67 inline markOop* mark_addr_raw() const; 68 69 inline void set_mark(volatile markOop m); 70 inline void set_mark_raw(volatile markOop m); 71 static inline void set_mark_raw(HeapWord* mem, markOop m); 72 73 inline void release_set_mark(markOop m); 74 inline markOop cas_set_mark(markOop new_mark, markOop old_mark); 75 inline markOop cas_set_mark_raw(markOop new_mark, markOop old_mark, atomic_memory_order order = memory_order_conservative); 76 77 // Used only to re-initialize the mark word (e.g., of promoted 78 // objects during a GC) -- requires a valid klass pointer 79 inline void init_mark(); 80 inline void init_mark_raw(); 81 82 inline Klass* klass() const; 83 inline Klass* klass_or_null() const volatile; 84 inline Klass* klass_or_null_acquire() const volatile; 85 static inline Klass** klass_addr(HeapWord* mem); 86 static inline narrowKlass* compressed_klass_addr(HeapWord* mem); 87 inline Klass** klass_addr(); 88 inline narrowKlass* compressed_klass_addr(); 89 90 inline void set_klass(Klass* k); 91 static inline void release_set_klass(HeapWord* mem, Klass* klass); 92 93 // For klass field compression 94 inline int klass_gap() const; 95 inline void set_klass_gap(int z); 96 static inline void set_klass_gap(HeapWord* mem, int z); 97 // For when the klass pointer is being used as a linked list "next" field. 98 inline void set_klass_to_list_ptr(oop k); 99 inline oop list_ptr_from_klass(); 100 101 // size of object header, aligned to platform wordSize 102 static int header_size() { return sizeof(oopDesc)/HeapWordSize; } 103 104 // Returns whether this is an instance of k or an instance of a subclass of k 105 inline bool is_a(Klass* k) const; 106 107 // Returns the actual oop size of the object 108 inline int size(); 109 110 // Sometimes (for complicated concurrency-related reasons), it is useful 111 // to be able to figure out the size of an object knowing its klass. | 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 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_OOPS_OOP_HPP 26 #define SHARE_OOPS_OOP_HPP 27 28 #include "memory/iterator.hpp" 29 #include "memory/memRegion.hpp" 30 #include "oops/access.hpp" 31 #include "oops/arrayStorageProperties.hpp" 32 #include "oops/metadata.hpp" 33 #include "runtime/atomic.hpp" 34 #include "utilities/macros.hpp" 35 36 // oopDesc is the top baseclass for objects classes. The {name}Desc classes describe 37 // the format of Java objects so the fields can be accessed from C++. 38 // oopDesc is abstract. 39 // (see oopHierarchy for complete oop class hierarchy) 40 // 41 // no virtual functions allowed 42 // 43 // oopDesc::_mark - the "oop mark word" encoding to be found separately in markOop.hpp 44 // 45 // oopDesc::_metadata - encodes both the object's klass pointer and potentially 46 // "storage properties" (currently confined to arrays in the form of 47 // ArrayStorageProperties). Storage properties are peculiar to the 48 // *instance*, and not necessarily the "type". 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 // "Wide" encoding of _metadata: 54 // bit number |63 0| 55 // bit length |--3|-----61-----| 56 // -------------------------------------- 57 // _klass [xxx| Klass* ] 58 // _wide_storage_props [ sp| ] 59 // -------------------------------------- 60 // with: 61 // xxx = klass_mask(), Klass* = Klass pointer to be masked 62 // sp = storage properties, bit number: wide_storage_props_shift 63 // 64 // "Narrow" encoding of _metadata: 65 // bit number |31 0| 66 // bit length |--3|-----29-----| 67 // ---------------------------------------- 68 // _compressed_klass [xxx| narrowKlass] 69 // _narrow_storage_props [ sp| ] 70 // ---------------------------------------- 71 // with: 72 // xxx = compressed_klass_mask(), narrowKlass = compressed Klass pointer to be masked 73 // narrowKlass may be further decoded (Klass::decode_klass()) to produce Klass* 74 // sp = storage properties, bit number: narrow_storage_props_shift 75 // 76 // Storage properties encodings are current confined to arrayStorageProperties.hpp 77 78 79 extern bool always_do_update_barrier; 80 81 // Forward declarations. 82 class OopClosure; 83 class ScanClosure; 84 class FastScanClosure; 85 class FilteringClosure; 86 class CMSIsAliveClosure; 87 88 class PSPromotionManager; 89 class ParCompactionManager; 90 91 class oopDesc { 92 friend class VMStructs; 93 friend class JVMCIVMStructs; 94 private: 95 volatile markOop _mark; 96 union _metadata { 97 Klass* _klass; 98 narrowKlass _compressed_klass; 99 uintptr_t _wide_storage_props; 100 uint32_t _narrow_storage_props; 101 } _metadata; 102 103 public: 104 inline markOop mark() const; 105 inline markOop mark_raw() const; 106 inline markOop* mark_addr_raw() const; 107 108 inline void set_mark(volatile markOop m); 109 inline void set_mark_raw(volatile markOop m); 110 static inline void set_mark_raw(HeapWord* mem, markOop m); 111 112 inline void release_set_mark(markOop m); 113 inline markOop cas_set_mark(markOop new_mark, markOop old_mark); 114 inline markOop cas_set_mark_raw(markOop new_mark, markOop old_mark, atomic_memory_order order = memory_order_conservative); 115 116 // Used only to re-initialize the mark word (e.g., of promoted 117 // objects during a GC) -- requires a valid klass pointer 118 inline void init_mark(); 119 inline void init_mark_raw(); 120 121 enum { 122 storage_props_nof_bits = LogKlassAlignmentInBytes, // This alignment gives us some "free bits" 123 narrow_storage_props_shift = (sizeof(narrowKlass) << 3) - storage_props_nof_bits, 124 wide_storage_props_shift = (sizeof(Klass*) << 3) - storage_props_nof_bits, 125 }; 126 127 static inline narrowKlass compressed_klass_mask(); 128 static inline narrowKlass compressed_klass_masked(narrowKlass raw); 129 static inline uintptr_t klass_mask(); 130 static inline Klass* klass_masked(uintptr_t raw); 131 132 inline Klass* klass() const; 133 inline Klass* klass_or_null() const volatile; 134 inline Klass* klass_or_null_acquire() const volatile; 135 static inline Klass** klass_addr(HeapWord* mem); 136 static inline narrowKlass* compressed_klass_addr(HeapWord* mem); 137 inline Klass** klass_addr(); 138 inline narrowKlass* compressed_klass_addr(); 139 140 inline void set_klass(Klass* k); 141 static inline void release_set_klass(HeapWord* mem, Klass* klass); 142 143 // Extra container metadata specific to arrays (encoded into high bits of _metadata) 144 static inline uintptr_t* wide_metadata_addr(HeapWord* mem); 145 inline ArrayStorageProperties array_storage_properties() const; 146 inline void set_metadata(ArrayStorageProperties storage_props, Klass* k); 147 static inline void release_set_metadata(HeapWord* mem, ArrayStorageProperties storage_props, Klass* klass); 148 149 150 // For klass field compression 151 inline int klass_gap() const; 152 inline void set_klass_gap(int z); 153 static inline void set_klass_gap(HeapWord* mem, int z); 154 // For when the klass pointer is being used as a linked list "next" field. 155 inline void set_klass_to_list_ptr(oop k); 156 inline oop list_ptr_from_klass(); 157 158 // size of object header, aligned to platform wordSize 159 static int header_size() { return sizeof(oopDesc)/HeapWordSize; } 160 161 // Returns whether this is an instance of k or an instance of a subclass of k 162 inline bool is_a(Klass* k) const; 163 164 // Returns the actual oop size of the object 165 inline int size(); 166 167 // Sometimes (for complicated concurrency-related reasons), it is useful 168 // to be able to figure out the size of an object knowing its klass. |