< 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_addr() const;
 63 
 64   inline void set_mark(markWord m);
 65   static inline void set_mark(HeapWord* mem, markWord m);
 66 
 67   inline void release_set_mark(markWord m);

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





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







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














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

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

258 
259   inline oop forwardee() const;

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

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

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
























311   // for error reporting
312   static void* load_klass_raw(oop obj);
313   static void* load_oop_raw(oop obj, int offset);
314 
315   // Avoid include gc_globals.hpp in oop.inline.hpp
316   DEBUG_ONLY(bool get_UseParallelGC();)
317   DEBUG_ONLY(bool get_UseG1GC();)
318 };
319 
320 #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 >