21 * questions. |
21 * questions. |
22 * |
22 * |
23 */ |
23 */ |
24 |
24 |
25 #include "precompiled.hpp" |
25 #include "precompiled.hpp" |
|
26 #include "jfr/jfrEvents.hpp" |
|
27 #include "jfr/support/jfrThreadId.hpp" |
26 #include "logging/log.hpp" |
28 #include "logging/log.hpp" |
27 #include "memory/resourceArea.hpp" |
29 #include "memory/resourceArea.hpp" |
28 #include "oops/klass.inline.hpp" |
30 #include "oops/klass.inline.hpp" |
29 #include "oops/markOop.hpp" |
31 #include "oops/markOop.hpp" |
30 #include "oops/oop.inline.hpp" |
32 #include "oops/oop.inline.hpp" |
35 #include "runtime/task.hpp" |
37 #include "runtime/task.hpp" |
36 #include "runtime/threadSMR.hpp" |
38 #include "runtime/threadSMR.hpp" |
37 #include "runtime/vframe.hpp" |
39 #include "runtime/vframe.hpp" |
38 #include "runtime/vmThread.hpp" |
40 #include "runtime/vmThread.hpp" |
39 #include "runtime/vm_operations.hpp" |
41 #include "runtime/vm_operations.hpp" |
40 #include "trace/tracing.hpp" |
42 |
41 |
43 |
42 static bool _biased_locking_enabled = false; |
44 static bool _biased_locking_enabled = false; |
43 BiasedLockingCounters BiasedLocking::_counters; |
45 BiasedLockingCounters BiasedLocking::_counters; |
44 |
46 |
45 static GrowableArray<Handle>* _preserved_oop_stack = NULL; |
47 static GrowableArray<Handle>* _preserved_oop_stack = NULL; |
538 if (_obj != NULL) { |
540 if (_obj != NULL) { |
539 log_info(biasedlocking)("Revoking bias with potentially per-thread safepoint:"); |
541 log_info(biasedlocking)("Revoking bias with potentially per-thread safepoint:"); |
540 JavaThread* biased_locker = NULL; |
542 JavaThread* biased_locker = NULL; |
541 _status_code = revoke_bias((*_obj)(), false, false, _requesting_thread, &biased_locker); |
543 _status_code = revoke_bias((*_obj)(), false, false, _requesting_thread, &biased_locker); |
542 if (biased_locker != NULL) { |
544 if (biased_locker != NULL) { |
543 _biased_locker_id = THREAD_TRACE_ID(biased_locker); |
545 _biased_locker_id = JFR_THREAD_ID(biased_locker); |
544 } |
546 } |
545 clean_up_cached_monitor_info(); |
547 clean_up_cached_monitor_info(); |
546 return; |
548 return; |
547 } else { |
549 } else { |
548 log_info(biasedlocking)("Revoking bias with global safepoint:"); |
550 log_info(biasedlocking)("Revoking bias with global safepoint:"); |
580 _status_code = bulk_revoke_or_rebias_at_safepoint((*_obj)(), _bulk_rebias, _attempt_rebias_of_object, _requesting_thread); |
582 _status_code = bulk_revoke_or_rebias_at_safepoint((*_obj)(), _bulk_rebias, _attempt_rebias_of_object, _requesting_thread); |
581 clean_up_cached_monitor_info(); |
583 clean_up_cached_monitor_info(); |
582 } |
584 } |
583 }; |
585 }; |
584 |
586 |
|
587 template <typename E> |
|
588 static void set_safepoint_id(E* event) { |
|
589 assert(event != NULL, "invariant"); |
|
590 // Subtract 1 to match the id of events committed inside the safepoint |
|
591 event->set_safepointId(SafepointSynchronize::safepoint_counter() - 1); |
|
592 } |
|
593 |
|
594 static void post_self_revocation_event(EventBiasedLockSelfRevocation* event, Klass* k) { |
|
595 assert(event != NULL, "invariant"); |
|
596 assert(k != NULL, "invariant"); |
|
597 assert(event->should_commit(), "invariant"); |
|
598 event->set_lockClass(k); |
|
599 event->commit(); |
|
600 } |
|
601 |
|
602 static void post_revocation_event(EventBiasedLockRevocation* event, Klass* k, VM_RevokeBias* revoke) { |
|
603 assert(event != NULL, "invariant"); |
|
604 assert(k != NULL, "invariant"); |
|
605 assert(revoke != NULL, "invariant"); |
|
606 assert(event->should_commit(), "invariant"); |
|
607 event->set_lockClass(k); |
|
608 set_safepoint_id(event); |
|
609 event->set_previousOwner(revoke->biased_locker()); |
|
610 event->commit(); |
|
611 } |
|
612 |
|
613 static void post_class_revocation_event(EventBiasedLockClassRevocation* event, Klass* k, bool disabled_bias) { |
|
614 assert(event != NULL, "invariant"); |
|
615 assert(k != NULL, "invariant"); |
|
616 assert(event->should_commit(), "invariant"); |
|
617 event->set_revokedClass(k); |
|
618 event->set_disableBiasing(disabled_bias); |
|
619 set_safepoint_id(event); |
|
620 event->commit(); |
|
621 } |
585 |
622 |
586 BiasedLocking::Condition BiasedLocking::revoke_and_rebias(Handle obj, bool attempt_rebias, TRAPS) { |
623 BiasedLocking::Condition BiasedLocking::revoke_and_rebias(Handle obj, bool attempt_rebias, TRAPS) { |
587 assert(!SafepointSynchronize::is_at_safepoint(), "must not be called while at safepoint"); |
624 assert(!SafepointSynchronize::is_at_safepoint(), "must not be called while at safepoint"); |
588 |
625 |
589 // We can revoke the biases of anonymously-biased objects |
626 // We can revoke the biases of anonymously-biased objects |
667 EventBiasedLockSelfRevocation event; |
704 EventBiasedLockSelfRevocation event; |
668 BiasedLocking::Condition cond = revoke_bias(obj(), false, false, (JavaThread*) THREAD, NULL); |
705 BiasedLocking::Condition cond = revoke_bias(obj(), false, false, (JavaThread*) THREAD, NULL); |
669 ((JavaThread*) THREAD)->set_cached_monitor_info(NULL); |
706 ((JavaThread*) THREAD)->set_cached_monitor_info(NULL); |
670 assert(cond == BIAS_REVOKED, "why not?"); |
707 assert(cond == BIAS_REVOKED, "why not?"); |
671 if (event.should_commit()) { |
708 if (event.should_commit()) { |
672 event.set_lockClass(k); |
709 post_self_revocation_event(&event, k); |
673 event.commit(); |
|
674 } |
710 } |
675 return cond; |
711 return cond; |
676 } else { |
712 } else { |
677 EventBiasedLockRevocation event; |
713 EventBiasedLockRevocation event; |
678 VM_RevokeBias revoke(&obj, (JavaThread*) THREAD); |
714 VM_RevokeBias revoke(&obj, (JavaThread*) THREAD); |
679 VMThread::execute(&revoke); |
715 VMThread::execute(&revoke); |
680 if (event.should_commit() && (revoke.status_code() != NOT_BIASED)) { |
716 if (event.should_commit() && revoke.status_code() != NOT_BIASED) { |
681 event.set_lockClass(k); |
717 post_revocation_event(&event, k, &revoke); |
682 // Subtract 1 to match the id of events committed inside the safepoint |
|
683 event.set_safepointId(SafepointSynchronize::safepoint_counter() - 1); |
|
684 event.set_previousOwner(revoke.biased_locker()); |
|
685 event.commit(); |
|
686 } |
718 } |
687 return revoke.status_code(); |
719 return revoke.status_code(); |
688 } |
720 } |
689 } |
721 } |
690 |
722 |
694 VM_BulkRevokeBias bulk_revoke(&obj, (JavaThread*) THREAD, |
726 VM_BulkRevokeBias bulk_revoke(&obj, (JavaThread*) THREAD, |
695 (heuristics == HR_BULK_REBIAS), |
727 (heuristics == HR_BULK_REBIAS), |
696 attempt_rebias); |
728 attempt_rebias); |
697 VMThread::execute(&bulk_revoke); |
729 VMThread::execute(&bulk_revoke); |
698 if (event.should_commit()) { |
730 if (event.should_commit()) { |
699 event.set_revokedClass(obj->klass()); |
731 post_class_revocation_event(&event, obj->klass(), heuristics != HR_BULK_REBIAS); |
700 event.set_disableBiasing((heuristics != HR_BULK_REBIAS)); |
|
701 // Subtract 1 to match the id of events committed inside the safepoint |
|
702 event.set_safepointId(SafepointSynchronize::safepoint_counter() - 1); |
|
703 event.commit(); |
|
704 } |
732 } |
705 return bulk_revoke.status_code(); |
733 return bulk_revoke.status_code(); |
706 } |
734 } |
707 |
735 |
708 |
736 |