Skip to content

Commit fbbc7c3

Browse files
author
Alan Bateman
committedDec 17, 2024
8346120: VirtualThreadPinned event recorded for Object.wait may have wrong duration or may record second event
Reviewed-by: dholmes, pchilanomate
1 parent 466c00a commit fbbc7c3

File tree

2 files changed

+485
-9
lines changed

2 files changed

+485
-9
lines changed
 

‎src/hotspot/share/runtime/objectMonitor.cpp

+9-9
Original file line numberDiff line numberDiff line change
@@ -597,10 +597,11 @@ void ObjectMonitor::enter_with_contention_mark(JavaThread *current, ObjectMonito
597597
enter_event.commit();
598598
}
599599

600-
ContinuationEntry* ce = current->last_continuation();
601-
if (ce != nullptr && ce->is_virtual_thread()) {
602-
assert(result != freeze_ok, "sanity check");
603-
current->post_vthread_pinned_event(&vthread_pinned_event, "Contended monitor enter", result);
600+
if (current->current_waiting_monitor() == nullptr) {
601+
ContinuationEntry* ce = current->last_continuation();
602+
if (ce != nullptr && ce->is_virtual_thread()) {
603+
current->post_vthread_pinned_event(&vthread_pinned_event, "Contended monitor enter", result);
604+
}
604605
}
605606

606607
OM_PERFDATA_OP(ContendedLockAttempts, inc());
@@ -1819,11 +1820,6 @@ void ObjectMonitor::wait(jlong millis, bool interruptible, TRAPS) {
18191820
post_monitor_wait_event(&wait_event, this, node._notifier_tid, millis, ret == OS_TIMEOUT);
18201821
}
18211822

1822-
if (ce != nullptr && ce->is_virtual_thread()) {
1823-
assert(result != freeze_ok, "sanity check");
1824-
current->post_vthread_pinned_event(&vthread_pinned_event, "Object.wait", result);
1825-
}
1826-
18271823
OrderAccess::fence();
18281824

18291825
assert(!has_owner(current), "invariant");
@@ -1863,6 +1859,10 @@ void ObjectMonitor::wait(jlong millis, bool interruptible, TRAPS) {
18631859
assert(!has_successor(current), "invariant");
18641860
assert_mark_word_consistency();
18651861

1862+
if (ce != nullptr && ce->is_virtual_thread()) {
1863+
current->post_vthread_pinned_event(&vthread_pinned_event, "Object.wait", result);
1864+
}
1865+
18661866
// check if the notification happened
18671867
if (!WasNotified) {
18681868
// no, it could be timeout or Thread.interrupt() or both

0 commit comments

Comments
 (0)
Please sign in to comment.