< prev index next >

src/hotspot/share/oops/oop.hpp

Print this page

 40 //
 41 // no virtual functions allowed
 42 
 43 // Forward declarations.
 44 class OopClosure;
 45 class FilteringClosure;
 46 
 47 class PSPromotionManager;
 48 class ParCompactionManager;
 49 
 50 class oopDesc {
 51   friend class VMStructs;
 52   friend class JVMCIVMStructs;
 53  private:
 54   volatile markWord _mark;
 55   union _metadata {
 56     Klass*      _klass;
 57     narrowKlass _compressed_klass;
 58   } _metadata;
 59 
 60  public:
 61   inline markWord  mark()          const;
 62   inline markWord  mark_acquire()  const;
 63   inline markWord* mark_addr() const;
 64 
 65   inline void set_mark(markWord m);
 66   static inline void set_mark(HeapWord* mem, markWord m);
 67 
 68   inline void release_set_mark(markWord m);

 69   inline markWord cas_set_mark(markWord new_mark, markWord old_mark);
 70   inline markWord cas_set_mark(markWord new_mark, markWord old_mark, atomic_memory_order order);
 71 





 72   // Used only to re-initialize the mark word (e.g., of promoted
 73   // objects during a GC) -- requires a valid klass pointer
 74   inline void init_mark();
 75 
 76   inline Klass* klass() const;
 77   inline Klass* klass_or_null() const;
 78   inline Klass* klass_or_null_acquire() const;
 79 
 80   void set_narrow_klass(narrowKlass nk) NOT_CDS_JAVA_HEAP_RETURN;
 81   inline void set_klass(Klass* k);
 82   static inline void release_set_klass(HeapWord* mem, Klass* k);
 83 
 84   // For klass field compression
 85   inline int klass_gap() const;
 86   inline void set_klass_gap(int z);
 87   static inline void set_klass_gap(HeapWord* mem, int z);
 88 
 89   // size of object header, aligned to platform wordSize
 90   static int header_size() { return sizeof(oopDesc)/HeapWordSize; }







 91 
 92   // Returns whether this is an instance of k or an instance of a subclass of k
 93   inline bool is_a(Klass* k) const;
 94 
 95   // Returns the actual oop size of the object
 96   inline int size();
 97 
 98   // Sometimes (for complicated concurrency-related reasons), it is useful
 99   // to be able to figure out the size of an object knowing its klass.
100   inline int size_given_klass(Klass* klass);
101 














102   // type test operations (inlined in oop.inline.hpp)
103   inline bool is_instance()            const;
104   inline bool is_array()               const;
105   inline bool is_objArray()            const;
106   inline bool is_typeArray()           const;
107 
108   // type test operations that don't require inclusion of oop.inline.hpp.
109   bool is_instance_noinline()          const;
110   bool is_array_noinline()             const;
111   bool is_objArray_noinline()          const;
112   bool is_typeArray_noinline()         const;
113 
114  protected:
115   inline oop        as_oop() const { return const_cast<oopDesc*>(this); }
116 
117  public:
118   // field addresses in oop
119   inline void* field_addr(int offset) const;
120 
121   // Need this as public for garbage collection.

232   static void verify(oopDesc* oopDesc);
233 
234   // locking operations
235   inline bool is_locked()   const;
236   inline bool is_unlocked() const;
237   inline bool has_bias_pattern() const;
238 
239   // asserts and guarantees
240   static bool is_oop(oop obj, bool ignore_mark_word = false);
241   static bool is_oop_or_null(oop obj, bool ignore_mark_word = false);
242 
243   // garbage collection
244   inline bool is_gc_marked() const;
245 
246   // Forward pointer operations for scavenge
247   inline bool is_forwarded() const;
248 
249   void verify_forwardee(oop forwardee) NOT_DEBUG_RETURN;
250 
251   inline void forward_to(oop p);
252   inline bool cas_forward_to(oop p, markWord compare, atomic_memory_order order = memory_order_conservative);
253 
254   // Like "forward_to", but inserts the forwarding pointer atomically.
255   // Exactly one thread succeeds in inserting the forwarding pointer, and
256   // this call returns "NULL" for that thread; any other thread has the
257   // value of the forwarding pointer returned and does not modify "this".
258   inline oop forward_to_atomic(oop p, markWord compare, atomic_memory_order order = memory_order_conservative);

259 
260   inline oop forwardee() const;

261 
262   // Age of object during scavenge
263   inline uint age() const;
264   inline void incr_age();
265 
266   template <typename OopClosureType>
267   inline void oop_iterate(OopClosureType* cl);
268 
269   template <typename OopClosureType>
270   inline void oop_iterate(OopClosureType* cl, MemRegion mr);
271 
272   template <typename OopClosureType>
273   inline int oop_iterate_size(OopClosureType* cl);
274 
275   template <typename OopClosureType>
276   inline int oop_iterate_size(OopClosureType* cl, MemRegion mr);
277 
278   template <typename OopClosureType>
279   inline void oop_iterate_backwards(OopClosureType* cl);
280 

286   // identity hash; returns the identity hash key (computes it if necessary)
287   // NOTE with the introduction of UseBiasedLocking that identity_hash() might reach a
288   // safepoint if called on a biased object. Calling code must be aware of that.
289   inline intptr_t identity_hash();
290   intptr_t slow_identity_hash();
291 
292   // marks are forwarded to stack when object is locked
293   inline bool     has_displaced_mark() const;
294   inline markWord displaced_mark() const;
295   inline void     set_displaced_mark(markWord m);
296 
297   // Checks if the mark word needs to be preserved
298   inline bool mark_must_be_preserved() const;
299   inline bool mark_must_be_preserved(markWord m) const;
300   inline bool mark_must_be_preserved_for_promotion_failure(markWord m) const;
301 
302   static bool has_klass_gap();
303 
304   // for code generation
305   static int mark_offset_in_bytes()      { return offset_of(oopDesc, _mark); }
306   static int klass_offset_in_bytes()     { return offset_of(oopDesc, _metadata._klass); }
307   static int klass_gap_offset_in_bytes() {
308     assert(has_klass_gap(), "only applicable to compressed klass pointers");

309     return klass_offset_in_bytes() + sizeof(narrowKlass);
310   }
311 
























312   // for error reporting
313   static void* load_klass_raw(oop obj);
314   static void* load_oop_raw(oop obj, int offset);
315 
316   // Avoid include gc_globals.hpp in oop.inline.hpp
317   DEBUG_ONLY(bool get_UseParallelGC();)
318   DEBUG_ONLY(bool get_UseG1GC();)
319 };
320 
321 #endif // SHARE_OOPS_OOP_HPP

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

