< prev index next >

src/hotspot/share/oops/oop.hpp

Print this page

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










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

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

 87 
 88   inline Klass* klass() const;
 89   inline Klass* klass_or_null() const;
 90   inline Klass* klass_or_null_acquire() const;
 91   // Get the klass without running any asserts.
 92   inline Klass* klass_without_asserts() const;
 93 
 94   void set_narrow_klass(narrowKlass nk) NOT_CDS_JAVA_HEAP_RETURN;
 95   inline narrowKlass narrow_klass() const;
 96   inline void set_klass(Klass* k);
 97   static inline void release_set_klass(HeapWord* mem, Klass* k);
 98 
 99   // For klass field compression
100   static inline void set_klass_gap(HeapWord* mem, int z);
101 
102   // Size of object header, aligned to platform wordSize
103   static int header_size() {
104     if (UseCompactObjectHeaders) {
105       return sizeof(markWord) / HeapWordSize;
106     } else {
107       return sizeof(oopDesc)  / HeapWordSize;
108     }
109   }
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_instanceRef() const;
124   inline bool is_stackChunk()  const;
125   inline bool is_array()       const;
126   inline bool is_objArray()    const;
127   inline bool is_typeArray()   const;





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



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

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

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