611 assert(k != NULL, "invariant");
612 assert(op != NULL, "invariant");
613 assert(event->should_commit(), "invariant");
614 event->set_lockClass(k);
615 event->set_safepointId(op->safepoint_id());
616 event->set_previousOwner(op->biased_locker());
617 event->commit();
618 }
619
620 static void post_class_revocation_event(EventBiasedLockClassRevocation* event, Klass* k, VM_BulkRevokeBias* op) {
621 assert(event != NULL, "invariant");
622 assert(k != NULL, "invariant");
623 assert(op != NULL, "invariant");
624 assert(event->should_commit(), "invariant");
625 event->set_revokedClass(k);
626 event->set_disableBiasing(!op->is_bulk_rebias());
627 event->set_safepointId(op->safepoint_id());
628 event->commit();
629 }
630
631 BiasedLocking::Condition BiasedLocking::revoke_and_rebias(Handle obj, bool attempt_rebias, TRAPS) {
632 assert(!SafepointSynchronize::is_at_safepoint(), "must not be called while at safepoint");
633
634 // We can revoke the biases of anonymously-biased objects
635 // efficiently enough that we should not cause these revocations to
636 // update the heuristics because doing so may cause unwanted bulk
637 // revocations (which are expensive) to occur.
638 markOop mark = obj->mark();
639 if (mark->is_biased_anonymously() && !attempt_rebias) {
640 // We are probably trying to revoke the bias of this object due to
641 // an identity hash code computation. Try to revoke the bias
642 // without a safepoint. This is possible if we can successfully
643 // compare-and-exchange an unbiased header into the mark word of
644 // the object, meaning that no other thread has raced to acquire
645 // the bias of the object.
646 markOop biased_value = mark;
647 markOop unbiased_prototype = markOopDesc::prototype()->set_age(mark->age());
648 markOop res_mark = obj->cas_set_mark(unbiased_prototype, mark);
649 if (res_mark == biased_value) {
650 return BIAS_REVOKED;
|
611 assert(k != NULL, "invariant");
612 assert(op != NULL, "invariant");
613 assert(event->should_commit(), "invariant");
614 event->set_lockClass(k);
615 event->set_safepointId(op->safepoint_id());
616 event->set_previousOwner(op->biased_locker());
617 event->commit();
618 }
619
620 static void post_class_revocation_event(EventBiasedLockClassRevocation* event, Klass* k, VM_BulkRevokeBias* op) {
621 assert(event != NULL, "invariant");
622 assert(k != NULL, "invariant");
623 assert(op != NULL, "invariant");
624 assert(event->should_commit(), "invariant");
625 event->set_revokedClass(k);
626 event->set_disableBiasing(!op->is_bulk_rebias());
627 event->set_safepointId(op->safepoint_id());
628 event->commit();
629 }
630
631 BiasedLocking::Condition BiasedLocking::revoke_own_locks_in_handshake(Handle obj, TRAPS) {
632 markOop mark = obj->mark();
633
634 if (!mark->has_bias_pattern()) {
635 return NOT_BIASED;
636 }
637
638 Klass *k = obj->klass();
639 markOop prototype_header = k->prototype_header();
640 assert(mark->biased_locker() == THREAD &&
641 prototype_header->bias_epoch() == mark->bias_epoch(), "Revoke failed, unhandled biased lock state");
642 ResourceMark rm;
643 log_info(biasedlocking)("Revoking bias by walking my own stack:");
644 EventBiasedLockSelfRevocation event;
645 BiasedLocking::Condition cond = revoke_bias(obj(), false, false, (JavaThread*) THREAD, NULL);
646 ((JavaThread*) THREAD)->set_cached_monitor_info(NULL);
647 assert(cond == BIAS_REVOKED, "why not?");
648 if (event.should_commit()) {
649 post_self_revocation_event(&event, k);
650 }
651 return cond;
652 }
653
654 BiasedLocking::Condition BiasedLocking::revoke_and_rebias(Handle obj, bool attempt_rebias, TRAPS) {
655 assert(!SafepointSynchronize::is_at_safepoint(), "must not be called while at safepoint");
656
657 // We can revoke the biases of anonymously-biased objects
658 // efficiently enough that we should not cause these revocations to
659 // update the heuristics because doing so may cause unwanted bulk
660 // revocations (which are expensive) to occur.
661 markOop mark = obj->mark();
662 if (mark->is_biased_anonymously() && !attempt_rebias) {
663 // We are probably trying to revoke the bias of this object due to
664 // an identity hash code computation. Try to revoke the bias
665 // without a safepoint. This is possible if we can successfully
666 // compare-and-exchange an unbiased header into the mark word of
667 // the object, meaning that no other thread has raced to acquire
668 // the bias of the object.
669 markOop biased_value = mark;
670 markOop unbiased_prototype = markOopDesc::prototype()->set_age(mark->age());
671 markOop res_mark = obj->cas_set_mark(unbiased_prototype, mark);
672 if (res_mark == biased_value) {
673 return BIAS_REVOKED;
|