1141 guarantee(_recursions == 0, "reenter recursion"); |
1141 guarantee(_recursions == 0, "reenter recursion"); |
1142 _recursions = recursions; |
1142 _recursions = recursions; |
1143 return; |
1143 return; |
1144 } |
1144 } |
1145 |
1145 |
1146 |
1146 // Checks that the current THREAD owns this monitor and causes an |
1147 // ----------------------------------------------------------------------------- |
1147 // immediate return if it doesn't. We don't use the CHECK macro |
1148 // A macro is used below because there may already be a pending |
1148 // because we want the IMSE to be the only exception that is thrown |
1149 // exception which should not abort the execution of the routines |
1149 // from the call site when false is returned. Any other pending |
1150 // which use this (which is why we don't put this into check_slow and |
1150 // exception is ignored. |
1151 // call it with a CHECK argument). |
1151 #define CHECK_OWNER() \ |
1152 |
1152 do { \ |
1153 #define CHECK_OWNER() \ |
1153 if (!check_owner(THREAD)) { \ |
1154 do { \ |
1154 assert(HAS_PENDING_EXCEPTION, "expected a pending IMSE here."); \ |
1155 if (THREAD != _owner) { \ |
1155 return; \ |
1156 if (THREAD->is_lock_owned((address) _owner)) { \ |
1156 } \ |
1157 _owner = THREAD; /* Convert from basiclock addr to Thread addr */ \ |
|
1158 _recursions = 0; \ |
|
1159 } else { \ |
|
1160 THROW(vmSymbols::java_lang_IllegalMonitorStateException()); \ |
|
1161 } \ |
|
1162 } \ |
|
1163 } while (false) |
1157 } while (false) |
1164 |
1158 |
1165 // check_slow() is a misnomer. It's called to simply to throw an IMSX exception. |
1159 // Returns true if the specified thread owns the ObjectMonitor. |
1166 // TODO-FIXME: remove check_slow() -- it's likely dead. |
1160 // Otherwise returns false and throws IllegalMonitorStateException |
1167 |
1161 // (IMSE). If there is a pending exception and the specified thread |
1168 void ObjectMonitor::check_slow(TRAPS) { |
1162 // is not the owner, that exception will be replaced by the IMSE. |
1169 assert(THREAD != _owner && !THREAD->is_lock_owned((address) _owner), "must not be owner"); |
1163 bool ObjectMonitor::check_owner(Thread* THREAD) { |
1170 THROW_MSG(vmSymbols::java_lang_IllegalMonitorStateException(), "current thread not owner"); |
1164 if (_owner == THREAD) { |
|
1165 return true; |
|
1166 } |
|
1167 if (THREAD->is_lock_owned((address)_owner)) { |
|
1168 _owner = THREAD; // convert from BasicLock addr to Thread addr |
|
1169 _recursions = 0; |
|
1170 return true; |
|
1171 } |
|
1172 THROW_MSG_(vmSymbols::java_lang_IllegalMonitorStateException(), |
|
1173 "current thread is not owner", false); |
1171 } |
1174 } |
1172 |
1175 |
1173 static void post_monitor_wait_event(EventJavaMonitorWait* event, |
1176 static void post_monitor_wait_event(EventJavaMonitorWait* event, |
1174 ObjectMonitor* monitor, |
1177 ObjectMonitor* monitor, |
1175 jlong notifier_tid, |
1178 jlong notifier_tid, |
1195 assert(Self->is_Java_thread(), "Must be Java thread!"); |
1198 assert(Self->is_Java_thread(), "Must be Java thread!"); |
1196 JavaThread *jt = (JavaThread *)THREAD; |
1199 JavaThread *jt = (JavaThread *)THREAD; |
1197 |
1200 |
1198 assert(InitDone, "Unexpectedly not initialized"); |
1201 assert(InitDone, "Unexpectedly not initialized"); |
1199 |
1202 |
1200 // Throw IMSX or IEX. |
1203 CHECK_OWNER(); // Throws IMSE if not owner. |
1201 CHECK_OWNER(); |
|
1202 |
1204 |
1203 EventJavaMonitorWait event; |
1205 EventJavaMonitorWait event; |
1204 |
1206 |
1205 // check for a pending interrupt |
1207 // check for a pending interrupt |
1206 if (interruptible && Thread::is_interrupted(Self, true) && !HAS_PENDING_EXCEPTION) { |
1208 if (interruptible && Thread::is_interrupted(Self, true) && !HAS_PENDING_EXCEPTION) { |
1475 // When the "minimum wait" is set to a small non-zero timeout value |
1477 // When the "minimum wait" is set to a small non-zero timeout value |
1476 // and the program does not hang whereas it did absent "minimum wait", |
1478 // and the program does not hang whereas it did absent "minimum wait", |
1477 // that suggests a lost wakeup bug. |
1479 // that suggests a lost wakeup bug. |
1478 |
1480 |
1479 void ObjectMonitor::notify(TRAPS) { |
1481 void ObjectMonitor::notify(TRAPS) { |
1480 CHECK_OWNER(); |
1482 CHECK_OWNER(); // Throws IMSE if not owner. |
1481 if (_WaitSet == NULL) { |
1483 if (_WaitSet == NULL) { |
1482 return; |
1484 return; |
1483 } |
1485 } |
1484 DTRACE_MONITOR_PROBE(notify, this, object(), THREAD); |
1486 DTRACE_MONITOR_PROBE(notify, this, object(), THREAD); |
1485 INotify(THREAD); |
1487 INotify(THREAD); |
1493 // that in prepend-mode we invert the order of the waiters. Let's say that the |
1495 // that in prepend-mode we invert the order of the waiters. Let's say that the |
1494 // waitset is "ABCD" and the EntryList is "XYZ". After a notifyAll() in prepend |
1496 // waitset is "ABCD" and the EntryList is "XYZ". After a notifyAll() in prepend |
1495 // mode the waitset will be empty and the EntryList will be "DCBAXYZ". |
1497 // mode the waitset will be empty and the EntryList will be "DCBAXYZ". |
1496 |
1498 |
1497 void ObjectMonitor::notifyAll(TRAPS) { |
1499 void ObjectMonitor::notifyAll(TRAPS) { |
1498 CHECK_OWNER(); |
1500 CHECK_OWNER(); // Throws IMSE if not owner. |
1499 if (_WaitSet == NULL) { |
1501 if (_WaitSet == NULL) { |
1500 return; |
1502 return; |
1501 } |
1503 } |
1502 |
1504 |
1503 DTRACE_MONITOR_PROBE(notifyAll, this, object(), THREAD); |
1505 DTRACE_MONITOR_PROBE(notifyAll, this, object(), THREAD); |