< prev index next >

src/hotspot/share/runtime/threads.cpp

Print this page

  51 #include "memory/iterator.hpp"
  52 #include "memory/oopFactory.hpp"
  53 #include "memory/resourceArea.hpp"
  54 #include "memory/universe.hpp"
  55 #include "oops/instanceKlass.hpp"
  56 #include "oops/klass.inline.hpp"
  57 #include "oops/oop.inline.hpp"
  58 #include "oops/symbol.hpp"
  59 #include "prims/jvm_misc.hpp"
  60 #include "runtime/arguments.hpp"
  61 #include "runtime/fieldDescriptor.inline.hpp"
  62 #include "runtime/flags/jvmFlagLimit.hpp"
  63 #include "runtime/handles.inline.hpp"
  64 #include "runtime/globals.hpp"
  65 #include "runtime/interfaceSupport.inline.hpp"
  66 #include "runtime/java.hpp"
  67 #include "runtime/javaCalls.hpp"
  68 #include "runtime/javaThread.inline.hpp"
  69 #include "runtime/jniHandles.inline.hpp"
  70 #include "runtime/jniPeriodicChecker.hpp"

  71 #include "runtime/monitorDeflationThread.hpp"
  72 #include "runtime/mutexLocker.hpp"
  73 #include "runtime/nonJavaThread.hpp"
  74 #include "runtime/objectMonitor.hpp"
  75 #include "runtime/osThread.hpp"
  76 #include "runtime/safepoint.hpp"
  77 #include "runtime/safepointMechanism.inline.hpp"
  78 #include "runtime/safepointVerifiers.hpp"
  79 #include "runtime/serviceThread.hpp"
  80 #include "runtime/sharedRuntime.hpp"
  81 #include "runtime/statSampler.hpp"
  82 #include "runtime/stubCodeGenerator.hpp"
  83 #include "runtime/thread.inline.hpp"
  84 #include "runtime/threads.hpp"
  85 #include "runtime/threadSMR.inline.hpp"
  86 #include "runtime/timer.hpp"
  87 #include "runtime/timerTrace.hpp"
  88 #include "runtime/vmOperations.hpp"
  89 #include "runtime/vm_version.hpp"
  90 #include "services/attachListener.hpp"
  91 #include "services/management.hpp"
  92 #include "services/memTracker.hpp"
  93 #include "services/threadIdTable.hpp"
  94 #include "services/threadService.hpp"

