1 /*
   2  * Copyright (c) 1997, 2016, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.
   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  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_VM_OOPS_OOP_INLINE_HPP
  26 #define SHARE_VM_OOPS_OOP_INLINE_HPP
  27 
  28 #include "gc/shared/ageTable.hpp"
  29 #include "gc/shared/collectedHeap.inline.hpp"
  30 #include "gc/shared/genCollectedHeap.hpp"
  31 #include "gc/shared/generation.hpp"
  32 #include "oops/arrayKlass.hpp"
  33 #include "oops/arrayOop.hpp"
  34 #include "oops/klass.inline.hpp"
  35 #include "oops/markOop.inline.hpp"
  36 #include "oops/oop.hpp"
  37 #include "runtime/access.hpp"
  38 #include "runtime/atomic.hpp"
  39 #include "runtime/orderAccess.inline.hpp"
  40 #include "runtime/os.hpp"
  41 #include "utilities/macros.hpp"
  42 
  43 // Implementation of all inlined member functions defined in oop.hpp
  44 // We need a separate file to avoid circular references
  45 
  46 void oopDesc::release_set_mark(markOop m) {
  47   OrderAccess::release_store_ptr(&_mark, m);
  48 }
  49 
  50 markOop oopDesc::cas_set_mark(markOop new_mark, markOop old_mark) {
  51   return (markOop) Atomic::cmpxchg_ptr(new_mark, &_mark, old_mark);
  52 }
  53 
  54 void oopDesc::init_mark() {
  55   set_mark(markOopDesc::prototype_for_object(this));
  56 }
  57 
  58 Klass* oopDesc::klass() const {
  59   if (UseCompressedClassPointers) {
  60     return Klass::decode_klass_not_null(_metadata._compressed_klass);
  61   } else {
  62     return _metadata._klass;
  63   }
  64 }
  65 
  66 Klass* oopDesc::klass_or_null() const volatile {
  67   if (UseCompressedClassPointers) {
  68     return Klass::decode_klass(_metadata._compressed_klass);
  69   } else {
  70     return _metadata._klass;
  71   }
  72 }
  73 
  74 Klass* oopDesc::klass_or_null_acquire() const volatile {
  75   if (UseCompressedClassPointers) {
  76     // Workaround for non-const load_acquire parameter.
  77     const volatile narrowKlass* addr = &_metadata._compressed_klass;
  78     volatile narrowKlass* xaddr = const_cast<volatile narrowKlass*>(addr);
  79     return Klass::decode_klass(OrderAccess::load_acquire(xaddr));
  80   } else {
  81     return (Klass*)OrderAccess::load_ptr_acquire(&_metadata._klass);
  82   }
  83 }
  84 
  85 Klass** oopDesc::klass_addr() {
  86   // Only used internally and with CMS and will not work with
  87   // UseCompressedOops
  88   assert(!UseCompressedClassPointers, "only supported with uncompressed klass pointers");
  89   return (Klass**) &_metadata._klass;
  90 }
  91 
  92 narrowKlass* oopDesc::compressed_klass_addr() {
  93   assert(UseCompressedClassPointers, "only called by compressed klass pointers");
  94   return &_metadata._compressed_klass;
  95 }
  96 
  97 #define CHECK_SET_KLASS(k)                                                \
  98   do {                                                                    \
  99     assert(Universe::is_bootstrapping() || k != NULL, "NULL Klass");      \
 100     assert(Universe::is_bootstrapping() || k->is_klass(), "not a Klass"); \
 101   } while (0)
 102 
 103 void oopDesc::set_klass(Klass* k) {
 104   CHECK_SET_KLASS(k);
 105   if (UseCompressedClassPointers) {
 106     *compressed_klass_addr() = Klass::encode_klass_not_null(k);
 107   } else {
 108     *klass_addr() = k;
 109   }
 110 }
 111 
 112 void oopDesc::release_set_klass(Klass* k) {
 113   CHECK_SET_KLASS(k);
 114   if (UseCompressedClassPointers) {
 115     OrderAccess::release_store(compressed_klass_addr(),
 116                                Klass::encode_klass_not_null(k));
 117   } else {
 118     OrderAccess::release_store_ptr(klass_addr(), k);
 119   }
 120 }
 121 
 122 #undef CHECK_SET_KLASS
 123 
 124 int oopDesc::klass_gap() const {
 125   return *(int*)(((intptr_t)this) + klass_gap_offset_in_bytes());
 126 }
 127 
 128 void oopDesc::set_klass_gap(int v) {
 129   if (UseCompressedClassPointers) {
 130     *(int*)(((intptr_t)this) + klass_gap_offset_in_bytes()) = v;
 131   }
 132 }
 133 
 134 void oopDesc::set_klass_to_list_ptr(oop k) {
 135   // This is only to be used during GC, for from-space objects, so no
 136   // barrier is needed.
 137   if (UseCompressedClassPointers) {
 138     _metadata._compressed_klass = (narrowKlass)encode_heap_oop(k);  // may be null (parnew overflow handling)
 139   } else {
 140     _metadata._klass = (Klass*)(address)k;
 141   }
 142 }
 143 
 144 oop oopDesc::list_ptr_from_klass() {
 145   // This is only to be used during GC, for from-space objects.
 146   if (UseCompressedClassPointers) {
 147     return decode_heap_oop((narrowOop)_metadata._compressed_klass);
 148   } else {
 149     // Special case for GC
 150     return (oop)(address)_metadata._klass;
 151   }
 152 }
 153 
 154 bool oopDesc::is_a(Klass* k) const {
 155   return klass()->is_subtype_of(k);
 156 }
 157 
 158 int oopDesc::size()  {
 159   return size_given_klass(klass());
 160 }
 161 
 162 int oopDesc::size_given_klass(Klass* klass)  {
 163   int lh = klass->layout_helper();
 164   int s;
 165 
 166   // lh is now a value computed at class initialization that may hint
 167   // at the size.  For instances, this is positive and equal to the
 168   // size.  For arrays, this is negative and provides log2 of the
 169   // array element size.  For other oops, it is zero and thus requires
 170   // a virtual call.
 171   //
 172   // We go to all this trouble because the size computation is at the
 173   // heart of phase 2 of mark-compaction, and called for every object,
 174   // alive or dead.  So the speed here is equal in importance to the
 175   // speed of allocation.
 176 
 177   if (lh > Klass::_lh_neutral_value) {
 178     if (!Klass::layout_helper_needs_slow_path(lh)) {
 179       s = lh >> LogHeapWordSize;  // deliver size scaled by wordSize
 180     } else {
 181       s = klass->oop_size(this);
 182     }
 183   } else if (lh <= Klass::_lh_neutral_value) {
 184     // The most common case is instances; fall through if so.
 185     if (lh < Klass::_lh_neutral_value) {
 186       // Second most common case is arrays.  We have to fetch the
 187       // length of the array, shift (multiply) it appropriately,
 188       // up to wordSize, add the header, and align to object size.
 189       size_t size_in_bytes;
 190 #ifdef _M_IA64
 191       // The Windows Itanium Aug 2002 SDK hoists this load above
 192       // the check for s < 0.  An oop at the end of the heap will
 193       // cause an access violation if this load is performed on a non
 194       // array oop.  Making the reference volatile prohibits this.
 195       // (%%% please explain by what magic the length is actually fetched!)
 196       volatile int *array_length;
 197       array_length = (volatile int *)( (intptr_t)this +
 198                           arrayOopDesc::length_offset_in_bytes() );
 199       assert(array_length > 0, "Integer arithmetic problem somewhere");
 200       // Put into size_t to avoid overflow.
 201       size_in_bytes = (size_t) array_length;
 202       size_in_bytes = size_in_bytes << Klass::layout_helper_log2_element_size(lh);
 203 #else
 204       size_t array_length = (size_t) ((arrayOop)this)->length();
 205       size_in_bytes = array_length << Klass::layout_helper_log2_element_size(lh);
 206 #endif
 207       size_in_bytes += Klass::layout_helper_header_size(lh);
 208 
 209       // This code could be simplified, but by keeping array_header_in_bytes
 210       // in units of bytes and doing it this way we can round up just once,
 211       // skipping the intermediate round to HeapWordSize.  Cast the result
 212       // of round_to to size_t to guarantee unsigned division == right shift.
 213       s = (int)((size_t)round_to(size_in_bytes, MinObjAlignmentInBytes) /
 214         HeapWordSize);
 215 
 216       // ParNew (used by CMS), UseParallelGC and UseG1GC can change the length field
 217       // of an "old copy" of an object array in the young gen so it indicates
 218       // the grey portion of an already copied array. This will cause the first
 219       // disjunct below to fail if the two comparands are computed across such
 220       // a concurrent change.
 221       // ParNew also runs with promotion labs (which look like int
 222       // filler arrays) which are subject to changing their declared size
 223       // when finally retiring a PLAB; this also can cause the first disjunct
 224       // to fail for another worker thread that is concurrently walking the block
 225       // offset table. Both these invariant failures are benign for their
 226       // current uses; we relax the assertion checking to cover these two cases below:
 227       //     is_objArray() && is_forwarded()   // covers first scenario above
 228       //  || is_typeArray()                    // covers second scenario above
 229       // If and when UseParallelGC uses the same obj array oop stealing/chunking
 230       // technique, we will need to suitably modify the assertion.
 231       assert((s == klass->oop_size(this)) ||
 232              (Universe::heap()->is_gc_active() &&
 233               ((is_typeArray() && UseConcMarkSweepGC) ||
 234                (is_objArray()  && is_forwarded() && (UseConcMarkSweepGC || UseParallelGC || UseG1GC)))),
 235              "wrong array object size");
 236     } else {
 237       // Must be zero, so bite the bullet and take the virtual call.
 238       s = klass->oop_size(this);
 239     }
 240   }
 241 
 242   assert(s % MinObjAlignment == 0, "Oop size is not properly aligned: %d", s);
 243   assert(s > 0, "Oop size must be greater than zero, not %d", s);
 244   return s;
 245 }
 246 
 247 bool oopDesc::is_instance()  const { return klass()->is_instance_klass();  }
 248 bool oopDesc::is_array()     const { return klass()->is_array_klass();     }
 249 bool oopDesc::is_objArray()  const { return klass()->is_objArray_klass();  }
 250 bool oopDesc::is_typeArray() const { return klass()->is_typeArray_klass(); }
 251 
 252 void*      oopDesc::field_base(int offset)          const { return (void*)&((char*)this)[offset]; }
 253 
 254 jbyte*     oopDesc::byte_field_addr(int offset)     const { return (jbyte*)    field_base(offset); }
 255 jchar*     oopDesc::char_field_addr(int offset)     const { return (jchar*)    field_base(offset); }
 256 jboolean*  oopDesc::bool_field_addr(int offset)     const { return (jboolean*) field_base(offset); }
 257 jint*      oopDesc::int_field_addr(int offset)      const { return (jint*)     field_base(offset); }
 258 jshort*    oopDesc::short_field_addr(int offset)    const { return (jshort*)   field_base(offset); }
 259 jlong*     oopDesc::long_field_addr(int offset)     const { return (jlong*)    field_base(offset); }
 260 jfloat*    oopDesc::float_field_addr(int offset)    const { return (jfloat*)   field_base(offset); }
 261 jdouble*   oopDesc::double_field_addr(int offset)   const { return (jdouble*)  field_base(offset); }
 262 Metadata** oopDesc::metadata_field_addr(int offset) const { return (Metadata**)field_base(offset); }
 263 
 264 template <class T> T* oopDesc::obj_field_addr(int offset) const { return (T*)  field_base(offset); }
 265 address*   oopDesc::address_field_addr(int offset)  const { return (address*)  field_base(offset); }
 266 
 267 
 268 // Functions for getting and setting oops within instance objects.
 269 // If the oops are compressed, the type passed to these overloaded functions
 270 // is narrowOop.  All functions are overloaded so they can be called by
 271 // template functions without conditionals (the compiler instantiates via
 272 // the right type and inlines the appopriate code).
 273 
 274 // Algorithm for encoding and decoding oops from 64 bit pointers to 32 bit
 275 // offset from the heap base.  Saving the check for null can save instructions
 276 // in inner GC loops so these are separated.
 277 
 278 inline bool check_obj_alignment(oop obj) {
 279   return (cast_from_oop<intptr_t>(obj) & MinObjAlignmentInBytesMask) == 0;
 280 }
 281 
 282 oop oopDesc::decode_heap_oop_not_null(narrowOop v) {
 283   assert(!is_null(v), "narrow oop value can never be zero");
 284   address base = Universe::narrow_oop_base();
 285   int    shift = Universe::narrow_oop_shift();
 286   oop result = (oop)(void*)((uintptr_t)base + ((uintptr_t)v << shift));
 287   assert(check_obj_alignment(result), "address not aligned: " INTPTR_FORMAT, p2i((void*) result));
 288   return result;
 289 }
 290 
 291 oop oopDesc::decode_heap_oop(narrowOop v) {
 292   return is_null(v) ? (oop)NULL : decode_heap_oop_not_null(v);
 293 }
 294 
 295 narrowOop oopDesc::encode_heap_oop_not_null(oop v) {
 296   assert(!is_null(v), "oop value can never be zero");
 297   assert(check_obj_alignment(v), "Address not aligned");
 298   assert(Universe::heap()->is_in_reserved(v), "Address not in heap");
 299   address base = Universe::narrow_oop_base();
 300   int    shift = Universe::narrow_oop_shift();
 301   uint64_t  pd = (uint64_t)(pointer_delta((void*)v, (void*)base, 1));
 302   assert(OopEncodingHeapMax > pd, "change encoding max if new encoding");
 303   uint64_t result = pd >> shift;
 304   assert((result & CONST64(0xffffffff00000000)) == 0, "narrow oop overflow");
 305   assert(decode_heap_oop(result) == v, "reversibility");
 306   return (narrowOop)result;
 307 }
 308 
 309 narrowOop oopDesc::encode_heap_oop(oop v) {
 310   return (is_null(v)) ? (narrowOop)0 : encode_heap_oop_not_null(v);
 311 }
 312 
 313 narrowOop oopDesc::load_heap_oop(narrowOop* p) { return *p; }
 314 oop       oopDesc::load_heap_oop(oop* p)       { return *p; }
 315 
 316 void oopDesc::store_heap_oop(narrowOop* p, narrowOop v) { *p = v; }
 317 void oopDesc::store_heap_oop(oop* p, oop v)             { *p = v; }
 318 
 319 // Load and decode an oop out of the Java heap into a wide oop.
 320 oop oopDesc::load_decode_heap_oop_not_null(narrowOop* p) {
 321   return decode_heap_oop_not_null(load_heap_oop(p));
 322 }
 323 
 324 // Load and decode an oop out of the heap accepting null
 325 oop oopDesc::load_decode_heap_oop(narrowOop* p) {
 326   return decode_heap_oop(load_heap_oop(p));
 327 }
 328 
 329 oop oopDesc::load_decode_heap_oop_not_null(oop* p) { return *p; }
 330 oop oopDesc::load_decode_heap_oop(oop* p)          { return *p; }
 331 
 332 void oopDesc::encode_store_heap_oop_not_null(oop* p, oop v) { *p = v; }
 333 void oopDesc::encode_store_heap_oop(oop* p, oop v)          { *p = v; }
 334 
 335 // Encode and store a heap oop.
 336 void oopDesc::encode_store_heap_oop_not_null(narrowOop* p, oop v) {
 337   *p = encode_heap_oop_not_null(v);
 338 }
 339 
 340 // Encode and store a heap oop allowing for null.
 341 void oopDesc::encode_store_heap_oop(narrowOop* p, oop v) {
 342   *p = encode_heap_oop(v);
 343 }
 344 
 345 inline oop oopDesc::obj_field(int offset) const                  { return HeapAccess<>::oop_load_at(oop_base(), offset); }
 346 inline void oopDesc::obj_field_put(int offset, oop value)        { HeapAccess<>::oop_store_at(oop_base(), offset, value); }
 347 
 348 inline jbyte oopDesc::byte_field(int offset) const               { return HeapAccess<>::load_at(oop_base(), offset); }
 349 inline void oopDesc::byte_field_put(int offset, jbyte value)     { HeapAccess<>::store_at(oop_base(), offset, value); }
 350 
 351 inline jchar oopDesc::char_field(int offset) const               { return HeapAccess<>::load_at(oop_base(), offset); }
 352 inline void oopDesc::char_field_put(int offset, jchar value)     { HeapAccess<>::store_at(oop_base(), offset, value); }
 353 
 354 inline jboolean oopDesc::bool_field(int offset) const            { return HeapAccess<>::load_at(oop_base(), offset); }
 355 inline void oopDesc::bool_field_put(int offset, jboolean value)  { HeapAccess<>::store_at(oop_base(), offset, jboolean(value & 1)); }
 356 
 357 inline jint oopDesc::int_field(int offset) const                 { return HeapAccess<>::load_at(oop_base(), offset); }
 358 inline void oopDesc::int_field_put(int offset, jint value)       { HeapAccess<>::store_at(oop_base(), offset, value); }
 359 
 360 inline jshort oopDesc::short_field(int offset) const             { return HeapAccess<>::load_at(oop_base(), offset); }
 361 inline void oopDesc::short_field_put(int offset, jshort value)   { HeapAccess<>::store_at(oop_base(), offset, value); }
 362 
 363 inline jlong oopDesc::long_field(int offset) const               { return HeapAccess<>::load_at(oop_base(), offset); }
 364 inline void oopDesc::long_field_put(int offset, jlong value)     { HeapAccess<>::store_at(oop_base(), offset, value); }
 365 
 366 inline jfloat oopDesc::float_field(int offset) const             { return HeapAccess<>::load_at(oop_base(), offset); }
 367 inline void oopDesc::float_field_put(int offset, jfloat value)   { HeapAccess<>::store_at(oop_base(), offset, value); }
 368 
 369 inline jdouble oopDesc::double_field(int offset) const           { return HeapAccess<>::load_at(oop_base(), offset); }
 370 inline void oopDesc::double_field_put(int offset, jdouble value) { HeapAccess<>::store_at(oop_base(), offset, value); }
 371 
 372 bool oopDesc::is_locked() const {
 373   return mark()->is_locked();
 374 }
 375 
 376 bool oopDesc::is_unlocked() const {
 377   return mark()->is_unlocked();
 378 }
 379 
 380 bool oopDesc::has_bias_pattern() const {
 381   return mark()->has_bias_pattern();
 382 }
 383 
 384 // used only for asserts
 385 bool oopDesc::is_oop(bool ignore_mark_word) const {
 386   oop obj = (oop) this;
 387   if (!check_obj_alignment(obj)) return false;
 388   if (!Universe::heap()->is_in_reserved(obj)) return false;
 389   // obj is aligned and accessible in heap
 390   if (Universe::heap()->is_in_reserved(obj->klass_or_null())) return false;
 391 
 392   // Header verification: the mark is typically non-NULL. If we're
 393   // at a safepoint, it must not be null.
 394   // Outside of a safepoint, the header could be changing (for example,
 395   // another thread could be inflating a lock on this object).
 396   if (ignore_mark_word) {
 397     return true;
 398   }
 399   if (mark() != NULL) {
 400     return true;
 401   }
 402   return !SafepointSynchronize::is_at_safepoint();
 403 }
 404 
 405 
 406 // used only for asserts
 407 bool oopDesc::is_oop_or_null(bool ignore_mark_word) const {
 408   return this == NULL ? true : is_oop(ignore_mark_word);
 409 }
 410 
 411 #ifndef PRODUCT
 412 // used only for asserts
 413 bool oopDesc::is_unlocked_oop() const {
 414   if (!Universe::heap()->is_in_reserved(this)) return false;
 415   return mark()->is_unlocked();
 416 }
 417 #endif // PRODUCT
 418 
 419 // Used only for markSweep, scavenging
 420 bool oopDesc::is_gc_marked() const {
 421   return mark()->is_marked();
 422 }
 423 
 424 bool oopDesc::is_scavengable() const {
 425   return Universe::heap()->is_scavengable(this);
 426 }
 427 
 428 // Used by scavengers
 429 bool oopDesc::is_forwarded() const {
 430   // The extra heap check is needed since the obj might be locked, in which case the
 431   // mark would point to a stack location and have the sentinel bit cleared
 432   return mark()->is_marked();
 433 }
 434 
 435 // Used by scavengers
 436 void oopDesc::forward_to(oop p) {
 437   assert(check_obj_alignment(p),
 438          "forwarding to something not aligned");
 439   assert(Universe::heap()->is_in_reserved(p),
 440          "forwarding to something not in heap");
 441   markOop m = markOopDesc::encode_pointer_as_mark(p);
 442   assert(m->decode_pointer() == p, "encoding must be reversable");
 443   set_mark(m);
 444 }
 445 
 446 // Used by parallel scavengers
 447 bool oopDesc::cas_forward_to(oop p, markOop compare) {
 448   assert(check_obj_alignment(p),
 449          "forwarding to something not aligned");
 450   assert(Universe::heap()->is_in_reserved(p),
 451          "forwarding to something not in heap");
 452   markOop m = markOopDesc::encode_pointer_as_mark(p);
 453   assert(m->decode_pointer() == p, "encoding must be reversable");
 454   return cas_set_mark(m, compare) == compare;
 455 }
 456 
 457 #if INCLUDE_ALL_GCS
 458 oop oopDesc::forward_to_atomic(oop p) {
 459   markOop oldMark = mark();
 460   markOop forwardPtrMark = markOopDesc::encode_pointer_as_mark(p);
 461   markOop curMark;
 462 
 463   assert(forwardPtrMark->decode_pointer() == p, "encoding must be reversable");
 464   assert(sizeof(markOop) == sizeof(intptr_t), "CAS below requires this.");
 465 
 466   while (!oldMark->is_marked()) {
 467     curMark = (markOop)Atomic::cmpxchg_ptr(forwardPtrMark, &_mark, oldMark);
 468     assert(is_forwarded(), "object should have been forwarded");
 469     if (curMark == oldMark) {
 470       return NULL;
 471     }
 472     // If the CAS was unsuccessful then curMark->is_marked()
 473     // should return true as another thread has CAS'd in another
 474     // forwarding pointer.
 475     oldMark = curMark;
 476   }
 477   return forwardee();
 478 }
 479 #endif
 480 
 481 // Note that the forwardee is not the same thing as the displaced_mark.
 482 // The forwardee is used when copying during scavenge and mark-sweep.
 483 // It does need to clear the low two locking- and GC-related bits.
 484 oop oopDesc::forwardee() const {
 485   return (oop) mark()->decode_pointer();
 486 }
 487 
 488 // The following method needs to be MT safe.
 489 uint oopDesc::age() const {
 490   assert(!is_forwarded(), "Attempt to read age from forwarded mark");
 491   if (has_displaced_mark()) {
 492     return displaced_mark()->age();
 493   } else {
 494     return mark()->age();
 495   }
 496 }
 497 
 498 void oopDesc::incr_age() {
 499   assert(!is_forwarded(), "Attempt to increment age of forwarded mark");
 500   if (has_displaced_mark()) {
 501     set_displaced_mark(displaced_mark()->incr_age());
 502   } else {
 503     set_mark(mark()->incr_age());
 504   }
 505 }
 506 
 507 int oopDesc::ms_adjust_pointers() {
 508   debug_only(int check_size = size());
 509   int s = klass()->oop_ms_adjust_pointers(this);
 510   assert(s == check_size, "should be the same");
 511   return s;
 512 }
 513 
 514 #if INCLUDE_ALL_GCS
 515 void oopDesc::pc_follow_contents(ParCompactionManager* cm) {
 516   klass()->oop_pc_follow_contents(this, cm);
 517 }
 518 
 519 void oopDesc::pc_update_contents(ParCompactionManager* cm) {
 520   Klass* k = klass();
 521   if (!k->is_typeArray_klass()) {
 522     // It might contain oops beyond the header, so take the virtual call.
 523     k->oop_pc_update_pointers(this, cm);
 524   }
 525   // Else skip it.  The TypeArrayKlass in the header never needs scavenging.
 526 }
 527 
 528 void oopDesc::ps_push_contents(PSPromotionManager* pm) {
 529   Klass* k = klass();
 530   if (!k->is_typeArray_klass()) {
 531     // It might contain oops beyond the header, so take the virtual call.
 532     k->oop_ps_push_contents(this, pm);
 533   }
 534   // Else skip it.  The TypeArrayKlass in the header never needs scavenging.
 535 }
 536 #endif // INCLUDE_ALL_GCS
 537 
 538 #define OOP_ITERATE_DEFN(OopClosureType, nv_suffix)                 \
 539                                                                     \
 540 void oopDesc::oop_iterate(OopClosureType* blk) {                    \
 541   klass()->oop_oop_iterate##nv_suffix(this, blk);                   \
 542 }                                                                   \
 543                                                                     \
 544 void oopDesc::oop_iterate(OopClosureType* blk, MemRegion mr) {      \
 545   klass()->oop_oop_iterate_bounded##nv_suffix(this, blk, mr);       \
 546 }
 547 
 548 #define OOP_ITERATE_SIZE_DEFN(OopClosureType, nv_suffix)            \
 549                                                                     \
 550 int oopDesc::oop_iterate_size(OopClosureType* blk) {                \
 551   Klass* k = klass();                                               \
 552   int size = size_given_klass(k);                                   \
 553   k->oop_oop_iterate##nv_suffix(this, blk);                         \
 554   return size;                                                      \
 555 }                                                                   \
 556                                                                     \
 557 int oopDesc::oop_iterate_size(OopClosureType* blk, MemRegion mr) {  \
 558   Klass* k = klass();                                               \
 559   int size = size_given_klass(k);                                   \
 560   k->oop_oop_iterate_bounded##nv_suffix(this, blk, mr);             \
 561   return size;                                                      \
 562 }
 563 
 564 int oopDesc::oop_iterate_no_header(OopClosure* blk) {
 565   // The NoHeaderExtendedOopClosure wraps the OopClosure and proxies all
 566   // the do_oop calls, but turns off all other features in ExtendedOopClosure.
 567   NoHeaderExtendedOopClosure cl(blk);
 568   return oop_iterate_size(&cl);
 569 }
 570 
 571 int oopDesc::oop_iterate_no_header(OopClosure* blk, MemRegion mr) {
 572   NoHeaderExtendedOopClosure cl(blk);
 573   return oop_iterate_size(&cl, mr);
 574 }
 575 
 576 #if INCLUDE_ALL_GCS
 577 #define OOP_ITERATE_BACKWARDS_DEFN(OopClosureType, nv_suffix)       \
 578                                                                     \
 579 inline void oopDesc::oop_iterate_backwards(OopClosureType* blk) {   \
 580   klass()->oop_oop_iterate_backwards##nv_suffix(this, blk);         \
 581 }
 582 #else
 583 #define OOP_ITERATE_BACKWARDS_DEFN(OopClosureType, nv_suffix)
 584 #endif // INCLUDE_ALL_GCS
 585 
 586 #define ALL_OOPDESC_OOP_ITERATE(OopClosureType, nv_suffix)  \
 587   OOP_ITERATE_DEFN(OopClosureType, nv_suffix)               \
 588   OOP_ITERATE_SIZE_DEFN(OopClosureType, nv_suffix)          \
 589   OOP_ITERATE_BACKWARDS_DEFN(OopClosureType, nv_suffix)
 590 
 591 ALL_OOP_OOP_ITERATE_CLOSURES_1(ALL_OOPDESC_OOP_ITERATE)
 592 ALL_OOP_OOP_ITERATE_CLOSURES_2(ALL_OOPDESC_OOP_ITERATE)
 593 
 594 intptr_t oopDesc::identity_hash() {
 595   // Fast case; if the object is unlocked and the hash value is set, no locking is needed
 596   // Note: The mark must be read into local variable to avoid concurrent updates.
 597   markOop mrk = mark();
 598   if (mrk->is_unlocked() && !mrk->has_no_hash()) {
 599     return mrk->hash();
 600   } else if (mrk->is_marked()) {
 601     return mrk->hash();
 602   } else {
 603     return slow_identity_hash();
 604   }
 605 }
 606 
 607 bool oopDesc::has_displaced_mark() const {
 608   return mark()->has_displaced_mark_helper();
 609 }
 610 
 611 markOop oopDesc::displaced_mark() const {
 612   return mark()->displaced_mark_helper();
 613 }
 614 
 615 void oopDesc::set_displaced_mark(markOop m) {
 616   mark()->set_displaced_mark_helper(m);
 617 }
 618 
 619 #endif // SHARE_VM_OOPS_OOP_INLINE_HPP