< prev index next >

src/hotspot/share/prims/jvmtiEnvBase.cpp

Print this page

  39 #include "prims/jvmtiEnvBase.hpp"
  40 #include "prims/jvmtiEventController.inline.hpp"
  41 #include "prims/jvmtiExtensions.hpp"
  42 #include "prims/jvmtiImpl.hpp"
  43 #include "prims/jvmtiManageCapabilities.hpp"
  44 #include "prims/jvmtiTagMap.hpp"
  45 #include "prims/jvmtiThreadState.inline.hpp"
  46 #include "runtime/continuationEntry.inline.hpp"
  47 #include "runtime/deoptimization.hpp"
  48 #include "runtime/frame.inline.hpp"
  49 #include "runtime/handles.inline.hpp"
  50 #include "runtime/interfaceSupport.inline.hpp"
  51 #include "runtime/javaCalls.hpp"
  52 #include "runtime/javaThread.inline.hpp"
  53 #include "runtime/jfieldIDWorkaround.hpp"
  54 #include "runtime/jniHandles.inline.hpp"
  55 #include "runtime/objectMonitor.inline.hpp"
  56 #include "runtime/osThread.hpp"
  57 #include "runtime/signature.hpp"
  58 #include "runtime/stackWatermarkSet.inline.hpp"

  59 #include "runtime/threads.hpp"
  60 #include "runtime/threadSMR.inline.hpp"
  61 #include "runtime/vframe.inline.hpp"
  62 #include "runtime/vframe_hp.hpp"
  63 #include "runtime/vmThread.hpp"
  64 #include "runtime/vmOperations.hpp"
  65 #include "services/threadService.hpp"
  66 
  67 
  68 ///////////////////////////////////////////////////////////////
  69 //
  70 // JvmtiEnvBase
  71 //
  72 
  73 JvmtiEnvBase* JvmtiEnvBase::_head_environment = nullptr;
  74 
  75 bool JvmtiEnvBase::_globally_initialized = false;
  76 volatile bool JvmtiEnvBase::_needs_clean_up = false;
  77 
  78 jvmtiPhase JvmtiEnvBase::_phase = JVMTI_PHASE_PRIMORDIAL;

