Thu, 28 Feb 2013 05:55:18 -0800
Merge
1.1 --- a/src/share/vm/prims/jvmtiEnvBase.cpp Wed Feb 27 22:40:14 2013 +0000 1.2 +++ b/src/share/vm/prims/jvmtiEnvBase.cpp Thu Feb 28 05:55:18 2013 -0800 1.3 @@ -997,13 +997,19 @@ 1.4 // move our object at this point. However, our owner value is safe 1.5 // since it is either the Lock word on a stack or a JavaThread *. 1.6 owning_thread = Threads::owning_thread_from_monitor_owner(owner, !at_safepoint); 1.7 - assert(owning_thread != NULL, "sanity check"); 1.8 - if (owning_thread != NULL) { // robustness 1.9 + // Cannot assume (owning_thread != NULL) here because this function 1.10 + // may not have been called at a safepoint and the owning_thread 1.11 + // might not be suspended. 1.12 + if (owning_thread != NULL) { 1.13 // The monitor's owner either has to be the current thread, at safepoint 1.14 // or it has to be suspended. Any of these conditions will prevent both 1.15 // contending and waiting threads from modifying the state of 1.16 // the monitor. 1.17 if (!at_safepoint && !JvmtiEnv::is_thread_fully_suspended(owning_thread, true, &debug_bits)) { 1.18 + // Don't worry! This return of JVMTI_ERROR_THREAD_NOT_SUSPENDED 1.19 + // will not make it back to the JVM/TI agent. The error code will 1.20 + // get intercepted in JvmtiEnv::GetObjectMonitorUsage() which 1.21 + // will retry the call via a VM_GetObjectMonitorUsage VM op. 1.22 return JVMTI_ERROR_THREAD_NOT_SUSPENDED; 1.23 } 1.24 HandleMark hm;
2.1 --- a/src/share/vm/runtime/synchronizer.cpp Wed Feb 27 22:40:14 2013 +0000 2.2 +++ b/src/share/vm/runtime/synchronizer.cpp Thu Feb 28 05:55:18 2013 -0800 2.3 @@ -813,6 +813,7 @@ 2.4 } 2.5 2.6 if (owner != NULL) { 2.7 + // owning_thread_from_monitor_owner() may also return NULL here 2.8 return Threads::owning_thread_from_monitor_owner(owner, doLock); 2.9 } 2.10
3.1 --- a/src/share/vm/runtime/thread.cpp Wed Feb 27 22:40:14 2013 +0000 3.2 +++ b/src/share/vm/runtime/thread.cpp Thu Feb 28 05:55:18 2013 -0800 3.3 @@ -4285,7 +4285,9 @@ 3.4 if (owner == (address)p) return p; 3.5 } 3.6 } 3.7 - assert(UseHeavyMonitors == false, "Did not find owning Java thread with UseHeavyMonitors enabled"); 3.8 + // Cannot assert on lack of success here since this function may be 3.9 + // used by code that is trying to report useful problem information 3.10 + // like deadlock detection. 3.11 if (UseHeavyMonitors) return NULL; 3.12 3.13 // 3.14 @@ -4303,7 +4305,7 @@ 3.15 } 3.16 } 3.17 } 3.18 - assert(the_owner != NULL, "Did not find owning Java thread for lock word address"); 3.19 + // cannot assert on lack of success here; see above comment 3.20 return the_owner; 3.21 } 3.22
4.1 --- a/src/share/vm/services/threadService.cpp Wed Feb 27 22:40:14 2013 +0000 4.2 +++ b/src/share/vm/services/threadService.cpp Thu Feb 28 05:55:18 2013 -0800 4.3 @@ -1,5 +1,5 @@ 4.4 /* 4.5 - * Copyright (c) 2003, 2012, Oracle and/or its affiliates. All rights reserved. 4.6 + * Copyright (c) 2003, 2013, Oracle and/or its affiliates. All rights reserved. 4.7 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4.8 * 4.9 * This code is free software; you can redistribute it and/or modify it 4.10 @@ -327,8 +327,28 @@ 4.11 while (waitingToLockMonitor != NULL || waitingToLockBlocker != NULL) { 4.12 cycle->add_thread(currentThread); 4.13 if (waitingToLockMonitor != NULL) { 4.14 - currentThread = Threads::owning_thread_from_monitor_owner((address)waitingToLockMonitor->owner(), 4.15 - false /* no locking needed */); 4.16 + currentThread = Threads::owning_thread_from_monitor_owner( 4.17 + (address)waitingToLockMonitor->owner(), 4.18 + false /* no locking needed */); 4.19 + if (currentThread == NULL) { 4.20 + // This function is called at a safepoint so the JavaThread 4.21 + // that owns waitingToLockMonitor should be findable, but 4.22 + // if it is not findable, then the previous currentThread is 4.23 + // blocked permanently. We record this as a deadlock. 4.24 + num_deadlocks++; 4.25 + 4.26 + cycle->set_deadlock(true); 4.27 + 4.28 + // add this cycle to the deadlocks list 4.29 + if (deadlocks == NULL) { 4.30 + deadlocks = cycle; 4.31 + } else { 4.32 + last->set_next(cycle); 4.33 + } 4.34 + last = cycle; 4.35 + cycle = new DeadlockCycle(); 4.36 + break; 4.37 + } 4.38 } else { 4.39 if (concurrent_locks) { 4.40 if (waitingToLockBlocker->is_a(SystemDictionary::abstract_ownable_synchronizer_klass())) { 4.41 @@ -841,7 +861,17 @@ 4.42 owner_desc = " (JVMTI raw monitor),\n which is held by"; 4.43 } 4.44 currentThread = Threads::owning_thread_from_monitor_owner( 4.45 - (address)waitingToLockMonitor->owner(), false /* no locking needed */); 4.46 + (address)waitingToLockMonitor->owner(), 4.47 + false /* no locking needed */); 4.48 + if (currentThread == NULL) { 4.49 + // The deadlock was detected at a safepoint so the JavaThread 4.50 + // that owns waitingToLockMonitor should be findable, but 4.51 + // if it is not findable, then the previous currentThread is 4.52 + // blocked permanently. 4.53 + st->print("%s UNKNOWN_owner_addr=" PTR_FORMAT, owner_desc, 4.54 + (address)waitingToLockMonitor->owner()); 4.55 + continue; 4.56 + } 4.57 } else { 4.58 st->print(" waiting for ownable synchronizer " INTPTR_FORMAT ", (a %s)", 4.59 (address)waitingToLockBlocker,