952 Handle hobj;
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
1028 ret.waiter_count = 0;
1029 ret.notify_waiter_count = 0;
1030 }
1031
1032 // Allocate memory for heavyweight and lightweight monitor.
1033 jvmtiError err;
1034 err = allocate(ret.waiter_count * sizeof(jthread *), (unsigned char**)&ret.waiters);
1035 if (err != JVMTI_ERROR_NONE) {
1036 return err;
1037 }
1038 err = allocate(ret.notify_waiter_count * sizeof(jthread *),
1039 (unsigned char**)&ret.notify_waiters);
1040 if (err != JVMTI_ERROR_NONE) {
|
952 Handle hobj;
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 owning_thread = ObjectSynchronizer::get_lock_owner(tlh.list(), hobj);
973 if (owning_thread != NULL) { // monitor is owned
974 Handle th(current_thread, owning_thread->threadObj());
975 ret.owner = (jthread)jni_reference(calling_thread, th);
976
977 // The recursions field of a monitor does not reflect recursions
978 // as lightweight locks before inflating the monitor are not included.
979 // We have to count the number of recursive monitor entries the hard way.
980 // We pass a handle to survive any GCs along the way.
981 ret.entry_count = count_locked_objects(owning_thread, hobj);
982 }
983 // implied else: entry_count == 0
984
985 jint nWant = 0, nWait = 0;
986 markWord mark = hobj->mark();
987 if (mark.has_monitor()) {
988 mon = mark.monitor();
989 assert(mon != NULL, "must have monitor");
990 // this object has a heavyweight monitor
991 nWant = mon->contentions(); // # of threads contending for monitor
992 nWait = mon->waiters(); // # of threads in Object.wait()
993 ret.waiter_count = nWant + nWait;
994 ret.notify_waiter_count = nWait;
995 } else {
996 // this object has a lightweight monitor
997 ret.waiter_count = 0;
998 ret.notify_waiter_count = 0;
999 }
1000
1001 // Allocate memory for heavyweight and lightweight monitor.
1002 jvmtiError err;
1003 err = allocate(ret.waiter_count * sizeof(jthread *), (unsigned char**)&ret.waiters);
1004 if (err != JVMTI_ERROR_NONE) {
1005 return err;
1006 }
1007 err = allocate(ret.notify_waiter_count * sizeof(jthread *),
1008 (unsigned char**)&ret.notify_waiters);
1009 if (err != JVMTI_ERROR_NONE) {
|