--- old/src/hotspot/share/runtime/objectMonitor.cpp 2019-08-09 15:17:39.000000000 -0400 +++ new/src/hotspot/share/runtime/objectMonitor.cpp 2019-08-09 15:17:39.000000000 -0400 @@ -1143,14 +1143,24 @@ return; } -// Returns true if the specified thread owns the ObjectMonitor. Otherwise -// returns false and throws IllegalMonitorStateException (IMSE). This -// function is not called with CHECK because we want the IMSE to be the -// only exception that is thrown from the call site when false is returned. -// If an IMSE needs to be thrown, then it takes precedence over any pending -// exception at the call sites. If true is returned, then we don't throw -// any exception (pending or otherwise) at the call site. -bool ObjectMonitor::check_owner_and_throw_IMSE_if_not(Thread* THREAD) { +// Checks that the current THREAD owns this monitor and causes an +// immediate return if it doesn't. We don't use the CHECK macro +// because we want the IMSE to be the only exception that is thrown +// from the call site when false is returned. Any other pending +// exception is ignored. +#define CHECK_OWNER() \ + do { \ + if (!check_owner(THREAD)) { \ + assert(HAS_PENDING_EXCEPTION, "expected a pending IMSE here."); \ + return; \ + } \ + } while (false) + +// Returns true if the specified thread owns the ObjectMonitor. +// Otherwise returns false and throws IllegalMonitorStateException +// (IMSE). If there is a pending exception and the specified thread +// is not the owner, that exception will be replaced by the IMSE. +bool ObjectMonitor::check_owner(Thread* THREAD) { if (_owner == THREAD) { return true; } @@ -1190,10 +1200,7 @@ assert(InitDone, "Unexpectedly not initialized"); - if (!check_owner_and_throw_IMSE_if_not(THREAD)) { - assert(HAS_PENDING_EXCEPTION, "expected a pending exception here."); - return; - } + CHECK_OWNER(); // Throws IMSE if not owner. EventJavaMonitorWait event; @@ -1472,10 +1479,7 @@ // that suggests a lost wakeup bug. void ObjectMonitor::notify(TRAPS) { - if (!check_owner_and_throw_IMSE_if_not(THREAD)) { - assert(HAS_PENDING_EXCEPTION, "expected a pending exception here."); - return; - } + CHECK_OWNER(); // Throws IMSE if not owner. if (_WaitSet == NULL) { return; } @@ -1493,10 +1497,7 @@ // mode the waitset will be empty and the EntryList will be "DCBAXYZ". void ObjectMonitor::notifyAll(TRAPS) { - if (!check_owner_and_throw_IMSE_if_not(THREAD)) { - assert(HAS_PENDING_EXCEPTION, "expected a pending exception here."); - return; - } + CHECK_OWNER(); // Throws IMSE if not owner. if (_WaitSet == NULL) { return; }