< prev index next >

src/hotspot/share/oops/oop.hpp

Print this page

 26 #define SHARE_OOPS_OOP_HPP
 27 
 28 #include "memory/iterator.hpp"
 29 #include "memory/memRegion.hpp"
 30 #include "oops/compressedKlass.hpp"
 31 #include "oops/accessDecorators.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 #include <type_traits>
 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 // Forward declarations.
 48 class OopClosure;
 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.
 64   NONCOPYABLE(oopDesc);
 65 

104   // Size of object header, aligned to platform wordSize
105   static int header_size() {
106     if (UseCompactObjectHeaders) {
107       return sizeof(markWord) / HeapWordSize;
108     } else {
109       return sizeof(oopDesc)  / HeapWordSize;
110     }
111   }
112 
113   // Returns whether this is an instance of k or an instance of a subclass of k
114   inline bool is_a(Klass* k) const;
115 
116   // Returns the actual oop size of the object in machine words
117   inline size_t size();
118 
119   // Sometimes (for complicated concurrency-related reasons), it is useful
120   // to be able to figure out the size of an object knowing its klass.
121   inline size_t size_given_klass(Klass* klass);
122 
123   // type test operations (inlined in oop.inline.hpp)
124   inline bool is_instance()    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 
131   // type test operations that don't require inclusion of oop.inline.hpp.
132   bool is_instance_noinline()    const;
133   bool is_instanceRef_noinline() const;
134   bool is_stackChunk_noinline()  const;
135   bool is_array_noinline()       const;
136   bool is_objArray_noinline()    const;
137   bool is_typeArray_noinline()   const;


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

 26 #define SHARE_OOPS_OOP_HPP
 27 
 28 #include "memory/iterator.hpp"
 29 #include "memory/memRegion.hpp"
 30 #include "oops/compressedKlass.hpp"
 31 #include "oops/accessDecorators.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 #include <type_traits>
 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 // Forward declarations.
 58 class OopClosure;
 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.
 74   NONCOPYABLE(oopDesc);
 75 

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_null_free_array()  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_typeArray_noinline()        const;
151   bool is_flatArray_noinline()        const;
152   bool is_null_free_array_noinline()  const;
153 
154  protected:
155   inline oop        as_oop() const { return const_cast<oopDesc*>(this); }
156 
157  public:
158   template<typename T>
159   inline T* field_addr(int offset) const;
160 
161   template <typename T> inline size_t field_offset(T* p) const;
162 
163   // Standard compare function returns negative value if o1 < o2
164   //                                   0              if o1 == o2
165   //                                   positive value if o1 > o2
166   inline static int  compare(oop o1, oop o2) {
167     void* o1_addr = (void*)o1;
168     void* o2_addr = (void*)o2;
169     if (o1_addr < o2_addr) {
170       return -1;
171     } else if (o1_addr > o2_addr) {
172       return 1;
< prev index next >