From ea28c2325ae1785a91face8a9b205153b2aa3d5a Mon Sep 17 00:00:00 2001 From: sendaoYan Date: Tue, 28 May 2024 14:49:18 +0800 Subject: [PATCH] 1. java_lang_VirtualThread::is_instance(thread_oop) -> thread_oop->is_a(vmClasses::BaseVirtualThread_klass()); 2. calculating nWant(mon->contentions()) --- src/hotspot/share/prims/jvmtiEnvBase.cpp | 18 +++++++++++++----- .../ObjectMonitorUsage/ObjectMonitorUsage.java | 1 - 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/src/hotspot/share/prims/jvmtiEnvBase.cpp b/src/hotspot/share/prims/jvmtiEnvBase.cpp index 94472baf27c49..5f249c14f10e9 100644 --- a/src/hotspot/share/prims/jvmtiEnvBase.cpp +++ b/src/hotspot/share/prims/jvmtiEnvBase.cpp @@ -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* 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 diff --git a/test/hotspot/jtreg/serviceability/jvmti/ObjectMonitorUsage/ObjectMonitorUsage.java b/test/hotspot/jtreg/serviceability/jvmti/ObjectMonitorUsage/ObjectMonitorUsage.java index 4e1219d514626..0d136cadef717 100644 --- a/test/hotspot/jtreg/serviceability/jvmti/ObjectMonitorUsage/ObjectMonitorUsage.java +++ b/test/hotspot/jtreg/serviceability/jvmti/ObjectMonitorUsage/ObjectMonitorUsage.java @@ -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