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

 96   static inline void set_klass_gap(HeapWord* mem, int z);
 97 
 98   // size of object header, aligned to platform wordSize
 99   static int header_size() { return sizeof(oopDesc)/HeapWordSize; }
100 
101   // Returns whether this is an instance of k or an instance of a subclass of k
102   inline bool is_a(Klass* k) const;
103 
104   // Returns the actual oop size of the object
105   inline int size();
106 
107   // Sometimes (for complicated concurrency-related reasons), it is useful
108   // to be able to figure out the size of an object knowing its klass.
109   inline int size_given_klass(Klass* klass);
110 
111   // type test operations (inlined in oop.inline.hpp)
112   inline bool is_instance()            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_array_noinline()             const;
120   bool is_objArray_noinline()          const;
121   bool is_typeArray_noinline()         const;


122 
123  protected:
124   inline oop        as_oop() const { return const_cast<oopDesc*>(this); }
125 
126  public:
127   // field addresses in oop
128   inline void* field_addr(int offset) const;
129 
130   // Need this as public for garbage collection.
131   template <class T> inline T* obj_field_addr(int offset) const;
132 
133   template <typename T> inline size_t field_offset(T* p) const;
134 
135   // Standard compare function returns negative value if o1 < o2
136   //                                   0              if o1 == o2
137   //                                   positive value if o1 > o2
138   inline static int  compare(oop o1, oop o2) {
139     void* o1_addr = (void*)o1;
140     void* o2_addr = (void*)o2;
141     if (o1_addr < o2_addr) {

 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.

106   static inline void set_klass_gap(HeapWord* mem, int z);
107 
108   // size of object header, aligned to platform wordSize
109   static int header_size() { return sizeof(oopDesc)/HeapWordSize; }
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
115   inline int 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 int 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_array()               const;
124   inline bool is_objArray()            const;
125   inline bool is_typeArray()           const;
126   inline bool is_inline_type()         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_array_noinline()             const;
133   bool is_objArray_noinline()          const;
134   bool is_typeArray_noinline()         const;
135   bool is_flatArray_noinline()         const;
136   bool is_null_free_array_noinline()   const;
137 
138  protected:
139   inline oop        as_oop() const { return const_cast<oopDesc*>(this); }
140 
141  public:
142   // field addresses in oop
143   inline void* field_addr(int offset) const;
144 
145   // Need this as public for garbage collection.
146   template <class T> inline T* obj_field_addr(int offset) const;
147 
148   template <typename T> inline size_t field_offset(T* p) const;
149 
150   // Standard compare function returns negative value if o1 < o2
151   //                                   0              if o1 == o2
152   //                                   positive value if o1 > o2
153   inline static int  compare(oop o1, oop o2) {
154     void* o1_addr = (void*)o1;
155     void* o2_addr = (void*)o2;
156     if (o1_addr < o2_addr) {
< prev index next >