< prev index next >

src/share/vm/runtime/biasedLocking.cpp

Print this page
rev 11465 : Revert obsolete shared-code changes in runtime synchronizer code


 526 };
 527 
 528 
 529 BiasedLocking::Condition BiasedLocking::revoke_and_rebias(Handle obj, bool attempt_rebias, TRAPS) {
 530   assert(!SafepointSynchronize::is_at_safepoint(), "must not be called while at safepoint");
 531 
 532   // We can revoke the biases of anonymously-biased objects
 533   // efficiently enough that we should not cause these revocations to
 534   // update the heuristics because doing so may cause unwanted bulk
 535   // revocations (which are expensive) to occur.
 536   markOop mark = obj->mark();
 537   if (mark->is_biased_anonymously() && !attempt_rebias) {
 538     // We are probably trying to revoke the bias of this object due to
 539     // an identity hash code computation. Try to revoke the bias
 540     // without a safepoint. This is possible if we can successfully
 541     // compare-and-exchange an unbiased header into the mark word of
 542     // the object, meaning that no other thread has raced to acquire
 543     // the bias of the object.
 544     markOop biased_value       = mark;
 545     markOop unbiased_prototype = markOopDesc::prototype()->set_age(mark->age());
 546     markOop res_mark = obj->cas_set_mark(unbiased_prototype, mark);
 547     if (res_mark == biased_value) {
 548       return BIAS_REVOKED;
 549     }
 550   } else if (mark->has_bias_pattern()) {
 551     Klass* k = obj->klass();
 552     markOop prototype_header = k->prototype_header();
 553     if (!prototype_header->has_bias_pattern()) {
 554       // This object has a stale bias from before the bulk revocation
 555       // for this data type occurred. It's pointless to update the
 556       // heuristics at this point so simply update the header with a
 557       // CAS. If we fail this race, the object's bias has been revoked
 558       // by another thread so we simply return and let the caller deal
 559       // with it.
 560       markOop biased_value       = mark;
 561       markOop res_mark = obj->cas_set_mark(prototype_header, mark);
 562       assert(! obj->mark()->has_bias_pattern(), "even if we raced, should still be revoked");
 563       return BIAS_REVOKED;
 564     } else if (prototype_header->bias_epoch() != mark->bias_epoch()) {
 565       // The epoch of this biasing has expired indicating that the
 566       // object is effectively unbiased. Depending on whether we need
 567       // to rebias or revoke the bias of this object we can do it
 568       // efficiently enough with a CAS that we shouldn't update the
 569       // heuristics. This is normally done in the assembly code but we
 570       // can reach this point due to various points in the runtime
 571       // needing to revoke biases.
 572       if (attempt_rebias) {
 573         assert(THREAD->is_Java_thread(), "");
 574         markOop biased_value       = mark;
 575         markOop rebiased_prototype = markOopDesc::encode((JavaThread*) THREAD, mark->age(), prototype_header->bias_epoch());
 576         markOop res_mark = obj->cas_set_mark(rebiased_prototype, mark);
 577         if (res_mark == biased_value) {
 578           return BIAS_REVOKED_AND_REBIASED;
 579         }
 580       } else {
 581         markOop biased_value       = mark;
 582         markOop unbiased_prototype = markOopDesc::prototype()->set_age(mark->age());
 583         markOop res_mark = obj->cas_set_mark(unbiased_prototype, mark);
 584         if (res_mark == biased_value) {
 585           return BIAS_REVOKED;
 586         }
 587       }
 588     }
 589   }
 590 
 591   HeuristicsResult heuristics = update_heuristics(obj(), attempt_rebias);
 592   if (heuristics == HR_NOT_BIASED) {
 593     return NOT_BIASED;
 594   } else if (heuristics == HR_SINGLE_REVOKE) {
 595     Klass *k = obj->klass();
 596     markOop prototype_header = k->prototype_header();
 597     if (mark->biased_locker() == THREAD &&
 598         prototype_header->bias_epoch() == mark->bias_epoch()) {
 599       // A thread is trying to revoke the bias of an object biased
 600       // toward it, again likely due to an identity hash code
 601       // computation. We can again avoid a safepoint in this case
 602       // since we are only going to walk our own stack. There are no
 603       // races with revocations occurring in other threads because we




 526 };
 527 
 528 
 529 BiasedLocking::Condition BiasedLocking::revoke_and_rebias(Handle obj, bool attempt_rebias, TRAPS) {
 530   assert(!SafepointSynchronize::is_at_safepoint(), "must not be called while at safepoint");
 531 
 532   // We can revoke the biases of anonymously-biased objects
 533   // efficiently enough that we should not cause these revocations to
 534   // update the heuristics because doing so may cause unwanted bulk
 535   // revocations (which are expensive) to occur.
 536   markOop mark = obj->mark();
 537   if (mark->is_biased_anonymously() && !attempt_rebias) {
 538     // We are probably trying to revoke the bias of this object due to
 539     // an identity hash code computation. Try to revoke the bias
 540     // without a safepoint. This is possible if we can successfully
 541     // compare-and-exchange an unbiased header into the mark word of
 542     // the object, meaning that no other thread has raced to acquire
 543     // the bias of the object.
 544     markOop biased_value       = mark;
 545     markOop unbiased_prototype = markOopDesc::prototype()->set_age(mark->age());
 546     markOop res_mark = (markOop) Atomic::cmpxchg_ptr(unbiased_prototype, obj->mark_addr(), mark);
 547     if (res_mark == biased_value) {
 548       return BIAS_REVOKED;
 549     }
 550   } else if (mark->has_bias_pattern()) {
 551     Klass* k = obj->klass();
 552     markOop prototype_header = k->prototype_header();
 553     if (!prototype_header->has_bias_pattern()) {
 554       // This object has a stale bias from before the bulk revocation
 555       // for this data type occurred. It's pointless to update the
 556       // heuristics at this point so simply update the header with a
 557       // CAS. If we fail this race, the object's bias has been revoked
 558       // by another thread so we simply return and let the caller deal
 559       // with it.
 560       markOop biased_value       = mark;
 561       markOop res_mark = (markOop) Atomic::cmpxchg_ptr(prototype_header, obj->mark_addr(), mark);
 562       assert(!(*(obj->mark_addr()))->has_bias_pattern(), "even if we raced, should still be revoked");
 563       return BIAS_REVOKED;
 564     } else if (prototype_header->bias_epoch() != mark->bias_epoch()) {
 565       // The epoch of this biasing has expired indicating that the
 566       // object is effectively unbiased. Depending on whether we need
 567       // to rebias or revoke the bias of this object we can do it
 568       // efficiently enough with a CAS that we shouldn't update the
 569       // heuristics. This is normally done in the assembly code but we
 570       // can reach this point due to various points in the runtime
 571       // needing to revoke biases.
 572       if (attempt_rebias) {
 573         assert(THREAD->is_Java_thread(), "");
 574         markOop biased_value       = mark;
 575         markOop rebiased_prototype = markOopDesc::encode((JavaThread*) THREAD, mark->age(), prototype_header->bias_epoch());
 576         markOop res_mark = (markOop) Atomic::cmpxchg_ptr(rebiased_prototype, obj->mark_addr(), mark);
 577         if (res_mark == biased_value) {
 578           return BIAS_REVOKED_AND_REBIASED;
 579         }
 580       } else {
 581         markOop biased_value       = mark;
 582         markOop unbiased_prototype = markOopDesc::prototype()->set_age(mark->age());
 583         markOop res_mark = (markOop) Atomic::cmpxchg_ptr(unbiased_prototype, obj->mark_addr(), mark);
 584         if (res_mark == biased_value) {
 585           return BIAS_REVOKED;
 586         }
 587       }
 588     }
 589   }
 590 
 591   HeuristicsResult heuristics = update_heuristics(obj(), attempt_rebias);
 592   if (heuristics == HR_NOT_BIASED) {
 593     return NOT_BIASED;
 594   } else if (heuristics == HR_SINGLE_REVOKE) {
 595     Klass *k = obj->klass();
 596     markOop prototype_header = k->prototype_header();
 597     if (mark->biased_locker() == THREAD &&
 598         prototype_header->bias_epoch() == mark->bias_epoch()) {
 599       // A thread is trying to revoke the bias of an object biased
 600       // toward it, again likely due to an identity hash code
 601       // computation. We can again avoid a safepoint in this case
 602       // since we are only going to walk our own stack. There are no
 603       // races with revocations occurring in other threads because we


< prev index next >