< prev index next >

src/hotspot/share/oops/oop.hpp

Print this page

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


 65  public:
 66   // Must be trivial; see verifying static assert after the class.
 67   oopDesc() = default;
 68 
 69   inline markWord  mark()          const;
 70   inline markWord  mark_acquire()  const;
 71   inline markWord* mark_addr() const;
 72 
 73   inline void set_mark(markWord m);
 74   static inline void set_mark(HeapWord* mem, markWord m);
 75   static inline void release_set_mark(HeapWord* mem, markWord m);
 76 
 77   inline void release_set_mark(markWord m);
 78   inline markWord cas_set_mark(markWord new_mark, markWord old_mark);
 79   inline markWord cas_set_mark(markWord new_mark, markWord old_mark, atomic_memory_order order);
 80 





 81   // Used only to re-initialize the mark word (e.g., of promoted
 82   // objects during a GC) -- requires a valid klass pointer
 83   inline void init_mark();
 84 
 85   inline Klass* klass() const;
 86   inline Klass* klass_or_null() const;
 87   inline Klass* klass_or_null_acquire() const;
 88   // Get the klass without running any asserts.
 89   inline Klass* klass_without_asserts() const;
 90 
 91   void set_narrow_klass(narrowKlass nk) NOT_CDS_JAVA_HEAP_RETURN;
 92   inline void set_klass(Klass* k);
 93   static inline void release_set_klass(HeapWord* mem, Klass* k);
 94 
 95   // For klass field compression
 96   static inline void set_klass_gap(HeapWord* mem, int z);
 97 
 98   // size of object header, aligned to platform wordSize
 99   static constexpr 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 in machine words
105   inline size_t 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 size_t 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_instanceRef() const;
114   inline bool is_stackChunk()  const;
115   inline bool is_array()       const;
116   inline bool is_objArray()    const;
117   inline bool is_typeArray()   const;
118 
119   // type test operations that don't require inclusion of oop.inline.hpp.
120   bool is_instance_noinline()    const;
121   bool is_instanceRef_noinline() const;
122   bool is_stackChunk_noinline()  const;
123   bool is_array_noinline()       const;
124   bool is_objArray_noinline()    const;
125   bool is_typeArray_noinline()   const;
126 
127  protected:
128   inline oop        as_oop() const { return const_cast<oopDesc*>(this); }
129 
130  public:

241   char* print_string();
242   char* print_value_string();
243 
244   // verification operations
245   static void verify_on(outputStream* st, oopDesc* oop_desc);
246   static void verify(oopDesc* oopDesc);
247 
248   // locking operations
249   inline bool is_locked()   const;
250   inline bool is_unlocked() const;
251 
252   // asserts and guarantees
253   static bool is_oop(oop obj, bool ignore_mark_word = false);
254   static bool is_oop_or_null(oop obj, bool ignore_mark_word = false);
255 
256   // garbage collection
257   inline bool is_gc_marked() const;
258 
259   // Forward pointer operations for scavenge
260   inline bool is_forwarded() const;

261 
262   inline void forward_to(oop p);

263 
264   // Like "forward_to", but inserts the forwarding pointer atomically.
265   // Exactly one thread succeeds in inserting the forwarding pointer, and
266   // this call returns null for that thread; any other thread has the
267   // value of the forwarding pointer returned and does not modify "this".
268   inline oop forward_to_atomic(oop p, markWord compare, atomic_memory_order order = memory_order_conservative);

269 
270   inline oop forwardee() const;



271 
272   // Age of object during scavenge
273   inline uint age() const;
274   inline void incr_age();
275 
276   template <typename OopClosureType>
277   inline void oop_iterate(OopClosureType* cl);
278 
279   template <typename OopClosureType>
280   inline void oop_iterate(OopClosureType* cl, MemRegion mr);
281 
282   template <typename OopClosureType>
283   inline size_t oop_iterate_size(OopClosureType* cl);
284 
285   template <typename OopClosureType>
286   inline size_t oop_iterate_size(OopClosureType* cl, MemRegion mr);
287 
288   template <typename OopClosureType>
289   inline void oop_iterate_backwards(OopClosureType* cl);
290 

294   inline static bool is_instanceof_or_null(oop obj, Klass* klass);
295 
296   // identity hash; returns the identity hash key (computes it if necessary)
297   inline intptr_t identity_hash();
298   intptr_t slow_identity_hash();
299   inline bool fast_no_hash_check();
300 
301   // marks are forwarded to stack when object is locked
302   inline bool     has_displaced_mark() const;
303   inline markWord displaced_mark() const;
304   inline void     set_displaced_mark(markWord m);
305 
306   // Checks if the mark word needs to be preserved
307   inline bool mark_must_be_preserved() const;
308   inline bool mark_must_be_preserved(markWord m) const;
309 
310   static bool has_klass_gap();
311 
312   // for code generation
313   static int mark_offset_in_bytes()      { return (int)offset_of(oopDesc, _mark); }
314   static int klass_offset_in_bytes()     { return (int)offset_of(oopDesc, _metadata._klass); }











