695 ObjectMonitor* monitor;
696 if (LockingMode == LM_LIGHTWEIGHT) {
697 monitor = LightweightSynchronizer::inflate_locked_or_imse(obj, inflate_cause_jni_exit, CHECK);
698 } else {
699 // The ObjectMonitor* can't be async deflated until ownership is
700 // dropped inside exit() and the ObjectMonitor* must be !is_busy().
701 monitor = inflate(current, obj, inflate_cause_jni_exit);
702 }
703 // If this thread has locked the object, exit the monitor. We
704 // intentionally do not use CHECK on check_owner because we must exit the
705 // monitor even if an exception was already pending.
706 if (monitor->check_owner(THREAD)) {
707 monitor->exit(current);
708 current->dec_held_monitor_count(1, true);
709 }
710 }
711
712 // -----------------------------------------------------------------------------
713 // Internal VM locks on java objects
714 // standard constructor, allows locking failures
715 ObjectLocker::ObjectLocker(Handle obj, JavaThread* thread) : _npm(thread) {
716 _thread = thread;
717 _thread->check_for_valid_safepoint_state();
718 _obj = obj;
719
720 if (_obj() != nullptr) {
721 ObjectSynchronizer::enter(_obj, &_lock, _thread);
722 }
723 }
724
725 ObjectLocker::~ObjectLocker() {
726 if (_obj() != nullptr) {
727 ObjectSynchronizer::exit(_obj(), &_lock, _thread);
728 }
729 }
730
731
732 // -----------------------------------------------------------------------------
733 // Wait/Notify/NotifyAll
734 // NOTE: must use heavy weight monitor to handle wait()
735
736 int ObjectSynchronizer::wait(Handle obj, jlong millis, TRAPS) {
737 JavaThread* current = THREAD;
738 if (millis < 0) {
739 THROW_MSG_0(vmSymbols::java_lang_IllegalArgumentException(), "timeout value is negative");
740 }
741
742 ObjectMonitor* monitor;
743 if (LockingMode == LM_LIGHTWEIGHT) {
744 monitor = LightweightSynchronizer::inflate_locked_or_imse(obj(), inflate_cause_wait, CHECK_0);
745 } else {
746 // The ObjectMonitor* can't be async deflated because the _waiters
747 // field is incremented before ownership is dropped and decremented
748 // after ownership is regained.
749 monitor = inflate(current, obj(), inflate_cause_wait);
750 }
751
752 DTRACE_MONITOR_WAIT_PROBE(monitor, obj(), current, millis);
753 monitor->wait(millis, true, THREAD); // Not CHECK as we need following code
754
755 // This dummy call is in place to get around dtrace bug 6254741. Once
756 // that's fixed we can uncomment the following line, remove the call
757 // and change this function back into a "void" func.
758 // DTRACE_MONITOR_PROBE(waited, monitor, obj(), THREAD);
759 int ret_code = dtrace_waited_probe(monitor, obj, THREAD);
760 return ret_code;
761 }
762
763 void ObjectSynchronizer::waitUninterruptibly(Handle obj, jlong millis, TRAPS) {
764 if (millis < 0) {
765 THROW_MSG(vmSymbols::java_lang_IllegalArgumentException(), "timeout value is negative");
766 }
767
768 ObjectMonitor* monitor;
769 if (LockingMode == LM_LIGHTWEIGHT) {
770 monitor = LightweightSynchronizer::inflate_locked_or_imse(obj(), inflate_cause_wait, CHECK);
771 } else {
772 monitor = inflate(THREAD, obj(), inflate_cause_wait);
773 }
774 monitor->wait(millis, false, THREAD);
775 }
776
777
778 void ObjectSynchronizer::notify(Handle obj, TRAPS) {
779 JavaThread* current = THREAD;
780
781 markWord mark = obj->mark();
782 if (LockingMode == LM_LIGHTWEIGHT) {
783 if ((mark.is_fast_locked() && current->lock_stack().contains(obj()))) {
784 // Not inflated so there can't be any waiters to notify.
785 return;
786 }
|
695 ObjectMonitor* monitor;
696 if (LockingMode == LM_LIGHTWEIGHT) {
697 monitor = LightweightSynchronizer::inflate_locked_or_imse(obj, inflate_cause_jni_exit, CHECK);
698 } else {
699 // The ObjectMonitor* can't be async deflated until ownership is
700 // dropped inside exit() and the ObjectMonitor* must be !is_busy().
701 monitor = inflate(current, obj, inflate_cause_jni_exit);
702 }
703 // If this thread has locked the object, exit the monitor. We
704 // intentionally do not use CHECK on check_owner because we must exit the
705 // monitor even if an exception was already pending.
706 if (monitor->check_owner(THREAD)) {
707 monitor->exit(current);
708 current->dec_held_monitor_count(1, true);
709 }
710 }
711
712 // -----------------------------------------------------------------------------
713 // Internal VM locks on java objects
714 // standard constructor, allows locking failures
715 ObjectLocker::ObjectLocker(Handle obj, TRAPS) : _thread(THREAD), _obj(obj),
716 _npm(_thread, _thread->at_preemptable_init() /* ignore_mark */), _skip_exit(false) {
717 assert(!_thread->preempting(), "");
718
719 _thread->check_for_valid_safepoint_state();
720
721 if (_obj() != nullptr) {
722 ObjectSynchronizer::enter(_obj, &_lock, _thread);
723
724 if (_thread->preempting()) {
725 // If preemption was cancelled we acquired the monitor after freezing
726 // the frames. Redoing the vm call laterĀ in thaw will require us to
727 // release it since the call should look like the original one. We
728 // do it in ~ObjectLocker to reduce the window of time we hold the
729 // monitor since we can't do anything useful with it now, and would
730 // otherwise just force other vthreads to preempt in case they try
731 // to acquire this monitor.
732 _skip_exit = !_thread->preemption_cancelled();
733 _thread->set_pending_preempted_exception();
734 }
735 }
736 }
737
738 ObjectLocker::~ObjectLocker() {
739 if (_obj() != nullptr && !_skip_exit) {
740 ObjectSynchronizer::exit(_obj(), &_lock, _thread);
741 }
742 }
743
744 void ObjectLocker::wait_uninterruptibly(TRAPS) {
745 ObjectSynchronizer::waitUninterruptibly(_obj, 0, _thread);
746 if (_thread->preempting()) {
747 _skip_exit = true;
748 _thread->set_pending_preempted_exception();
749 }
750 }
751
752 // -----------------------------------------------------------------------------
753 // Wait/Notify/NotifyAll
754 // NOTE: must use heavy weight monitor to handle wait()
755
756 int ObjectSynchronizer::wait(Handle obj, jlong millis, TRAPS) {
757 JavaThread* current = THREAD;
758 if (millis < 0) {
759 THROW_MSG_0(vmSymbols::java_lang_IllegalArgumentException(), "timeout value is negative");
760 }
761
762 ObjectMonitor* monitor;
763 if (LockingMode == LM_LIGHTWEIGHT) {
764 monitor = LightweightSynchronizer::inflate_locked_or_imse(obj(), inflate_cause_wait, CHECK_0);
765 } else {
766 // The ObjectMonitor* can't be async deflated because the _waiters
767 // field is incremented before ownership is dropped and decremented
768 // after ownership is regained.
769 monitor = inflate(current, obj(), inflate_cause_wait);
770 }
771
772 DTRACE_MONITOR_WAIT_PROBE(monitor, obj(), current, millis);
773 monitor->wait(millis, true, THREAD); // Not CHECK as we need following code
774
775 // This dummy call is in place to get around dtrace bug 6254741. Once
776 // that's fixed we can uncomment the following line, remove the call
777 // and change this function back into a "void" func.
778 // DTRACE_MONITOR_PROBE(waited, monitor, obj(), THREAD);
779 int ret_code = dtrace_waited_probe(monitor, obj, THREAD);
780 return ret_code;
781 }
782
783 void ObjectSynchronizer::waitUninterruptibly(Handle obj, jlong millis, TRAPS) {
784 assert(millis >= 0, "timeout value is negative");
785
786 ObjectMonitor* monitor;
787 if (LockingMode == LM_LIGHTWEIGHT) {
788 monitor = LightweightSynchronizer::inflate_locked_or_imse(obj(), inflate_cause_wait, CHECK);
789 } else {
790 monitor = inflate(THREAD, obj(), inflate_cause_wait);
791 }
792 monitor->wait(millis, false, THREAD);
793 }
794
795
796 void ObjectSynchronizer::notify(Handle obj, TRAPS) {
797 JavaThread* current = THREAD;
798
799 markWord mark = obj->mark();
800 if (LockingMode == LM_LIGHTWEIGHT) {
801 if ((mark.is_fast_locked() && current->lock_stack().contains(obj()))) {
802 // Not inflated so there can't be any waiters to notify.
803 return;
804 }
|