< prev index next >

src/hotspot/share/prims/jvmtiEnvBase.cpp

Print this page

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

1019 
1020   jint nWant = 0, nWait = 0;
1021   if (mon != NULL) {



1022     // this object has a heavyweight monitor
1023     nWant = mon->contentions(); // # of threads contending for monitor
1024     nWait = mon->waiters();     // # of threads in Object.wait()
1025     ret.waiter_count = nWant + nWait;
1026     ret.notify_waiter_count = nWait;
1027   } else {
1028     // this object has a lightweight monitor
1029     ret.waiter_count = 0;
1030     ret.notify_waiter_count = 0;
1031   }
1032 
1033   // Allocate memory for heavyweight and lightweight monitor.
1034   jvmtiError err;
1035   err = allocate(ret.waiter_count * sizeof(jthread *), (unsigned char**)&ret.waiters);
1036   if (err != JVMTI_ERROR_NONE) {
1037     return err;
1038   }
1039   err = allocate(ret.notify_waiter_count * sizeof(jthread *),
1040                  (unsigned char**)&ret.notify_waiters);
1041   if (err != JVMTI_ERROR_NONE) {

 953   Handle hobj;
 954 
 955   // Check arguments
 956   {
 957     oop mirror = JNIHandles::resolve_external_guard(object);
 958     NULL_CHECK(mirror, JVMTI_ERROR_INVALID_OBJECT);
 959     NULL_CHECK(info_ptr, JVMTI_ERROR_NULL_POINTER);
 960 
 961     hobj = Handle(current_thread, mirror);
 962   }
 963 
 964   ThreadsListHandle tlh(current_thread);
 965   JavaThread *owning_thread = NULL;
 966   ObjectMonitor *mon = NULL;
 967   jvmtiMonitorUsage ret = {
 968       NULL, 0, 0, NULL, 0, NULL
 969   };
 970 
 971   uint32_t debug_bits = 0;
 972   // first derive the object's owner and entry_count (if any)
 973   owning_thread = ObjectSynchronizer::get_lock_owner(tlh.list(), hobj);
 974   if (owning_thread != NULL) {  // monitor is owned
 975     Handle th(current_thread, owning_thread->threadObj());
 976     ret.owner = (jthread)jni_reference(calling_thread, th);






 977 
 978     // The recursions field of a monitor does not reflect recursions
 979     // as lightweight locks before inflating the monitor are not included.
 980     // We have to count the number of recursive monitor entries the hard way.
 981     // We pass a handle to survive any GCs along the way.
 982     ret.entry_count = count_locked_objects(owning_thread, hobj);





























 983   }
 984   // implied else: entry_count == 0
 985 
 986   jint nWant = 0, nWait = 0;
 987   markWord mark = hobj->mark();
 988   if (mark.has_monitor()) {
 989     mon = mark.monitor();
 990     assert(mon != NULL, "must have monitor");
 991     // this object has a heavyweight monitor
 992     nWant = mon->contentions(); // # of threads contending for monitor
 993     nWait = mon->waiters();     // # of threads in Object.wait()
 994     ret.waiter_count = nWant + nWait;
 995     ret.notify_waiter_count = nWait;
 996   } else {
 997     // this object has a lightweight monitor
 998     ret.waiter_count = 0;
 999     ret.notify_waiter_count = 0;
1000   }
1001 
1002   // Allocate memory for heavyweight and lightweight monitor.
1003   jvmtiError err;
1004   err = allocate(ret.waiter_count * sizeof(jthread *), (unsigned char**)&ret.waiters);
1005   if (err != JVMTI_ERROR_NONE) {
1006     return err;
1007   }
1008   err = allocate(ret.notify_waiter_count * sizeof(jthread *),
1009                  (unsigned char**)&ret.notify_waiters);
1010   if (err != JVMTI_ERROR_NONE) {
< prev index next >