1348 jvmtiError
1349 JvmtiEnv::GetOwnedMonitorInfo(jthread thread, jint* owned_monitor_count_ptr, jobject** owned_monitors_ptr) {
1350 JavaThread* calling_thread = JavaThread::current();
1351 HandleMark hm(calling_thread);
1352
1353 // growable array of jvmti monitors info on the C-heap
1354 GrowableArray<jvmtiMonitorStackDepthInfo*> *owned_monitors_list =
1355 new (mtServiceability) GrowableArray<jvmtiMonitorStackDepthInfo*>(1, mtServiceability);
1356
1357 JvmtiVTMSTransitionDisabler disabler(thread);
1358 ThreadsListHandle tlh(calling_thread);
1359
1360 JavaThread* java_thread = nullptr;
1361 oop thread_oop = nullptr;
1362 jvmtiError err = get_threadOop_and_JavaThread(tlh.list(), thread, calling_thread, &java_thread, &thread_oop);
1363 if (err != JVMTI_ERROR_NONE) {
1364 delete owned_monitors_list;
1365 return err;
1366 }
1367
1368 if (java_thread != nullptr) {
1369 Handle thread_handle(calling_thread, thread_oop);
1370 EscapeBarrier eb(true, calling_thread, java_thread);
1371 if (!eb.deoptimize_objects(MaxJavaStackTraceDepth)) {
1372 delete owned_monitors_list;
1373 return JVMTI_ERROR_OUT_OF_MEMORY;
1374 }
1375 // get owned monitors info with handshake
1376 GetOwnedMonitorInfoClosure op(this, calling_thread, owned_monitors_list);
1377 JvmtiHandshake::execute(&op, &tlh, java_thread, thread_handle);
1378 err = op.result();
1379 }
1380
1381 jint owned_monitor_count = owned_monitors_list->length();
1382 if (err == JVMTI_ERROR_NONE) {
1383 if ((err = allocate(owned_monitor_count * sizeof(jobject *),
1384 (unsigned char**)owned_monitors_ptr)) == JVMTI_ERROR_NONE) {
1385 // copy into the returned array
1386 for (int i = 0; i < owned_monitor_count; i++) {
1387 (*owned_monitors_ptr)[i] =
1388 ((jvmtiMonitorStackDepthInfo*)owned_monitors_list->at(i))->monitor;
1389 }
1390 *owned_monitor_count_ptr = owned_monitor_count;
1391 }
1392 }
1393 // clean up.
1394 for (int i = 0; i < owned_monitor_count; i++) {
1395 deallocate((unsigned char*)owned_monitors_list->at(i));
1396 }
1397 delete owned_monitors_list;
1398
1399 return err;
1406 jvmtiError
1407 JvmtiEnv::GetOwnedMonitorStackDepthInfo(jthread thread, jint* monitor_info_count_ptr, jvmtiMonitorStackDepthInfo** monitor_info_ptr) {
1408 JavaThread* calling_thread = JavaThread::current();
1409 HandleMark hm(calling_thread);
1410
1411 // growable array of jvmti monitors info on the C-heap
1412 GrowableArray<jvmtiMonitorStackDepthInfo*> *owned_monitors_list =
1413 new (mtServiceability) GrowableArray<jvmtiMonitorStackDepthInfo*>(1, mtServiceability);
1414
1415 JvmtiVTMSTransitionDisabler disabler(thread);
1416 ThreadsListHandle tlh(calling_thread);
1417
1418 JavaThread* java_thread = nullptr;
1419 oop thread_oop = nullptr;
1420 jvmtiError err = get_threadOop_and_JavaThread(tlh.list(), thread, calling_thread, &java_thread, &thread_oop);
1421 if (err != JVMTI_ERROR_NONE) {
1422 delete owned_monitors_list;
1423 return err;
1424 }
1425
1426 if (java_thread != nullptr) {
1427 Handle thread_handle(calling_thread, thread_oop);
1428 EscapeBarrier eb(true, calling_thread, java_thread);
1429 if (!eb.deoptimize_objects(MaxJavaStackTraceDepth)) {
1430 delete owned_monitors_list;
1431 return JVMTI_ERROR_OUT_OF_MEMORY;
1432 }
1433 // get owned monitors info with handshake
1434 GetOwnedMonitorInfoClosure op(this, calling_thread, owned_monitors_list);
1435 JvmtiHandshake::execute(&op, &tlh, java_thread, thread_handle);
1436 err = op.result();
1437 }
1438
1439 jint owned_monitor_count = owned_monitors_list->length();
1440 if (err == JVMTI_ERROR_NONE) {
1441 if ((err = allocate(owned_monitor_count * sizeof(jvmtiMonitorStackDepthInfo),
1442 (unsigned char**)monitor_info_ptr)) == JVMTI_ERROR_NONE) {
1443 // copy to output array.
1444 for (int i = 0; i < owned_monitor_count; i++) {
1445 (*monitor_info_ptr)[i].monitor =
1446 ((jvmtiMonitorStackDepthInfo*)owned_monitors_list->at(i))->monitor;
1447 (*monitor_info_ptr)[i].stack_depth =
1448 ((jvmtiMonitorStackDepthInfo*)owned_monitors_list->at(i))->stack_depth;
1449 }
1450 }
1451 *monitor_info_count_ptr = owned_monitor_count;
1452 }
1453
1454 // clean up.
1455 for (int i = 0; i < owned_monitor_count; i++) {
1456 deallocate((unsigned char*)owned_monitors_list->at(i));
1457 }
|
1348 jvmtiError
1349 JvmtiEnv::GetOwnedMonitorInfo(jthread thread, jint* owned_monitor_count_ptr, jobject** owned_monitors_ptr) {
1350 JavaThread* calling_thread = JavaThread::current();
1351 HandleMark hm(calling_thread);
1352
1353 // growable array of jvmti monitors info on the C-heap
1354 GrowableArray<jvmtiMonitorStackDepthInfo*> *owned_monitors_list =
1355 new (mtServiceability) GrowableArray<jvmtiMonitorStackDepthInfo*>(1, mtServiceability);
1356
1357 JvmtiVTMSTransitionDisabler disabler(thread);
1358 ThreadsListHandle tlh(calling_thread);
1359
1360 JavaThread* java_thread = nullptr;
1361 oop thread_oop = nullptr;
1362 jvmtiError err = get_threadOop_and_JavaThread(tlh.list(), thread, calling_thread, &java_thread, &thread_oop);
1363 if (err != JVMTI_ERROR_NONE) {
1364 delete owned_monitors_list;
1365 return err;
1366 }
1367
1368 Handle thread_handle(calling_thread, thread_oop);
1369 EscapeBarrier eb(java_thread != nullptr, calling_thread, java_thread);
1370 if (!eb.deoptimize_objects(MaxJavaStackTraceDepth)) {
1371 delete owned_monitors_list;
1372 return JVMTI_ERROR_OUT_OF_MEMORY;
1373 }
1374 // get owned monitors info with handshake
1375 GetOwnedMonitorInfoClosure op(this, calling_thread, owned_monitors_list);
1376 JvmtiHandshake::execute(&op, &tlh, java_thread, thread_handle);
1377 err = op.result();
1378
1379 jint owned_monitor_count = owned_monitors_list->length();
1380 if (err == JVMTI_ERROR_NONE) {
1381 if ((err = allocate(owned_monitor_count * sizeof(jobject *),
1382 (unsigned char**)owned_monitors_ptr)) == JVMTI_ERROR_NONE) {
1383 // copy into the returned array
1384 for (int i = 0; i < owned_monitor_count; i++) {
1385 (*owned_monitors_ptr)[i] =
1386 ((jvmtiMonitorStackDepthInfo*)owned_monitors_list->at(i))->monitor;
1387 }
1388 *owned_monitor_count_ptr = owned_monitor_count;
1389 }
1390 }
1391 // clean up.
1392 for (int i = 0; i < owned_monitor_count; i++) {
1393 deallocate((unsigned char*)owned_monitors_list->at(i));
1394 }
1395 delete owned_monitors_list;
1396
1397 return err;
1404 jvmtiError
1405 JvmtiEnv::GetOwnedMonitorStackDepthInfo(jthread thread, jint* monitor_info_count_ptr, jvmtiMonitorStackDepthInfo** monitor_info_ptr) {
1406 JavaThread* calling_thread = JavaThread::current();
1407 HandleMark hm(calling_thread);
1408
1409 // growable array of jvmti monitors info on the C-heap
1410 GrowableArray<jvmtiMonitorStackDepthInfo*> *owned_monitors_list =
1411 new (mtServiceability) GrowableArray<jvmtiMonitorStackDepthInfo*>(1, mtServiceability);
1412
1413 JvmtiVTMSTransitionDisabler disabler(thread);
1414 ThreadsListHandle tlh(calling_thread);
1415
1416 JavaThread* java_thread = nullptr;
1417 oop thread_oop = nullptr;
1418 jvmtiError err = get_threadOop_and_JavaThread(tlh.list(), thread, calling_thread, &java_thread, &thread_oop);
1419 if (err != JVMTI_ERROR_NONE) {
1420 delete owned_monitors_list;
1421 return err;
1422 }
1423
1424 Handle thread_handle(calling_thread, thread_oop);
1425 EscapeBarrier eb(java_thread != nullptr, calling_thread, java_thread);
1426 if (!eb.deoptimize_objects(MaxJavaStackTraceDepth)) {
1427 delete owned_monitors_list;
1428 return JVMTI_ERROR_OUT_OF_MEMORY;
1429 }
1430 // get owned monitors info with handshake
1431 GetOwnedMonitorInfoClosure op(this, calling_thread, owned_monitors_list);
1432 JvmtiHandshake::execute(&op, &tlh, java_thread, thread_handle);
1433 err = op.result();
1434
1435 jint owned_monitor_count = owned_monitors_list->length();
1436 if (err == JVMTI_ERROR_NONE) {
1437 if ((err = allocate(owned_monitor_count * sizeof(jvmtiMonitorStackDepthInfo),
1438 (unsigned char**)monitor_info_ptr)) == JVMTI_ERROR_NONE) {
1439 // copy to output array.
1440 for (int i = 0; i < owned_monitor_count; i++) {
1441 (*monitor_info_ptr)[i].monitor =
1442 ((jvmtiMonitorStackDepthInfo*)owned_monitors_list->at(i))->monitor;
1443 (*monitor_info_ptr)[i].stack_depth =
1444 ((jvmtiMonitorStackDepthInfo*)owned_monitors_list->at(i))->stack_depth;
1445 }
1446 }
1447 *monitor_info_count_ptr = owned_monitor_count;
1448 }
1449
1450 // clean up.
1451 for (int i = 0; i < owned_monitor_count; i++) {
1452 deallocate((unsigned char*)owned_monitors_list->at(i));
1453 }
|