@@ -119,15 +119,6 @@ OopStorage* ObjectMonitor::_oop_storage = nullptr;
119
119
OopHandle ObjectMonitor::_vthread_cxq_head;
120
120
ParkEvent* ObjectMonitor::_vthread_unparker_ParkEvent = nullptr ;
121
121
122
- static void post_virtual_thread_pinned_event (JavaThread* current, const char * reason) {
123
- EventVirtualThreadPinned e;
124
- if (e.should_commit ()) {
125
- e.set_pinnedReason (reason);
126
- e.set_carrierThread (JFR_JVM_THREAD_ID (current));
127
- e.commit ();
128
- }
129
- }
130
-
131
122
// -----------------------------------------------------------------------------
132
123
// Theory of operations -- Monitors lists, thread residency, etc:
133
124
//
@@ -480,14 +471,15 @@ void ObjectMonitor::enter_with_contention_mark(JavaThread *current, ObjectMonito
480
471
assert (!is_being_async_deflated (), " must be" );
481
472
482
473
JFR_ONLY (JfrConditionalFlush<EventJavaMonitorEnter> flush (current);)
483
- EventJavaMonitorEnter event ;
484
- if (event .is_started ()) {
485
- event .set_monitorClass (object ()->klass ());
474
+ EventJavaMonitorEnter enter_event ;
475
+ if (enter_event .is_started ()) {
476
+ enter_event .set_monitorClass (object ()->klass ());
486
477
// Set an address that is 'unique enough', such that events close in
487
478
// time and with the same address are likely (but not guaranteed) to
488
479
// belong to the same object.
489
- event .set_address ((uintptr_t )this );
480
+ enter_event .set_address ((uintptr_t )this );
490
481
}
482
+ EventVirtualThreadPinned vthread_pinned_event;
491
483
492
484
{ // Change java thread status to indicate blocked on monitor enter.
493
485
JavaThreadBlockedOnMonitorEnterState jtbmes (current, this );
@@ -528,11 +520,6 @@ void ObjectMonitor::enter_with_contention_mark(JavaThread *current, ObjectMonito
528
520
(!acquired && !current->preemption_cancelled () && state == java_lang_VirtualThread::BLOCKING), " invariant" );
529
521
return ;
530
522
}
531
- if (result == freeze_pinned_native) {
532
- post_virtual_thread_pinned_event (current, " Native frame or <clinit> on stack" );
533
- } else if (result == freeze_unsupported) {
534
- post_virtual_thread_pinned_event (current, " Native frame or <clinit> or monitors on stack" );
535
- }
536
523
}
537
524
538
525
OSThreadContendState osts (current->osthread ());
@@ -594,10 +581,16 @@ void ObjectMonitor::enter_with_contention_mark(JavaThread *current, ObjectMonito
594
581
// event handler consumed an unpark() issued by the thread that
595
582
// just exited the monitor.
596
583
}
597
- if (event.should_commit ()) {
598
- event.set_previousOwner (_previous_owner_tid);
599
- event.commit ();
584
+ if (enter_event.should_commit ()) {
585
+ enter_event.set_previousOwner (_previous_owner_tid);
586
+ enter_event.commit ();
587
+ }
588
+
589
+ ContinuationEntry* ce = current->last_continuation ();
590
+ if (ce != nullptr && ce->is_virtual_thread ()) {
591
+ current->post_vthread_pinned_event (&vthread_pinned_event, " Blocked on monitor enter" );
600
592
}
593
+
601
594
OM_PERFDATA_OP (ContendedLockAttempts, inc ());
602
595
}
603
596
@@ -1646,7 +1639,8 @@ void ObjectMonitor::wait(jlong millis, bool interruptible, TRAPS) {
1646
1639
1647
1640
CHECK_OWNER (); // Throws IMSE if not owner.
1648
1641
1649
- EventJavaMonitorWait event;
1642
+ EventJavaMonitorWait wait_event;
1643
+ EventVirtualThreadPinned vthread_pinned_event;
1650
1644
1651
1645
// check for a pending interrupt
1652
1646
if (interruptible && current->is_interrupted (true ) && !HAS_PENDING_EXCEPTION) {
@@ -1664,8 +1658,8 @@ void ObjectMonitor::wait(jlong millis, bool interruptible, TRAPS) {
1664
1658
// consume an unpark() meant for the ParkEvent associated with
1665
1659
// this ObjectMonitor.
1666
1660
}
1667
- if (event .should_commit ()) {
1668
- post_monitor_wait_event (&event , this , 0 , millis, false );
1661
+ if (wait_event .should_commit ()) {
1662
+ post_monitor_wait_event (&wait_event , this , 0 , millis, false );
1669
1663
}
1670
1664
THROW (vmSymbols::java_lang_InterruptedException ());
1671
1665
return ;
@@ -1681,16 +1675,6 @@ void ObjectMonitor::wait(jlong millis, bool interruptible, TRAPS) {
1681
1675
current->set_current_waiting_monitor (nullptr );
1682
1676
return ;
1683
1677
}
1684
- if (result == freeze_pinned_native || result == freeze_unsupported) {
1685
- const Klass* monitor_klass = object ()->klass ();
1686
- if (!is_excluded (monitor_klass)) {
1687
- if (result == freeze_pinned_native) {
1688
- post_virtual_thread_pinned_event (current," Native frame or <clinit> on stack" );
1689
- } else if (result == freeze_unsupported) {
1690
- post_virtual_thread_pinned_event (current, " Native frame or <clinit> or monitors on stack" );
1691
- }
1692
- }
1693
- }
1694
1678
}
1695
1679
1696
1680
// create a node to be put into the queue
@@ -1816,8 +1800,12 @@ void ObjectMonitor::wait(jlong millis, bool interruptible, TRAPS) {
1816
1800
}
1817
1801
}
1818
1802
1819
- if (event.should_commit ()) {
1820
- post_monitor_wait_event (&event, this , node._notifier_tid , millis, ret == OS_TIMEOUT);
1803
+ if (wait_event.should_commit ()) {
1804
+ post_monitor_wait_event (&wait_event, this , node._notifier_tid , millis, ret == OS_TIMEOUT);
1805
+ }
1806
+
1807
+ if (ce != nullptr && ce->is_virtual_thread ()) {
1808
+ current->post_vthread_pinned_event (&vthread_pinned_event, " Waited in Object.wait" );
1821
1809
}
1822
1810
1823
1811
OrderAccess::fence ();
@@ -2049,9 +2037,9 @@ bool ObjectMonitor::VThreadWaitReenter(JavaThread* current, ObjectWaiter* node,
2049
2037
node->_interrupted = !was_notified && current->is_interrupted (false );
2050
2038
2051
2039
// Post JFR and JVMTI events.
2052
- EventJavaMonitorWait event ;
2053
- if (event .should_commit () || JvmtiExport::should_post_monitor_waited ()) {
2054
- vthread_monitor_waited_event (current, node, cont, &event , !was_notified && !node->_interrupted );
2040
+ EventJavaMonitorWait wait_event ;
2041
+ if (wait_event .should_commit () || JvmtiExport::should_post_monitor_waited ()) {
2042
+ vthread_monitor_waited_event (current, node, cont, &wait_event , !was_notified && !node->_interrupted );
2055
2043
}
2056
2044
2057
2045
// Mark that we are at reenter so that we don't call this method again.
0 commit comments