< prev index next >

src/hotspot/share/oops/oop.hpp

Print this page

 27 
 28 #include "memory/iterator.hpp"
 29 #include "memory/memRegion.hpp"
 30 #include "oops/accessDecorators.hpp"
 31 #include "oops/compressedKlass.hpp"
 32 #include "oops/markWord.hpp"
 33 #include "oops/metadata.hpp"
 34 #include "oops/objLayout.hpp"
 35 #include "runtime/atomicAccess.hpp"
 36 #include "utilities/globalDefinitions.hpp"
 37 #include "utilities/macros.hpp"
 38 
 39 #include <type_traits>
 40 
 41 // oopDesc is the top baseclass for objects classes. The {name}Desc classes describe
 42 // the format of Java objects so the fields can be accessed from C++.
 43 // oopDesc is abstract.
 44 // (see oopHierarchy for complete oop class hierarchy)
 45 //
 46 // no virtual functions allowed










 47 
 48 class oopDesc {
 49   friend class VMStructs;
 50   friend class JVMCIVMStructs;
 51  private:
 52   volatile markWord _mark;
 53   union _metadata {
 54     Klass*      _klass;
 55     narrowKlass _compressed_klass;
 56   } _metadata;
 57 
 58   // There may be ordering constraints on the initialization of fields that
 59   // make use of the C++ copy/assign incorrect.
 60   NONCOPYABLE(oopDesc);
 61 
 62   inline oop cas_set_forwardee(markWord new_mark, markWord old_mark, atomic_memory_order order);
 63 
 64  public:
 65   // Must be trivial; see verifying static assert after the class.
 66   oopDesc() = default;

 68   inline void* base_addr();
 69   inline const void* base_addr() const;
 70 
 71   inline markWord  mark()          const;
 72   inline markWord  mark_acquire()  const;
 73 
 74   inline void set_mark(markWord m);
 75   static inline void set_mark(HeapWord* mem, markWord m);
 76   static inline void release_set_mark(HeapWord* mem, markWord m);
 77 
 78   inline void release_set_mark(markWord m);
 79   inline markWord cas_set_mark(markWord new_mark, markWord old_mark);
 80   inline markWord cas_set_mark(markWord new_mark, markWord old_mark, atomic_memory_order order);
 81 
 82   // Returns the prototype mark that should be used for this object.
 83   inline markWord prototype_mark() const;
 84 
 85   // Used only to re-initialize the mark word (e.g., of promoted
 86   // objects during a GC) -- requires a valid klass pointer
 87   inline void init_mark();

 88 
 89   inline Klass* klass() const;
 90   inline Klass* klass_or_null() const;
 91   inline Klass* klass_or_null_acquire() const;
 92   // Get the klass without running any asserts.
 93   inline Klass* klass_without_asserts() const;
 94 
 95   void set_narrow_klass(narrowKlass nk) NOT_CDS_JAVA_HEAP_RETURN;
 96   inline narrowKlass narrow_klass() const;
 97   inline void set_klass(Klass* k);
 98   static inline void release_set_klass(HeapWord* mem, Klass* k);
 99 
100   // For klass field compression
101   static inline void set_klass_gap(HeapWord* mem, int z);
102 
103   // Size of object header, aligned to platform wordSize
104   static int header_size() {
105     if (UseCompactObjectHeaders) {
106       return sizeof(markWord) / HeapWordSize;
107     } else {
108       return sizeof(oopDesc)  / HeapWordSize;
109     }
110   }
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_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 
130   // type test operations that don't require inclusion of oop.inline.hpp.
131   bool is_instance_noinline()    const;
132   bool is_instanceRef_noinline() const;
133   bool is_stackChunk_noinline()  const;
134   bool is_array_noinline()       const;
135   bool is_objArray_noinline()    const;
136   bool is_typeArray_noinline()   const;



137 
138  protected:
139   inline oop        as_oop() const { return const_cast<oopDesc*>(this); }
140 
141  public:
142   template<typename T>
143   inline T* field_addr(int offset) const;
144 
145   template <typename T> inline size_t field_offset(T* p) const;
146 
147   // Standard compare function returns negative value if o1 < o2
148   //                                   0              if o1 == o2
149   //                                   positive value if o1 > o2
150   inline static int  compare(oop o1, oop o2) {
151     void* o1_addr = (void*)o1;
152     void* o2_addr = (void*)o2;
153     if (o1_addr < o2_addr) {
154       return -1;
155     } else if (o1_addr > o2_addr) {
156       return 1;

 27 
 28 #include "memory/iterator.hpp"
 29 #include "memory/memRegion.hpp"
 30 #include "oops/accessDecorators.hpp"
 31 #include "oops/compressedKlass.hpp"
 32 #include "oops/markWord.hpp"
 33 #include "oops/metadata.hpp"
 34 #include "oops/objLayout.hpp"
 35 #include "runtime/atomicAccess.hpp"
 36 #include "utilities/globalDefinitions.hpp"
 37 #include "utilities/macros.hpp"
 38 
 39 #include <type_traits>
 40 
 41 // oopDesc is the top baseclass for objects classes. The {name}Desc classes describe
 42 // the format of Java objects so the fields can be accessed from C++.
 43 // oopDesc is abstract.
 44 // (see oopHierarchy for complete oop class hierarchy)
 45 //
 46 // no virtual functions allowed
 47 //
 48 // oopDesc::_mark - the "oop mark word" encoding to be found separately in markWord.hpp
 49 //
 50 // oopDesc::_metadata - encodes the object's klass pointer, as a raw pointer in "_klass"
 51 //                      or compressed pointer in "_compressed_klass"
 52 //
 53 // The overall size of the _metadata field is dependent on "UseCompressedClassPointers",
 54 // hence the terms "narrow" (32 bits) vs "wide" (64 bits).
 55 //
 56 
 57 
 58 class oopDesc {
 59   friend class VMStructs;
 60   friend class JVMCIVMStructs;
 61  private:
 62   volatile markWord _mark;
 63   union _metadata {
 64     Klass*      _klass;
 65     narrowKlass _compressed_klass;
 66   } _metadata;
 67 
 68   // There may be ordering constraints on the initialization of fields that
 69   // make use of the C++ copy/assign incorrect.
 70   NONCOPYABLE(oopDesc);
 71 
 72   inline oop cas_set_forwardee(markWord new_mark, markWord old_mark, atomic_memory_order order);
 73 
 74  public:
 75   // Must be trivial; see verifying static assert after the class.
 76   oopDesc() = default;

 78   inline void* base_addr();
 79   inline const void* base_addr() const;
 80 
 81   inline markWord  mark()          const;
 82   inline markWord  mark_acquire()  const;
 83 
 84   inline void set_mark(markWord m);
 85   static inline void set_mark(HeapWord* mem, markWord m);
 86   static inline void release_set_mark(HeapWord* mem, markWord m);
 87 
 88   inline void release_set_mark(markWord m);
 89   inline markWord cas_set_mark(markWord new_mark, markWord old_mark);
 90   inline markWord cas_set_mark(markWord new_mark, markWord old_mark, atomic_memory_order order);
 91 
 92   // Returns the prototype mark that should be used for this object.
 93   inline markWord prototype_mark() const;
 94 
 95   // Used only to re-initialize the mark word (e.g., of promoted
 96   // objects during a GC) -- requires a valid klass pointer
 97   inline void init_mark();
 98   inline void reinit_mark(); // special for parallelGC
 99 
100   inline Klass* klass() const;
101   inline Klass* klass_or_null() const;
102   inline Klass* klass_or_null_acquire() const;
103   // Get the klass without running any asserts.
104   inline Klass* klass_without_asserts() const;
105 
106   void set_narrow_klass(narrowKlass nk) NOT_CDS_JAVA_HEAP_RETURN;
107   inline narrowKlass narrow_klass() const;
108   inline void set_klass(Klass* k);
109   static inline void release_set_klass(HeapWord* mem, Klass* k);
110 
111   // For klass field compression
112   static inline void set_klass_gap(HeapWord* mem, int z);
113 
114   // Size of object header, aligned to platform wordSize
115   static int header_size() {
116     if (UseCompactObjectHeaders) {
117       return sizeof(markWord) / HeapWordSize;
118     } else {
119       return sizeof(oopDesc)  / HeapWordSize;
120     }
121   }
122 
123   // Returns whether this is an instance of k or an instance of a subclass of k
124   inline bool is_a(Klass* k) const;
125 
126   // Returns the actual oop size of the object in machine words
127   inline size_t size();
128 
129   // Sometimes (for complicated concurrency-related reasons), it is useful
130   // to be able to figure out the size of an object knowing its klass.
131   inline size_t size_given_klass(Klass* klass);
132 
133   // type test operations (inlined in oop.inline.hpp)
134   inline bool is_instance()         const;
135   inline bool is_inline_type()      const;
136   inline bool is_instanceRef()      const;
137   inline bool is_stackChunk()       const;
138   inline bool is_array()            const;
139   inline bool is_objArray()         const;
140   inline bool is_typeArray()        const;
141   inline bool is_flatArray()        const;
142   inline bool is_refArray()         const;
143   inline bool is_null_free_array()  const;
144   inline bool is_refined_objArray() const;
145 
146   // type test operations that don't require inclusion of oop.inline.hpp.
147   bool is_instance_noinline()         const;
148   bool is_instanceRef_noinline()      const;
149   bool is_stackChunk_noinline()       const;
150   bool is_array_noinline()            const;
151   bool is_objArray_noinline()         const;
152   bool is_refArray_noinline()         const;
153   bool is_typeArray_noinline()        const;
154   bool is_flatArray_noinline()        const;
155   bool is_null_free_array_noinline()  const;
156 
157  protected:
158   inline oop        as_oop() const { return const_cast<oopDesc*>(this); }
159 
160  public:
161   template<typename T>
162   inline T* field_addr(int offset) const;
163 
164   template <typename T> inline size_t field_offset(T* p) const;
165 
166   // Standard compare function returns negative value if o1 < o2
167   //                                   0              if o1 == o2
168   //                                   positive value if o1 > o2
169   inline static int  compare(oop o1, oop o2) {
170     void* o1_addr = (void*)o1;
171     void* o2_addr = (void*)o2;
172     if (o1_addr < o2_addr) {
173       return -1;
174     } else if (o1_addr > o2_addr) {
175       return 1;
< prev index next >