5959#include " utilities/globalDefinitions.hpp"
6060#include " utilities/macros.hpp"
6161#include " utilities/preserveException.hpp"
62+ #include " utilities/spinCriticalSection.hpp"
6263#if INCLUDE_JFR
6364#include " jfr/support/jfrFlush.hpp"
6465#endif
@@ -1863,9 +1864,10 @@ void ObjectMonitor::wait(jlong millis, bool interruptible, TRAPS) {
18631864 // returns because of a timeout of interrupt. Contention is exceptionally rare
18641865 // so we use a simple spin-lock instead of a heavier-weight blocking lock.
18651866
1866- Thread::SpinAcquire (&_wait_set_lock);
1867- add_waiter (&node);
1868- Thread::SpinRelease (&_wait_set_lock);
1867+ {
1868+ SpinCriticalSection scs (&_wait_set_lock);
1869+ add_waiter (&node);
1870+ }
18691871
18701872 intx save = _recursions; // record the old recursion count
18711873 _waiters++; // increment the number of waiters
@@ -1922,12 +1924,11 @@ void ObjectMonitor::wait(jlong millis, bool interruptible, TRAPS) {
19221924 // That is, we fail toward safety.
19231925
19241926 if (node.TState == ObjectWaiter::TS_WAIT) {
1925- Thread::SpinAcquire (&_wait_set_lock);
1927+ SpinCriticalSection scs (&_wait_set_lock);
19261928 if (node.TState == ObjectWaiter::TS_WAIT) {
19271929 dequeue_specific_waiter (&node); // unlink from wait_set
19281930 node.TState = ObjectWaiter::TS_RUN;
19291931 }
1930- Thread::SpinRelease (&_wait_set_lock);
19311932 }
19321933
19331934 // The thread is now either on off-list (TS_RUN),
@@ -2036,7 +2037,7 @@ void ObjectMonitor::wait(jlong millis, bool interruptible, TRAPS) {
20362037
20372038bool ObjectMonitor::notify_internal (JavaThread* current) {
20382039 bool did_notify = false ;
2039- Thread::SpinAcquire (&_wait_set_lock);
2040+ SpinCriticalSection scs (&_wait_set_lock);
20402041 ObjectWaiter* iterator = dequeue_waiter ();
20412042 if (iterator != nullptr ) {
20422043 guarantee (iterator->TState == ObjectWaiter::TS_WAIT, " invariant" );
@@ -2095,7 +2096,6 @@ bool ObjectMonitor::notify_internal(JavaThread* current) {
20952096 }
20962097 }
20972098 }
2098- Thread::SpinRelease (&_wait_set_lock);
20992099 return did_notify;
21002100}
21012101
@@ -2198,9 +2198,10 @@ void ObjectMonitor::vthread_wait(JavaThread* current, jlong millis, bool interru
21982198 // returns because of a timeout or interrupt. Contention is exceptionally rare
21992199 // so we use a simple spin-lock instead of a heavier-weight blocking lock.
22002200
2201- Thread::SpinAcquire (&_wait_set_lock);
2202- add_waiter (node);
2203- Thread::SpinRelease (&_wait_set_lock);
2201+ {
2202+ SpinCriticalSection scs (&_wait_set_lock);
2203+ add_waiter (node);
2204+ }
22042205
22052206 node->_recursions = _recursions; // record the old recursion count
22062207 _recursions = 0 ; // set the recursion level to be 0
@@ -2221,12 +2222,11 @@ bool ObjectMonitor::vthread_wait_reenter(JavaThread* current, ObjectWaiter* node
22212222 // need to check if we were interrupted or the wait timed-out, and
22222223 // in that case remove ourselves from the _wait_set queue.
22232224 if (node->TState == ObjectWaiter::TS_WAIT) {
2224- Thread::SpinAcquire (&_wait_set_lock);
2225+ SpinCriticalSection scs (&_wait_set_lock);
22252226 if (node->TState == ObjectWaiter::TS_WAIT) {
22262227 dequeue_specific_waiter (node); // unlink from wait_set
22272228 node->TState = ObjectWaiter::TS_RUN;
22282229 }
2229- Thread::SpinRelease (&_wait_set_lock);
22302230 }
22312231
22322232 // If this was an interrupted case, set the _interrupted boolean so that
0 commit comments