< prev index next >

src/hotspot/share/oops/oop.hpp

Print this page

 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/compressedKlass.hpp"
 31 #include "oops/accessDecorators.hpp"
 32 #include "oops/markWord.hpp"
 33 #include "oops/metadata.hpp"
 34 #include "runtime/atomic.hpp"
 35 #include "utilities/globalDefinitions.hpp"
 36 #include "utilities/macros.hpp"
 37 #include <type_traits>
 38 
 39 // oopDesc is the top baseclass for objects classes. The {name}Desc classes describe
 40 // the format of Java objects so the fields can be accessed from C++.
 41 // oopDesc is abstract.
 42 // (see oopHierarchy for complete oop class hierarchy)
 43 //
 44 // no virtual functions allowed










 45 
 46 // Forward declarations.
 47 class OopClosure;
 48 class FilteringClosure;
 49 
 50 class PSPromotionManager;
 51 class ParCompactionManager;
 52 
 53 class oopDesc {
 54   friend class VMStructs;
 55   friend class JVMCIVMStructs;
 56  private:
 57   volatile markWord _mark;
 58   union _metadata {
 59     Klass*      _klass;
 60     narrowKlass _compressed_klass;
 61   } _metadata;
 62 
 63   // There may be ordering constraints on the initialization of fields that
 64   // make use of the C++ copy/assign incorrect.

 94   inline void set_klass(Klass* k);
 95   static inline void release_set_klass(HeapWord* mem, Klass* k);
 96 
 97   // For klass field compression
 98   static inline void set_klass_gap(HeapWord* mem, int z);
 99 
100   // size of object header, aligned to platform wordSize
101   static constexpr int header_size() { return sizeof(oopDesc)/HeapWordSize; }
102 
103   // Returns whether this is an instance of k or an instance of a subclass of k
104   inline bool is_a(Klass* k) const;
105 
106   // Returns the actual oop size of the object in machine words
107   inline size_t size();
108 
109   // Sometimes (for complicated concurrency-related reasons), it is useful
110   // to be able to figure out the size of an object knowing its klass.
111   inline size_t size_given_klass(Klass* klass);
112 
113   // type test operations (inlined in oop.inline.hpp)
114   inline bool is_instance()    const;
115   inline bool is_instanceRef() const;
116   inline bool is_stackChunk()  const;
117   inline bool is_array()       const;
118   inline bool is_objArray()    const;
119   inline bool is_typeArray()   const;



120 
121   // type test operations that don't require inclusion of oop.inline.hpp.
122   bool is_instance_noinline()    const;
123   bool is_instanceRef_noinline() const;
124   bool is_stackChunk_noinline()  const;
125   bool is_array_noinline()       const;
126   bool is_objArray_noinline()    const;
127   bool is_typeArray_noinline()   const;


128 
129  protected:
130   inline oop        as_oop() const { return const_cast<oopDesc*>(this); }
131 
132  public:
133   template<typename T>
134   inline T* field_addr(int offset) const;
135 
136   template <typename T> inline size_t field_offset(T* p) const;
137 
138   // Standard compare function returns negative value if o1 < o2
139   //                                   0              if o1 == o2
140   //                                   positive value if o1 > o2
141   inline static int  compare(oop o1, oop o2) {
142     void* o1_addr = (void*)o1;
143     void* o2_addr = (void*)o2;
144     if (o1_addr < o2_addr) {
145       return -1;
146     } else if (o1_addr > o2_addr) {
147       return 1;

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

104   inline void set_klass(Klass* k);
105   static inline void release_set_klass(HeapWord* mem, Klass* k);
106 
107   // For klass field compression
108   static inline void set_klass_gap(HeapWord* mem, int z);
109 
110   // size of object header, aligned to platform wordSize
111   static constexpr int header_size() { return sizeof(oopDesc)/HeapWordSize; }
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_inline_type()      const;
126   inline bool is_instanceRef()      const;
127   inline bool is_stackChunk()       const;
128   inline bool is_array()            const;
129   inline bool is_objArray()         const;
130   inline bool is_typeArray()        const;
131   inline bool is_flatArray()        const;
132   inline bool is_null_free_array()  const;
133 
134   // type test operations that don't require inclusion of oop.inline.hpp.
135   bool is_instance_noinline()         const;
136   bool is_instanceRef_noinline()      const;
137   bool is_stackChunk_noinline()       const;
138   bool is_array_noinline()            const;
139   bool is_objArray_noinline()         const;
140   bool is_typeArray_noinline()        const;
141   bool is_flatArray_noinline()        const;
142   bool is_null_free_array_noinline()  const;
143 
144  protected:
145   inline oop        as_oop() const { return const_cast<oopDesc*>(this); }
146 
147  public:
148   template<typename T>
149   inline T* field_addr(int offset) const;
150 
151   template <typename T> inline size_t field_offset(T* p) const;
152 
153   // Standard compare function returns negative value if o1 < o2
154   //                                   0              if o1 == o2
155   //                                   positive value if o1 > o2
156   inline static int  compare(oop o1, oop o2) {
157     void* o1_addr = (void*)o1;
158     void* o2_addr = (void*)o2;
159     if (o1_addr < o2_addr) {
160       return -1;
161     } else if (o1_addr > o2_addr) {
162       return 1;
< prev index next >