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_INLINE_HPP
26 #define SHARE_OOPS_OOP_INLINE_HPP
27
28 #include "oops/oop.hpp"
29
30 #include "memory/universe.hpp"
31 #include "oops/access.inline.hpp"
32 #include "oops/arrayKlass.hpp"
33 #include "oops/arrayOop.hpp"
34 #include "oops/compressedOops.inline.hpp"
35 #include "oops/markWord.inline.hpp"
36 #include "oops/oopsHierarchy.hpp"
37 #include "runtime/atomic.hpp"
38 #include "runtime/globals.hpp"
39 #include "utilities/align.hpp"
40 #include "utilities/debug.hpp"
41 #include "utilities/macros.hpp"
42 #include "utilities/globalDefinitions.hpp"
43
44 // Implementation of all inlined member functions defined in oop.hpp
45 // We need a separate file to avoid circular references
46
47 markWord oopDesc::mark() const {
48 return Atomic::load(&_mark);
49 }
50
51 markWord oopDesc::mark_acquire() const {
52 return Atomic::load_acquire(&_mark);
53 }
54
55 markWord* oopDesc::mark_addr() const {
56 return (markWord*) &_mark;
57 }
58
59 void oopDesc::set_mark(markWord m) {
60 Atomic::store(&_mark, m);
61 }
62
63 void oopDesc::set_mark(HeapWord* mem, markWord m) {
64 *(markWord*)(((char*)mem) + mark_offset_in_bytes()) = m;
65 }
66
67 void oopDesc::release_set_mark(markWord m) {
68 Atomic::release_store(&_mark, m);
69 }
70
71 markWord oopDesc::cas_set_mark(markWord new_mark, markWord old_mark) {
72 return Atomic::cmpxchg(&_mark, old_mark, new_mark);
73 }
74
75 markWord oopDesc::cas_set_mark(markWord new_mark, markWord old_mark, atomic_memory_order order) {
76 return Atomic::cmpxchg(&_mark, old_mark, new_mark, order);
77 }
78
79 void oopDesc::init_mark() {
80 set_mark(markWord::prototype_for_klass(klass()));
81 }
82
83 Klass* oopDesc::klass() const {
84 if (UseCompressedClassPointers) {
85 return CompressedKlassPointers::decode_not_null(_metadata._compressed_klass);
86 } else {
87 return _metadata._klass;
88 }
89 }
90
91 Klass* oopDesc::klass_or_null() const {
92 if (UseCompressedClassPointers) {
93 return CompressedKlassPointers::decode(_metadata._compressed_klass);
94 } else {
95 return _metadata._klass;
96 }
97 }
98
99 Klass* oopDesc::klass_or_null_acquire() const {
100 if (UseCompressedClassPointers) {
101 narrowKlass nklass = Atomic::load_acquire(&_metadata._compressed_klass);
102 return CompressedKlassPointers::decode(nklass);
103 } else {
104 return Atomic::load_acquire(&_metadata._klass);
105 }
106 }
107
108 void oopDesc::set_klass(Klass* k) {
109 assert(Universe::is_bootstrapping() || (k != NULL && k->is_klass()), "incorrect Klass");
110 if (UseCompressedClassPointers) {
111 _metadata._compressed_klass = CompressedKlassPointers::encode_not_null(k);
112 } else {
113 _metadata._klass = k;
114 }
115 }
116
117 void oopDesc::release_set_klass(HeapWord* mem, Klass* k) {
118 assert(Universe::is_bootstrapping() || (k != NULL && k->is_klass()), "incorrect Klass");
119 char* raw_mem = ((char*)mem + klass_offset_in_bytes());
120 if (UseCompressedClassPointers) {
121 Atomic::release_store((narrowKlass*)raw_mem,
122 CompressedKlassPointers::encode_not_null(k));
123 } else {
124 Atomic::release_store((Klass**)raw_mem, k);
125 }
126 }
127
128 int oopDesc::klass_gap() const {
129 return *(int*)(((intptr_t)this) + klass_gap_offset_in_bytes());
130 }
131
132 void oopDesc::set_klass_gap(HeapWord* mem, int v) {
133 if (UseCompressedClassPointers) {
134 *(int*)(((char*)mem) + klass_gap_offset_in_bytes()) = v;
135 }
136 }
137
138 void oopDesc::set_klass_gap(int v) {
139 set_klass_gap((HeapWord*)this, v);
140 }
141
142 bool oopDesc::is_a(Klass* k) const {
143 return klass()->is_subtype_of(k);
144 }
145
146 int oopDesc::size() {
147 return size_given_klass(klass());
148 }
149
150 int oopDesc::size_given_klass(Klass* klass) {
151 int lh = klass->layout_helper();
152 int s;
153
154 // lh is now a value computed at class initialization that may hint
155 // at the size. For instances, this is positive and equal to the
156 // size. For arrays, this is negative and provides log2 of the
157 // array element size. For other oops, it is zero and thus requires
158 // a virtual call.
186
187 // UseParallelGC and UseG1GC can change the length field
188 // of an "old copy" of an object array in the young gen so it indicates
189 // the grey portion of an already copied array. This will cause the first
190 // disjunct below to fail if the two comparands are computed across such
191 // a concurrent change.
192 assert((s == klass->oop_size(this)) ||
193 (Universe::is_gc_active() && is_objArray() && is_forwarded() && (get_UseParallelGC() || get_UseG1GC())),
194 "wrong array object size");
195 } else {
196 // Must be zero, so bite the bullet and take the virtual call.
197 s = klass->oop_size(this);
198 }
199 }
200
201 assert(s > 0, "Oop size must be greater than zero, not %d", s);
202 assert(is_object_aligned(s), "Oop size is not properly aligned: %d", s);
203 return s;
204 }
205
206 bool oopDesc::is_instance() const { return klass()->is_instance_klass(); }
207 bool oopDesc::is_array() const { return klass()->is_array_klass(); }
208 bool oopDesc::is_objArray() const { return klass()->is_objArray_klass(); }
209 bool oopDesc::is_typeArray() const { return klass()->is_typeArray_klass(); }
210
211 void* oopDesc::field_addr(int offset) const { return reinterpret_cast<void*>(cast_from_oop<intptr_t>(as_oop()) + offset); }
212
213 template <class T>
214 T* oopDesc::obj_field_addr(int offset) const { return (T*) field_addr(offset); }
215
216 template <typename T>
217 size_t oopDesc::field_offset(T* p) const { return pointer_delta((void*)p, (void*)this, 1); }
218
219 template <DecoratorSet decorators>
220 inline oop oopDesc::obj_field_access(int offset) const { return HeapAccess<decorators>::oop_load_at(as_oop(), offset); }
221 inline oop oopDesc::obj_field(int offset) const { return HeapAccess<>::oop_load_at(as_oop(), offset); }
222
223 inline void oopDesc::obj_field_put(int offset, oop value) { HeapAccess<>::oop_store_at(as_oop(), offset, value); }
224
225 inline jbyte oopDesc::byte_field(int offset) const { return HeapAccess<>::load_at(as_oop(), offset); }
257 }
258
259 bool oopDesc::has_bias_pattern() const {
260 return mark().has_bias_pattern();
261 }
262
263 // Used only for markSweep, scavenging
264 bool oopDesc::is_gc_marked() const {
265 return mark().is_marked();
266 }
267
268 // Used by scavengers
269 bool oopDesc::is_forwarded() const {
270 // The extra heap check is needed since the obj might be locked, in which case the
271 // mark would point to a stack location and have the sentinel bit cleared
272 return mark().is_marked();
273 }
274
275 // Used by scavengers
276 void oopDesc::forward_to(oop p) {
277 verify_forwardee(p);
278 markWord m = markWord::encode_pointer_as_mark(p);
279 assert(m.decode_pointer() == p, "encoding must be reversable");
280 set_mark(m);
281 }
282
283 // Used by parallel scavengers
284 bool oopDesc::cas_forward_to(oop p, markWord compare, atomic_memory_order order) {
285 verify_forwardee(p);
286 markWord m = markWord::encode_pointer_as_mark(p);
287 assert(m.decode_pointer() == p, "encoding must be reversable");
288 return cas_set_mark(m, compare, order) == compare;
289 }
290
291 oop oopDesc::forward_to_atomic(oop p, markWord compare, atomic_memory_order order) {
292 verify_forwardee(p);
293 markWord m = markWord::encode_pointer_as_mark(p);
294 assert(m.decode_pointer() == p, "encoding must be reversable");
295 markWord old_mark = cas_set_mark(m, compare, order);
296 if (old_mark == compare) {
297 return NULL;
298 } else {
299 return cast_to_oop(old_mark.decode_pointer());
300 }
301 }
302
303 // Note that the forwardee is not the same thing as the displaced_mark.
304 // The forwardee is used when copying during scavenge and mark-sweep.
305 // It does need to clear the low two locking- and GC-related bits.
306 oop oopDesc::forwardee() const {
307 return cast_to_oop(mark().decode_pointer());
308 }
309
310 // The following method needs to be MT safe.
311 uint oopDesc::age() const {
312 assert(!is_forwarded(), "Attempt to read age from forwarded mark");
313 if (has_displaced_mark()) {
314 return displaced_mark().age();
315 } else {
316 return mark().age();
317 }
318 }
319
320 void oopDesc::incr_age() {
321 assert(!is_forwarded(), "Attempt to increment age of forwarded mark");
322 if (has_displaced_mark()) {
323 set_displaced_mark(displaced_mark().incr_age());
324 } else {
325 set_mark(mark().incr_age());
326 }
327 }
342 int size = size_given_klass(k);
343 OopIteratorClosureDispatch::oop_oop_iterate(cl, this, k);
344 return size;
345 }
346
347 template <typename OopClosureType>
348 int oopDesc::oop_iterate_size(OopClosureType* cl, MemRegion mr) {
349 Klass* k = klass();
350 int size = size_given_klass(k);
351 OopIteratorClosureDispatch::oop_oop_iterate(cl, this, k, mr);
352 return size;
353 }
354
355 template <typename OopClosureType>
356 void oopDesc::oop_iterate_backwards(OopClosureType* cl) {
357 oop_iterate_backwards(cl, klass());
358 }
359
360 template <typename OopClosureType>
361 void oopDesc::oop_iterate_backwards(OopClosureType* cl, Klass* k) {
362 assert(k == klass(), "wrong klass");
363 OopIteratorClosureDispatch::oop_oop_iterate_backwards(cl, this, k);
364 }
365
366 bool oopDesc::is_instanceof_or_null(oop obj, Klass* klass) {
367 return obj == NULL || obj->klass()->is_subtype_of(klass);
368 }
369
370 intptr_t oopDesc::identity_hash() {
371 // Fast case; if the object is unlocked and the hash value is set, no locking is needed
372 // Note: The mark must be read into local variable to avoid concurrent updates.
373 markWord mrk = mark();
374 if (mrk.is_unlocked() && !mrk.has_no_hash()) {
375 return mrk.hash();
376 } else if (mrk.is_marked()) {
377 return mrk.hash();
378 } else {
379 return slow_identity_hash();
380 }
381 }
382
|
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_INLINE_HPP
26 #define SHARE_OOPS_OOP_INLINE_HPP
27
28 #include "oops/oop.hpp"
29
30 #include "memory/universe.hpp"
31 #include "oops/access.inline.hpp"
32 #include "oops/arrayKlass.hpp"
33 #include "oops/arrayOop.hpp"
34 #include "oops/compressedOops.inline.hpp"
35 #include "oops/markWord.inline.hpp"
36 #include "oops/oopsHierarchy.hpp"
37 #include "runtime/atomic.hpp"
38 #include "runtime/globals.hpp"
39 #include "runtime/safepoint.hpp"
40 #include "runtime/objectMonitor.inline.hpp"
41 #include "utilities/align.hpp"
42 #include "utilities/debug.hpp"
43 #include "utilities/macros.hpp"
44 #include "utilities/globalDefinitions.hpp"
45
46 // Implementation of all inlined member functions defined in oop.hpp
47 // We need a separate file to avoid circular references
48
49 markWord oopDesc::mark() const {
50 return Atomic::load(&_mark);
51 }
52
53 markWord oopDesc::mark_acquire() const {
54 return Atomic::load_acquire(&_mark);
55 }
56 markWord* oopDesc::mark_addr() const {
57 return (markWord*) &_mark;
58 }
59
60 void oopDesc::set_mark(markWord m) {
61 Atomic::store(&_mark, m);
62 }
63
64 void oopDesc::set_mark(HeapWord* mem, markWord m) {
65 *(markWord*)(((char*)mem) + mark_offset_in_bytes()) = m;
66 }
67
68 void oopDesc::release_set_mark(markWord m) {
69 Atomic::release_store(&_mark, m);
70 }
71
72 void oopDesc::release_set_mark(HeapWord* mem, markWord m) {
73 Atomic::release_store((markWord*)(((char*)mem) + mark_offset_in_bytes()), m);
74 }
75
76 markWord oopDesc::cas_set_mark(markWord new_mark, markWord old_mark) {
77 return Atomic::cmpxchg(&_mark, old_mark, new_mark);
78 }
79
80 markWord oopDesc::cas_set_mark(markWord new_mark, markWord old_mark, atomic_memory_order order) {
81 return Atomic::cmpxchg(&_mark, old_mark, new_mark, order);
82 }
83
84 markWord oopDesc::resolve_mark() const {
85 assert(LockingMode != LM_LEGACY, "Not safe with legacy stack-locking");
86 markWord hdr = mark();
87 if (hdr.has_displaced_mark_helper()) {
88 hdr = hdr.displaced_mark_helper();
89 }
90 return hdr;
91 }
92
93 markWord oopDesc::prototype_mark() const {
94 if (UseCompactObjectHeaders) {
95 return klass()->prototype_header();
96 } else {
97 return markWord::prototype();
98 }
99 }
100
101 void oopDesc::init_mark() {
102 set_mark(markWord::prototype_for_klass(klass()));
103 }
104
105 Klass* oopDesc::klass() const {
106 #ifdef _LP64
107 if (UseCompactObjectHeaders) {
108 assert(UseCompressedClassPointers, "only with compressed class pointers");
109 markWord header = resolve_mark();
110 return header.klass();
111 } else if (UseCompressedClassPointers) {
112 return CompressedKlassPointers::decode_not_null(_metadata._compressed_klass);
113 } else
114 #endif
115 return _metadata._klass;
116 }
117
118 Klass* oopDesc::klass_or_null() const {
119 #ifdef _LP64
120 if (UseCompactObjectHeaders) {
121 assert(UseCompressedClassPointers, "only with compressed class pointers");
122 markWord header = resolve_mark();
123 return header.klass_or_null();
124 } else if (UseCompressedClassPointers) {
125 return CompressedKlassPointers::decode(_metadata._compressed_klass);
126 } else
127 #endif
128 return _metadata._klass;
129 }
130
131 Klass* oopDesc::klass_or_null_acquire() const {
132 #ifdef _LP64
133 if (UseCompactObjectHeaders) {
134 assert(UseCompressedClassPointers, "only with compressed class pointers");
135 markWord header = mark_acquire();
136 if (header.has_monitor()) {
137 header = header.monitor()->header();
138 }
139 return header.klass_or_null();
140 } else if (UseCompressedClassPointers) {
141 narrowKlass nklass = Atomic::load_acquire(&_metadata._compressed_klass);
142 return CompressedKlassPointers::decode(nklass);
143 } else
144 #endif
145 return Atomic::load_acquire(&_metadata._klass);
146 }
147
148 void oopDesc::set_klass(Klass* k) {
149 assert(Universe::is_bootstrapping() || (k != NULL && k->is_klass()), "incorrect Klass");
150 assert(!UseCompactObjectHeaders, "don't set Klass* with compact headers");
151 if (UseCompressedClassPointers) {
152 _metadata._compressed_klass = CompressedKlassPointers::encode_not_null(k);
153 } else {
154 _metadata._klass = k;
155 }
156 }
157
158 void oopDesc::release_set_klass(HeapWord* mem, Klass* k) {
159 assert(Universe::is_bootstrapping() || (k != NULL && k->is_klass()), "incorrect Klass");
160 assert(!UseCompactObjectHeaders, "don't set Klass* with compact headers");
161 char* raw_mem = ((char*)mem + klass_offset_in_bytes());
162 if (UseCompressedClassPointers) {
163 Atomic::release_store((narrowKlass*)raw_mem,
164 CompressedKlassPointers::encode_not_null(k));
165 } else {
166 Atomic::release_store((Klass**)raw_mem, k);
167 }
168 }
169
170 int oopDesc::klass_gap() const {
171 assert(!UseCompactObjectHeaders, "don't get Klass* gap with compact headers");
172 return *(int*)(((intptr_t)this) + klass_gap_offset_in_bytes());
173 }
174
175 void oopDesc::set_klass_gap(HeapWord* mem, int v) {
176 assert(!UseCompactObjectHeaders, "don't set Klass* gap with compact headers");
177 if (UseCompressedClassPointers) {
178 *(int*)(((char*)mem) + klass_gap_offset_in_bytes()) = v;
179 }
180 }
181
182 void oopDesc::set_klass_gap(int v) {
183 assert(!UseCompactObjectHeaders, "don't set Klass* gap with compact headers");
184 set_klass_gap((HeapWord*)this, v);
185 }
186
187 bool oopDesc::is_a(Klass* k) const {
188 return klass()->is_subtype_of(k);
189 }
190
191 int oopDesc::size() {
192 return size_given_klass(klass());
193 }
194
195 int oopDesc::size_given_klass(Klass* klass) {
196 int lh = klass->layout_helper();
197 int s;
198
199 // lh is now a value computed at class initialization that may hint
200 // at the size. For instances, this is positive and equal to the
201 // size. For arrays, this is negative and provides log2 of the
202 // array element size. For other oops, it is zero and thus requires
203 // a virtual call.
231
232 // UseParallelGC and UseG1GC can change the length field
233 // of an "old copy" of an object array in the young gen so it indicates
234 // the grey portion of an already copied array. This will cause the first
235 // disjunct below to fail if the two comparands are computed across such
236 // a concurrent change.
237 assert((s == klass->oop_size(this)) ||
238 (Universe::is_gc_active() && is_objArray() && is_forwarded() && (get_UseParallelGC() || get_UseG1GC())),
239 "wrong array object size");
240 } else {
241 // Must be zero, so bite the bullet and take the virtual call.
242 s = klass->oop_size(this);
243 }
244 }
245
246 assert(s > 0, "Oop size must be greater than zero, not %d", s);
247 assert(is_object_aligned(s), "Oop size is not properly aligned: %d", s);
248 return s;
249 }
250
251 #ifdef _LP64
252 Klass* oopDesc::forward_safe_klass_impl(markWord m) const {
253 assert(UseCompactObjectHeaders, "Only get here with compact headers");
254 if (m.is_marked()) {
255 oop fwd = forwardee(m);
256 markWord m2 = fwd->mark();
257 assert(!m2.is_marked() || m2.self_forwarded(), "no double forwarding: this: " PTR_FORMAT " (" INTPTR_FORMAT "), fwd: " PTR_FORMAT " (" INTPTR_FORMAT ")", p2i(this), m.value(), p2i(fwd), m2.value());
258 m = m2;
259 }
260 return m.actual_mark().klass();
261 }
262 #endif
263
264 Klass* oopDesc::forward_safe_klass(markWord m) const {
265 #ifdef _LP64
266 if (UseCompactObjectHeaders) {
267 return forward_safe_klass_impl(m);
268 } else
269 #endif
270 {
271 return klass();
272 }
273 }
274
275 Klass* oopDesc::forward_safe_klass() const {
276 #ifdef _LP64
277 if (UseCompactObjectHeaders) {
278 return forward_safe_klass_impl(mark());
279 } else
280 #endif
281 {
282 return klass();
283 }
284 }
285
286 size_t oopDesc::forward_safe_size() {
287 return size_given_klass(forward_safe_klass());
288 }
289
290 void oopDesc::forward_safe_init_mark() {
291 if (UseCompactObjectHeaders) {
292 set_mark(forward_safe_klass()->prototype_header());
293 } else {
294 init_mark();
295 }
296 }
297
298 bool oopDesc::is_instance() const { return klass()->is_instance_klass(); }
299 bool oopDesc::is_array() const { return klass()->is_array_klass(); }
300 bool oopDesc::is_objArray() const { return klass()->is_objArray_klass(); }
301 bool oopDesc::is_typeArray() const { return klass()->is_typeArray_klass(); }
302
303 void* oopDesc::field_addr(int offset) const { return reinterpret_cast<void*>(cast_from_oop<intptr_t>(as_oop()) + offset); }
304
305 template <class T>
306 T* oopDesc::obj_field_addr(int offset) const { return (T*) field_addr(offset); }
307
308 template <typename T>
309 size_t oopDesc::field_offset(T* p) const { return pointer_delta((void*)p, (void*)this, 1); }
310
311 template <DecoratorSet decorators>
312 inline oop oopDesc::obj_field_access(int offset) const { return HeapAccess<decorators>::oop_load_at(as_oop(), offset); }
313 inline oop oopDesc::obj_field(int offset) const { return HeapAccess<>::oop_load_at(as_oop(), offset); }
314
315 inline void oopDesc::obj_field_put(int offset, oop value) { HeapAccess<>::oop_store_at(as_oop(), offset, value); }
316
317 inline jbyte oopDesc::byte_field(int offset) const { return HeapAccess<>::load_at(as_oop(), offset); }
349 }
350
351 bool oopDesc::has_bias_pattern() const {
352 return mark().has_bias_pattern();
353 }
354
355 // Used only for markSweep, scavenging
356 bool oopDesc::is_gc_marked() const {
357 return mark().is_marked();
358 }
359
360 // Used by scavengers
361 bool oopDesc::is_forwarded() const {
362 // The extra heap check is needed since the obj might be locked, in which case the
363 // mark would point to a stack location and have the sentinel bit cleared
364 return mark().is_marked();
365 }
366
367 // Used by scavengers
368 void oopDesc::forward_to(oop p) {
369 assert(p != cast_to_oop(this) || !UseAltGCForwarding, "Must not be called with self-forwarding");
370 verify_forwardee(p);
371 markWord m = markWord::encode_pointer_as_mark(p);
372 assert(forwardee(m) == p, "encoding must be reversable");
373 set_mark(m);
374 }
375
376 void oopDesc::forward_to_self() {
377 #ifdef _LP64
378 if (UseAltGCForwarding) {
379 markWord m = mark();
380 // If mark is displaced, we need to preserve the real header during GC.
381 // It will be restored to the displaced header after GC.
382 assert(SafepointSynchronize::is_at_safepoint(), "we can only safely fetch the displaced header at safepoint");
383 if (m.has_displaced_mark_helper()) {
384 m = m.displaced_mark_helper();
385 }
386 m = m.set_self_forwarded();
387 assert(forwardee(m) == cast_to_oop(this), "encoding must be reversible");
388 set_mark(m);
389 } else
390 #endif
391 {
392 forward_to(oop(this));
393 }
394 }
395
396 oop oopDesc::forward_to_atomic(oop p, markWord compare, atomic_memory_order order) {
397 assert(p != cast_to_oop(this) || !UseAltGCForwarding, "Must not be called with self-forwarding");
398 verify_forwardee(p);
399 markWord m = markWord::encode_pointer_as_mark(p);
400 assert(forwardee(m) == p, "encoding must be reversable");
401 markWord old_mark = cas_set_mark(m, compare, order);
402 if (old_mark == compare) {
403 return NULL;
404 } else {
405 return forwardee(old_mark);
406 }
407 }
408
409 oop oopDesc::forward_to_self_atomic(markWord compare, atomic_memory_order order) {
410 #ifdef _LP64
411 if (UseAltGCForwarding) {
412 markWord m = compare;
413 // If mark is displaced, we need to preserve the real header during GC.
414 // It will be restored to the displaced header after GC.
415 assert(SafepointSynchronize::is_at_safepoint(), "we can only safely fetch the displaced header at safepoint");
416 if (m.has_displaced_mark_helper()) {
417 m = m.displaced_mark_helper();
418 }
419 m = m.set_self_forwarded();
420 assert(forwardee(m) == cast_to_oop(this), "encoding must be reversible");
421 markWord old_mark = cas_set_mark(m, compare, order);
422 if (old_mark == compare) {
423 return nullptr;
424 } else {
425 assert(old_mark.is_marked(), "must be marked here");
426 return forwardee(old_mark);
427 }
428 } else
429 #endif
430 {
431 return forward_to_atomic(cast_to_oop(this), compare, order);
432 }
433 }
434
435 oop oopDesc::forwardee(markWord header) const {
436 assert(header.is_marked(), "only decode when actually forwarded");
437 #ifdef _LP64
438 if (header.self_forwarded()) {
439 return cast_to_oop(this);
440 } else
441 #endif
442 {
443 return cast_to_oop(header.decode_pointer());
444 }
445 }
446
447 // Note that the forwardee is not the same thing as the displaced_mark.
448 // The forwardee is used when copying during scavenge and mark-sweep.
449 // It does need to clear the low two locking- and GC-related bits.
450 oop oopDesc::forwardee() const {
451 return forwardee(mark());
452 }
453
454 // The following method needs to be MT safe.
455 uint oopDesc::age() const {
456 assert(!is_forwarded(), "Attempt to read age from forwarded mark");
457 if (has_displaced_mark()) {
458 return displaced_mark().age();
459 } else {
460 return mark().age();
461 }
462 }
463
464 void oopDesc::incr_age() {
465 assert(!is_forwarded(), "Attempt to increment age of forwarded mark");
466 if (has_displaced_mark()) {
467 set_displaced_mark(displaced_mark().incr_age());
468 } else {
469 set_mark(mark().incr_age());
470 }
471 }
486 int size = size_given_klass(k);
487 OopIteratorClosureDispatch::oop_oop_iterate(cl, this, k);
488 return size;
489 }
490
491 template <typename OopClosureType>
492 int oopDesc::oop_iterate_size(OopClosureType* cl, MemRegion mr) {
493 Klass* k = klass();
494 int size = size_given_klass(k);
495 OopIteratorClosureDispatch::oop_oop_iterate(cl, this, k, mr);
496 return size;
497 }
498
499 template <typename OopClosureType>
500 void oopDesc::oop_iterate_backwards(OopClosureType* cl) {
501 oop_iterate_backwards(cl, klass());
502 }
503
504 template <typename OopClosureType>
505 void oopDesc::oop_iterate_backwards(OopClosureType* cl, Klass* k) {
506 assert(UseCompactObjectHeaders || k == klass(), "wrong klass");
507 OopIteratorClosureDispatch::oop_oop_iterate_backwards(cl, this, k);
508 }
509
510 bool oopDesc::is_instanceof_or_null(oop obj, Klass* klass) {
511 return obj == NULL || obj->klass()->is_subtype_of(klass);
512 }
513
514 intptr_t oopDesc::identity_hash() {
515 // Fast case; if the object is unlocked and the hash value is set, no locking is needed
516 // Note: The mark must be read into local variable to avoid concurrent updates.
517 markWord mrk = mark();
518 if (mrk.is_unlocked() && !mrk.has_no_hash()) {
519 return mrk.hash();
520 } else if (mrk.is_marked()) {
521 return mrk.hash();
522 } else {
523 return slow_identity_hash();
524 }
525 }
526
|