310 continue;
311 }
312
313 thisDfn = globalDfn;
314 jt->set_depth_first_number(globalDfn++);
315 previousThread = jt;
316 currentThread = jt;
317
318 cycle->reset();
319
320 // When there is a deadlock, all the monitors involved in the dependency
321 // cycle must be contended and heavyweight. So we only care about the
322 // heavyweight monitor a thread is waiting to lock.
323 waitingToLockMonitor = (ObjectMonitor*)jt->current_pending_monitor();
324 if (concurrent_locks) {
325 waitingToLockBlocker = jt->current_park_blocker();
326 }
327 while (waitingToLockMonitor != NULL || waitingToLockBlocker != NULL) {
328 cycle->add_thread(currentThread);
329 if (waitingToLockMonitor != NULL) {
330 currentThread = Threads::owning_thread_from_monitor_owner(
331 (address)waitingToLockMonitor->owner(),
332 false /* no locking needed */);
333 if (currentThread == NULL) {
334 // This function is called at a safepoint so the JavaThread
335 // that owns waitingToLockMonitor should be findable, but
336 // if it is not findable, then the previous currentThread is
337 // blocked permanently. We record this as a deadlock.
338 num_deadlocks++;
339
340 cycle->set_deadlock(true);
341
342 // add this cycle to the deadlocks list
343 if (deadlocks == NULL) {
344 deadlocks = cycle;
345 } else {
346 last->set_next(cycle);
347 }
348 last = cycle;
349 cycle = new DeadlockCycle();
350 break;
351 }
352 } else {
353 if (concurrent_locks) {
354 if (waitingToLockBlocker->is_a(SystemDictionary::abstract_ownable_synchronizer_klass())) {
355 oop threadObj = java_util_concurrent_locks_AbstractOwnableSynchronizer::get_owner_threadObj(waitingToLockBlocker);
356 currentThread = threadObj != NULL ? java_lang_Thread::thread(threadObj) : NULL;
357 } else {
358 currentThread = NULL;
359 }
360 }
361 }
362
363 if (currentThread == NULL) {
364 // No dependency on another thread
365 break;
366 }
367 if (currentThread->depth_first_number() < 0) {
368 // First visit to this thread
369 currentThread->set_depth_first_number(globalDfn++);
370 } else if (currentThread->depth_first_number() < thisDfn) {
371 // Thread already visited, and not on a (new) cycle
|
310 continue;
311 }
312
313 thisDfn = globalDfn;
314 jt->set_depth_first_number(globalDfn++);
315 previousThread = jt;
316 currentThread = jt;
317
318 cycle->reset();
319
320 // When there is a deadlock, all the monitors involved in the dependency
321 // cycle must be contended and heavyweight. So we only care about the
322 // heavyweight monitor a thread is waiting to lock.
323 waitingToLockMonitor = (ObjectMonitor*)jt->current_pending_monitor();
324 if (concurrent_locks) {
325 waitingToLockBlocker = jt->current_park_blocker();
326 }
327 while (waitingToLockMonitor != NULL || waitingToLockBlocker != NULL) {
328 cycle->add_thread(currentThread);
329 if (waitingToLockMonitor != NULL) {
330 address currentOwner = (address)waitingToLockMonitor->owner();
331 if (currentOwner != NULL) {
332 currentThread = Threads::owning_thread_from_monitor_owner(
333 currentOwner,
334 false /* no locking needed */);
335 if (currentThread == NULL) {
336 // This function is called at a safepoint so the JavaThread
337 // that owns waitingToLockMonitor should be findable, but
338 // if it is not findable, then the previous currentThread is
339 // blocked permanently. We record this as a deadlock.
340 num_deadlocks++;
341
342 cycle->set_deadlock(true);
343
344 // add this cycle to the deadlocks list
345 if (deadlocks == NULL) {
346 deadlocks = cycle;
347 } else {
348 last->set_next(cycle);
349 }
350 last = cycle;
351 cycle = new DeadlockCycle();
352 break;
353 }
354 }
355 } else {
356 if (concurrent_locks) {
357 if (waitingToLockBlocker->is_a(SystemDictionary::abstract_ownable_synchronizer_klass())) {
358 oop threadObj = java_util_concurrent_locks_AbstractOwnableSynchronizer::get_owner_threadObj(waitingToLockBlocker);
359 currentThread = threadObj != NULL ? java_lang_Thread::thread(threadObj) : NULL;
360 } else {
361 currentThread = NULL;
362 }
363 }
364 }
365
366 if (currentThread == NULL) {
367 // No dependency on another thread
368 break;
369 }
370 if (currentThread->depth_first_number() < 0) {
371 // First visit to this thread
372 currentThread->set_depth_first_number(globalDfn++);
373 } else if (currentThread->depth_first_number() < thisDfn) {
374 // Thread already visited, and not on a (new) cycle
|