1.1 --- a/src/share/vm/services/threadService.cpp Wed Feb 27 16:40:30 2013 +0000 1.2 +++ b/src/share/vm/services/threadService.cpp Wed Feb 27 15:00:30 2013 -0800 1.3 @@ -1,5 +1,5 @@ 1.4 /* 1.5 - * Copyright (c) 2003, 2012, Oracle and/or its affiliates. All rights reserved. 1.6 + * Copyright (c) 2003, 2013, Oracle and/or its affiliates. All rights reserved. 1.7 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 1.8 * 1.9 * This code is free software; you can redistribute it and/or modify it 1.10 @@ -327,8 +327,28 @@ 1.11 while (waitingToLockMonitor != NULL || waitingToLockBlocker != NULL) { 1.12 cycle->add_thread(currentThread); 1.13 if (waitingToLockMonitor != NULL) { 1.14 - currentThread = Threads::owning_thread_from_monitor_owner((address)waitingToLockMonitor->owner(), 1.15 - false /* no locking needed */); 1.16 + currentThread = Threads::owning_thread_from_monitor_owner( 1.17 + (address)waitingToLockMonitor->owner(), 1.18 + false /* no locking needed */); 1.19 + if (currentThread == NULL) { 1.20 + // This function is called at a safepoint so the JavaThread 1.21 + // that owns waitingToLockMonitor should be findable, but 1.22 + // if it is not findable, then the previous currentThread is 1.23 + // blocked permanently. We record this as a deadlock. 1.24 + num_deadlocks++; 1.25 + 1.26 + cycle->set_deadlock(true); 1.27 + 1.28 + // add this cycle to the deadlocks list 1.29 + if (deadlocks == NULL) { 1.30 + deadlocks = cycle; 1.31 + } else { 1.32 + last->set_next(cycle); 1.33 + } 1.34 + last = cycle; 1.35 + cycle = new DeadlockCycle(); 1.36 + break; 1.37 + } 1.38 } else { 1.39 if (concurrent_locks) { 1.40 if (waitingToLockBlocker->is_a(SystemDictionary::abstract_ownable_synchronizer_klass())) { 1.41 @@ -841,7 +861,17 @@ 1.42 owner_desc = " (JVMTI raw monitor),\n which is held by"; 1.43 } 1.44 currentThread = Threads::owning_thread_from_monitor_owner( 1.45 - (address)waitingToLockMonitor->owner(), false /* no locking needed */); 1.46 + (address)waitingToLockMonitor->owner(), 1.47 + false /* no locking needed */); 1.48 + if (currentThread == NULL) { 1.49 + // The deadlock was detected at a safepoint so the JavaThread 1.50 + // that owns waitingToLockMonitor should be findable, but 1.51 + // if it is not findable, then the previous currentThread is 1.52 + // blocked permanently. 1.53 + st->print("%s UNKNOWN_owner_addr=" PTR_FORMAT, owner_desc, 1.54 + (address)waitingToLockMonitor->owner()); 1.55 + continue; 1.56 + } 1.57 } else { 1.58 st->print(" waiting for ownable synchronizer " INTPTR_FORMAT ", (a %s)", 1.59 (address)waitingToLockBlocker,