953
954 // Check arguments
955 {
956 oop mirror = JNIHandles::resolve_external_guard(object);
957 NULL_CHECK(mirror, JVMTI_ERROR_INVALID_OBJECT);
958 NULL_CHECK(info_ptr, JVMTI_ERROR_NULL_POINTER);
959
960 hobj = Handle(current_thread, mirror);
961 }
962
963 ThreadsListHandle tlh(current_thread);
964 JavaThread *owning_thread = NULL;
965 ObjectMonitor *mon = NULL;
966 jvmtiMonitorUsage ret = {
967 NULL, 0, 0, NULL, 0, NULL
968 };
969
970 uint32_t debug_bits = 0;
971 // first derive the object's owner and entry_count (if any)
972 {
973 // Revoke any biases before querying the mark word
974 BiasedLocking::revoke_at_safepoint(hobj);
975
976 address owner = NULL;
977 {
978 markWord mark = hobj()->mark();
979
980 if (!mark.has_monitor()) {
981 // this object has a lightweight monitor
982
983 if (mark.has_locker()) {
984 owner = (address)mark.locker(); // save the address of the Lock word
985 }
986 // implied else: no owner
987 } else {
988 // this object has a heavyweight monitor
989 mon = mark.monitor();
990
991 // The owner field of a heavyweight monitor may be NULL for no
992 // owner, a JavaThread * or it may still be the address of the
993 // Lock word in a JavaThread's stack. A monitor can be inflated
994 // by a non-owning JavaThread, but only the owning JavaThread
995 // can change the owner field from the Lock word to the
996 // JavaThread * and it may not have done that yet.
997 owner = (address)mon->owner();
998 }
999 }
1000
1001 if (owner != NULL) {
1002 // This monitor is owned so we have to find the owning JavaThread.
1003 owning_thread = Threads::owning_thread_from_monitor_owner(tlh.list(), owner);
1004 assert(owning_thread != NULL, "owning JavaThread must not be NULL");
1005 Handle th(current_thread, owning_thread->threadObj());
1006 ret.owner = (jthread)jni_reference(calling_thread, th);
1007 }
1008
1009 if (owning_thread != NULL) { // monitor is owned
1010 // The recursions field of a monitor does not reflect recursions
1011 // as lightweight locks before inflating the monitor are not included.
1012 // We have to count the number of recursive monitor entries the hard way.
1013 // We pass a handle to survive any GCs along the way.
1014 ret.entry_count = count_locked_objects(owning_thread, hobj);
1015 }
1016 // implied else: entry_count == 0
1017 }
1018
1019 jint nWant = 0, nWait = 0;
1020 if (mon != NULL) {
1021 // this object has a heavyweight monitor
1022 nWant = mon->contentions(); // # of threads contending for monitor
1023 nWait = mon->waiters(); // # of threads in Object.wait()
1024 ret.waiter_count = nWant + nWait;
1025 ret.notify_waiter_count = nWait;
1026 } else {
1027 // this object has a lightweight monitor
|
953
954 // Check arguments
955 {
956 oop mirror = JNIHandles::resolve_external_guard(object);
957 NULL_CHECK(mirror, JVMTI_ERROR_INVALID_OBJECT);
958 NULL_CHECK(info_ptr, JVMTI_ERROR_NULL_POINTER);
959
960 hobj = Handle(current_thread, mirror);
961 }
962
963 ThreadsListHandle tlh(current_thread);
964 JavaThread *owning_thread = NULL;
965 ObjectMonitor *mon = NULL;
966 jvmtiMonitorUsage ret = {
967 NULL, 0, 0, NULL, 0, NULL
968 };
969
970 uint32_t debug_bits = 0;
971 // first derive the object's owner and entry_count (if any)
972 {
973 owning_thread = ObjectSynchronizer::get_lock_owner(tlh.list(), hobj);
974
975 if (owning_thread != NULL) { // monitor is owned
976 // The recursions field of a monitor does not reflect recursions
977 // as lightweight locks before inflating the monitor are not included.
978 // We have to count the number of recursive monitor entries the hard way.
979 // We pass a handle to survive any GCs along the way.
980 ret.entry_count = count_locked_objects(owning_thread, hobj);
981 }
982 // implied else: entry_count == 0
983 }
984
985 jint nWant = 0, nWait = 0;
986 if (mon != NULL) {
987 // this object has a heavyweight monitor
988 nWant = mon->contentions(); // # of threads contending for monitor
989 nWait = mon->waiters(); // # of threads in Object.wait()
990 ret.waiter_count = nWant + nWait;
991 ret.notify_waiter_count = nWait;
992 } else {
993 // this object has a lightweight monitor
|