< prev index next >

src/hotspot/share/prims/jvmtiEnv.cpp

Print this page

1352 JvmtiEnv::GetOwnedMonitorInfo(jthread thread, jint* owned_monitor_count_ptr, jobject** owned_monitors_ptr) {
1353   JavaThread* calling_thread = JavaThread::current();
1354   HandleMark hm(calling_thread);
1355 
1356   // growable array of jvmti monitors info on the C-heap
1357   GrowableArray<jvmtiMonitorStackDepthInfo*> *owned_monitors_list =
1358       new (mtServiceability) GrowableArray<jvmtiMonitorStackDepthInfo*>(1, mtServiceability);
1359 
1360   JvmtiVTMSTransitionDisabler disabler(thread);
1361   ThreadsListHandle tlh(calling_thread);
1362 
1363   JavaThread* java_thread = nullptr;
1364   oop thread_oop = nullptr;
1365   jvmtiError err = get_threadOop_and_JavaThread(tlh.list(), thread, &java_thread, &thread_oop);
1366   if (err != JVMTI_ERROR_NONE) {
1367     delete owned_monitors_list;
1368     return err;
1369   }
1370 
1371   if (java_lang_VirtualThread::is_instance(thread_oop)) {
1372     // There is no monitor info to collect if target virtual thread is unmounted.
1373     if (java_thread != nullptr) {
1374       VirtualThreadGetOwnedMonitorInfoClosure op(this,
1375                                                  Handle(calling_thread, thread_oop),
1376                                                  owned_monitors_list);
1377       Handshake::execute(&op, java_thread);
1378       err = op.result();





1379     }
1380   } else {
1381     EscapeBarrier eb(true, calling_thread, java_thread);
1382     if (!eb.deoptimize_objects(MaxJavaStackTraceDepth)) {
1383       delete owned_monitors_list;
1384       return JVMTI_ERROR_OUT_OF_MEMORY;
1385     }
1386 
1387     if (java_thread == calling_thread) {
1388       // It is only safe to make a direct call on the current thread.
1389       // All other usage needs to use a direct handshake for safety.
1390       err = get_owned_monitors(calling_thread, java_thread, owned_monitors_list);
1391     } else {
1392       // get owned monitors info with handshake
1393       GetOwnedMonitorInfoClosure op(calling_thread, this, owned_monitors_list);
1394       Handshake::execute(&op, java_thread);
1395       err = op.result();
1396     }
1397   }
1398 

1432 
1433   JvmtiVTMSTransitionDisabler disabler(thread);
1434   ThreadsListHandle tlh(calling_thread);
1435 
1436   JavaThread* java_thread = nullptr;
1437   oop thread_oop = nullptr;
1438   jvmtiError err = get_threadOop_and_JavaThread(tlh.list(), thread, &java_thread, &thread_oop);
1439   if (err != JVMTI_ERROR_NONE) {
1440     delete owned_monitors_list;
1441     return err;
1442   }
1443 
1444   if (java_lang_VirtualThread::is_instance(thread_oop)) {
1445     // There is no monitor info to collect if target virtual thread is unmounted.
1446     if (java_thread != nullptr) {
1447       VirtualThreadGetOwnedMonitorInfoClosure op(this,
1448                                                  Handle(calling_thread, thread_oop),
1449                                                  owned_monitors_list);
1450       Handshake::execute(&op, java_thread);
1451       err = op.result();





1452     }
1453   } else {
1454     EscapeBarrier eb(true, calling_thread, java_thread);
1455     if (!eb.deoptimize_objects(MaxJavaStackTraceDepth)) {
1456       delete owned_monitors_list;
1457       return JVMTI_ERROR_OUT_OF_MEMORY;
1458     }
1459 
1460     if (java_thread == calling_thread) {
1461       // It is only safe to make a direct call on the current thread.
1462       // All other usage needs to use a direct handshake for safety.
1463       err = get_owned_monitors(calling_thread, java_thread, owned_monitors_list);
1464     } else {
1465       // get owned monitors info with handshake
1466       GetOwnedMonitorInfoClosure op(calling_thread, this, owned_monitors_list);
1467       Handshake::execute(&op, java_thread);
1468       err = op.result();
1469     }
1470   }
1471   jint owned_monitor_count = owned_monitors_list->length();

1488     deallocate((unsigned char*)owned_monitors_list->at(i));
1489   }
1490   delete owned_monitors_list;
1491 
1492   return err;
1493 } /* end GetOwnedMonitorStackDepthInfo */
1494 
1495 
1496 // thread - NOT protected by ThreadsListHandle and NOT pre-checked
1497 // monitor_ptr - pre-checked for null
1498 jvmtiError
1499 JvmtiEnv::GetCurrentContendedMonitor(jthread thread, jobject* monitor_ptr) {
1500   JavaThread* calling_thread = JavaThread::current();
1501   HandleMark hm(calling_thread);
1502 
1503   JvmtiVTMSTransitionDisabler disabler(thread);
1504   ThreadsListHandle tlh(calling_thread);
1505 
1506   JavaThread* java_thread = nullptr;
1507   oop thread_oop = nullptr;

1508   jvmtiError err = get_threadOop_and_JavaThread(tlh.list(), thread, &java_thread, &thread_oop);
1509   if (err != JVMTI_ERROR_NONE) {
1510     return err;
1511   }
1512 
1513   if (java_lang_VirtualThread::is_instance(thread_oop)) {
1514     // There is no monitor info to collect if target virtual thread is unmounted.


1515     if (java_thread != nullptr) {
1516       GetCurrentContendedMonitorClosure op(calling_thread, this, monitor_ptr, /* is_virtual */ true);
1517       Handshake::execute(&op, java_thread);
1518       err = op.result();
1519     } else {
1520       *monitor_ptr = nullptr;
1521       if (!JvmtiEnvBase::is_vthread_alive(thread_oop)) {
1522         err = JVMTI_ERROR_THREAD_NOT_ALIVE;



1523       }

1524     }
1525     return err;
1526   }
1527   if (java_thread == calling_thread) {
1528     // It is only safe to make a direct call on the current thread.
1529     // All other usage needs to use a direct handshake for safety.
1530     err = get_current_contended_monitor(calling_thread, java_thread, monitor_ptr, /* is_virtual */ false);
1531   } else {
1532     // get contended monitor information with handshake
1533     GetCurrentContendedMonitorClosure op(calling_thread, this, monitor_ptr, /* is_virtual */ false);
1534     Handshake::execute(&op, java_thread);
1535     err = op.result();
1536   }
1537   return err;
1538 } /* end GetCurrentContendedMonitor */
1539 
1540 
1541 // thread - NOT protected by ThreadsListHandle and NOT pre-checked
1542 // proc - pre-checked for null
1543 // arg - null is a valid value, must be checked

