Pseudocode for a JvmtiRawMonitor based on PlatformMutex and PlatformMonitor. Basic idea is to split JvmtiRawMonitor into a PlatformMutex M1 and a PlatformMonitor M2. M2 would be used for wait/notify. This allows notified threads to do something immediately after notification, because M2 will always be locked very shortly. A third PlatformMonitor M3 could be shared (like RawMonitor_lock) or it could be allocated dynamically if interrupt() is called. - So JvmtiRawMonitor could use PlatformMutex as base class adding fields. M1 is an alias for the this pointer. Fields: M2 // Protects the counters and status fields and provides wait/notify. // Could be allocated dynamically M3 // Used to synchronize interrupts with other interrupts and with wait/notify // Could be allocated dynamically or shared. num_waiters pending_notifications pending_interrupt_checks interrupt_in_progress - Wait/notify would delegate to M2. notify: M2.lock() wait_if_interrupt_in_progress() pending_notifications++ M2.notify() M2.unlock() notify_all: M2.lock() wait_if_interrupt_in_progress() pending_notifications = num_waiters M2.notify() M2.unlock() wait: T := current thread M2.lock() wait_if_interrupt_in_progress() if (Thread::is_interrupted()) { M2.unlock() return } M1.unlock() num_waiters++ T._jvmti_raw_monitor_waiting_for = M1 while (true) { M2.wait() if (pending_notifications > 0) { if (--pending_notifications == 0 && interrupt_in_progress) { M3.notify_all() } break } else if (pending_interrupt_checks > 0) { assert(pending_notifications == 0) if (--pending_interrupt_checks == 0) { interrupt_in_progress = false M3.notify_all() } if (Thread::is_interrupted()) { break } } else { // spurious wake-up? ShouldNotReachHere() } } T._jvmti_raw_monitor_waiting_for = NULL num_waiters-- M1.lock() M2.unlock() - Interrupt: wait until no real notifications are pending then notify all for interrupt check Note: M1 is not owned interrupt: M2.lock() wait_if_interrupt_in_progress() // interrupts on the same JvmtiRawMonitor are serialized interrupt_in_progress = true wait_while_notifications_pending() pending_interrupt_checks = num_waiters M2.notify_all() M2.unlock() - Helper methods. wait_if_interrupt_in_progress: while(interrupt_in_progress) { M3.lock() M2.unlock() M3.wait() M2.lock() M3.unlock() } wait_while_notifications_pending while(pending_notifications > 0) { M3.lock() M2.unlock() M3.wait() M2.lock() M3.unlock() }