315   static int klass_gap_offset_in_bytes() {
316     assert(has_klass_gap(), "only applicable to compressed klass pointers");

317     return klass_offset_in_bytes() + sizeof(narrowKlass);
318   }
319 
















320   // for error reporting
321   static void* load_oop_raw(oop obj, int offset);
322 
323   DEBUG_ONLY(bool size_might_change();)
324 };
325 
326 // An oopDesc is not initialized via a constructor.  Space is allocated in
327 // the Java heap, and static functions provided here on HeapWord* are used
328 // to fill in certain parts of that memory.  The allocated memory is then
329 // treated as referring to an oopDesc.  For that to be valid, the oopDesc
330 // class must have a trivial default constructor (C++14 3.8/1).
331 static_assert(std::is_trivially_default_constructible<oopDesc>::value, "required");
332 
333 #endif // SHARE_OOPS_OOP_HPP

 45 
 46 // Forward declarations.
 47 class OopClosure;
 48 class PSPromotionManager;
 49 class ParCompactionManager;
 50 
 51 class oopDesc {
 52   friend class VMStructs;
 53   friend class JVMCIVMStructs;
 54  private:
 55   volatile markWord _mark;
 56   union _metadata {
 57     Klass*      _klass;
 58     narrowKlass _compressed_klass;
 59   } _metadata;
 60 
 61   // There may be ordering constraints on the initialization of fields that
 62   // make use of the C++ copy/assign incorrect.
 63   NONCOPYABLE(oopDesc);
 64 
 65   inline oop cas_set_forwardee(markWord new_mark, markWord old_mark, atomic_memory_order order);
 66 
 67  public:
 68   // Must be trivial; see verifying static assert after the class.
 69   oopDesc() = default;
 70 
 71   inline markWord  mark()          const;
 72   inline markWord  mark_acquire()  const;
 73   inline markWord* mark_addr() const;
 74 
 75   inline void set_mark(markWord m);
 76   static inline void set_mark(HeapWord* mem, markWord m);
 77   static inline void release_set_mark(HeapWord* mem, markWord m);
 78 
 79   inline void release_set_mark(markWord m);
 80   inline markWord cas_set_mark(markWord new_mark, markWord old_mark);
 81   inline markWord cas_set_mark(markWord new_mark, markWord old_mark, atomic_memory_order order);
 82 
 83   inline markWord resolve_mark() const;
 84 
 85   // Returns the prototype mark that should be used for this object.
 86   inline markWord prototype_mark() const;
 87 
 88   // Used only to re-initialize the mark word (e.g., of promoted
 89   // objects during a GC) -- requires a valid klass pointer
 90   inline void init_mark();
 91 
 92   inline Klass* klass() const;
 93   inline Klass* klass_or_null() const;
 94   inline Klass* klass_or_null_acquire() const;
 95   // Get the klass without running any asserts.
 96   inline Klass* klass_without_asserts() const;
 97 
 98   void set_narrow_klass(narrowKlass nk) NOT_CDS_JAVA_HEAP_RETURN;
 99   inline void set_klass(Klass* k);
100   static inline void release_set_klass(HeapWord* mem, Klass* k);
101 
102   // For klass field compression
103   static inline void set_klass_gap(HeapWord* mem, int z);
104 
105   // size of object header, aligned to platform wordSize
106   static int header_size() {
107     if (UseCompactObjectHeaders) {
108       return sizeof(markWord) / HeapWordSize;
109     } else {
110       return sizeof(oopDesc)/HeapWordSize;
111     }
112   }
113 
114   // Returns whether this is an instance of k or an instance of a subclass of k
115   inline bool is_a(Klass* k) const;
116 
117   // Returns the actual oop size of the object in machine words
118   inline size_t size();
119 
120   // Sometimes (for complicated concurrency-related reasons), it is useful
121   // to be able to figure out the size of an object knowing its klass.
122   inline size_t size_given_klass(Klass* klass);
123 
124   // The following set of methods is used to access the mark-word and related
125   // properties when the object may be forwarded. Be careful where and when
126   // using this method. It assumes that the forwardee is installed in
127   // the header as a plain pointer (or self-forwarded). In particular,
128   // those methods can not deal with the sliding-forwarding that is used
129   // in Serial, G1 and Shenandoah full-GCs.
130 private:
131   inline Klass*   forward_safe_klass_impl(markWord m) const;
132 public:
133   inline Klass*   forward_safe_klass() const;
134   inline Klass*   forward_safe_klass(markWord m) const;
135   inline size_t   forward_safe_size();
136   inline void     forward_safe_init_mark();
137 
138   // type test operations (inlined in oop.inline.hpp)
139   inline bool is_instance()    const;
140   inline bool is_instanceRef() const;
141   inline bool is_stackChunk()  const;
142   inline bool is_array()       const;
143   inline bool is_objArray()    const;
144   inline bool is_typeArray()   const;
145 
146   // type test operations that don't require inclusion of oop.inline.hpp.
147   bool is_instance_noinline()    const;
148   bool is_instanceRef_noinline() const;
149   bool is_stackChunk_noinline()  const;
150   bool is_array_noinline()       const;
151   bool is_objArray_noinline()    const;
152   bool is_typeArray_noinline()   const;
153 
154  protected:
155   inline oop        as_oop() const { return const_cast<oopDesc*>(this); }
156 
157  public:

268   char* print_string();
269   char* print_value_string();
270 
271   // verification operations
272   static void verify_on(outputStream* st, oopDesc* oop_desc);
273   static void verify(oopDesc* oopDesc);
274 
275   // locking operations
276   inline bool is_locked()   const;
277   inline bool is_unlocked() const;
278 
279   // asserts and guarantees
280   static bool is_oop(oop obj, bool ignore_mark_word = false);
281   static bool is_oop_or_null(oop obj, bool ignore_mark_word = false);
282 
283   // garbage collection
284   inline bool is_gc_marked() const;
285 
286   // Forward pointer operations for scavenge
287   inline bool is_forwarded() const;
288   inline bool is_self_forwarded() const;
289 
290   inline void forward_to(oop p);
291   inline void forward_to_self();
292 
293   // Like "forward_to", but inserts the forwarding pointer atomically.
294   // Exactly one thread succeeds in inserting the forwarding pointer, and
295   // this call returns null for that thread; any other thread has the
296   // value of the forwarding pointer returned and does not modify "this".
297   inline oop forward_to_atomic(oop p, markWord compare, atomic_memory_order order = memory_order_conservative);
298   inline oop forward_to_self_atomic(markWord compare, atomic_memory_order order = memory_order_conservative);
299 
300   inline oop forwardee() const;
301   inline oop forwardee(markWord header) const;
302 
303   inline void unset_self_forwarded();
304 
305   // Age of object during scavenge
306   inline uint age() const;
307   inline void incr_age();
308 
309   template <typename OopClosureType>
310   inline void oop_iterate(OopClosureType* cl);
311 
312   template <typename OopClosureType>
313   inline void oop_iterate(OopClosureType* cl, MemRegion mr);
314 
315   template <typename OopClosureType>
316   inline size_t oop_iterate_size(OopClosureType* cl);
317 
318   template <typename OopClosureType>
319   inline size_t oop_iterate_size(OopClosureType* cl, MemRegion mr);
320 
321   template <typename OopClosureType>
322   inline void oop_iterate_backwards(OopClosureType* cl);
323 

327   inline static bool is_instanceof_or_null(oop obj, Klass* klass);
328 
329   // identity hash; returns the identity hash key (computes it if necessary)
330   inline intptr_t identity_hash();
331   intptr_t slow_identity_hash();
332   inline bool fast_no_hash_check();
333 
334   // marks are forwarded to stack when object is locked
335   inline bool     has_displaced_mark() const;
336   inline markWord displaced_mark() const;
337   inline void     set_displaced_mark(markWord m);
338 
339   // Checks if the mark word needs to be preserved
340   inline bool mark_must_be_preserved() const;
341   inline bool mark_must_be_preserved(markWord m) const;
342 
343   static bool has_klass_gap();
344 
345   // for code generation
346   static int mark_offset_in_bytes()      { return (int)offset_of(oopDesc, _mark); }
347   static int klass_offset_in_bytes()     {
348 #ifdef _LP64
349     if (UseCompactObjectHeaders) {
350       constexpr int load_shift = markWord::klass_load_shift;
351       STATIC_ASSERT(load_shift % 8 == 0);
352       return mark_offset_in_bytes() + load_shift / 8;
353     } else
354 #endif
355     {
356       return (int)offset_of(oopDesc, _metadata._klass);
357     }
358   }
359   static int klass_gap_offset_in_bytes() {
360     assert(has_klass_gap(), "only applicable to compressed klass pointers");
361     assert(!UseCompactObjectHeaders, "don't use klass_offset_in_bytes() with compact headers");
362     return klass_offset_in_bytes() + sizeof(narrowKlass);
363   }
364 
365   static int base_offset_in_bytes() {
366 #ifdef _LP64
367     if (UseCompactObjectHeaders) {
368       // With compact headers, the Klass* field is not used for the Klass*
369       // and is used for the object fields instead.
370       STATIC_ASSERT(sizeof(markWord) == 8);
371       return sizeof(markWord);
372     } else if (UseCompressedClassPointers) {
373       return sizeof(markWord) + sizeof(narrowKlass);
374     } else
375 #endif
376     {
377       return sizeof(oopDesc);
378     }
379   }
380 
381   // for error reporting
382   static void* load_oop_raw(oop obj, int offset);
383 
384   DEBUG_ONLY(bool size_might_change(Klass* klass);)
385 };
386 
387 // An oopDesc is not initialized via a constructor.  Space is allocated in
388 // the Java heap, and static functions provided here on HeapWord* are used
389 // to fill in certain parts of that memory.  The allocated memory is then
390 // treated as referring to an oopDesc.  For that to be valid, the oopDesc
391 // class must have a trivial default constructor (C++14 3.8/1).
392 static_assert(std::is_trivially_default_constructible<oopDesc>::value, "required");
393 
394 #endif // SHARE_OOPS_OOP_HPP
< prev index next >