< prev index next >

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

Print this page




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


 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 >