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 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 // Used only to re-initialize the mark word (e.g., of promoted
84 // objects during a GC) -- requires a valid klass pointer
85 inline void init_mark();
86
87 inline Klass* klass() const;
88 inline Klass* klass_or_null() const;
89 inline Klass* klass_or_null_acquire() const;
90 // Get the raw value without any checks.
91 inline Klass* klass_raw() const;
92
93 void set_narrow_klass(narrowKlass nk) NOT_CDS_JAVA_HEAP_RETURN;
94 inline void set_klass(Klass* k);
95 static inline void release_set_klass(HeapWord* mem, Klass* k);
96
97 // For klass field compression
98 static inline void set_klass_gap(HeapWord* mem, int z);
99
100 // size of object header, aligned to platform wordSize
101 static constexpr int header_size() { return sizeof(oopDesc)/HeapWordSize; }
102
103 // Returns whether this is an instance of k or an instance of a subclass of k
104 inline bool is_a(Klass* k) const;
105
106 // Returns the actual oop size of the object in machine words
107 inline size_t size();
108
109 // Sometimes (for complicated concurrency-related reasons), it is useful
110 // to be able to figure out the size of an object knowing its klass.
111 inline size_t size_given_klass(Klass* klass);
112
113 // type test operations (inlined in oop.inline.hpp)
114 inline bool is_instance() const;
115 inline bool is_instanceRef() const;
116 inline bool is_stackChunk() const;
117 inline bool is_array() const;
118 inline bool is_objArray() const;
119 inline bool is_typeArray() const;
120
121 // type test operations that don't require inclusion of oop.inline.hpp.
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_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
|
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 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 // 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.
252
253 // verification operations
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 inline void forward_to(oop p);
272 inline void forward_to_self();
273
274 // Like "forward_to", but inserts the forwarding pointer atomically.
275 // Exactly one thread succeeds in inserting the forwarding pointer, and
276 // this call returns null for that thread; any other thread has the
277 // value of the forwarding pointer returned and does not modify "this".
278 inline oop forward_to_atomic(oop p, markWord compare, atomic_memory_order order = memory_order_conservative);
279 inline oop forward_to_self_atomic(markWord compare, atomic_memory_order order = memory_order_conservative);
280
281 inline oop forwardee() const;
282 inline oop forwardee(markWord header) const;
283
284 // Age of object during scavenge
285 inline uint age() const;
286 inline void incr_age();
287
288 template <typename OopClosureType>
289 inline void oop_iterate(OopClosureType* cl);
290
291 template <typename OopClosureType>
292 inline void oop_iterate(OopClosureType* cl, MemRegion mr);
293
294 template <typename OopClosureType>
295 inline size_t oop_iterate_size(OopClosureType* cl);
296
297 template <typename OopClosureType>
298 inline size_t oop_iterate_size(OopClosureType* cl, MemRegion mr);
299
300 template <typename OopClosureType>
301 inline void oop_iterate_backwards(OopClosureType* cl);
302
306 inline static bool is_instanceof_or_null(oop obj, Klass* klass);
307
308 // identity hash; returns the identity hash key (computes it if necessary)
309 inline intptr_t identity_hash();
310 intptr_t slow_identity_hash();
311 inline bool fast_no_hash_check();
312
313 // marks are forwarded to stack when object is locked
314 inline bool has_displaced_mark() const;
315 inline markWord displaced_mark() const;
316 inline void set_displaced_mark(markWord m);
317
318 // Checks if the mark word needs to be preserved
319 inline bool mark_must_be_preserved() const;
320 inline bool mark_must_be_preserved(markWord m) const;
321
322 static bool has_klass_gap();
323
324 // for code generation
325 static int mark_offset_in_bytes() { return (int)offset_of(oopDesc, _mark); }
326 static int klass_gap_offset_in_bytes() {
327 assert(has_klass_gap(), "only applicable to compressed klass pointers");
328 assert(!UseCompactObjectHeaders, "don't use klass_offset_in_bytes() with compact headers");
329 return klass_offset_in_bytes() + sizeof(narrowKlass);
330 }
331
332 static int klass_offset_in_bytes() {
333 #ifdef _LP64
334 if (UseCompactObjectHeaders) {
335 STATIC_ASSERT(markWord::klass_shift % 8 == 0);
336 return mark_offset_in_bytes() + markWord::klass_shift / 8;
337 } else
338 #endif
339 return offset_of(oopDesc, _metadata._klass);
340 }
341
342 static int base_offset_in_bytes() {
343 #ifdef _LP64
344 if (UseCompactObjectHeaders) {
345 // With compact headers, the Klass* field is not used for the Klass*
346 // and is used for the object fields instead.
347 assert(sizeof(markWord) == 8, "sanity");
348 return sizeof(markWord);
349 } else if (UseCompressedClassPointers) {
350 return sizeof(markWord) + sizeof(narrowKlass);
351 } else
352 #endif
353 return sizeof(oopDesc);
354 }
355
356 // for error reporting
357 static void* load_klass_raw(oop obj);
358 static void* load_oop_raw(oop obj, int offset);
359
360 DEBUG_ONLY(bool size_might_change();)
361 };
362
363 // An oopDesc is not initialized via a constructor. Space is allocated in
364 // the Java heap, and static functions provided here on HeapWord* are used
365 // to fill in certain parts of that memory. The allocated memory is then
366 // treated as referring to an oopDesc. For that to be valid, the oopDesc
367 // class must have a trivial default constructor (C++14 3.8/1).
368 static_assert(std::is_trivially_default_constructible<oopDesc>::value, "required");
369
370 #endif // SHARE_OOPS_OOP_HPP
|