< prev index next >

src/hotspot/share/runtime/synchronizer.cpp

Print this page

 696   ObjectMonitor* monitor;
 697   if (LockingMode == LM_LIGHTWEIGHT) {
 698     monitor = LightweightSynchronizer::inflate_locked_or_imse(obj, inflate_cause_jni_exit, CHECK);
 699   } else {
 700     // The ObjectMonitor* can't be async deflated until ownership is
 701     // dropped inside exit() and the ObjectMonitor* must be !is_busy().
 702     monitor = inflate(current, obj, inflate_cause_jni_exit);
 703   }
 704   // If this thread has locked the object, exit the monitor. We
 705   // intentionally do not use CHECK on check_owner because we must exit the
 706   // monitor even if an exception was already pending.
 707   if (monitor->check_owner(THREAD)) {
 708     monitor->exit(current);
 709     current->dec_held_monitor_count(1, true);
 710   }
 711 }
 712 
 713 // -----------------------------------------------------------------------------
 714 // Internal VM locks on java objects
 715 // standard constructor, allows locking failures
 716 ObjectLocker::ObjectLocker(Handle obj, JavaThread* thread) : _npm(thread) {
 717   _thread = thread;


 718   _thread->check_for_valid_safepoint_state();
 719   _obj = obj;
 720 
 721   if (_obj() != nullptr) {
 722     ObjectSynchronizer::enter(_obj, &_lock, _thread);












 723   }
 724 }
 725 
 726 ObjectLocker::~ObjectLocker() {
 727   if (_obj() != nullptr) {
 728     ObjectSynchronizer::exit(_obj(), &_lock, _thread);
 729   }
 730 }
 731 








 732 
 733 // -----------------------------------------------------------------------------
 734 //  Wait/Notify/NotifyAll
 735 // NOTE: must use heavy weight monitor to handle wait()
 736 
 737 int ObjectSynchronizer::wait(Handle obj, jlong millis, TRAPS) {
 738   JavaThread* current = THREAD;
 739   if (millis < 0) {
 740     THROW_MSG_0(vmSymbols::java_lang_IllegalArgumentException(), "timeout value is negative");
 741   }
 742 
 743   ObjectMonitor* monitor;
 744   if (LockingMode == LM_LIGHTWEIGHT) {
 745     monitor = LightweightSynchronizer::inflate_locked_or_imse(obj(), inflate_cause_wait, CHECK_0);
 746   } else {
 747     // The ObjectMonitor* can't be async deflated because the _waiters
 748     // field is incremented before ownership is dropped and decremented
 749     // after ownership is regained.
 750     monitor = inflate(current, obj(), inflate_cause_wait);
 751   }
 752 
 753   DTRACE_MONITOR_WAIT_PROBE(monitor, obj(), current, millis);
 754   monitor->wait(millis, true, THREAD); // Not CHECK as we need following code
 755 
 756   // This dummy call is in place to get around dtrace bug 6254741.  Once
 757   // that's fixed we can uncomment the following line, remove the call
 758   // and change this function back into a "void" func.
 759   // DTRACE_MONITOR_PROBE(waited, monitor, obj(), THREAD);
 760   int ret_code = dtrace_waited_probe(monitor, obj, THREAD);
 761   return ret_code;
 762 }
 763 
 764 void ObjectSynchronizer::waitUninterruptibly(Handle obj, jlong millis, TRAPS) {
 765   if (millis < 0) {
 766     THROW_MSG(vmSymbols::java_lang_IllegalArgumentException(), "timeout value is negative");
 767   }
 768 
 769   ObjectMonitor* monitor;
 770   if (LockingMode == LM_LIGHTWEIGHT) {
 771     monitor = LightweightSynchronizer::inflate_locked_or_imse(obj(), inflate_cause_wait, CHECK);
 772   } else {
 773     monitor = inflate(THREAD, obj(), inflate_cause_wait);
 774   }
 775   monitor->wait(millis, false, THREAD);
 776 }
 777 
 778 
 779 void ObjectSynchronizer::notify(Handle obj, TRAPS) {
 780   JavaThread* current = THREAD;
 781 
 782   markWord mark = obj->mark();
 783   if (LockingMode == LM_LIGHTWEIGHT) {
 784     if ((mark.is_fast_locked() && current->lock_stack().contains(obj()))) {
 785       // Not inflated so there can't be any waiters to notify.
 786       return;
 787     }

 696   ObjectMonitor* monitor;
 697   if (LockingMode == LM_LIGHTWEIGHT) {
 698     monitor = LightweightSynchronizer::inflate_locked_or_imse(obj, inflate_cause_jni_exit, CHECK);
 699   } else {
 700     // The ObjectMonitor* can't be async deflated until ownership is
 701     // dropped inside exit() and the ObjectMonitor* must be !is_busy().
 702     monitor = inflate(current, obj, inflate_cause_jni_exit);
 703   }
 704   // If this thread has locked the object, exit the monitor. We
 705   // intentionally do not use CHECK on check_owner because we must exit the
 706   // monitor even if an exception was already pending.
 707   if (monitor->check_owner(THREAD)) {
 708     monitor->exit(current);
 709     current->dec_held_monitor_count(1, true);
 710   }
 711 }
 712 
 713 // -----------------------------------------------------------------------------
 714 // Internal VM locks on java objects
 715 // standard constructor, allows locking failures
 716 ObjectLocker::ObjectLocker(Handle obj, TRAPS) : _thread(THREAD), _obj(obj),
 717   _npm(_thread, _thread->at_preemptable_init() /* ignore_mark */), _skip_exit(false) {
 718   assert(!_thread->preempting(), "");
 719 
 720   _thread->check_for_valid_safepoint_state();

 721 
 722   if (_obj() != nullptr) {
 723     ObjectSynchronizer::enter(_obj, &_lock, _thread);
 724 
 725     if (_thread->preempting()) {
 726       // If preemption was cancelled we acquired the monitor after freezing
 727       // the frames. Redoing the vm call laterĀ in thaw will require us to
 728       // release it since the call should look like the original one. We
 729       // do it in ~ObjectLocker to reduce the window of time we hold the
 730       // monitor since we can't do anything useful with it now, and would
 731       // otherwise just force other vthreads to preempt in case they try
 732       // to acquire this monitor.
 733       _skip_exit = !_thread->preemption_cancelled();
 734       _thread->set_pending_preempted_exception();
 735     }
 736   }
 737 }
 738 
 739 ObjectLocker::~ObjectLocker() {
 740   if (_obj() != nullptr && !_skip_exit) {
 741     ObjectSynchronizer::exit(_obj(), &_lock, _thread);
 742   }
 743 }
 744 
 745 void ObjectLocker::wait_uninterruptibly(TRAPS) {
 746   ObjectSynchronizer::waitUninterruptibly(_obj, 0, _thread);
 747   if (_thread->preempting()) {
 748     _skip_exit = true;
 749     _thread->set_pending_preempted_exception();
 750     _thread->set_class_to_be_initialized(nullptr);
 751   }
 752 }
 753 
 754 // -----------------------------------------------------------------------------
 755 //  Wait/Notify/NotifyAll
 756 // NOTE: must use heavy weight monitor to handle wait()
 757 
 758 int ObjectSynchronizer::wait(Handle obj, jlong millis, TRAPS) {
 759   JavaThread* current = THREAD;
 760   if (millis < 0) {
 761     THROW_MSG_0(vmSymbols::java_lang_IllegalArgumentException(), "timeout value is negative");
 762   }
 763 
 764   ObjectMonitor* monitor;
 765   if (LockingMode == LM_LIGHTWEIGHT) {
 766     monitor = LightweightSynchronizer::inflate_locked_or_imse(obj(), inflate_cause_wait, CHECK_0);
 767   } else {
 768     // The ObjectMonitor* can't be async deflated because the _waiters
 769     // field is incremented before ownership is dropped and decremented
 770     // after ownership is regained.
 771     monitor = inflate(current, obj(), inflate_cause_wait);
 772   }
 773 
 774   DTRACE_MONITOR_WAIT_PROBE(monitor, obj(), current, millis);
 775   monitor->wait(millis, true, THREAD); // Not CHECK as we need following code
 776 
 777   // This dummy call is in place to get around dtrace bug 6254741.  Once
 778   // that's fixed we can uncomment the following line, remove the call
 779   // and change this function back into a "void" func.
 780   // DTRACE_MONITOR_PROBE(waited, monitor, obj(), THREAD);
 781   int ret_code = dtrace_waited_probe(monitor, obj, THREAD);
 782   return ret_code;
 783 }
 784 
 785 void ObjectSynchronizer::waitUninterruptibly(Handle obj, jlong millis, TRAPS) {
 786   assert(millis >= 0, "timeout value is negative");


 787 
 788   ObjectMonitor* monitor;
 789   if (LockingMode == LM_LIGHTWEIGHT) {
 790     monitor = LightweightSynchronizer::inflate_locked_or_imse(obj(), inflate_cause_wait, CHECK);
 791   } else {
 792     monitor = inflate(THREAD, obj(), inflate_cause_wait);
 793   }
 794   monitor->wait(millis, false, THREAD);
 795 }
 796 
 797 
 798 void ObjectSynchronizer::notify(Handle obj, TRAPS) {
 799   JavaThread* current = THREAD;
 800 
 801   markWord mark = obj->mark();
 802   if (LockingMode == LM_LIGHTWEIGHT) {
 803     if ((mark.is_fast_locked() && current->lock_stack().contains(obj()))) {
 804       // Not inflated so there can't be any waiters to notify.
 805       return;
 806     }
< prev index next >