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

 86 
 87   inline Klass* klass() const;
 88   inline Klass* klass_or_null() const;
 89   inline Klass* klass_or_null_acquire() const;
 90   // Get the klass without running any asserts.
 91   inline Klass* klass_without_asserts() const;
 92 
 93   void set_narrow_klass(narrowKlass nk) NOT_CDS_JAVA_HEAP_RETURN;
 94   inline narrowKlass narrow_klass() const;
 95   inline void set_klass(Klass* k);
 96   static inline void release_set_klass(HeapWord* mem, Klass* k);
 97 
 98   // For klass field compression
 99   static inline void set_klass_gap(HeapWord* mem, int z);
100 
101   // Size of object header, aligned to platform wordSize
102   static int header_size() {
103     if (UseCompactObjectHeaders) {
104       return sizeof(markWord) / HeapWordSize;
105     } else {
106       return sizeof(oopDesc)  / HeapWordSize;
107     }
108   }
109 
110   // Returns whether this is an instance of k or an instance of a subclass of k
111   inline bool is_a(Klass* k) const;
112 
113   // Returns the actual oop size of the object in machine words
114   inline size_t size();
115 
116   // Sometimes (for complicated concurrency-related reasons), it is useful
117   // to be able to figure out the size of an object knowing its klass.
118   inline size_t size_given_klass(Klass* klass);
119 
120   // type test operations (inlined in oop.inline.hpp)
121   inline bool is_instance()    const;
122   inline bool is_instanceRef() const;
123   inline bool is_stackChunk()  const;
124   inline bool is_array()       const;
125   inline bool is_objArray()    const;
126   inline bool is_typeArray()   const;





127 
128   // type test operations that don't require inclusion of oop.inline.hpp.
129   bool is_instance_noinline()    const;
130   bool is_instanceRef_noinline() const;
131   bool is_stackChunk_noinline()  const;
132   bool is_array_noinline()       const;
133   bool is_objArray_noinline()    const;
134   bool is_typeArray_noinline()   const;



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