1448 jvmtiError
1449 JvmtiEnvBase::get_object_monitor_usage(JavaThread* calling_thread, jobject object, jvmtiMonitorUsage* info_ptr) {
1450   assert(SafepointSynchronize::is_at_safepoint(), "must be at safepoint");
1451   Thread* current_thread = VMThread::vm_thread();
1452   assert(current_thread == Thread::current(), "must be");
1453 
1454   HandleMark hm(current_thread);
1455   Handle hobj;
1456 
1457   // Check arguments
1458   {
1459     oop mirror = JNIHandles::resolve_external_guard(object);
1460     NULL_CHECK(mirror, JVMTI_ERROR_INVALID_OBJECT);
1461     NULL_CHECK(info_ptr, JVMTI_ERROR_NULL_POINTER);
1462 
1463     hobj = Handle(current_thread, mirror);
1464   }
1465 
1466   ThreadsListHandle tlh(current_thread);
1467   JavaThread *owning_thread = nullptr;
1468   ObjectMonitor *mon = nullptr;
1469   jvmtiMonitorUsage ret = {
1470       nullptr, 0, 0, nullptr, 0, nullptr
1471   };
1472 
1473   uint32_t debug_bits = 0;
1474   // first derive the object's owner and entry_count (if any)
1475   owning_thread = ObjectSynchronizer::get_lock_owner(tlh.list(), hobj);
1476   if (owning_thread != nullptr) {
1477     oop thread_oop = get_vthread_or_thread_oop(owning_thread);
1478     bool is_virtual = thread_oop->is_a(vmClasses::BaseVirtualThread_klass());
1479     if (is_virtual) {
1480       thread_oop = nullptr;
1481     }
1482     Handle th(current_thread, thread_oop);
1483     ret.owner = (jthread)jni_reference(calling_thread, th);
1484 
1485     // The recursions field of a monitor does not reflect recursions
1486     // as lightweight locks before inflating the monitor are not included.
1487     // We have to count the number of recursive monitor entries the hard way.
1488     // We pass a handle to survive any GCs along the way.
1489     ret.entry_count = is_virtual ? 0 : count_locked_objects(owning_thread, hobj);
1490   }
1491   // implied else: entry_count == 0
1492 
1493   jint nWant = 0, nWait = 0;
1494   markWord mark = hobj->mark();
1495   ResourceMark rm(current_thread);
1496   GrowableArray<JavaThread*>* wantList = nullptr;
1497 
1498   if (mark.has_monitor()) {
1499     mon = mark.monitor();



1500     assert(mon != nullptr, "must have monitor");
1501     // this object has a heavyweight monitor
1502     nWant = mon->contentions(); // # of threads contending for monitor entry, but not re-entry
1503     nWait = mon->waiters();     // # of threads waiting for notification,
1504                                 // or to re-enter monitor, in Object.wait()
1505 
1506     // Get the actual set of threads trying to enter, or re-enter, the monitor.
1507     wantList = Threads::get_pending_threads(tlh.list(), nWant + nWait, (address)mon);
1508     nWant = wantList->length();
1509   } else {
1510     // this object has a lightweight monitor
1511   }
1512 
1513   jint skipped = 0;
1514   if (mon != nullptr) {
1515     // Robustness: the actual waiting list can be smaller.
1516     // The nWait count we got from the mon->waiters() may include the re-entering
1517     // the monitor threads after being notified. Here we are correcting the actual
1518     // number of the waiting threads by excluding those re-entering the monitor.
1519     nWait = 0;

  39 #include "prims/jvmtiEnvBase.hpp"
  40 #include "prims/jvmtiEventController.inline.hpp"
  41 #include "prims/jvmtiExtensions.hpp"
  42 #include "prims/jvmtiImpl.hpp"
  43 #include "prims/jvmtiManageCapabilities.hpp"
  44 #include "prims/jvmtiTagMap.hpp"
  45 #include "prims/jvmtiThreadState.inline.hpp"
  46 #include "runtime/continuationEntry.inline.hpp"
  47 #include "runtime/deoptimization.hpp"
  48 #include "runtime/frame.inline.hpp"
  49 #include "runtime/handles.inline.hpp"
  50 #include "runtime/interfaceSupport.inline.hpp"
  51 #include "runtime/javaCalls.hpp"
  52 #include "runtime/javaThread.inline.hpp"
  53 #include "runtime/jfieldIDWorkaround.hpp"
  54 #include "runtime/jniHandles.inline.hpp"
  55 #include "runtime/objectMonitor.inline.hpp"
  56 #include "runtime/osThread.hpp"
  57 #include "runtime/signature.hpp"
  58 #include "runtime/stackWatermarkSet.inline.hpp"
  59 #include "runtime/synchronizer.inline.hpp"
  60 #include "runtime/threads.hpp"
  61 #include "runtime/threadSMR.inline.hpp"
  62 #include "runtime/vframe.inline.hpp"
  63 #include "runtime/vframe_hp.hpp"
  64 #include "runtime/vmThread.hpp"
  65 #include "runtime/vmOperations.hpp"
  66 #include "services/threadService.hpp"
  67 
  68 
  69 ///////////////////////////////////////////////////////////////
  70 //
  71 // JvmtiEnvBase
  72 //
  73 
  74 JvmtiEnvBase* JvmtiEnvBase::_head_environment = nullptr;
  75 
  76 bool JvmtiEnvBase::_globally_initialized = false;
  77 volatile bool JvmtiEnvBase::_needs_clean_up = false;
  78 
  79 jvmtiPhase JvmtiEnvBase::_phase = JVMTI_PHASE_PRIMORDIAL;

1449 jvmtiError
1450 JvmtiEnvBase::get_object_monitor_usage(JavaThread* calling_thread, jobject object, jvmtiMonitorUsage* info_ptr) {
1451   assert(SafepointSynchronize::is_at_safepoint(), "must be at safepoint");
1452   Thread* current_thread = VMThread::vm_thread();
1453   assert(current_thread == Thread::current(), "must be");
1454 
1455   HandleMark hm(current_thread);
1456   Handle hobj;
1457 
1458   // Check arguments
1459   {
1460     oop mirror = JNIHandles::resolve_external_guard(object);
1461     NULL_CHECK(mirror, JVMTI_ERROR_INVALID_OBJECT);
1462     NULL_CHECK(info_ptr, JVMTI_ERROR_NULL_POINTER);
1463 
1464     hobj = Handle(current_thread, mirror);
1465   }
1466 
1467   ThreadsListHandle tlh(current_thread);
1468   JavaThread *owning_thread = nullptr;

1469   jvmtiMonitorUsage ret = {
1470       nullptr, 0, 0, nullptr, 0, nullptr
1471   };
1472 
1473   uint32_t debug_bits = 0;
1474   // first derive the object's owner and entry_count (if any)
1475   owning_thread = ObjectSynchronizer::get_lock_owner(tlh.list(), hobj);
1476   if (owning_thread != nullptr) {
1477     oop thread_oop = get_vthread_or_thread_oop(owning_thread);
1478     bool is_virtual = thread_oop->is_a(vmClasses::BaseVirtualThread_klass());
1479     if (is_virtual) {
1480       thread_oop = nullptr;
1481     }
1482     Handle th(current_thread, thread_oop);
1483     ret.owner = (jthread)jni_reference(calling_thread, th);
1484 
1485     // The recursions field of a monitor does not reflect recursions
1486     // as lightweight locks before inflating the monitor are not included.
1487     // We have to count the number of recursive monitor entries the hard way.
1488     // We pass a handle to survive any GCs along the way.
1489     ret.entry_count = is_virtual ? 0 : count_locked_objects(owning_thread, hobj);
1490   }
1491   // implied else: entry_count == 0
1492 
1493   jint nWant = 0, nWait = 0;
1494   markWord mark = hobj->mark();
1495   ResourceMark rm(current_thread);
1496   GrowableArray<JavaThread*>* wantList = nullptr;
1497 
1498   ObjectMonitor* mon = mark.has_monitor()
1499       ? ObjectSynchronizer::read_monitor(current_thread, hobj(), mark)
1500       : nullptr;
1501 
1502   if (mon != nullptr) {
1503     assert(mon != nullptr, "must have monitor");
1504     // this object has a heavyweight monitor
1505     nWant = mon->contentions(); // # of threads contending for monitor entry, but not re-entry
1506     nWait = mon->waiters();     // # of threads waiting for notification,
1507                                 // or to re-enter monitor, in Object.wait()
1508 
1509     // Get the actual set of threads trying to enter, or re-enter, the monitor.
1510     wantList = Threads::get_pending_threads(tlh.list(), nWant + nWait, (address)mon);
1511     nWant = wantList->length();
1512   } else {
1513     // this object has a lightweight monitor
1514   }
1515 
1516   jint skipped = 0;
1517   if (mon != nullptr) {
1518     // Robustness: the actual waiting list can be smaller.
1519     // The nWait count we got from the mon->waiters() may include the re-entering
1520     // the monitor threads after being notified. Here we are correcting the actual
1521     // number of the waiting threads by excluding those re-entering the monitor.
1522     nWait = 0;
< prev index next >