259   static void verify(oopDesc* oopDesc);
260 
261   // locking operations
262   inline bool is_locked()   const;
263   inline bool is_unlocked() const;
264   inline bool has_bias_pattern() const;
265 
266   // asserts and guarantees
267   static bool is_oop(oop obj, bool ignore_mark_word = false);
268   static bool is_oop_or_null(oop obj, bool ignore_mark_word = false);
269 
270   // garbage collection
271   inline bool is_gc_marked() const;
272 
273   // Forward pointer operations for scavenge
274   inline bool is_forwarded() const;
275 
276   void verify_forwardee(oop forwardee) NOT_DEBUG_RETURN;
277 
278   inline void forward_to(oop p);
279   inline void forward_to_self();
280 
281   // Like "forward_to", but inserts the forwarding pointer atomically.
282   // Exactly one thread succeeds in inserting the forwarding pointer, and
283   // this call returns "NULL" for that thread; any other thread has the
284   // value of the forwarding pointer returned and does not modify "this".
285   inline oop forward_to_atomic(oop p, markWord compare, atomic_memory_order order = memory_order_conservative);
286   inline oop forward_to_self_atomic(markWord compare, atomic_memory_order order = memory_order_conservative);
287 
288   inline oop forwardee() const;
289   inline oop forwardee(markWord header) const;
290 
291   // Age of object during scavenge
292   inline uint age() const;
293   inline void incr_age();
294 
295   template <typename OopClosureType>
296   inline void oop_iterate(OopClosureType* cl);
297 
298   template <typename OopClosureType>
299   inline void oop_iterate(OopClosureType* cl, MemRegion mr);
300 
301   template <typename OopClosureType>
302   inline int oop_iterate_size(OopClosureType* cl);
303 
304   template <typename OopClosureType>
305   inline int oop_iterate_size(OopClosureType* cl, MemRegion mr);
306 
307   template <typename OopClosureType>
308   inline void oop_iterate_backwards(OopClosureType* cl);
309 

315   // identity hash; returns the identity hash key (computes it if necessary)
316   // NOTE with the introduction of UseBiasedLocking that identity_hash() might reach a
317   // safepoint if called on a biased object. Calling code must be aware of that.
318   inline intptr_t identity_hash();
319   intptr_t slow_identity_hash();
320 
321   // marks are forwarded to stack when object is locked
322   inline bool     has_displaced_mark() const;
323   inline markWord displaced_mark() const;
324   inline void     set_displaced_mark(markWord m);
325 
326   // Checks if the mark word needs to be preserved
327   inline bool mark_must_be_preserved() const;
328   inline bool mark_must_be_preserved(markWord m) const;
329   inline bool mark_must_be_preserved_for_promotion_failure(markWord m) const;
330 
331   static bool has_klass_gap();
332 
333   // for code generation
334   static int mark_offset_in_bytes()      { return offset_of(oopDesc, _mark); }

335   static int klass_gap_offset_in_bytes() {
336     assert(has_klass_gap(), "only applicable to compressed klass pointers");
337     assert(!UseCompactObjectHeaders, "don't use klass_offset_in_bytes() with compact headers");
338     return klass_offset_in_bytes() + sizeof(narrowKlass);
339   }
340 
341   static int klass_offset_in_bytes()     {
342 #ifdef _LP64
343     if (UseCompactObjectHeaders) {
344       STATIC_ASSERT(markWord::klass_shift % 8 == 0);
345       return mark_offset_in_bytes() + markWord::klass_shift / 8;
346     } else
347 #endif
348     return offset_of(oopDesc, _metadata._klass);
349   }
350 
351   static int base_offset_in_bytes() {
352 #ifdef _LP64
353     if (UseCompactObjectHeaders) {
354       // With compact headers, the Klass* field is not used for the Klass*
355       // and is used for the object fields instead.
356       assert(sizeof(markWord) == 8, "sanity");
357       return sizeof(markWord);
358     } else if (UseCompressedClassPointers) {
359       return sizeof(markWord) + sizeof(narrowKlass);
360     } else
361 #endif
362     return sizeof(oopDesc);
363   }
364 
365   // for error reporting
366   static void* load_klass_raw(oop obj);
367   static void* load_oop_raw(oop obj, int offset);
368 
369   // Avoid include gc_globals.hpp in oop.inline.hpp
370   DEBUG_ONLY(bool get_UseParallelGC();)
371   DEBUG_ONLY(bool get_UseG1GC();)
372 };
373 
374 #endif // SHARE_OOPS_OOP_HPP
< prev index next >