709 }
710 if (highest_lock != NULL) {
711 // Fix up highest lock to contain displaced header and point
712 // object at it
713 highest_lock->set_displaced_header(unbiased_prototype);
714 // Reset object header to point to displaced mark.
715 // Must release store the lock address for platforms without TSO
716 // ordering (e.g. ppc).
717 obj->release_set_mark(markWord::encode(highest_lock));
718 assert(!obj->mark().has_bias_pattern(), "illegal mark state: stack lock used bias bit");
719 log_info(biasedlocking)(" Revoked bias of currently-locked object");
720 } else {
721 log_info(biasedlocking)(" Revoked bias of currently-unlocked object");
722 // Store the unlocked value into the object's header.
723 obj->set_mark(unbiased_prototype);
724 }
725
726 assert(!obj->mark().has_bias_pattern(), "must not be biased");
727 }
728
729
730 void BiasedLocking::revoke(Handle obj, TRAPS) {
731 assert(!SafepointSynchronize::is_at_safepoint(), "must not be called while at safepoint");
732
733 while (true) {
734 // We can revoke the biases of anonymously-biased objects
735 // efficiently enough that we should not cause these revocations to
736 // update the heuristics because doing so may cause unwanted bulk
737 // revocations (which are expensive) to occur.
738 markWord mark = obj->mark();
739
740 if (!mark.has_bias_pattern()) {
741 return;
742 }
743
744 if (mark.is_biased_anonymously()) {
745 // We are probably trying to revoke the bias of this object due to
746 // an identity hash code computation. Try to revoke the bias
747 // without a safepoint. This is possible if we can successfully
748 // compare-and-exchange an unbiased header into the mark word of
844 clean_up_cached_monitor_info(biaser);
845 }
846 }
847
848
849 void BiasedLocking::revoke_at_safepoint(Handle h_obj) {
850 assert(SafepointSynchronize::is_at_safepoint(), "must only be called while at safepoint");
851 oop obj = h_obj();
852 HeuristicsResult heuristics = update_heuristics(obj);
853 if (heuristics == HR_SINGLE_REVOKE) {
854 JavaThread* biased_locker = NULL;
855 single_revoke_at_safepoint(obj, false, NULL, &biased_locker);
856 if (biased_locker) {
857 clean_up_cached_monitor_info(biased_locker);
858 }
859 } else if ((heuristics == HR_BULK_REBIAS) ||
860 (heuristics == HR_BULK_REVOKE)) {
861 bulk_revoke_at_safepoint(obj, (heuristics == HR_BULK_REBIAS), NULL);
862 clean_up_cached_monitor_info();
863 }
864 }
865
866
867 void BiasedLocking::revoke_at_safepoint(GrowableArray<Handle>* objs) {
868 assert(SafepointSynchronize::is_at_safepoint(), "must only be called while at safepoint");
869 int len = objs->length();
870 for (int i = 0; i < len; i++) {
871 oop obj = (objs->at(i))();
872 HeuristicsResult heuristics = update_heuristics(obj);
873 if (heuristics == HR_SINGLE_REVOKE) {
874 single_revoke_at_safepoint(obj, false, NULL, NULL);
875 } else if ((heuristics == HR_BULK_REBIAS) ||
876 (heuristics == HR_BULK_REVOKE)) {
877 bulk_revoke_at_safepoint(obj, (heuristics == HR_BULK_REBIAS), NULL);
878 }
879 }
880 clean_up_cached_monitor_info();
881 }
882
883
884 void BiasedLocking::preserve_marks() {
885 if (!UseBiasedLocking)
886 return;
887
888 assert(SafepointSynchronize::is_at_safepoint(), "must only be called while at safepoint");
889
890 assert(_preserved_oop_stack == NULL, "double initialization");
891 assert(_preserved_mark_stack == NULL, "double initialization");
892
893 // In order to reduce the number of mark words preserved during GC
894 // due to the presence of biased locking, we reinitialize most mark
895 // words to the class's prototype during GC -- even those which have
896 // a currently valid bias owner. One important situation where we
897 // must not clobber a bias is when a biased object is currently
898 // locked. To handle this case we iterate over the currently-locked
899 // monitors in a prepass and, if they are biased, preserve their
900 // mark words here. This should be a relatively small set of objects
|
709 }
710 if (highest_lock != NULL) {
711 // Fix up highest lock to contain displaced header and point
712 // object at it
713 highest_lock->set_displaced_header(unbiased_prototype);
714 // Reset object header to point to displaced mark.
715 // Must release store the lock address for platforms without TSO
716 // ordering (e.g. ppc).
717 obj->release_set_mark(markWord::encode(highest_lock));
718 assert(!obj->mark().has_bias_pattern(), "illegal mark state: stack lock used bias bit");
719 log_info(biasedlocking)(" Revoked bias of currently-locked object");
720 } else {
721 log_info(biasedlocking)(" Revoked bias of currently-unlocked object");
722 // Store the unlocked value into the object's header.
723 obj->set_mark(unbiased_prototype);
724 }
725
726 assert(!obj->mark().has_bias_pattern(), "must not be biased");
727 }
728
729 void BiasedLocking::revoke_own_lock(Handle obj, TRAPS) {
730 assert(THREAD->is_Java_thread(), "must be called by a JavaThread");
731 JavaThread* thread = (JavaThread*)THREAD;
732
733 markWord mark = obj->mark();
734
735 if (!mark.has_bias_pattern()) {
736 return;
737 }
738
739 Klass *k = obj->klass();
740 assert(mark.biased_locker() == thread &&
741 k->prototype_header().bias_epoch() == mark.bias_epoch(), "Revoke failed, unhandled biased lock state");
742 ResourceMark rm;
743 log_info(biasedlocking)("Revoking bias by walking my own stack:");
744 EventBiasedLockSelfRevocation event;
745 BiasedLocking::walk_stack_and_revoke(obj(), (JavaThread*) thread);
746 thread->set_cached_monitor_info(NULL);
747 assert(!obj->mark().has_bias_pattern(), "invariant");
748 if (event.should_commit()) {
749 post_self_revocation_event(&event, k);
750 }
751 }
752
753 void BiasedLocking::revoke(Handle obj, TRAPS) {
754 assert(!SafepointSynchronize::is_at_safepoint(), "must not be called while at safepoint");
755
756 while (true) {
757 // We can revoke the biases of anonymously-biased objects
758 // efficiently enough that we should not cause these revocations to
759 // update the heuristics because doing so may cause unwanted bulk
760 // revocations (which are expensive) to occur.
761 markWord mark = obj->mark();
762
763 if (!mark.has_bias_pattern()) {
764 return;
765 }
766
767 if (mark.is_biased_anonymously()) {
768 // We are probably trying to revoke the bias of this object due to
769 // an identity hash code computation. Try to revoke the bias
770 // without a safepoint. This is possible if we can successfully
771 // compare-and-exchange an unbiased header into the mark word of
867 clean_up_cached_monitor_info(biaser);
868 }
869 }
870
871
872 void BiasedLocking::revoke_at_safepoint(Handle h_obj) {
873 assert(SafepointSynchronize::is_at_safepoint(), "must only be called while at safepoint");
874 oop obj = h_obj();
875 HeuristicsResult heuristics = update_heuristics(obj);
876 if (heuristics == HR_SINGLE_REVOKE) {
877 JavaThread* biased_locker = NULL;
878 single_revoke_at_safepoint(obj, false, NULL, &biased_locker);
879 if (biased_locker) {
880 clean_up_cached_monitor_info(biased_locker);
881 }
882 } else if ((heuristics == HR_BULK_REBIAS) ||
883 (heuristics == HR_BULK_REVOKE)) {
884 bulk_revoke_at_safepoint(obj, (heuristics == HR_BULK_REBIAS), NULL);
885 clean_up_cached_monitor_info();
886 }
887 }
888
889
890 void BiasedLocking::preserve_marks() {
891 if (!UseBiasedLocking)
892 return;
893
894 assert(SafepointSynchronize::is_at_safepoint(), "must only be called while at safepoint");
895
896 assert(_preserved_oop_stack == NULL, "double initialization");
897 assert(_preserved_mark_stack == NULL, "double initialization");
898
899 // In order to reduce the number of mark words preserved during GC
900 // due to the presence of biased locking, we reinitialize most mark
901 // words to the class's prototype during GC -- even those which have
902 // a currently valid bias owner. One important situation where we
903 // must not clobber a bias is when a biased object is currently
904 // locked. To handle this case we iterate over the currently-locked
905 // monitors in a prepass and, if they are biased, preserve their
906 // mark words here. This should be a relatively small set of objects
|