< prev index next >

src/hotspot/share/services/management.cpp

Print this page


 837   // exclude externally visible JavaThreads
 838   if (thread->is_Java_thread() && !thread->is_hidden_from_external_view()) {
 839     return;
 840   }
 841 
 842   _count++;
 843 }
 844 
 845 static jint get_vm_thread_count() {
 846   VmThreadCountClosure vmtcc;
 847   {
 848     MutexLocker ml(Threads_lock);
 849     Threads::threads_do(&vmtcc);
 850   }
 851 
 852   return vmtcc.count();
 853 }
 854 
 855 static jint get_num_flags() {
 856   // last flag entry is always NULL, so subtract 1
 857   int nFlags = (int) JVMFlag::numFlags - 1;
 858   int count = 0;
 859   for (int i = 0; i < nFlags; i++) {
 860     JVMFlag* flag = &JVMFlag::flags[i];
 861     // Exclude the locked (diagnostic, experimental) flags
 862     if (flag->is_unlocked() || flag->is_unlocker()) {
 863       count++;
 864     }
 865   }
 866   return count;
 867 }
 868 
 869 static jlong get_long_attribute(jmmLongAttribute att) {
 870   switch (att) {
 871   case JMM_CLASS_LOADED_COUNT:
 872     return ClassLoadingService::loaded_class_count();
 873 
 874   case JMM_CLASS_UNLOADED_COUNT:
 875     return ClassLoadingService::unloaded_class_count();
 876 
 877   case JMM_THREAD_TOTAL_COUNT:
 878     return ThreadService::get_total_thread_count();
 879 
 880   case JMM_THREAD_LIVE_COUNT:


1381     THROW_MSG_(vmSymbols::java_lang_IllegalArgumentException(),
1382                "Invalid thread ID", -1);
1383   }
1384 
1385   JavaThread* java_thread = NULL;
1386   if (thread_id == 0) {
1387     // current thread
1388     return os::current_thread_cpu_time();
1389   } else {
1390     ThreadsListHandle tlh;
1391     java_thread = tlh.list()->find_JavaThread_from_java_tid(thread_id);
1392     if (java_thread != NULL) {
1393       return os::thread_cpu_time((Thread*) java_thread);
1394     }
1395   }
1396   return -1;
1397 JVM_END
1398 
1399 // Returns a String array of all VM global flag names
1400 JVM_ENTRY(jobjectArray, jmm_GetVMGlobalNames(JNIEnv *env))
1401   // last flag entry is always NULL, so subtract 1
1402   int nFlags = (int) JVMFlag::numFlags - 1;
1403   // allocate a temp array
1404   objArrayOop r = oopFactory::new_objArray(SystemDictionary::String_klass(),
1405                                            nFlags, CHECK_NULL);
1406   objArrayHandle flags_ah(THREAD, r);
1407   int num_entries = 0;
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;


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(),




 837   // exclude externally visible JavaThreads
 838   if (thread->is_Java_thread() && !thread->is_hidden_from_external_view()) {
 839     return;
 840   }
 841 
 842   _count++;
 843 }
 844 
 845 static jint get_vm_thread_count() {
 846   VmThreadCountClosure vmtcc;
 847   {
 848     MutexLocker ml(Threads_lock);
 849     Threads::threads_do(&vmtcc);
 850   }
 851 
 852   return vmtcc.count();
 853 }
 854 
 855 static jint get_num_flags() {
 856   // last flag entry is always NULL, so subtract 1

 857   int count = 0;
 858   JVMFlag* flag;
 859   JVMFLAG_FOR_EACH(flag) {
 860     // Exclude the locked (diagnostic, experimental) flags
 861     if (flag->is_unlocked() || flag->is_unlocker()) {
 862       count++;
 863     }
 864   }
 865   return count;
 866 }
 867 
 868 static jlong get_long_attribute(jmmLongAttribute att) {
 869   switch (att) {
 870   case JMM_CLASS_LOADED_COUNT:
 871     return ClassLoadingService::loaded_class_count();
 872 
 873   case JMM_CLASS_UNLOADED_COUNT:
 874     return ClassLoadingService::unloaded_class_count();
 875 
 876   case JMM_THREAD_TOTAL_COUNT:
 877     return ThreadService::get_total_thread_count();
 878 
 879   case JMM_THREAD_LIVE_COUNT:


1380     THROW_MSG_(vmSymbols::java_lang_IllegalArgumentException(),
1381                "Invalid thread ID", -1);
1382   }
1383 
1384   JavaThread* java_thread = NULL;
1385   if (thread_id == 0) {
1386     // current thread
1387     return os::current_thread_cpu_time();
1388   } else {
1389     ThreadsListHandle tlh;
1390     java_thread = tlh.list()->find_JavaThread_from_java_tid(thread_id);
1391     if (java_thread != NULL) {
1392       return os::thread_cpu_time((Thread*) java_thread);
1393     }
1394   }
1395   return -1;
1396 JVM_END
1397 
1398 // Returns a String array of all VM global flag names
1399 JVM_ENTRY(jobjectArray, jmm_GetVMGlobalNames(JNIEnv *env))
1400   int nFlags = JVMFlag::num_flags();

1401   // allocate a temp array
1402   objArrayOop r = oopFactory::new_objArray(SystemDictionary::String_klass(),
1403                                            nFlags, CHECK_NULL);
1404   objArrayHandle flags_ah(THREAD, r);
1405   int num_entries = 0;
1406   JVMFlag* flag;
1407   JVMFLAG_FOR_EACH(flag) {
1408     // Exclude notproduct and develop flags in product builds.
1409     if (flag->is_constant_in_binary()) {
1410       continue;
1411     }
1412     // Exclude the locked (experimental, diagnostic) flags
1413     if (flag->is_unlocked() || flag->is_unlocker()) {
1414       Handle s = java_lang_String::create_from_str(flag->name(), CHECK_NULL);
1415       flags_ah->obj_at_put(num_entries, s());
1416       num_entries++;
1417     }
1418   }
1419 
1420   if (num_entries < nFlags) {
1421     // Return array of right length
1422     objArrayOop res = oopFactory::new_objArray(SystemDictionary::String_klass(), num_entries, CHECK_NULL);
1423     for(int i = 0; i < num_entries; i++) {
1424       res->obj_at_put(i, flags_ah->obj_at(i));
1425     }
1426     return (jobjectArray)JNIHandles::make_local(env, res);
1427   }
1428 
1429   return (jobjectArray)JNIHandles::make_local(env, flags_ah());
1430 JVM_END
1431 
1432 // Utility function used by jmm_GetVMGlobals.  Returns false if flag type
1433 // can't be determined, true otherwise.  If false is returned, then *global
1434 // will be incomplete and invalid.
1435 bool add_global_entry(JNIEnv* env, Handle name, jmmVMGlobal *global, JVMFlag *flag, TRAPS) {
1436   Handle flag_name;
1437   if (name() == NULL) {
1438     flag_name = java_lang_String::create_from_str(flag->name(), CHECK_false);
1439   } else {
1440     flag_name = name;
1441   }
1442   global->name = (jstring)JNIHandles::make_local(env, flag_name());
1443 
1444   if (flag->is_bool()) {
1445     global->value.z = flag->get_bool() ? JNI_TRUE : JNI_FALSE;
1446     global->type = JMM_VMGLOBAL_TYPE_JBOOLEAN;
1447   } else if (flag->is_int()) {
1448     global->value.j = (jlong)flag->get_int();
1449     global->type = JMM_VMGLOBAL_TYPE_JLONG;
1450   } else if (flag->is_uint()) {
1451     global->value.j = (jlong)flag->get_uint();
1452     global->type = JMM_VMGLOBAL_TYPE_JLONG;
1453   } else if (flag->is_intx()) {
1454     global->value.j = (jlong)flag->get_intx();
1455     global->type = JMM_VMGLOBAL_TYPE_JLONG;
1456   } else if (flag->is_uintx()) {
1457     global->value.j = (jlong)flag->get_uintx();
1458     global->type = JMM_VMGLOBAL_TYPE_JLONG;


1540       oop s = names_ah->obj_at(i);
1541       if (s == NULL) {
1542         THROW_(vmSymbols::java_lang_NullPointerException(), 0);
1543       }
1544 
1545       Handle sh(THREAD, s);
1546       char* str = java_lang_String::as_utf8_string(s);
1547       JVMFlag* flag = JVMFlag::find_flag(str);
1548       if (flag != NULL &&
1549           add_global_entry(env, sh, &globals[i], flag, THREAD)) {
1550         num_entries++;
1551       } else {
1552         globals[i].name = NULL;
1553       }
1554     }
1555     return num_entries;
1556   } else {
1557     // return all globals if names == NULL
1558 
1559     // last flag entry is always NULL, so subtract 1

1560     Handle null_h;
1561     int num_entries = 0;
1562     JVMFlag* flag;
1563     JVMFLAG_FOR_EACH(flag) {
1564       if (num_entries >= count) {
1565         break;
1566       }
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(),


< prev index next >