< 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.

 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
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_array()               const;
112   inline bool is_objArray()            const;
113   inline bool is_typeArray()           const;



114 
115   // type test operations that don't require inclusion of oop.inline.hpp.
116   bool is_instance_noinline()          const;
117   bool is_array_noinline()             const;
118   bool is_objArray_noinline()          const;
119   bool is_typeArray_noinline()         const;


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

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
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_array()               const;
122   inline bool is_objArray()            const;
123   inline bool is_typeArray()           const;
124   inline bool is_inline_type()         const;
125   inline bool is_flatArray()           const;
126   inline bool is_null_free_array()     const;
127 
128   // type test operations that don't require inclusion of oop.inline.hpp.
129   bool is_instance_noinline()          const;
130   bool is_array_noinline()             const;
131   bool is_objArray_noinline()          const;
132   bool is_typeArray_noinline()         const;
133   bool is_flatArray_noinline()         const;
134   bool is_null_free_array_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;
< prev index next >