1358                                                          int count,
1359                                                          address monitor) {
1360   GrowableArray<JavaThread*>* result = new GrowableArray<JavaThread*>(count);
1361 
1362   int i = 0;
1363   for (JavaThread* p : *t_list) {
1364     if (!p->can_call_java()) continue;
1365 
1366     // The first stage of async deflation does not affect any field
1367     // used by this comparison so the ObjectMonitor* is usable here.
1368     address pending = (address)p->current_pending_monitor();
1369     if (pending == monitor) {             // found a match
1370       if (i < count) result->append(p);   // save the first count matches
1371       i++;
1372     }
1373   }
1374 
1375   return result;
1376 }
1377 
1378 
1379 JavaThread *Threads::owning_thread_from_monitor_owner(ThreadsList * t_list,
1380                                                       address owner) {
1381   // NULL owner means not locked so we can skip the search
1382   if (owner == NULL) return NULL;
1383 
1384   for (JavaThread* p : *t_list) {
1385     // first, see if owner is the address of a Java thread
1386     if (owner == (address)p) return p;
1387   }
1388 
1389   // Cannot assert on lack of success here since this function may be
1390   // used by code that is trying to report useful problem information
1391   // like deadlock detection.
1392   if (UseHeavyMonitors) return NULL;
1393 
1394   // If we didn't find a matching Java thread and we didn't force use of
1395   // heavyweight monitors, then the owner is the stack address of the
1396   // Lock Word in the owning Java thread's stack.
1397   //
1398   JavaThread* the_owner = NULL;
1399   for (JavaThread* q : *t_list) {
1400     if (q->is_lock_owned(owner)) {
1401       the_owner = q;
1402       break;
1403     }
1404   }














1405 
1406   // cannot assert on lack of success here; see above comment
1407   return the_owner;










1408 }
1409 
1410 class PrintOnClosure : public ThreadClosure {
1411 private:
1412   outputStream* _st;
1413 
1414 public:
1415   PrintOnClosure(outputStream* st) :
1416       _st(st) {}
1417 
1418   virtual void do_thread(Thread* thread) {
1419     if (thread != NULL) {
1420       thread->print_on(_st);
1421       _st->cr();
1422     }
1423   }
1424 };
1425 
1426 // Threads::print_on() is called at safepoint by VM_PrintThreads operation.
1427 void Threads::print_on(outputStream* st, bool print_stacks,

  51 #include "memory/iterator.hpp"
  52 #include "memory/oopFactory.hpp"
  53 #include "memory/resourceArea.hpp"
  54 #include "memory/universe.hpp"
  55 #include "oops/instanceKlass.hpp"
  56 #include "oops/klass.inline.hpp"
  57 #include "oops/oop.inline.hpp"
  58 #include "oops/symbol.hpp"
  59 #include "prims/jvm_misc.hpp"
  60 #include "runtime/arguments.hpp"
  61 #include "runtime/fieldDescriptor.inline.hpp"
  62 #include "runtime/flags/jvmFlagLimit.hpp"
  63 #include "runtime/handles.inline.hpp"
  64 #include "runtime/globals.hpp"
  65 #include "runtime/interfaceSupport.inline.hpp"
  66 #include "runtime/java.hpp"
  67 #include "runtime/javaCalls.hpp"
  68 #include "runtime/javaThread.inline.hpp"
  69 #include "runtime/jniHandles.inline.hpp"
  70 #include "runtime/jniPeriodicChecker.hpp"
  71 #include "runtime/lockStack.inline.hpp"
  72 #include "runtime/monitorDeflationThread.hpp"
  73 #include "runtime/mutexLocker.hpp"
  74 #include "runtime/nonJavaThread.hpp"
  75 #include "runtime/objectMonitor.inline.hpp"
  76 #include "runtime/osThread.hpp"
  77 #include "runtime/safepoint.hpp"
  78 #include "runtime/safepointMechanism.inline.hpp"
  79 #include "runtime/safepointVerifiers.hpp"
  80 #include "runtime/serviceThread.hpp"
  81 #include "runtime/sharedRuntime.hpp"
  82 #include "runtime/statSampler.hpp"
  83 #include "runtime/stubCodeGenerator.hpp"
  84 #include "runtime/thread.inline.hpp"
  85 #include "runtime/threads.hpp"
  86 #include "runtime/threadSMR.inline.hpp"
  87 #include "runtime/timer.hpp"
  88 #include "runtime/timerTrace.hpp"
  89 #include "runtime/vmOperations.hpp"
  90 #include "runtime/vm_version.hpp"
  91 #include "services/attachListener.hpp"
  92 #include "services/management.hpp"
  93 #include "services/memTracker.hpp"
  94 #include "services/threadIdTable.hpp"
  95 #include "services/threadService.hpp"

1359                                                          int count,
1360                                                          address monitor) {
1361   GrowableArray<JavaThread*>* result = new GrowableArray<JavaThread*>(count);
1362 
1363   int i = 0;
1364   for (JavaThread* p : *t_list) {
1365     if (!p->can_call_java()) continue;
1366 
1367     // The first stage of async deflation does not affect any field
1368     // used by this comparison so the ObjectMonitor* is usable here.
1369     address pending = (address)p->current_pending_monitor();
1370     if (pending == monitor) {             // found a match
1371       if (i < count) result->append(p);   // save the first count matches
1372       i++;
1373     }
1374   }
1375 
1376   return result;
1377 }
1378 
1379 JavaThread* Threads::owning_thread_impl(ThreadsList * t_list, oop obj) {




















1380   for (JavaThread* q : *t_list) {
1381     if (q->lock_stack().contains(obj)) {
1382       return q;

1383     }
1384   }
1385   return NULL;
1386 }
1387 
1388 JavaThread* Threads::owning_thread_from_object(ThreadsList * t_list, oop obj, ObjectMonitor** monitor_out) {
1389   markWord header = obj->mark();
1390   if (header.is_fast_locked()) {
1391     return owning_thread_impl(t_list, obj);
1392   } else if (header.has_monitor()) {
1393     *monitor_out = header.monitor();
1394     return owning_thread_from_monitor(t_list, *monitor_out);
1395   } else {
1396     return NULL;
1397   }
1398 }
1399 
1400 JavaThread *Threads::owning_thread_from_monitor(ThreadsList * t_list,
1401                                                 ObjectMonitor* monitor) {
1402   if (monitor->is_owner_anonymous()) {
1403     return owning_thread_impl(t_list, monitor->object());
1404   } else {
1405     // TODO: owner could return Thread* or even JavaThread* already.
1406     Thread* owner = reinterpret_cast<Thread*>(monitor->owner());
1407     // NULL owner means not locked.
1408     if (owner == NULL) return NULL;
1409     assert(owner->is_Java_thread(), "only JavaThreads own monitors");
1410     return reinterpret_cast<JavaThread*>(owner);
1411   }
1412 }
1413 
1414 class PrintOnClosure : public ThreadClosure {
1415 private:
1416   outputStream* _st;
1417 
1418 public:
1419   PrintOnClosure(outputStream* st) :
1420       _st(st) {}
1421 
1422   virtual void do_thread(Thread* thread) {
1423     if (thread != NULL) {
1424       thread->print_on(_st);
1425       _st->cr();
1426     }
1427   }
1428 };
1429 
1430 // Threads::print_on() is called at safepoint by VM_PrintThreads operation.
1431 void Threads::print_on(outputStream* st, bool print_stacks,
< prev index next >