< prev index next >

src/hotspot/share/oops/oop.hpp

Print this page

 11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
 12  * version 2 for more details (a copy is included in the LICENSE file that
 13  * accompanied this code).
 14  *
 15  * You should have received a copy of the GNU General Public License version
 16  * 2 along with this work; if not, write to the Free Software Foundation,
 17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
 18  *
 19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
 20  * or visit www.oracle.com if you need additional information or have any
 21  * questions.
 22  *
 23  */
 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;

 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.
 64   NONCOPYABLE(oopDesc);
 65 
 66  public:
 67   // Must be trivial; see verifying static assert after the class.
 68   oopDesc() = default;
 69 
 70   inline markWord  mark()          const;
 71   inline markWord  mark_acquire()  const;
 72   inline markWord* mark_addr() const;
 73 
 74   inline void set_mark(markWord m);
 75   static inline void 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 raw value without any checks.
 89   inline Klass* klass_raw() 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.

243   static void verify_on(outputStream* st, oopDesc* oop_desc);
244   static void verify(oopDesc* oopDesc);
245 
246   // locking operations
247   inline bool is_locked()   const;
248   inline bool is_unlocked() const;
249 
250   // asserts and guarantees
251   static bool is_oop(oop obj, bool ignore_mark_word = false);
252   static bool is_oop_or_null(oop obj, bool ignore_mark_word = false);
253 
254   // garbage collection
255   inline bool is_gc_marked() const;
256 
257   // Forward pointer operations for scavenge
258   inline bool is_forwarded() const;
259 
260   void verify_forwardee(oop forwardee) NOT_DEBUG_RETURN;
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 offset_of(oopDesc, _mark); }
314   static int klass_offset_in_bytes()     { return 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_klass_raw(oop obj);
322   static void* load_oop_raw(oop obj, int offset);
323 
324   DEBUG_ONLY(bool size_might_change();)
325 };
326 
327 // An oopDesc is not initialized via a constructor.  Space is allocated in
328 // the Java heap, and static functions provided here on HeapWord* are used
329 // to fill in certain parts of that memory.  The allocated memory is then
330 // treated as referring to an oopDesc.  For that to be valid, the oopDesc
331 // class must have a trivial default constructor (C++14 3.8/1).
332 static_assert(std::is_trivially_default_constructible<oopDesc>::value, "required");
333 
334 #endif // SHARE_OOPS_OOP_HPP

 11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
 12  * version 2 for more details (a copy is included in the LICENSE file that
 13  * accompanied this code).
 14  *
 15  * You should have received a copy of the GNU General Public License version
 16  * 2 along with this work; if not, write to the Free Software Foundation,
 17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
 18  *
 19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
 20  * or visit www.oracle.com if you need additional information or have any
 21  * questions.
 22  *
 23  */
 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/compressedKlass.hpp"
 32 #include "oops/markWord.hpp"
 33 #include "oops/metadata.hpp"
 34 #include "runtime/atomic.hpp"
 35 #include "utilities/globalDefinitions.hpp"
 36 #include "utilities/macros.hpp"
 37 #include <type_traits>
 38 
 39 // oopDesc is the top baseclass for objects classes. The {name}Desc classes describe
 40 // the format of Java objects so the fields can be accessed from C++.
 41 // oopDesc is abstract.
 42 // (see oopHierarchy for complete oop class hierarchy)
 43 //
 44 // no virtual functions allowed
 45 
 46 // Forward declarations.
 47 class OopClosure;
 48 class FilteringClosure;
 49 
 50 class PSPromotionManager;
 51 class ParCompactionManager;

 59     Klass*      _klass;
 60     narrowKlass _compressed_klass;
 61   } _metadata;
 62 
 63   // There may be ordering constraints on the initialization of fields that
 64   // make use of the C++ copy/assign incorrect.
 65   NONCOPYABLE(oopDesc);
 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 
 78   inline void release_set_mark(markWord m);
 79   static inline void release_set_mark(HeapWord* mem, 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   // Used only to re-initialize the mark word (e.g., of promoted
 86   // objects during a GC) -- requires a valid klass pointer
 87   inline void init_mark();
 88 
 89   inline Klass* klass() const;
 90   inline Klass* klass_or_null() const;
 91   inline Klass* klass_or_null_acquire() const;
 92   // Get the raw value without any checks.
 93   inline Klass* klass_raw() const;
 94 
 95   void set_narrow_klass(narrowKlass nk) NOT_CDS_JAVA_HEAP_RETURN;
 96   inline void set_klass(Klass* k);
 97   static inline void release_set_klass(HeapWord* mem, Klass* k);
 98 
 99   // For klass field compression
100   static inline void set_klass_gap(HeapWord* mem, int z);
101 
102   // size of object header, aligned to platform wordSize
103   static int header_size() {
104 #ifdef _LP64
105     if (UseCompactObjectHeaders) {
106       return sizeof(markWord) / HeapWordSize;
107     } else
108 #endif
109     return sizeof(oopDesc)/HeapWordSize;
110   }
111 
112   // Returns whether this is an instance of k or an instance of a subclass of k
113   inline bool is_a(Klass* k) const;
114 
115   // Returns the actual oop size of the object in machine words
116   inline size_t size();
117 
118   // Sometimes (for complicated concurrency-related reasons), it is useful
119   // to be able to figure out the size of an object knowing its klass.
120   inline size_t size_given_klass(Klass* klass);
121 
122   // type test operations (inlined in oop.inline.hpp)
123   inline bool is_instance()    const;
124   inline bool is_instanceRef() const;
125   inline bool is_stackChunk()  const;
126   inline bool is_array()       const;
127   inline bool is_objArray()    const;
128   inline bool is_typeArray()   const;
129 
130   // type test operations that don't require inclusion of oop.inline.hpp.

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

308   inline static bool is_instanceof_or_null(oop obj, Klass* klass);
309 
310   // identity hash; returns the identity hash key (computes it if necessary)
311   inline intptr_t identity_hash();
312   intptr_t slow_identity_hash();
313   inline bool fast_no_hash_check();
314 
315   // marks are forwarded to stack when object is locked
316   inline bool     has_displaced_mark() const;
317   inline markWord displaced_mark() const;
318   inline void     set_displaced_mark(markWord m);
319 
320   // Checks if the mark word needs to be preserved
321   inline bool mark_must_be_preserved() const;
322   inline bool mark_must_be_preserved(markWord m) const;
323 
324   static bool has_klass_gap();
325 
326   // for code generation
327   static int mark_offset_in_bytes()      { return offset_of(oopDesc, _mark); }

328   static int klass_gap_offset_in_bytes() {
329     assert(has_klass_gap(), "only applicable to compressed klass pointers");
330     assert(!UseCompactObjectHeaders, "don't use klass_offset_in_bytes() with compact headers");
331     return klass_offset_in_bytes() + sizeof(narrowKlass);
332   }
333 
334   static int klass_offset_in_bytes()     {
335 #ifdef _LP64
336     if (UseCompactObjectHeaders) {
337       STATIC_ASSERT(markWord::klass_shift % 8 == 0);
338       return mark_offset_in_bytes() + markWord::klass_shift / 8;
339     } else
340 #endif
341     return offset_of(oopDesc, _metadata._klass);
342   }
343 
344   static int base_offset_in_bytes() {
345 #ifdef _LP64
346     if (UseCompactObjectHeaders) {
347       // With compact headers, the Klass* field is not used for the Klass*
348       // and is used for the object fields instead.
349       assert(sizeof(markWord) == 8, "sanity");
350       return sizeof(markWord);
351     } else if (UseCompressedClassPointers) {
352       return sizeof(markWord) + sizeof(narrowKlass);
353     } else
354 #endif
355     return sizeof(oopDesc);
356   }
357 
358   // for error reporting
359   static void* load_klass_raw(oop obj);
360   static void* load_oop_raw(oop obj, int offset);
361 
362   DEBUG_ONLY(bool size_might_change();)
363 };
364 
365 // An oopDesc is not initialized via a constructor.  Space is allocated in
366 // the Java heap, and static functions provided here on HeapWord* are used
367 // to fill in certain parts of that memory.  The allocated memory is then
368 // treated as referring to an oopDesc.  For that to be valid, the oopDesc
369 // class must have a trivial default constructor (C++14 3.8/1).
370 static_assert(std::is_trivially_default_constructible<oopDesc>::value, "required");
371 
372 #endif // SHARE_OOPS_OOP_HPP
< prev index next >