@@ -1666,6 +1666,11 @@ void ObjectMonitor::wait(jlong millis, bool interruptible, TRAPS) {
1666
1666
1667
1667
// check for a pending interrupt
1668
1668
if (interruptible && current->is_interrupted (true ) && !HAS_PENDING_EXCEPTION) {
1669
+ JavaThreadInObjectWaitState jtiows (current, millis != 0 , interruptible);
1670
+
1671
+ if (JvmtiExport::should_post_monitor_wait ()) {
1672
+ JvmtiExport::post_monitor_wait (current, object (), millis);
1673
+ }
1669
1674
// post monitor waited event. Note that this is past-tense, we are done waiting.
1670
1675
if (JvmtiExport::should_post_monitor_waited ()) {
1671
1676
// Note: 'false' parameter is passed here because the
@@ -1687,19 +1692,36 @@ void ObjectMonitor::wait(jlong millis, bool interruptible, TRAPS) {
1687
1692
return ;
1688
1693
}
1689
1694
1690
- current->set_current_waiting_monitor (this );
1691
-
1692
1695
freeze_result result;
1693
1696
ContinuationEntry* ce = current->last_continuation ();
1694
- if (ce != nullptr && ce->is_virtual_thread ()) {
1697
+ bool is_virtual = ce != nullptr && ce->is_virtual_thread ();
1698
+ if (is_virtual) {
1699
+ if (interruptible && JvmtiExport::should_post_monitor_wait ()) {
1700
+ JvmtiExport::post_monitor_wait (current, object (), millis);
1701
+ }
1702
+ current->set_current_waiting_monitor (this );
1695
1703
result = Continuation::try_preempt (current, ce->cont_oop (current));
1696
1704
if (result == freeze_ok) {
1697
1705
VThreadWait (current, millis);
1698
1706
current->set_current_waiting_monitor (nullptr );
1699
1707
return ;
1700
1708
}
1701
1709
}
1710
+ // The jtiows does nothing for non-interruptible.
1711
+ JavaThreadInObjectWaitState jtiows (current, millis != 0 , interruptible);
1712
+
1713
+ if (!is_virtual) { // it was already set for virtual thread
1714
+ if (interruptible && JvmtiExport::should_post_monitor_wait ()) {
1715
+ JvmtiExport::post_monitor_wait (current, object (), millis);
1702
1716
1717
+ // The current thread already owns the monitor and it has not yet
1718
+ // been added to the wait queue so the current thread cannot be
1719
+ // made the successor. This means that the JVMTI_EVENT_MONITOR_WAIT
1720
+ // event handler cannot accidentally consume an unpark() meant for
1721
+ // the ParkEvent associated with this ObjectMonitor.
1722
+ }
1723
+ current->set_current_waiting_monitor (this );
1724
+ }
1703
1725
// create a node to be put into the queue
1704
1726
// Critically, after we reset() the event but prior to park(), we must check
1705
1727
// for a pending interrupt.
0 commit comments