< prev index next >

src/hotspot/share/oops/oop.hpp

Print this page

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










 44 
 45 // Forward declarations.
 46 class OopClosure;
 47 class FilteringClosure;
 48 
 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.

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



116 
117   // type test operations that don't require inclusion of oop.inline.hpp.
118   bool is_instance_noinline()    const;
119   bool is_instanceRef_noinline() const;
120   bool is_stackChunk_noinline()  const;
121   bool is_array_noinline()       const;
122   bool is_objArray_noinline()    const;
123   bool is_typeArray_noinline()   const;


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

 24 
 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/accessDecorators.hpp"
 31 #include "oops/markWord.hpp"
 32 #include "oops/metadata.hpp"
 33 #include "runtime/atomic.hpp"
 34 #include "utilities/globalDefinitions.hpp"
 35 #include "utilities/macros.hpp"
 36 #include <type_traits>
 37 
 38 // oopDesc is the top baseclass for objects classes. The {name}Desc classes describe
 39 // the format of Java objects so the fields can be accessed from C++.
 40 // oopDesc is abstract.
 41 // (see oopHierarchy for complete oop class hierarchy)
 42 //
 43 // no virtual functions allowed
 44 //
 45 // oopDesc::_mark - the "oop mark word" encoding to be found separately in markWord.hpp
 46 //
 47 // oopDesc::_metadata - encodes the object's klass pointer, as a raw pointer in "_klass"
 48 //                      or compressed pointer in "_compressed_klass"
 49 //
 50 // The overall size of the _metadata field is dependent on "UseCompressedClassPointers",
 51 // hence the terms "narrow" (32 bits) vs "wide" (64 bits).
 52 //
 53 
 54 
 55 // Forward declarations.
 56 class OopClosure;
 57 class FilteringClosure;
 58 
 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.

100   inline void set_klass(Klass* k);
101   static inline void release_set_klass(HeapWord* mem, Klass* k);
102 
103   // For klass field compression
104   static inline void set_klass_gap(HeapWord* mem, int z);
105 
106   // size of object header, aligned to platform wordSize
107   static constexpr int header_size() { return sizeof(oopDesc)/HeapWordSize; }
108 
109   // Returns whether this is an instance of k or an instance of a subclass of k
110   inline bool is_a(Klass* k) const;
111 
112   // Returns the actual oop size of the object in machine words
113   inline size_t size();
114 
115   // Sometimes (for complicated concurrency-related reasons), it is useful
116   // to be able to figure out the size of an object knowing its klass.
117   inline size_t size_given_klass(Klass* klass);
118 
119   // type test operations (inlined in oop.inline.hpp)
120   inline bool is_instance()         const;
121   inline bool is_inline_type()      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   inline bool is_flatArray()        const;
128   inline bool is_null_free_array()  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   bool is_flatArray_noinline()        const;
138   bool is_null_free_array_noinline()  const;
139 
140  protected:
141   inline oop        as_oop() const { return const_cast<oopDesc*>(this); }
142 
143  public:
144   template<typename T>
145   inline T* field_addr(int offset) const;
146 
147   template <typename T> inline size_t field_offset(T* p) const;
148 
149   // Standard compare function returns negative value if o1 < o2
150   //                                   0              if o1 == o2
151   //                                   positive value if o1 > o2
152   inline static int  compare(oop o1, oop o2) {
153     void* o1_addr = (void*)o1;
154     void* o2_addr = (void*)o2;
155     if (o1_addr < o2_addr) {
156       return -1;
157     } else if (o1_addr > o2_addr) {
158       return 1;
< prev index next >