980 } else { 981 // this object has a heavyweight monitor 982 mon = mark->monitor(); 983 984 // The owner field of a heavyweight monitor may be NULL for no 985 // owner, a JavaThread * or it may still be the address of the 986 // Lock word in a JavaThread's stack. A monitor can be inflated 987 // by a non-owning JavaThread, but only the owning JavaThread 988 // can change the owner field from the Lock word to the 989 // JavaThread * and it may not have done that yet. 990 owner = (address)mon->owner(); 991 } 992 } 993 994 if (owner != NULL) { 995 // This monitor is owned so we have to find the owning JavaThread. 996 // Since owning_thread_from_monitor_owner() grabs a lock, GC can 997 // move our object at this point. However, our owner value is safe 998 // since it is either the Lock word on a stack or a JavaThread *. 999 owning_thread = Threads::owning_thread_from_monitor_owner(owner, !at_safepoint); 1000 assert(owning_thread != NULL, "sanity check"); 1001 if (owning_thread != NULL) { // robustness 1002 // The monitor's owner either has to be the current thread, at safepoint 1003 // or it has to be suspended. Any of these conditions will prevent both 1004 // contending and waiting threads from modifying the state of 1005 // the monitor. 1006 if (!at_safepoint && !JvmtiEnv::is_thread_fully_suspended(owning_thread, true, &debug_bits)) { 1007 return JVMTI_ERROR_THREAD_NOT_SUSPENDED; 1008 } 1009 HandleMark hm; 1010 Handle th(owning_thread->threadObj()); 1011 ret.owner = (jthread)jni_reference(calling_thread, th); 1012 } 1013 // implied else: no owner 1014 } 1015 1016 if (owning_thread != NULL) { // monitor is owned 1017 if ((address)owning_thread == owner) { 1018 // the owner field is the JavaThread * 1019 assert(mon != NULL, 1020 "must have heavyweight monitor with JavaThread * owner"); 1021 ret.entry_count = mon->recursions() + 1; 1022 } else { 1023 // The owner field is the Lock word on the JavaThread's stack 1024 // so the recursions field is not valid. We have to count the 1025 // number of recursive monitor entries the hard way. We pass 1026 // a handle to survive any GCs along the way. | 980 } else { 981 // this object has a heavyweight monitor 982 mon = mark->monitor(); 983 984 // The owner field of a heavyweight monitor may be NULL for no 985 // owner, a JavaThread * or it may still be the address of the 986 // Lock word in a JavaThread's stack. A monitor can be inflated 987 // by a non-owning JavaThread, but only the owning JavaThread 988 // can change the owner field from the Lock word to the 989 // JavaThread * and it may not have done that yet. 990 owner = (address)mon->owner(); 991 } 992 } 993 994 if (owner != NULL) { 995 // This monitor is owned so we have to find the owning JavaThread. 996 // Since owning_thread_from_monitor_owner() grabs a lock, GC can 997 // move our object at this point. However, our owner value is safe 998 // since it is either the Lock word on a stack or a JavaThread *. 999 owning_thread = Threads::owning_thread_from_monitor_owner(owner, !at_safepoint); 1000 // Cannot assume (owning_thread != NULL) here because this function 1001 // may not have been called at a safepoint and the owning_thread 1002 // might not be suspended. 1003 if (owning_thread != NULL) { 1004 // The monitor's owner either has to be the current thread, at safepoint 1005 // or it has to be suspended. Any of these conditions will prevent both 1006 // contending and waiting threads from modifying the state of 1007 // the monitor. 1008 if (!at_safepoint && !JvmtiEnv::is_thread_fully_suspended(owning_thread, true, &debug_bits)) { 1009 // Don't worry! This return of JVMTI_ERROR_THREAD_NOT_SUSPENDED 1010 // will not make it back to the JVM/TI agent. The error code will 1011 // get intercepted in JvmtiEnv::GetObjectMonitorUsage() which 1012 // will retry the call via a VM_GetObjectMonitorUsage VM op. 1013 return JVMTI_ERROR_THREAD_NOT_SUSPENDED; 1014 } 1015 HandleMark hm; 1016 Handle th(owning_thread->threadObj()); 1017 ret.owner = (jthread)jni_reference(calling_thread, th); 1018 } 1019 // implied else: no owner 1020 } 1021 1022 if (owning_thread != NULL) { // monitor is owned 1023 if ((address)owning_thread == owner) { 1024 // the owner field is the JavaThread * 1025 assert(mon != NULL, 1026 "must have heavyweight monitor with JavaThread * owner"); 1027 ret.entry_count = mon->recursions() + 1; 1028 } else { 1029 // The owner field is the Lock word on the JavaThread's stack 1030 // so the recursions field is not valid. We have to count the 1031 // number of recursive monitor entries the hard way. We pass 1032 // a handle to survive any GCs along the way. |