src/share/vm/services/threadService.cpp

Print this page


   1 /*
   2  * Copyright (c) 2003, 2012, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.
   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  *


 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((address)waitingToLockMonitor->owner(),

 331                                                                   false /* no locking needed */);












 332       } else {







 333         if (concurrent_locks) {
 334           if (waitingToLockBlocker->is_a(SystemDictionary::abstract_ownable_synchronizer_klass())) {
 335             oop threadObj = java_util_concurrent_locks_AbstractOwnableSynchronizer::get_owner_threadObj(waitingToLockBlocker);
 336             currentThread = threadObj != NULL ? java_lang_Thread::thread(threadObj) : NULL;
 337           } else {
 338             currentThread = NULL;
 339           }
 340         }
 341       }
 342 
 343       if (currentThread == NULL) {
 344         // No dependency on another thread
 345         break;
 346       }
 347       if (currentThread->depth_first_number() < 0) {
 348         // First visit to this thread
 349         currentThread->set_depth_first_number(globalDfn++);
 350       } else if (currentThread->depth_first_number() < thisDfn) {
 351         // Thread already visited, and not on a (new) cycle
 352         break;


 824     waitingToLockMonitor = (ObjectMonitor*)currentThread->current_pending_monitor();
 825     waitingToLockBlocker = currentThread->current_park_blocker();
 826     st->cr();
 827     st->print_cr("\"%s\":", currentThread->get_thread_name());
 828     const char* owner_desc = ",\n  which is held by";
 829     if (waitingToLockMonitor != NULL) {
 830       st->print("  waiting to lock monitor " INTPTR_FORMAT, waitingToLockMonitor);
 831       oop obj = (oop)waitingToLockMonitor->object();
 832       if (obj != NULL) {
 833         st->print(" (object "INTPTR_FORMAT ", a %s)", (address)obj,
 834                    (InstanceKlass::cast(obj->klass()))->external_name());
 835 
 836         if (!currentThread->current_pending_monitor_is_from_java()) {
 837           owner_desc = "\n  in JNI, which is held by";
 838         }
 839       } else {
 840         // No Java object associated - a JVMTI raw monitor
 841         owner_desc = " (JVMTI raw monitor),\n  which is held by";
 842       }
 843       currentThread = Threads::owning_thread_from_monitor_owner(
 844         (address)waitingToLockMonitor->owner(), false /* no locking needed */);










 845     } else {
 846       st->print("  waiting for ownable synchronizer " INTPTR_FORMAT ", (a %s)",
 847                 (address)waitingToLockBlocker,
 848                 (InstanceKlass::cast(waitingToLockBlocker->klass()))->external_name());
 849       assert(waitingToLockBlocker->is_a(SystemDictionary::abstract_ownable_synchronizer_klass()),
 850              "Must be an AbstractOwnableSynchronizer");
 851       oop ownerObj = java_util_concurrent_locks_AbstractOwnableSynchronizer::get_owner_threadObj(waitingToLockBlocker);
 852       currentThread = java_lang_Thread::thread(ownerObj);
 853     }
 854     st->print("%s \"%s\"", owner_desc, currentThread->get_thread_name());
 855   }
 856 
 857   st->cr();
 858   st->cr();
 859 
 860   // Print stack traces
 861   bool oldJavaMonitorsInStackTrace = JavaMonitorsInStackTrace;
 862   JavaMonitorsInStackTrace = true;
 863   st->print_cr("Java stack information for the threads listed above:");
 864   st->print_cr("===================================================");


   1 /*
   2  * Copyright (c) 2003, 2013, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.
   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  *


 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
 372         break;


 844     waitingToLockMonitor = (ObjectMonitor*)currentThread->current_pending_monitor();
 845     waitingToLockBlocker = currentThread->current_park_blocker();
 846     st->cr();
 847     st->print_cr("\"%s\":", currentThread->get_thread_name());
 848     const char* owner_desc = ",\n  which is held by";
 849     if (waitingToLockMonitor != NULL) {
 850       st->print("  waiting to lock monitor " INTPTR_FORMAT, waitingToLockMonitor);
 851       oop obj = (oop)waitingToLockMonitor->object();
 852       if (obj != NULL) {
 853         st->print(" (object "INTPTR_FORMAT ", a %s)", (address)obj,
 854                    (InstanceKlass::cast(obj->klass()))->external_name());
 855 
 856         if (!currentThread->current_pending_monitor_is_from_java()) {
 857           owner_desc = "\n  in JNI, which is held by";
 858         }
 859       } else {
 860         // No Java object associated - a JVMTI raw monitor
 861         owner_desc = " (JVMTI raw monitor),\n  which is held by";
 862       }
 863       currentThread = Threads::owning_thread_from_monitor_owner(
 864                         (address)waitingToLockMonitor->owner(),
 865                         false /* no locking needed */);
 866       if (currentThread == NULL) {
 867         // The deadlock was detected at a safepoint so the JavaThread
 868         // that owns waitingToLockMonitor should be findable, but
 869         // if it is not findable, then the previous currentThread is
 870         // blocked permanently.
 871         st->print("%s UNKNOWN_owner_addr=" PTR_FORMAT, owner_desc,
 872                   (address)waitingToLockMonitor->owner());
 873         continue;
 874       }
 875     } else {
 876       st->print("  waiting for ownable synchronizer " INTPTR_FORMAT ", (a %s)",
 877                 (address)waitingToLockBlocker,
 878                 (InstanceKlass::cast(waitingToLockBlocker->klass()))->external_name());
 879       assert(waitingToLockBlocker->is_a(SystemDictionary::abstract_ownable_synchronizer_klass()),
 880              "Must be an AbstractOwnableSynchronizer");
 881       oop ownerObj = java_util_concurrent_locks_AbstractOwnableSynchronizer::get_owner_threadObj(waitingToLockBlocker);
 882       currentThread = java_lang_Thread::thread(ownerObj);
 883     }
 884     st->print("%s \"%s\"", owner_desc, currentThread->get_thread_name());
 885   }
 886 
 887   st->cr();
 888   st->cr();
 889 
 890   // Print stack traces
 891   bool oldJavaMonitorsInStackTrace = JavaMonitorsInStackTrace;
 892   JavaMonitorsInStackTrace = true;
 893   st->print_cr("Java stack information for the threads listed above:");
 894   st->print_cr("===================================================");