Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

8332923: ObjectMonitorUsage.java failed with unexpected waiter_count #19405

Closed
wants to merge 3 commits into from
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 13 additions & 5 deletions src/hotspot/share/prims/jvmtiEnvBase.cpp
Original file line number Diff line number Diff line change
@@ -1483,7 +1483,7 @@ JvmtiEnvBase::get_object_monitor_usage(JavaThread* calling_thread, jobject objec
owning_thread = ObjectSynchronizer::get_lock_owner(tlh.list(), hobj);
if (owning_thread != nullptr) {
oop thread_oop = get_vthread_or_thread_oop(owning_thread);
bool is_virtual = java_lang_VirtualThread::is_instance(thread_oop);
bool is_virtual = thread_oop->is_a(vmClasses::BaseVirtualThread_klass());
if (is_virtual) {
thread_oop = nullptr;
}
@@ -1503,6 +1503,7 @@ JvmtiEnvBase::get_object_monitor_usage(JavaThread* calling_thread, jobject objec
ResourceMark rm(current_thread);
GrowableArray<JavaThread*>* wantList = nullptr;

jint nWant_Skip = 0;
if (mark.has_monitor()) {
mon = mark.monitor();
assert(mon != nullptr, "must have monitor");
@@ -1514,6 +1515,13 @@ JvmtiEnvBase::get_object_monitor_usage(JavaThread* calling_thread, jobject objec
// Get the actual set of threads trying to enter, or re-enter, the monitor.
wantList = Threads::get_pending_threads(tlh.list(), nWant + nWait, (address)mon);
nWant = wantList->length();
for(jint i = 0; i < nWant; i++) {
JavaThread* w = wantList->at(i);
oop thread_oop = get_vthread_or_thread_oop(w);
if (thread_oop->is_a(vmClasses::BaseVirtualThread_klass())) {
nWant_Skip++;
}
}
} else {
// this object has a lightweight monitor
}
@@ -1530,13 +1538,13 @@ JvmtiEnvBase::get_object_monitor_usage(JavaThread* calling_thread, jobject objec
waiter = mon->next_waiter(waiter)) {
JavaThread *w = mon->thread_of_waiter(waiter);
oop thread_oop = get_vthread_or_thread_oop(w);
if (java_lang_VirtualThread::is_instance(thread_oop)) {
if (thread_oop->is_a(vmClasses::BaseVirtualThread_klass())) {
skipped++;
}
nWait++;
}
}
ret.waiter_count = nWant;
ret.waiter_count = nWant - nWant_Skip;
ret.notify_waiter_count = nWait - skipped;

// Allocate memory for heavyweight and lightweight monitor.
@@ -1576,9 +1584,9 @@ JvmtiEnvBase::get_object_monitor_usage(JavaThread* calling_thread, jobject objec
for (int i = 0; i < nWait; i++) {
JavaThread *w = mon->thread_of_waiter(waiter);
oop thread_oop = get_vthread_or_thread_oop(w);
bool is_virtual = java_lang_VirtualThread::is_instance(thread_oop);
bool is_virtual = thread_oop->is_a(vmClasses::BaseVirtualThread_klass());
assert(w != nullptr, "sanity check");
if (java_lang_VirtualThread::is_instance(thread_oop)) {
if (is_virtual) {
skipped++;
} else {
// If the thread was found on the ObjectWaiter list, then
Original file line number Diff line number Diff line change
@@ -40,7 +40,6 @@
* waiting to re-enter, from N to 0 threads waiting to be notified
* - all the above scenarios are executed with platform and virtual threads
* @requires vm.jvmti
* @requires vm.continuations
* @run main/othervm/native
* -Djdk.virtualThreadScheduler.parallelism=10
* -agentlib:ObjectMonitorUsage ObjectMonitorUsage