< prev index next >

src/hotspot/share/oops/oop.inline.hpp

Print this page
rev 49910 : imported patch removeAllGCs.fixIncludes
rev 49911 : imported patch removeAllGCs


   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.hpp"
  30 #include "gc/shared/generation.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/klass.inline.hpp"
  36 #include "oops/markOop.inline.hpp"
  37 #include "oops/oop.hpp"
  38 #include "runtime/atomic.hpp"
  39 #include "runtime/orderAccess.inline.hpp"
  40 #include "runtime/os.hpp"
  41 #include "utilities/align.hpp"
  42 #include "utilities/macros.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 markOop  oopDesc::mark()      const {
  48   return HeapAccess<MO_VOLATILE>::load_at(as_oop(), mark_offset_in_bytes());
  49 }
  50 


 333          "forwarding to something not in heap");
 334   assert(!is_archive_object(oop(this)) &&
 335          !is_archive_object(p),
 336          "forwarding archive object");
 337   markOop m = markOopDesc::encode_pointer_as_mark(p);
 338   assert(m->decode_pointer() == p, "encoding must be reversable");
 339   set_mark_raw(m);
 340 }
 341 
 342 // Used by parallel scavengers
 343 bool oopDesc::cas_forward_to(oop p, markOop compare) {
 344   assert(check_obj_alignment(p),
 345          "forwarding to something not aligned");
 346   assert(Universe::heap()->is_in_reserved(p),
 347          "forwarding to something not in heap");
 348   markOop m = markOopDesc::encode_pointer_as_mark(p);
 349   assert(m->decode_pointer() == p, "encoding must be reversable");
 350   return cas_set_mark_raw(m, compare) == compare;
 351 }
 352 
 353 #if INCLUDE_ALL_GCS
 354 oop oopDesc::forward_to_atomic(oop p) {
 355   markOop oldMark = mark_raw();
 356   markOop forwardPtrMark = markOopDesc::encode_pointer_as_mark(p);
 357   markOop curMark;
 358 
 359   assert(forwardPtrMark->decode_pointer() == p, "encoding must be reversable");
 360   assert(sizeof(markOop) == sizeof(intptr_t), "CAS below requires this.");
 361 
 362   while (!oldMark->is_marked()) {
 363     curMark = cas_set_mark_raw(forwardPtrMark, oldMark);
 364     assert(is_forwarded(), "object should have been forwarded");
 365     if (curMark == oldMark) {
 366       return NULL;
 367     }
 368     // If the CAS was unsuccessful then curMark->is_marked()
 369     // should return true as another thread has CAS'd in another
 370     // forwarding pointer.
 371     oldMark = curMark;
 372   }
 373   return forwardee();
 374 }
 375 #endif
 376 
 377 // Note that the forwardee is not the same thing as the displaced_mark.
 378 // The forwardee is used when copying during scavenge and mark-sweep.
 379 // It does need to clear the low two locking- and GC-related bits.
 380 oop oopDesc::forwardee() const {
 381   return (oop) mark_raw()->decode_pointer();
 382 }
 383 
 384 // The following method needs to be MT safe.
 385 uint oopDesc::age() const {
 386   assert(!is_forwarded(), "Attempt to read age from forwarded mark");
 387   if (has_displaced_mark_raw()) {
 388     return displaced_mark_raw()->age();
 389   } else {
 390     return mark_raw()->age();
 391   }
 392 }
 393 
 394 void oopDesc::incr_age() {
 395   assert(!is_forwarded(), "Attempt to increment age of forwarded mark");
 396   if (has_displaced_mark_raw()) {
 397     set_displaced_mark_raw(displaced_mark_raw()->incr_age());
 398   } else {
 399     set_mark_raw(mark_raw()->incr_age());
 400   }
 401 }
 402 
 403 #if INCLUDE_ALL_GCS
 404 void oopDesc::pc_follow_contents(ParCompactionManager* cm) {
 405   klass()->oop_pc_follow_contents(this, cm);
 406 }
 407 
 408 void oopDesc::pc_update_contents(ParCompactionManager* cm) {
 409   Klass* k = klass();
 410   if (!k->is_typeArray_klass()) {
 411     // It might contain oops beyond the header, so take the virtual call.
 412     k->oop_pc_update_pointers(this, cm);
 413   }
 414   // Else skip it.  The TypeArrayKlass in the header never needs scavenging.
 415 }
 416 
 417 void oopDesc::ps_push_contents(PSPromotionManager* pm) {
 418   Klass* k = klass();
 419   if (!k->is_typeArray_klass()) {
 420     // It might contain oops beyond the header, so take the virtual call.
 421     k->oop_ps_push_contents(this, pm);
 422   }
 423   // Else skip it.  The TypeArrayKlass in the header never needs scavenging.
 424 }
 425 #endif // INCLUDE_ALL_GCS
 426 
 427 #define OOP_ITERATE_DEFN(OopClosureType, nv_suffix)                 \
 428                                                                     \
 429 void oopDesc::oop_iterate(OopClosureType* blk) {                    \
 430   klass()->oop_oop_iterate##nv_suffix(this, blk);                   \
 431 }                                                                   \
 432                                                                     \
 433 void oopDesc::oop_iterate(OopClosureType* blk, MemRegion mr) {      \
 434   klass()->oop_oop_iterate_bounded##nv_suffix(this, blk, mr);       \
 435 }
 436 
 437 #define OOP_ITERATE_SIZE_DEFN(OopClosureType, nv_suffix)            \
 438                                                                     \
 439 int oopDesc::oop_iterate_size(OopClosureType* blk) {                \
 440   Klass* k = klass();                                               \
 441   int size = size_given_klass(k);                                   \
 442   k->oop_oop_iterate##nv_suffix(this, blk);                         \
 443   return size;                                                      \
 444 }                                                                   \
 445                                                                     \
 446 int oopDesc::oop_iterate_size(OopClosureType* blk, MemRegion mr) {  \
 447   Klass* k = klass();                                               \
 448   int size = size_given_klass(k);                                   \
 449   k->oop_oop_iterate_bounded##nv_suffix(this, blk, mr);             \
 450   return size;                                                      \
 451 }
 452 
 453 int oopDesc::oop_iterate_no_header(OopClosure* blk) {
 454   // The NoHeaderExtendedOopClosure wraps the OopClosure and proxies all
 455   // the do_oop calls, but turns off all other features in ExtendedOopClosure.
 456   NoHeaderExtendedOopClosure cl(blk);
 457   return oop_iterate_size(&cl);
 458 }
 459 
 460 int oopDesc::oop_iterate_no_header(OopClosure* blk, MemRegion mr) {
 461   NoHeaderExtendedOopClosure cl(blk);
 462   return oop_iterate_size(&cl, mr);
 463 }
 464 
 465 #if INCLUDE_ALL_GCS
 466 #define OOP_ITERATE_BACKWARDS_DEFN(OopClosureType, nv_suffix)       \
 467                                                                     \
 468 inline void oopDesc::oop_iterate_backwards(OopClosureType* blk) {   \
 469   klass()->oop_oop_iterate_backwards##nv_suffix(this, blk);         \
 470 }
 471 #else
 472 #define OOP_ITERATE_BACKWARDS_DEFN(OopClosureType, nv_suffix)
 473 #endif // INCLUDE_ALL_GCS
 474 
 475 #define ALL_OOPDESC_OOP_ITERATE(OopClosureType, nv_suffix)  \
 476   OOP_ITERATE_DEFN(OopClosureType, nv_suffix)               \
 477   OOP_ITERATE_SIZE_DEFN(OopClosureType, nv_suffix)          \
 478   OOP_ITERATE_BACKWARDS_DEFN(OopClosureType, nv_suffix)
 479 
 480 ALL_OOP_OOP_ITERATE_CLOSURES_1(ALL_OOPDESC_OOP_ITERATE)
 481 ALL_OOP_OOP_ITERATE_CLOSURES_2(ALL_OOPDESC_OOP_ITERATE)
 482 
 483 bool oopDesc::is_instanceof_or_null(oop obj, Klass* klass) {
 484   return obj == NULL || obj->klass()->is_subtype_of(klass);
 485 }
 486 
 487 intptr_t oopDesc::identity_hash() {
 488   // Fast case; if the object is unlocked and the hash value is set, no locking is needed
 489   // Note: The mark must be read into local variable to avoid concurrent updates.
 490   markOop mrk = mark();
 491   if (mrk->is_unlocked() && !mrk->has_no_hash()) {
 492     return mrk->hash();
 493   } else if (mrk->is_marked()) {


   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/collectedHeap.hpp"

  29 #include "oops/access.inline.hpp"
  30 #include "oops/arrayKlass.hpp"
  31 #include "oops/arrayOop.hpp"
  32 #include "oops/compressedOops.inline.hpp"
  33 #include "oops/klass.inline.hpp"
  34 #include "oops/markOop.inline.hpp"
  35 #include "oops/oop.hpp"
  36 #include "runtime/atomic.hpp"
  37 #include "runtime/orderAccess.inline.hpp"
  38 #include "runtime/os.hpp"
  39 #include "utilities/align.hpp"
  40 #include "utilities/macros.hpp"
  41 
  42 // Implementation of all inlined member functions defined in oop.hpp
  43 // We need a separate file to avoid circular references
  44 
  45 markOop  oopDesc::mark()      const {
  46   return HeapAccess<MO_VOLATILE>::load_at(as_oop(), mark_offset_in_bytes());
  47 }
  48 


 331          "forwarding to something not in heap");
 332   assert(!is_archive_object(oop(this)) &&
 333          !is_archive_object(p),
 334          "forwarding archive object");
 335   markOop m = markOopDesc::encode_pointer_as_mark(p);
 336   assert(m->decode_pointer() == p, "encoding must be reversable");
 337   set_mark_raw(m);
 338 }
 339 
 340 // Used by parallel scavengers
 341 bool oopDesc::cas_forward_to(oop p, markOop compare) {
 342   assert(check_obj_alignment(p),
 343          "forwarding to something not aligned");
 344   assert(Universe::heap()->is_in_reserved(p),
 345          "forwarding to something not in heap");
 346   markOop m = markOopDesc::encode_pointer_as_mark(p);
 347   assert(m->decode_pointer() == p, "encoding must be reversable");
 348   return cas_set_mark_raw(m, compare) == compare;
 349 }
 350 

 351 oop oopDesc::forward_to_atomic(oop p) {
 352   markOop oldMark = mark_raw();
 353   markOop forwardPtrMark = markOopDesc::encode_pointer_as_mark(p);
 354   markOop curMark;
 355 
 356   assert(forwardPtrMark->decode_pointer() == p, "encoding must be reversable");
 357   assert(sizeof(markOop) == sizeof(intptr_t), "CAS below requires this.");
 358 
 359   while (!oldMark->is_marked()) {
 360     curMark = cas_set_mark_raw(forwardPtrMark, oldMark);
 361     assert(is_forwarded(), "object should have been forwarded");
 362     if (curMark == oldMark) {
 363       return NULL;
 364     }
 365     // If the CAS was unsuccessful then curMark->is_marked()
 366     // should return true as another thread has CAS'd in another
 367     // forwarding pointer.
 368     oldMark = curMark;
 369   }
 370   return forwardee();
 371 }

 372 
 373 // Note that the forwardee is not the same thing as the displaced_mark.
 374 // The forwardee is used when copying during scavenge and mark-sweep.
 375 // It does need to clear the low two locking- and GC-related bits.
 376 oop oopDesc::forwardee() const {
 377   return (oop) mark_raw()->decode_pointer();
 378 }
 379 
 380 // The following method needs to be MT safe.
 381 uint oopDesc::age() const {
 382   assert(!is_forwarded(), "Attempt to read age from forwarded mark");
 383   if (has_displaced_mark_raw()) {
 384     return displaced_mark_raw()->age();
 385   } else {
 386     return mark_raw()->age();
 387   }
 388 }
 389 
 390 void oopDesc::incr_age() {
 391   assert(!is_forwarded(), "Attempt to increment age of forwarded mark");
 392   if (has_displaced_mark_raw()) {
 393     set_displaced_mark_raw(displaced_mark_raw()->incr_age());
 394   } else {
 395     set_mark_raw(mark_raw()->incr_age());
 396   }
 397 }
 398 
 399 #if INCLUDE_PARALLELGC
 400 void oopDesc::pc_follow_contents(ParCompactionManager* cm) {
 401   klass()->oop_pc_follow_contents(this, cm);
 402 }
 403 
 404 void oopDesc::pc_update_contents(ParCompactionManager* cm) {
 405   Klass* k = klass();
 406   if (!k->is_typeArray_klass()) {
 407     // It might contain oops beyond the header, so take the virtual call.
 408     k->oop_pc_update_pointers(this, cm);
 409   }
 410   // Else skip it.  The TypeArrayKlass in the header never needs scavenging.
 411 }
 412 
 413 void oopDesc::ps_push_contents(PSPromotionManager* pm) {
 414   Klass* k = klass();
 415   if (!k->is_typeArray_klass()) {
 416     // It might contain oops beyond the header, so take the virtual call.
 417     k->oop_ps_push_contents(this, pm);
 418   }
 419   // Else skip it.  The TypeArrayKlass in the header never needs scavenging.
 420 }
 421 #endif // INCLUDE_PARALLELGC
 422 
 423 #define OOP_ITERATE_DEFN(OopClosureType, nv_suffix)                 \
 424                                                                     \
 425 void oopDesc::oop_iterate(OopClosureType* blk) {                    \
 426   klass()->oop_oop_iterate##nv_suffix(this, blk);                   \
 427 }                                                                   \
 428                                                                     \
 429 void oopDesc::oop_iterate(OopClosureType* blk, MemRegion mr) {      \
 430   klass()->oop_oop_iterate_bounded##nv_suffix(this, blk, mr);       \
 431 }
 432 
 433 #define OOP_ITERATE_SIZE_DEFN(OopClosureType, nv_suffix)            \
 434                                                                     \
 435 int oopDesc::oop_iterate_size(OopClosureType* blk) {                \
 436   Klass* k = klass();                                               \
 437   int size = size_given_klass(k);                                   \
 438   k->oop_oop_iterate##nv_suffix(this, blk);                         \
 439   return size;                                                      \
 440 }                                                                   \
 441                                                                     \
 442 int oopDesc::oop_iterate_size(OopClosureType* blk, MemRegion mr) {  \
 443   Klass* k = klass();                                               \
 444   int size = size_given_klass(k);                                   \
 445   k->oop_oop_iterate_bounded##nv_suffix(this, blk, mr);             \
 446   return size;                                                      \
 447 }
 448 
 449 int oopDesc::oop_iterate_no_header(OopClosure* blk) {
 450   // The NoHeaderExtendedOopClosure wraps the OopClosure and proxies all
 451   // the do_oop calls, but turns off all other features in ExtendedOopClosure.
 452   NoHeaderExtendedOopClosure cl(blk);
 453   return oop_iterate_size(&cl);
 454 }
 455 
 456 int oopDesc::oop_iterate_no_header(OopClosure* blk, MemRegion mr) {
 457   NoHeaderExtendedOopClosure cl(blk);
 458   return oop_iterate_size(&cl, mr);
 459 }
 460 
 461 #if INCLUDE_OOP_OOP_ITERATE_BACKWARDS
 462 #define OOP_ITERATE_BACKWARDS_DEFN(OopClosureType, nv_suffix)       \
 463                                                                     \
 464 inline void oopDesc::oop_iterate_backwards(OopClosureType* blk) {   \
 465   klass()->oop_oop_iterate_backwards##nv_suffix(this, blk);         \
 466 }
 467 #else
 468 #define OOP_ITERATE_BACKWARDS_DEFN(OopClosureType, nv_suffix)
 469 #endif
 470 
 471 #define ALL_OOPDESC_OOP_ITERATE(OopClosureType, nv_suffix)  \
 472   OOP_ITERATE_DEFN(OopClosureType, nv_suffix)               \
 473   OOP_ITERATE_SIZE_DEFN(OopClosureType, nv_suffix)          \
 474   OOP_ITERATE_BACKWARDS_DEFN(OopClosureType, nv_suffix)
 475 
 476 ALL_OOP_OOP_ITERATE_CLOSURES_1(ALL_OOPDESC_OOP_ITERATE)
 477 ALL_OOP_OOP_ITERATE_CLOSURES_2(ALL_OOPDESC_OOP_ITERATE)
 478 
 479 bool oopDesc::is_instanceof_or_null(oop obj, Klass* klass) {
 480   return obj == NULL || obj->klass()->is_subtype_of(klass);
 481 }
 482 
 483 intptr_t oopDesc::identity_hash() {
 484   // Fast case; if the object is unlocked and the hash value is set, no locking is needed
 485   // Note: The mark must be read into local variable to avoid concurrent updates.
 486   markOop mrk = mark();
 487   if (mrk->is_unlocked() && !mrk->has_no_hash()) {
 488     return mrk->hash();
 489   } else if (mrk->is_marked()) {
< prev index next >