Skip to content

Commit

Permalink
1. java_lang_VirtualThread::is_instance(thread_oop) -> thread_oop->is…
Browse files Browse the repository at this point in the history
…_a(vmClasses::BaseVirtualThread_klass()); 2. calculating nWant(mon->contentions())
  • Loading branch information
sendaoYan committed May 28, 2024
1 parent 4a4326c commit ea28c23
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 6 deletions.
18 changes: 13 additions & 5 deletions src/hotspot/share/prims/jvmtiEnvBase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand All @@ -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");
Expand All @@ -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
}
Expand All @@ -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.
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit ea28c23

Please sign in to comment.