496 objArrayOop r = oopFactory::new_objArray(ik, num_memory_pools, CHECK_NULL);
497 objArrayHandle poolArray(THREAD, r);
498
499 if (mgr == NULL) {
500 // Get all memory pools
501 for (int i = 0; i < num_memory_pools; i++) {
502 MemoryPool* pool = MemoryService::get_memory_pool(i);
503 instanceOop p = pool->get_memory_pool_instance(CHECK_NULL);
504 instanceHandle ph(THREAD, p);
505 poolArray->obj_at_put(i, ph());
506 }
507 } else {
508 // Get memory pools managed by a given memory manager
509 for (int i = 0; i < num_memory_pools; i++) {
510 MemoryPool* pool = mgr->get_memory_pool(i);
511 instanceOop p = pool->get_memory_pool_instance(CHECK_NULL);
512 instanceHandle ph(THREAD, p);
513 poolArray->obj_at_put(i, ph());
514 }
515 }
516 return (jobjectArray) JNIHandles::make_local(env, poolArray());
517 JVM_END
518
519 // Returns an array of java/lang/management/MemoryManagerMXBean object
520 // one for each memory manager if obj == null; otherwise returns
521 // an array of memory managers for a given memory pool if
522 // it is a valid memory pool.
523 JVM_ENTRY(jobjectArray, jmm_GetMemoryManagers(JNIEnv* env, jobject obj))
524 ResourceMark rm(THREAD);
525
526 int num_mgrs;
527 MemoryPool* pool = NULL;
528 if (obj == NULL) {
529 num_mgrs = MemoryService::num_memory_managers();
530 } else {
531 pool = get_memory_pool_from_jobject(obj, CHECK_NULL);
532 if (pool == NULL) {
533 return NULL;
534 }
535 num_mgrs = pool->num_memory_managers();
536 }
540 objArrayOop r = oopFactory::new_objArray(ik, num_mgrs, CHECK_NULL);
541 objArrayHandle mgrArray(THREAD, r);
542
543 if (pool == NULL) {
544 // Get all memory managers
545 for (int i = 0; i < num_mgrs; i++) {
546 MemoryManager* mgr = MemoryService::get_memory_manager(i);
547 instanceOop p = mgr->get_memory_manager_instance(CHECK_NULL);
548 instanceHandle ph(THREAD, p);
549 mgrArray->obj_at_put(i, ph());
550 }
551 } else {
552 // Get memory managers for a given memory pool
553 for (int i = 0; i < num_mgrs; i++) {
554 MemoryManager* mgr = pool->get_memory_manager(i);
555 instanceOop p = mgr->get_memory_manager_instance(CHECK_NULL);
556 instanceHandle ph(THREAD, p);
557 mgrArray->obj_at_put(i, ph());
558 }
559 }
560 return (jobjectArray) JNIHandles::make_local(env, mgrArray());
561 JVM_END
562
563
564 // Returns a java/lang/management/MemoryUsage object containing the memory usage
565 // of a given memory pool.
566 JVM_ENTRY(jobject, jmm_GetMemoryPoolUsage(JNIEnv* env, jobject obj))
567 ResourceMark rm(THREAD);
568
569 MemoryPool* pool = get_memory_pool_from_jobject(obj, CHECK_NULL);
570 if (pool != NULL) {
571 MemoryUsage usage = pool->get_memory_usage();
572 Handle h = MemoryService::create_MemoryUsage_obj(usage, CHECK_NULL);
573 return JNIHandles::make_local(env, h());
574 } else {
575 return NULL;
576 }
577 JVM_END
578
579 // Returns a java/lang/management/MemoryUsage object containing the memory usage
580 // of a given memory pool.
581 JVM_ENTRY(jobject, jmm_GetPeakMemoryPoolUsage(JNIEnv* env, jobject obj))
582 ResourceMark rm(THREAD);
583
584 MemoryPool* pool = get_memory_pool_from_jobject(obj, CHECK_NULL);
585 if (pool != NULL) {
586 MemoryUsage usage = pool->get_peak_memory_usage();
587 Handle h = MemoryService::create_MemoryUsage_obj(usage, CHECK_NULL);
588 return JNIHandles::make_local(env, h());
589 } else {
590 return NULL;
591 }
592 JVM_END
593
594 // Returns a java/lang/management/MemoryUsage object containing the memory usage
595 // of a given memory pool after most recent GC.
596 JVM_ENTRY(jobject, jmm_GetPoolCollectionUsage(JNIEnv* env, jobject obj))
597 ResourceMark rm(THREAD);
598
599 MemoryPool* pool = get_memory_pool_from_jobject(obj, CHECK_NULL);
600 if (pool != NULL && pool->is_collected_pool()) {
601 MemoryUsage usage = pool->get_last_collection_usage();
602 Handle h = MemoryService::create_MemoryUsage_obj(usage, CHECK_NULL);
603 return JNIHandles::make_local(env, h());
604 } else {
605 return NULL;
606 }
607 JVM_END
608
609 // Sets the memory pool sensor for a threshold type
610 JVM_ENTRY(void, jmm_SetPoolSensor(JNIEnv* env, jobject obj, jmmThresholdType type, jobject sensorObj))
611 if (obj == NULL || sensorObj == NULL) {
612 THROW(vmSymbols::java_lang_NullPointerException());
613 }
614
615 InstanceKlass* sensor_klass = Management::sun_management_Sensor_klass(CHECK);
616 oop s = JNIHandles::resolve(sensorObj);
617 assert(s->is_instance(), "Sensor should be an instanceOop");
618 instanceHandle sensor_h(THREAD, (instanceOop) s);
619 if (!sensor_h->is_a(sensor_klass)) {
620 THROW_MSG(vmSymbols::java_lang_IllegalArgumentException(),
621 "Sensor is not an instance of sun.management.Sensor class");
622 }
623
747 }
748 if (!has_undefined_max_size) {
749 total_max += u.max_size();
750 }
751 }
752 }
753
754 // if any one of the memory pool has undefined init_size or max_size,
755 // set it to MemoryUsage::undefined_size()
756 if (has_undefined_init_size) {
757 total_init = MemoryUsage::undefined_size();
758 }
759 if (has_undefined_max_size) {
760 total_max = MemoryUsage::undefined_size();
761 }
762
763 usage = MemoryUsage(total_init, total_used, total_committed, total_max);
764 }
765
766 Handle obj = MemoryService::create_MemoryUsage_obj(usage, CHECK_NULL);
767 return JNIHandles::make_local(env, obj());
768 JVM_END
769
770 // Returns the boolean value of a given attribute.
771 JVM_LEAF(jboolean, jmm_GetBoolAttribute(JNIEnv *env, jmmBoolAttribute att))
772 switch (att) {
773 case JMM_VERBOSE_GC:
774 return MemoryService::get_verbose();
775 case JMM_VERBOSE_CLASS:
776 return ClassLoadingService::get_verbose();
777 case JMM_THREAD_CONTENTION_MONITORING:
778 return ThreadService::is_thread_monitoring_contention();
779 case JMM_THREAD_CPU_TIME:
780 return ThreadService::is_thread_cpu_time_enabled();
781 case JMM_THREAD_ALLOCATED_MEMORY:
782 return ThreadService::is_thread_allocated_memory_enabled();
783 default:
784 assert(0, "Unrecognized attribute");
785 return false;
786 }
787 JVM_END
1262 int num_locked_synchronizers = (locks != NULL ? locks->length() : 0);
1263
1264 objArrayOop array = oopFactory::new_objArray(SystemDictionary::Object_klass(), num_locked_synchronizers, CHECK_NULL);
1265 objArrayHandle sh(THREAD, array);
1266 synchronizers_array = sh;
1267
1268 for (int k = 0; k < num_locked_synchronizers; k++) {
1269 synchronizers_array->obj_at_put(k, locks->at(k));
1270 }
1271 }
1272
1273 // Create java.lang.management.ThreadInfo object
1274 instanceOop info_obj = Management::create_thread_info_instance(ts,
1275 monitors_array,
1276 depths_array,
1277 synchronizers_array,
1278 CHECK_NULL);
1279 result_h->obj_at_put(index, info_obj);
1280 }
1281
1282 return (jobjectArray) JNIHandles::make_local(env, result_h());
1283 JVM_END
1284
1285 // Reset statistic. Return true if the requested statistic is reset.
1286 // Otherwise, return false.
1287 //
1288 // Input parameters:
1289 // obj - specify which instance the statistic associated with to be reset
1290 // For PEAK_POOL_USAGE stat, obj is required to be a memory pool object.
1291 // For THREAD_CONTENTION_COUNT and TIME stat, obj is required to be a thread ID.
1292 // type - the type of statistic to be reset
1293 //
1294 JVM_ENTRY(jboolean, jmm_ResetStatistic(JNIEnv *env, jvalue obj, jmmStatisticType type))
1295 ResourceMark rm(THREAD);
1296
1297 switch (type) {
1298 case JMM_STAT_PEAK_THREAD_COUNT:
1299 ThreadService::reset_peak_thread_count();
1300 return true;
1301
1302 case JMM_STAT_THREAD_CONTENTION_COUNT:
1408 for (int i = 0; i < nFlags; i++) {
1409 JVMFlag* flag = &JVMFlag::flags[i];
1410 // Exclude notproduct and develop flags in product builds.
1411 if (flag->is_constant_in_binary()) {
1412 continue;
1413 }
1414 // Exclude the locked (experimental, diagnostic) flags
1415 if (flag->is_unlocked() || flag->is_unlocker()) {
1416 Handle s = java_lang_String::create_from_str(flag->_name, CHECK_NULL);
1417 flags_ah->obj_at_put(num_entries, s());
1418 num_entries++;
1419 }
1420 }
1421
1422 if (num_entries < nFlags) {
1423 // Return array of right length
1424 objArrayOop res = oopFactory::new_objArray(SystemDictionary::String_klass(), num_entries, CHECK_NULL);
1425 for(int i = 0; i < num_entries; i++) {
1426 res->obj_at_put(i, flags_ah->obj_at(i));
1427 }
1428 return (jobjectArray)JNIHandles::make_local(env, res);
1429 }
1430
1431 return (jobjectArray)JNIHandles::make_local(env, flags_ah());
1432 JVM_END
1433
1434 // Utility function used by jmm_GetVMGlobals. Returns false if flag type
1435 // can't be determined, true otherwise. If false is returned, then *global
1436 // will be incomplete and invalid.
1437 bool add_global_entry(JNIEnv* env, Handle name, jmmVMGlobal *global, JVMFlag *flag, TRAPS) {
1438 Handle flag_name;
1439 if (name() == NULL) {
1440 flag_name = java_lang_String::create_from_str(flag->_name, CHECK_false);
1441 } else {
1442 flag_name = name;
1443 }
1444 global->name = (jstring)JNIHandles::make_local(env, flag_name());
1445
1446 if (flag->is_bool()) {
1447 global->value.z = flag->get_bool() ? JNI_TRUE : JNI_FALSE;
1448 global->type = JMM_VMGLOBAL_TYPE_JBOOLEAN;
1449 } else if (flag->is_int()) {
1450 global->value.j = (jlong)flag->get_int();
1451 global->type = JMM_VMGLOBAL_TYPE_JLONG;
1452 } else if (flag->is_uint()) {
1453 global->value.j = (jlong)flag->get_uint();
1454 global->type = JMM_VMGLOBAL_TYPE_JLONG;
1455 } else if (flag->is_intx()) {
1456 global->value.j = (jlong)flag->get_intx();
1457 global->type = JMM_VMGLOBAL_TYPE_JLONG;
1458 } else if (flag->is_uintx()) {
1459 global->value.j = (jlong)flag->get_uintx();
1460 global->type = JMM_VMGLOBAL_TYPE_JLONG;
1461 } else if (flag->is_uint64_t()) {
1462 global->value.j = (jlong)flag->get_uint64_t();
1463 global->type = JMM_VMGLOBAL_TYPE_JLONG;
1464 } else if (flag->is_double()) {
1465 global->value.d = (jdouble)flag->get_double();
1466 global->type = JMM_VMGLOBAL_TYPE_JDOUBLE;
1467 } else if (flag->is_size_t()) {
1468 global->value.j = (jlong)flag->get_size_t();
1469 global->type = JMM_VMGLOBAL_TYPE_JLONG;
1470 } else if (flag->is_ccstr()) {
1471 Handle str = java_lang_String::create_from_str(flag->get_ccstr(), CHECK_false);
1472 global->value.l = (jobject)JNIHandles::make_local(env, str());
1473 global->type = JMM_VMGLOBAL_TYPE_JSTRING;
1474 } else {
1475 global->type = JMM_VMGLOBAL_TYPE_UNKNOWN;
1476 return false;
1477 }
1478
1479 global->writeable = flag->is_writeable();
1480 global->external = flag->is_external();
1481 switch (flag->get_origin()) {
1482 case JVMFlag::DEFAULT:
1483 global->origin = JMM_VMGLOBAL_ORIGIN_DEFAULT;
1484 break;
1485 case JVMFlag::COMMAND_LINE:
1486 global->origin = JMM_VMGLOBAL_ORIGIN_COMMAND_LINE;
1487 break;
1488 case JVMFlag::ENVIRON_VAR:
1489 global->origin = JMM_VMGLOBAL_ORIGIN_ENVIRON_VAR;
1490 break;
1491 case JVMFlag::CONFIG_FILE:
1492 global->origin = JMM_VMGLOBAL_ORIGIN_CONFIG_FILE;
1531 objArrayHandle names_ah(THREAD, ta);
1532 // Make sure we have a String array
1533 Klass* element_klass = ObjArrayKlass::cast(names_ah->klass())->element_klass();
1534 if (element_klass != SystemDictionary::String_klass()) {
1535 THROW_MSG_(vmSymbols::java_lang_IllegalArgumentException(),
1536 "Array element type is not String class", 0);
1537 }
1538
1539 int names_length = names_ah->length();
1540 int num_entries = 0;
1541 for (int i = 0; i < names_length && i < count; i++) {
1542 oop s = names_ah->obj_at(i);
1543 if (s == NULL) {
1544 THROW_(vmSymbols::java_lang_NullPointerException(), 0);
1545 }
1546
1547 Handle sh(THREAD, s);
1548 char* str = java_lang_String::as_utf8_string(s);
1549 JVMFlag* flag = JVMFlag::find_flag(str);
1550 if (flag != NULL &&
1551 add_global_entry(env, sh, &globals[i], flag, THREAD)) {
1552 num_entries++;
1553 } else {
1554 globals[i].name = NULL;
1555 }
1556 }
1557 return num_entries;
1558 } else {
1559 // return all globals if names == NULL
1560
1561 // last flag entry is always NULL, so subtract 1
1562 int nFlags = (int) JVMFlag::numFlags - 1;
1563 Handle null_h;
1564 int num_entries = 0;
1565 for (int i = 0; i < nFlags && num_entries < count; i++) {
1566 JVMFlag* flag = &JVMFlag::flags[i];
1567 // Exclude notproduct and develop flags in product builds.
1568 if (flag->is_constant_in_binary()) {
1569 continue;
1570 }
1571 // Exclude the locked (diagnostic, experimental) flags
1572 if ((flag->is_unlocked() || flag->is_unlocker()) &&
1573 add_global_entry(env, null_h, &globals[num_entries], flag, THREAD)) {
1574 num_entries++;
1575 }
1576 }
1577 return num_entries;
1578 }
1579 JVM_END
1580
1581 JVM_ENTRY(void, jmm_SetVMGlobal(JNIEnv *env, jstring flag_name, jvalue new_value))
1582 ResourceMark rm(THREAD);
1583
1584 oop fn = JNIHandles::resolve_external_guard(flag_name);
1585 if (fn == NULL) {
1586 THROW_MSG(vmSymbols::java_lang_NullPointerException(),
1587 "The flag name cannot be null.");
1588 }
1589 char* name = java_lang_String::as_utf8_string(fn);
1590
1591 FormatBuffer<80> error_msg("%s", "");
1592 int succeed = WriteableFlags::set_flag(name, new_value, JVMFlag::MANAGEMENT, error_msg);
1593
1738 GrowableArray<JavaThread*>* deadlock_threads = cycle->threads();
1739 int len = deadlock_threads->length();
1740 for (int i = 0; i < len; i++) {
1741 threads_ah->obj_at_put(index, deadlock_threads->at(i)->threadObj());
1742 index++;
1743 }
1744 }
1745 return threads_ah;
1746 }
1747
1748 // Finds cycles of threads that are deadlocked involved in object monitors
1749 // and JSR-166 synchronizers.
1750 // Returns an array of Thread objects which are in deadlock, if any.
1751 // Otherwise, returns NULL.
1752 //
1753 // Input parameter:
1754 // object_monitors_only - if true, only check object monitors
1755 //
1756 JVM_ENTRY(jobjectArray, jmm_FindDeadlockedThreads(JNIEnv *env, jboolean object_monitors_only))
1757 Handle result = find_deadlocks(object_monitors_only != 0, CHECK_NULL);
1758 return (jobjectArray) JNIHandles::make_local(env, result());
1759 JVM_END
1760
1761 // Finds cycles of threads that are deadlocked on monitor locks
1762 // Returns an array of Thread objects which are in deadlock, if any.
1763 // Otherwise, returns NULL.
1764 JVM_ENTRY(jobjectArray, jmm_FindMonitorDeadlockedThreads(JNIEnv *env))
1765 Handle result = find_deadlocks(true, CHECK_NULL);
1766 return (jobjectArray) JNIHandles::make_local(env, result());
1767 JVM_END
1768
1769 // Gets the information about GC extension attributes including
1770 // the name of the attribute, its type, and a short description.
1771 //
1772 // Input parameters:
1773 // mgr - GC memory manager
1774 // info - caller allocated array of jmmExtAttributeInfo
1775 // count - number of elements of the info array
1776 //
1777 // Returns the number of GC extension attributes filled in the info array; or
1778 // -1 if info is not big enough
1779 //
1780 JVM_ENTRY(jint, jmm_GetGCExtAttributeInfo(JNIEnv *env, jobject mgr, jmmExtAttributeInfo* info, jint count))
1781 // All GC memory managers have 1 attribute (number of GC threads)
1782 if (count == 0) {
1783 return 0;
1784 }
1785
1786 if (info == NULL) {
1928 if (dumper.dump(name) != 0) {
1929 const char* errmsg = dumper.error_as_C_string();
1930 THROW_MSG_(vmSymbols::java_io_IOException(), errmsg, -1);
1931 }
1932 return 0;
1933 #else // INCLUDE_SERVICES
1934 return -1;
1935 #endif // INCLUDE_SERVICES
1936 JVM_END
1937
1938 JVM_ENTRY(jobjectArray, jmm_GetDiagnosticCommands(JNIEnv *env))
1939 ResourceMark rm(THREAD);
1940 GrowableArray<const char *>* dcmd_list = DCmdFactory::DCmd_list(DCmd_Source_MBean);
1941 objArrayOop cmd_array_oop = oopFactory::new_objArray(SystemDictionary::String_klass(),
1942 dcmd_list->length(), CHECK_NULL);
1943 objArrayHandle cmd_array(THREAD, cmd_array_oop);
1944 for (int i = 0; i < dcmd_list->length(); i++) {
1945 oop cmd_name = java_lang_String::create_oop_from_str(dcmd_list->at(i), CHECK_NULL);
1946 cmd_array->obj_at_put(i, cmd_name);
1947 }
1948 return (jobjectArray) JNIHandles::make_local(env, cmd_array());
1949 JVM_END
1950
1951 JVM_ENTRY(void, jmm_GetDiagnosticCommandInfo(JNIEnv *env, jobjectArray cmds,
1952 dcmdInfo* infoArray))
1953 if (cmds == NULL || infoArray == NULL) {
1954 THROW(vmSymbols::java_lang_NullPointerException());
1955 }
1956
1957 ResourceMark rm(THREAD);
1958
1959 objArrayOop ca = objArrayOop(JNIHandles::resolve_non_null(cmds));
1960 objArrayHandle cmds_ah(THREAD, ca);
1961
1962 // Make sure we have a String array
1963 Klass* element_klass = ObjArrayKlass::cast(cmds_ah->klass())->element_klass();
1964 if (element_klass != SystemDictionary::String_klass()) {
1965 THROW_MSG(vmSymbols::java_lang_IllegalArgumentException(),
1966 "Array element type is not String class");
1967 }
1968
2037 infoArray[i].position = array->at(i)->position();
2038 }
2039 return;
2040 JVM_END
2041
2042 JVM_ENTRY(jstring, jmm_ExecuteDiagnosticCommand(JNIEnv *env, jstring commandline))
2043 ResourceMark rm(THREAD);
2044 oop cmd = JNIHandles::resolve_external_guard(commandline);
2045 if (cmd == NULL) {
2046 THROW_MSG_NULL(vmSymbols::java_lang_NullPointerException(),
2047 "Command line cannot be null.");
2048 }
2049 char* cmdline = java_lang_String::as_utf8_string(cmd);
2050 if (cmdline == NULL) {
2051 THROW_MSG_NULL(vmSymbols::java_lang_NullPointerException(),
2052 "Command line content cannot be null.");
2053 }
2054 bufferedStream output;
2055 DCmd::parse_and_execute(DCmd_Source_MBean, &output, cmdline, ' ', CHECK_NULL);
2056 oop result = java_lang_String::create_oop_from_str(output.as_string(), CHECK_NULL);
2057 return (jstring) JNIHandles::make_local(env, result);
2058 JVM_END
2059
2060 JVM_ENTRY(void, jmm_SetDiagnosticFrameworkNotificationEnabled(JNIEnv *env, jboolean enabled))
2061 DCmdFactory::set_jmx_notification_enabled(enabled?true:false);
2062 JVM_END
2063
2064 jlong Management::ticks_to_ms(jlong ticks) {
2065 assert(os::elapsed_frequency() > 0, "Must be non-zero");
2066 return (jlong)(((double)ticks / (double)os::elapsed_frequency())
2067 * (double)1000.0);
2068 }
2069 #endif // INCLUDE_MANAGEMENT
2070
2071 // Gets the amount of memory allocated on the Java heap for a single thread.
2072 // Returns -1 if the thread does not exist or has terminated.
2073 JVM_ENTRY(jlong, jmm_GetOneThreadAllocatedMemory(JNIEnv *env, jlong thread_id))
2074 if (thread_id < 0) {
2075 THROW_MSG_(vmSymbols::java_lang_IllegalArgumentException(),
2076 "Invalid thread ID", -1);
2077 }
|
496 objArrayOop r = oopFactory::new_objArray(ik, num_memory_pools, CHECK_NULL);
497 objArrayHandle poolArray(THREAD, r);
498
499 if (mgr == NULL) {
500 // Get all memory pools
501 for (int i = 0; i < num_memory_pools; i++) {
502 MemoryPool* pool = MemoryService::get_memory_pool(i);
503 instanceOop p = pool->get_memory_pool_instance(CHECK_NULL);
504 instanceHandle ph(THREAD, p);
505 poolArray->obj_at_put(i, ph());
506 }
507 } else {
508 // Get memory pools managed by a given memory manager
509 for (int i = 0; i < num_memory_pools; i++) {
510 MemoryPool* pool = mgr->get_memory_pool(i);
511 instanceOop p = pool->get_memory_pool_instance(CHECK_NULL);
512 instanceHandle ph(THREAD, p);
513 poolArray->obj_at_put(i, ph());
514 }
515 }
516 return (jobjectArray) JNIHandles::make_local(THREAD, poolArray());
517 JVM_END
518
519 // Returns an array of java/lang/management/MemoryManagerMXBean object
520 // one for each memory manager if obj == null; otherwise returns
521 // an array of memory managers for a given memory pool if
522 // it is a valid memory pool.
523 JVM_ENTRY(jobjectArray, jmm_GetMemoryManagers(JNIEnv* env, jobject obj))
524 ResourceMark rm(THREAD);
525
526 int num_mgrs;
527 MemoryPool* pool = NULL;
528 if (obj == NULL) {
529 num_mgrs = MemoryService::num_memory_managers();
530 } else {
531 pool = get_memory_pool_from_jobject(obj, CHECK_NULL);
532 if (pool == NULL) {
533 return NULL;
534 }
535 num_mgrs = pool->num_memory_managers();
536 }
540 objArrayOop r = oopFactory::new_objArray(ik, num_mgrs, CHECK_NULL);
541 objArrayHandle mgrArray(THREAD, r);
542
543 if (pool == NULL) {
544 // Get all memory managers
545 for (int i = 0; i < num_mgrs; i++) {
546 MemoryManager* mgr = MemoryService::get_memory_manager(i);
547 instanceOop p = mgr->get_memory_manager_instance(CHECK_NULL);
548 instanceHandle ph(THREAD, p);
549 mgrArray->obj_at_put(i, ph());
550 }
551 } else {
552 // Get memory managers for a given memory pool
553 for (int i = 0; i < num_mgrs; i++) {
554 MemoryManager* mgr = pool->get_memory_manager(i);
555 instanceOop p = mgr->get_memory_manager_instance(CHECK_NULL);
556 instanceHandle ph(THREAD, p);
557 mgrArray->obj_at_put(i, ph());
558 }
559 }
560 return (jobjectArray) JNIHandles::make_local(THREAD, mgrArray());
561 JVM_END
562
563
564 // Returns a java/lang/management/MemoryUsage object containing the memory usage
565 // of a given memory pool.
566 JVM_ENTRY(jobject, jmm_GetMemoryPoolUsage(JNIEnv* env, jobject obj))
567 ResourceMark rm(THREAD);
568
569 MemoryPool* pool = get_memory_pool_from_jobject(obj, CHECK_NULL);
570 if (pool != NULL) {
571 MemoryUsage usage = pool->get_memory_usage();
572 Handle h = MemoryService::create_MemoryUsage_obj(usage, CHECK_NULL);
573 return JNIHandles::make_local(THREAD, h());
574 } else {
575 return NULL;
576 }
577 JVM_END
578
579 // Returns a java/lang/management/MemoryUsage object containing the memory usage
580 // of a given memory pool.
581 JVM_ENTRY(jobject, jmm_GetPeakMemoryPoolUsage(JNIEnv* env, jobject obj))
582 ResourceMark rm(THREAD);
583
584 MemoryPool* pool = get_memory_pool_from_jobject(obj, CHECK_NULL);
585 if (pool != NULL) {
586 MemoryUsage usage = pool->get_peak_memory_usage();
587 Handle h = MemoryService::create_MemoryUsage_obj(usage, CHECK_NULL);
588 return JNIHandles::make_local(THREAD, h());
589 } else {
590 return NULL;
591 }
592 JVM_END
593
594 // Returns a java/lang/management/MemoryUsage object containing the memory usage
595 // of a given memory pool after most recent GC.
596 JVM_ENTRY(jobject, jmm_GetPoolCollectionUsage(JNIEnv* env, jobject obj))
597 ResourceMark rm(THREAD);
598
599 MemoryPool* pool = get_memory_pool_from_jobject(obj, CHECK_NULL);
600 if (pool != NULL && pool->is_collected_pool()) {
601 MemoryUsage usage = pool->get_last_collection_usage();
602 Handle h = MemoryService::create_MemoryUsage_obj(usage, CHECK_NULL);
603 return JNIHandles::make_local(THREAD, h());
604 } else {
605 return NULL;
606 }
607 JVM_END
608
609 // Sets the memory pool sensor for a threshold type
610 JVM_ENTRY(void, jmm_SetPoolSensor(JNIEnv* env, jobject obj, jmmThresholdType type, jobject sensorObj))
611 if (obj == NULL || sensorObj == NULL) {
612 THROW(vmSymbols::java_lang_NullPointerException());
613 }
614
615 InstanceKlass* sensor_klass = Management::sun_management_Sensor_klass(CHECK);
616 oop s = JNIHandles::resolve(sensorObj);
617 assert(s->is_instance(), "Sensor should be an instanceOop");
618 instanceHandle sensor_h(THREAD, (instanceOop) s);
619 if (!sensor_h->is_a(sensor_klass)) {
620 THROW_MSG(vmSymbols::java_lang_IllegalArgumentException(),
621 "Sensor is not an instance of sun.management.Sensor class");
622 }
623
747 }
748 if (!has_undefined_max_size) {
749 total_max += u.max_size();
750 }
751 }
752 }
753
754 // if any one of the memory pool has undefined init_size or max_size,
755 // set it to MemoryUsage::undefined_size()
756 if (has_undefined_init_size) {
757 total_init = MemoryUsage::undefined_size();
758 }
759 if (has_undefined_max_size) {
760 total_max = MemoryUsage::undefined_size();
761 }
762
763 usage = MemoryUsage(total_init, total_used, total_committed, total_max);
764 }
765
766 Handle obj = MemoryService::create_MemoryUsage_obj(usage, CHECK_NULL);
767 return JNIHandles::make_local(THREAD, obj());
768 JVM_END
769
770 // Returns the boolean value of a given attribute.
771 JVM_LEAF(jboolean, jmm_GetBoolAttribute(JNIEnv *env, jmmBoolAttribute att))
772 switch (att) {
773 case JMM_VERBOSE_GC:
774 return MemoryService::get_verbose();
775 case JMM_VERBOSE_CLASS:
776 return ClassLoadingService::get_verbose();
777 case JMM_THREAD_CONTENTION_MONITORING:
778 return ThreadService::is_thread_monitoring_contention();
779 case JMM_THREAD_CPU_TIME:
780 return ThreadService::is_thread_cpu_time_enabled();
781 case JMM_THREAD_ALLOCATED_MEMORY:
782 return ThreadService::is_thread_allocated_memory_enabled();
783 default:
784 assert(0, "Unrecognized attribute");
785 return false;
786 }
787 JVM_END
1262 int num_locked_synchronizers = (locks != NULL ? locks->length() : 0);
1263
1264 objArrayOop array = oopFactory::new_objArray(SystemDictionary::Object_klass(), num_locked_synchronizers, CHECK_NULL);
1265 objArrayHandle sh(THREAD, array);
1266 synchronizers_array = sh;
1267
1268 for (int k = 0; k < num_locked_synchronizers; k++) {
1269 synchronizers_array->obj_at_put(k, locks->at(k));
1270 }
1271 }
1272
1273 // Create java.lang.management.ThreadInfo object
1274 instanceOop info_obj = Management::create_thread_info_instance(ts,
1275 monitors_array,
1276 depths_array,
1277 synchronizers_array,
1278 CHECK_NULL);
1279 result_h->obj_at_put(index, info_obj);
1280 }
1281
1282 return (jobjectArray) JNIHandles::make_local(THREAD, result_h());
1283 JVM_END
1284
1285 // Reset statistic. Return true if the requested statistic is reset.
1286 // Otherwise, return false.
1287 //
1288 // Input parameters:
1289 // obj - specify which instance the statistic associated with to be reset
1290 // For PEAK_POOL_USAGE stat, obj is required to be a memory pool object.
1291 // For THREAD_CONTENTION_COUNT and TIME stat, obj is required to be a thread ID.
1292 // type - the type of statistic to be reset
1293 //
1294 JVM_ENTRY(jboolean, jmm_ResetStatistic(JNIEnv *env, jvalue obj, jmmStatisticType type))
1295 ResourceMark rm(THREAD);
1296
1297 switch (type) {
1298 case JMM_STAT_PEAK_THREAD_COUNT:
1299 ThreadService::reset_peak_thread_count();
1300 return true;
1301
1302 case JMM_STAT_THREAD_CONTENTION_COUNT:
1408 for (int i = 0; i < nFlags; i++) {
1409 JVMFlag* flag = &JVMFlag::flags[i];
1410 // Exclude notproduct and develop flags in product builds.
1411 if (flag->is_constant_in_binary()) {
1412 continue;
1413 }
1414 // Exclude the locked (experimental, diagnostic) flags
1415 if (flag->is_unlocked() || flag->is_unlocker()) {
1416 Handle s = java_lang_String::create_from_str(flag->_name, CHECK_NULL);
1417 flags_ah->obj_at_put(num_entries, s());
1418 num_entries++;
1419 }
1420 }
1421
1422 if (num_entries < nFlags) {
1423 // Return array of right length
1424 objArrayOop res = oopFactory::new_objArray(SystemDictionary::String_klass(), num_entries, CHECK_NULL);
1425 for(int i = 0; i < num_entries; i++) {
1426 res->obj_at_put(i, flags_ah->obj_at(i));
1427 }
1428 return (jobjectArray)JNIHandles::make_local(THREAD, res);
1429 }
1430
1431 return (jobjectArray)JNIHandles::make_local(THREAD, flags_ah());
1432 JVM_END
1433
1434 // Utility function used by jmm_GetVMGlobals. Returns false if flag type
1435 // can't be determined, true otherwise. If false is returned, then *global
1436 // will be incomplete and invalid.
1437 bool add_global_entry(Handle name, jmmVMGlobal *global, JVMFlag *flag, TRAPS) {
1438 Handle flag_name;
1439 if (name() == NULL) {
1440 flag_name = java_lang_String::create_from_str(flag->_name, CHECK_false);
1441 } else {
1442 flag_name = name;
1443 }
1444 global->name = (jstring)JNIHandles::make_local(THREAD, flag_name());
1445
1446 if (flag->is_bool()) {
1447 global->value.z = flag->get_bool() ? JNI_TRUE : JNI_FALSE;
1448 global->type = JMM_VMGLOBAL_TYPE_JBOOLEAN;
1449 } else if (flag->is_int()) {
1450 global->value.j = (jlong)flag->get_int();
1451 global->type = JMM_VMGLOBAL_TYPE_JLONG;
1452 } else if (flag->is_uint()) {
1453 global->value.j = (jlong)flag->get_uint();
1454 global->type = JMM_VMGLOBAL_TYPE_JLONG;
1455 } else if (flag->is_intx()) {
1456 global->value.j = (jlong)flag->get_intx();
1457 global->type = JMM_VMGLOBAL_TYPE_JLONG;
1458 } else if (flag->is_uintx()) {
1459 global->value.j = (jlong)flag->get_uintx();
1460 global->type = JMM_VMGLOBAL_TYPE_JLONG;
1461 } else if (flag->is_uint64_t()) {
1462 global->value.j = (jlong)flag->get_uint64_t();
1463 global->type = JMM_VMGLOBAL_TYPE_JLONG;
1464 } else if (flag->is_double()) {
1465 global->value.d = (jdouble)flag->get_double();
1466 global->type = JMM_VMGLOBAL_TYPE_JDOUBLE;
1467 } else if (flag->is_size_t()) {
1468 global->value.j = (jlong)flag->get_size_t();
1469 global->type = JMM_VMGLOBAL_TYPE_JLONG;
1470 } else if (flag->is_ccstr()) {
1471 Handle str = java_lang_String::create_from_str(flag->get_ccstr(), CHECK_false);
1472 global->value.l = (jobject)JNIHandles::make_local(THREAD, str());
1473 global->type = JMM_VMGLOBAL_TYPE_JSTRING;
1474 } else {
1475 global->type = JMM_VMGLOBAL_TYPE_UNKNOWN;
1476 return false;
1477 }
1478
1479 global->writeable = flag->is_writeable();
1480 global->external = flag->is_external();
1481 switch (flag->get_origin()) {
1482 case JVMFlag::DEFAULT:
1483 global->origin = JMM_VMGLOBAL_ORIGIN_DEFAULT;
1484 break;
1485 case JVMFlag::COMMAND_LINE:
1486 global->origin = JMM_VMGLOBAL_ORIGIN_COMMAND_LINE;
1487 break;
1488 case JVMFlag::ENVIRON_VAR:
1489 global->origin = JMM_VMGLOBAL_ORIGIN_ENVIRON_VAR;
1490 break;
1491 case JVMFlag::CONFIG_FILE:
1492 global->origin = JMM_VMGLOBAL_ORIGIN_CONFIG_FILE;
1531 objArrayHandle names_ah(THREAD, ta);
1532 // Make sure we have a String array
1533 Klass* element_klass = ObjArrayKlass::cast(names_ah->klass())->element_klass();
1534 if (element_klass != SystemDictionary::String_klass()) {
1535 THROW_MSG_(vmSymbols::java_lang_IllegalArgumentException(),
1536 "Array element type is not String class", 0);
1537 }
1538
1539 int names_length = names_ah->length();
1540 int num_entries = 0;
1541 for (int i = 0; i < names_length && i < count; i++) {
1542 oop s = names_ah->obj_at(i);
1543 if (s == NULL) {
1544 THROW_(vmSymbols::java_lang_NullPointerException(), 0);
1545 }
1546
1547 Handle sh(THREAD, s);
1548 char* str = java_lang_String::as_utf8_string(s);
1549 JVMFlag* flag = JVMFlag::find_flag(str);
1550 if (flag != NULL &&
1551 add_global_entry(sh, &globals[i], flag, THREAD)) {
1552 num_entries++;
1553 } else {
1554 globals[i].name = NULL;
1555 }
1556 }
1557 return num_entries;
1558 } else {
1559 // return all globals if names == NULL
1560
1561 // last flag entry is always NULL, so subtract 1
1562 int nFlags = (int) JVMFlag::numFlags - 1;
1563 Handle null_h;
1564 int num_entries = 0;
1565 for (int i = 0; i < nFlags && num_entries < count; i++) {
1566 JVMFlag* flag = &JVMFlag::flags[i];
1567 // Exclude notproduct and develop flags in product builds.
1568 if (flag->is_constant_in_binary()) {
1569 continue;
1570 }
1571 // Exclude the locked (diagnostic, experimental) flags
1572 if ((flag->is_unlocked() || flag->is_unlocker()) &&
1573 add_global_entry(null_h, &globals[num_entries], flag, THREAD)) {
1574 num_entries++;
1575 }
1576 }
1577 return num_entries;
1578 }
1579 JVM_END
1580
1581 JVM_ENTRY(void, jmm_SetVMGlobal(JNIEnv *env, jstring flag_name, jvalue new_value))
1582 ResourceMark rm(THREAD);
1583
1584 oop fn = JNIHandles::resolve_external_guard(flag_name);
1585 if (fn == NULL) {
1586 THROW_MSG(vmSymbols::java_lang_NullPointerException(),
1587 "The flag name cannot be null.");
1588 }
1589 char* name = java_lang_String::as_utf8_string(fn);
1590
1591 FormatBuffer<80> error_msg("%s", "");
1592 int succeed = WriteableFlags::set_flag(name, new_value, JVMFlag::MANAGEMENT, error_msg);
1593
1738 GrowableArray<JavaThread*>* deadlock_threads = cycle->threads();
1739 int len = deadlock_threads->length();
1740 for (int i = 0; i < len; i++) {
1741 threads_ah->obj_at_put(index, deadlock_threads->at(i)->threadObj());
1742 index++;
1743 }
1744 }
1745 return threads_ah;
1746 }
1747
1748 // Finds cycles of threads that are deadlocked involved in object monitors
1749 // and JSR-166 synchronizers.
1750 // Returns an array of Thread objects which are in deadlock, if any.
1751 // Otherwise, returns NULL.
1752 //
1753 // Input parameter:
1754 // object_monitors_only - if true, only check object monitors
1755 //
1756 JVM_ENTRY(jobjectArray, jmm_FindDeadlockedThreads(JNIEnv *env, jboolean object_monitors_only))
1757 Handle result = find_deadlocks(object_monitors_only != 0, CHECK_NULL);
1758 return (jobjectArray) JNIHandles::make_local(THREAD, result());
1759 JVM_END
1760
1761 // Finds cycles of threads that are deadlocked on monitor locks
1762 // Returns an array of Thread objects which are in deadlock, if any.
1763 // Otherwise, returns NULL.
1764 JVM_ENTRY(jobjectArray, jmm_FindMonitorDeadlockedThreads(JNIEnv *env))
1765 Handle result = find_deadlocks(true, CHECK_NULL);
1766 return (jobjectArray) JNIHandles::make_local(THREAD, result());
1767 JVM_END
1768
1769 // Gets the information about GC extension attributes including
1770 // the name of the attribute, its type, and a short description.
1771 //
1772 // Input parameters:
1773 // mgr - GC memory manager
1774 // info - caller allocated array of jmmExtAttributeInfo
1775 // count - number of elements of the info array
1776 //
1777 // Returns the number of GC extension attributes filled in the info array; or
1778 // -1 if info is not big enough
1779 //
1780 JVM_ENTRY(jint, jmm_GetGCExtAttributeInfo(JNIEnv *env, jobject mgr, jmmExtAttributeInfo* info, jint count))
1781 // All GC memory managers have 1 attribute (number of GC threads)
1782 if (count == 0) {
1783 return 0;
1784 }
1785
1786 if (info == NULL) {
1928 if (dumper.dump(name) != 0) {
1929 const char* errmsg = dumper.error_as_C_string();
1930 THROW_MSG_(vmSymbols::java_io_IOException(), errmsg, -1);
1931 }
1932 return 0;
1933 #else // INCLUDE_SERVICES
1934 return -1;
1935 #endif // INCLUDE_SERVICES
1936 JVM_END
1937
1938 JVM_ENTRY(jobjectArray, jmm_GetDiagnosticCommands(JNIEnv *env))
1939 ResourceMark rm(THREAD);
1940 GrowableArray<const char *>* dcmd_list = DCmdFactory::DCmd_list(DCmd_Source_MBean);
1941 objArrayOop cmd_array_oop = oopFactory::new_objArray(SystemDictionary::String_klass(),
1942 dcmd_list->length(), CHECK_NULL);
1943 objArrayHandle cmd_array(THREAD, cmd_array_oop);
1944 for (int i = 0; i < dcmd_list->length(); i++) {
1945 oop cmd_name = java_lang_String::create_oop_from_str(dcmd_list->at(i), CHECK_NULL);
1946 cmd_array->obj_at_put(i, cmd_name);
1947 }
1948 return (jobjectArray) JNIHandles::make_local(THREAD, cmd_array());
1949 JVM_END
1950
1951 JVM_ENTRY(void, jmm_GetDiagnosticCommandInfo(JNIEnv *env, jobjectArray cmds,
1952 dcmdInfo* infoArray))
1953 if (cmds == NULL || infoArray == NULL) {
1954 THROW(vmSymbols::java_lang_NullPointerException());
1955 }
1956
1957 ResourceMark rm(THREAD);
1958
1959 objArrayOop ca = objArrayOop(JNIHandles::resolve_non_null(cmds));
1960 objArrayHandle cmds_ah(THREAD, ca);
1961
1962 // Make sure we have a String array
1963 Klass* element_klass = ObjArrayKlass::cast(cmds_ah->klass())->element_klass();
1964 if (element_klass != SystemDictionary::String_klass()) {
1965 THROW_MSG(vmSymbols::java_lang_IllegalArgumentException(),
1966 "Array element type is not String class");
1967 }
1968
2037 infoArray[i].position = array->at(i)->position();
2038 }
2039 return;
2040 JVM_END
2041
2042 JVM_ENTRY(jstring, jmm_ExecuteDiagnosticCommand(JNIEnv *env, jstring commandline))
2043 ResourceMark rm(THREAD);
2044 oop cmd = JNIHandles::resolve_external_guard(commandline);
2045 if (cmd == NULL) {
2046 THROW_MSG_NULL(vmSymbols::java_lang_NullPointerException(),
2047 "Command line cannot be null.");
2048 }
2049 char* cmdline = java_lang_String::as_utf8_string(cmd);
2050 if (cmdline == NULL) {
2051 THROW_MSG_NULL(vmSymbols::java_lang_NullPointerException(),
2052 "Command line content cannot be null.");
2053 }
2054 bufferedStream output;
2055 DCmd::parse_and_execute(DCmd_Source_MBean, &output, cmdline, ' ', CHECK_NULL);
2056 oop result = java_lang_String::create_oop_from_str(output.as_string(), CHECK_NULL);
2057 return (jstring) JNIHandles::make_local(THREAD, result);
2058 JVM_END
2059
2060 JVM_ENTRY(void, jmm_SetDiagnosticFrameworkNotificationEnabled(JNIEnv *env, jboolean enabled))
2061 DCmdFactory::set_jmx_notification_enabled(enabled?true:false);
2062 JVM_END
2063
2064 jlong Management::ticks_to_ms(jlong ticks) {
2065 assert(os::elapsed_frequency() > 0, "Must be non-zero");
2066 return (jlong)(((double)ticks / (double)os::elapsed_frequency())
2067 * (double)1000.0);
2068 }
2069 #endif // INCLUDE_MANAGEMENT
2070
2071 // Gets the amount of memory allocated on the Java heap for a single thread.
2072 // Returns -1 if the thread does not exist or has terminated.
2073 JVM_ENTRY(jlong, jmm_GetOneThreadAllocatedMemory(JNIEnv *env, jlong thread_id))
2074 if (thread_id < 0) {
2075 THROW_MSG_(vmSymbols::java_lang_IllegalArgumentException(),
2076 "Invalid thread ID", -1);
2077 }
|