1352 JvmtiEnv::GetOwnedMonitorInfo(jthread thread, jint* owned_monitor_count_ptr, jobject** owned_monitors_ptr) {
1353   JavaThread* calling_thread = JavaThread::current();
1354   HandleMark hm(calling_thread);
1355 
1356   // growable array of jvmti monitors info on the C-heap
1357   GrowableArray<jvmtiMonitorStackDepthInfo*> *owned_monitors_list =
1358       new (mtServiceability) GrowableArray<jvmtiMonitorStackDepthInfo*>(1, mtServiceability);
1359 
1360   JvmtiVTMSTransitionDisabler disabler(thread);
1361   ThreadsListHandle tlh(calling_thread);
1362 
1363   JavaThread* java_thread = nullptr;
1364   oop thread_oop = nullptr;
1365   jvmtiError err = get_threadOop_and_JavaThread(tlh.list(), thread, &java_thread, &thread_oop);
1366   if (err != JVMTI_ERROR_NONE) {
1367     delete owned_monitors_list;
1368     return err;
1369   }
1370 
1371   if (java_lang_VirtualThread::is_instance(thread_oop)) {

1372     if (java_thread != nullptr) {
1373       VirtualThreadGetOwnedMonitorInfoClosure op(this,
1374                                                  Handle(calling_thread, thread_oop),
1375                                                  owned_monitors_list);
1376       Handshake::execute(&op, java_thread);
1377       err = op.result();
1378     } else {
1379       VirtualThreadGetOwnedMonitorInfoClosure op(this,
1380                                                  Handle(calling_thread, thread_oop),
1381                                                  owned_monitors_list);
1382       op.do_thread(nullptr);
1383     }
1384   } else {
1385     EscapeBarrier eb(true, calling_thread, java_thread);
1386     if (!eb.deoptimize_objects(MaxJavaStackTraceDepth)) {
1387       delete owned_monitors_list;
1388       return JVMTI_ERROR_OUT_OF_MEMORY;
1389     }
1390 
1391     if (java_thread == calling_thread) {
1392       // It is only safe to make a direct call on the current thread.
1393       // All other usage needs to use a direct handshake for safety.
1394       err = get_owned_monitors(calling_thread, java_thread, owned_monitors_list);
1395     } else {
1396       // get owned monitors info with handshake
1397       GetOwnedMonitorInfoClosure op(calling_thread, this, owned_monitors_list);
1398       Handshake::execute(&op, java_thread);
1399       err = op.result();
1400     }
1401   }
1402 

1436 
1437   JvmtiVTMSTransitionDisabler disabler(thread);
1438   ThreadsListHandle tlh(calling_thread);
1439 
1440   JavaThread* java_thread = nullptr;
1441   oop thread_oop = nullptr;
1442   jvmtiError err = get_threadOop_and_JavaThread(tlh.list(), thread, &java_thread, &thread_oop);
1443   if (err != JVMTI_ERROR_NONE) {
1444     delete owned_monitors_list;
1445     return err;
1446   }
1447 
1448   if (java_lang_VirtualThread::is_instance(thread_oop)) {
1449     // There is no monitor info to collect if target virtual thread is unmounted.
1450     if (java_thread != nullptr) {
1451       VirtualThreadGetOwnedMonitorInfoClosure op(this,
1452                                                  Handle(calling_thread, thread_oop),
1453                                                  owned_monitors_list);
1454       Handshake::execute(&op, java_thread);
1455       err = op.result();
1456     } else {
1457       VirtualThreadGetOwnedMonitorInfoClosure op(this,
1458                                                  Handle(calling_thread, thread_oop),
1459                                                  owned_monitors_list);
1460       op.do_thread(nullptr);
1461     }
1462   } else {
1463     EscapeBarrier eb(true, calling_thread, java_thread);
1464     if (!eb.deoptimize_objects(MaxJavaStackTraceDepth)) {
1465       delete owned_monitors_list;
1466       return JVMTI_ERROR_OUT_OF_MEMORY;
1467     }
1468 
1469     if (java_thread == calling_thread) {
1470       // It is only safe to make a direct call on the current thread.
1471       // All other usage needs to use a direct handshake for safety.
1472       err = get_owned_monitors(calling_thread, java_thread, owned_monitors_list);
1473     } else {
1474       // get owned monitors info with handshake
1475       GetOwnedMonitorInfoClosure op(calling_thread, this, owned_monitors_list);
1476       Handshake::execute(&op, java_thread);
1477       err = op.result();
1478     }
1479   }
1480   jint owned_monitor_count = owned_monitors_list->length();

1497     deallocate((unsigned char*)owned_monitors_list->at(i));
1498   }
1499   delete owned_monitors_list;
1500 
1501   return err;
1502 } /* end GetOwnedMonitorStackDepthInfo */
1503 
1504 
1505 // thread - NOT protected by ThreadsListHandle and NOT pre-checked
1506 // monitor_ptr - pre-checked for null
1507 jvmtiError
1508 JvmtiEnv::GetCurrentContendedMonitor(jthread thread, jobject* monitor_ptr) {
1509   JavaThread* calling_thread = JavaThread::current();
1510   HandleMark hm(calling_thread);
1511 
1512   JvmtiVTMSTransitionDisabler disabler(thread);
1513   ThreadsListHandle tlh(calling_thread);
1514 
1515   JavaThread* java_thread = nullptr;
1516   oop thread_oop = nullptr;
1517   *monitor_ptr = nullptr;
1518   jvmtiError err = get_threadOop_and_JavaThread(tlh.list(), thread, &java_thread, &thread_oop);
1519   if (err != JVMTI_ERROR_NONE) {
1520     return err;
1521   }
1522 
1523   if (java_lang_VirtualThread::is_instance(thread_oop)) {
1524     if (!JvmtiEnvBase::is_vthread_alive(thread_oop)) {
1525       return JVMTI_ERROR_THREAD_NOT_ALIVE;
1526     }
1527     if (java_thread != nullptr) {
1528       GetCurrentContendedMonitorClosure op(calling_thread, this, monitor_ptr, /* is_virtual */ true);
1529       Handshake::execute(&op, java_thread);
1530       err = op.result();
1531     } else {
1532       oop cont = java_lang_VirtualThread::continuation(thread_oop);
1533       assert(cont != nullptr, "vthread with no continuation");
1534       stackChunkOop chunk = jdk_internal_vm_Continuation::tail(cont);
1535       assert(chunk != nullptr, "unmounted vthread should have a chunk");
1536       if (chunk->objectMonitor() != nullptr) {
1537         *monitor_ptr = JNIHandles::make_local(calling_thread, chunk->objectMonitor()->object());
1538       }
1539       err = JVMTI_ERROR_NONE;
1540     }
1541     return err;
1542   }
1543   if (java_thread == calling_thread) {
1544     // It is only safe to make a direct call on the current thread.
1545     // All other usage needs to use a direct handshake for safety.
1546     err = get_current_contended_monitor(calling_thread, java_thread, monitor_ptr, /* is_virtual */ false);
1547   } else {
1548     // get contended monitor information with handshake
1549     GetCurrentContendedMonitorClosure op(calling_thread, this, monitor_ptr, /* is_virtual */ false);
1550     Handshake::execute(&op, java_thread);
1551     err = op.result();
1552   }
1553   return err;
1554 } /* end GetCurrentContendedMonitor */
1555 
1556 
1557 // thread - NOT protected by ThreadsListHandle and NOT pre-checked
1558 // proc - pre-checked for null
1559 // arg - null is a valid value, must be checked
< prev index next >