4268 return result; 4269 } 4270 4271 4272 JavaThread *Threads::owning_thread_from_monitor_owner(address owner, bool doLock) { 4273 assert(doLock || 4274 Threads_lock->owned_by_self() || 4275 SafepointSynchronize::is_at_safepoint(), 4276 "must grab Threads_lock or be at safepoint"); 4277 4278 // NULL owner means not locked so we can skip the search 4279 if (owner == NULL) return NULL; 4280 4281 { 4282 MutexLockerEx ml(doLock ? Threads_lock : NULL); 4283 ALL_JAVA_THREADS(p) { 4284 // first, see if owner is the address of a Java thread 4285 if (owner == (address)p) return p; 4286 } 4287 } 4288 assert(UseHeavyMonitors == false, "Did not find owning Java thread with UseHeavyMonitors enabled"); 4289 if (UseHeavyMonitors) return NULL; 4290 4291 // 4292 // If we didn't find a matching Java thread and we didn't force use of 4293 // heavyweight monitors, then the owner is the stack address of the 4294 // Lock Word in the owning Java thread's stack. 4295 // 4296 JavaThread* the_owner = NULL; 4297 { 4298 MutexLockerEx ml(doLock ? Threads_lock : NULL); 4299 ALL_JAVA_THREADS(q) { 4300 if (q->is_lock_owned(owner)) { 4301 the_owner = q; 4302 break; 4303 } 4304 } 4305 } 4306 assert(the_owner != NULL, "Did not find owning Java thread for lock word address"); 4307 return the_owner; 4308 } 4309 4310 // Threads::print_on() is called at safepoint by VM_PrintThreads operation. 4311 void Threads::print_on(outputStream* st, bool print_stacks, bool internal_format, bool print_concurrent_locks) { 4312 char buf[32]; 4313 st->print_cr(os::local_time_string(buf, sizeof(buf))); 4314 4315 st->print_cr("Full thread dump %s (%s %s):", 4316 Abstract_VM_Version::vm_name(), 4317 Abstract_VM_Version::vm_release(), 4318 Abstract_VM_Version::vm_info_string() 4319 ); 4320 st->cr(); 4321 4322 #if INCLUDE_ALL_GCS 4323 // Dump concurrent locks 4324 ConcurrentLocksDump concurrent_locks; 4325 if (print_concurrent_locks) { 4326 concurrent_locks.dump_at_safepoint(); | 4268 return result; 4269 } 4270 4271 4272 JavaThread *Threads::owning_thread_from_monitor_owner(address owner, bool doLock) { 4273 assert(doLock || 4274 Threads_lock->owned_by_self() || 4275 SafepointSynchronize::is_at_safepoint(), 4276 "must grab Threads_lock or be at safepoint"); 4277 4278 // NULL owner means not locked so we can skip the search 4279 if (owner == NULL) return NULL; 4280 4281 { 4282 MutexLockerEx ml(doLock ? Threads_lock : NULL); 4283 ALL_JAVA_THREADS(p) { 4284 // first, see if owner is the address of a Java thread 4285 if (owner == (address)p) return p; 4286 } 4287 } 4288 // Cannot assert on lack of success here since this function may be 4289 // used by code that is trying to report useful problem information 4290 // like deadlock detection. 4291 if (UseHeavyMonitors) return NULL; 4292 4293 // 4294 // If we didn't find a matching Java thread and we didn't force use of 4295 // heavyweight monitors, then the owner is the stack address of the 4296 // Lock Word in the owning Java thread's stack. 4297 // 4298 JavaThread* the_owner = NULL; 4299 { 4300 MutexLockerEx ml(doLock ? Threads_lock : NULL); 4301 ALL_JAVA_THREADS(q) { 4302 if (q->is_lock_owned(owner)) { 4303 the_owner = q; 4304 break; 4305 } 4306 } 4307 } 4308 // cannot assert on lack of success here; see above comment 4309 return the_owner; 4310 } 4311 4312 // Threads::print_on() is called at safepoint by VM_PrintThreads operation. 4313 void Threads::print_on(outputStream* st, bool print_stacks, bool internal_format, bool print_concurrent_locks) { 4314 char buf[32]; 4315 st->print_cr(os::local_time_string(buf, sizeof(buf))); 4316 4317 st->print_cr("Full thread dump %s (%s %s):", 4318 Abstract_VM_Version::vm_name(), 4319 Abstract_VM_Version::vm_release(), 4320 Abstract_VM_Version::vm_info_string() 4321 ); 4322 st->cr(); 4323 4324 #if INCLUDE_ALL_GCS 4325 // Dump concurrent locks 4326 ConcurrentLocksDump concurrent_locks; 4327 if (print_concurrent_locks) { 4328 concurrent_locks.dump_at_safepoint(); |