src/share/vm/services/management.cpp
Index Unified diffs Context diffs Sdiffs Patch New Old Previous File Next File 8024545 Sdiff src/share/vm/services

src/share/vm/services/management.cpp

Print this page




1626   for (int i = 0; i < num_threads; i++) {
1627     JavaThread* java_thread = find_java_thread_from_id(ids_ah->long_at(i));
1628     if (java_thread != NULL) {
1629       timeArray_h->long_at_put(i, os::thread_cpu_time((Thread*)java_thread,
1630                                                       user_sys_cpu_time != 0));
1631     }
1632   }
1633 JVM_END
1634 
1635 // Returns a String array of all VM global flag names
1636 JVM_ENTRY(jobjectArray, jmm_GetVMGlobalNames(JNIEnv *env))
1637   // last flag entry is always NULL, so subtract 1
1638   int nFlags = (int) Flag::numFlags - 1;
1639   // allocate a temp array
1640   objArrayOop r = oopFactory::new_objArray(SystemDictionary::String_klass(),
1641                                            nFlags, CHECK_0);
1642   objArrayHandle flags_ah(THREAD, r);
1643   int num_entries = 0;
1644   for (int i = 0; i < nFlags; i++) {
1645     Flag* flag = &Flag::flags[i];




1646     // Exclude the locked (experimental, diagnostic) flags
1647     if (flag->is_unlocked() || flag->is_unlocker()) {
1648       Handle s = java_lang_String::create_from_str(flag->name, CHECK_0);
1649       flags_ah->obj_at_put(num_entries, s());
1650       num_entries++;
1651     }
1652   }
1653 
1654   if (num_entries < nFlags) {
1655     // Return array of right length
1656     objArrayOop res = oopFactory::new_objArray(SystemDictionary::String_klass(), num_entries, CHECK_0);
1657     for(int i = 0; i < num_entries; i++) {
1658       res->obj_at_put(i, flags_ah->obj_at(i));
1659     }
1660     return (jobjectArray)JNIHandles::make_local(env, res);
1661   }
1662 
1663   return (jobjectArray)JNIHandles::make_local(env, flags_ah());
1664 JVM_END
1665 
1666 // Utility function used by jmm_GetVMGlobals.  Returns false if flag type
1667 // can't be determined, true otherwise.  If false is returned, then *global
1668 // will be incomplete and invalid.
1669 bool add_global_entry(JNIEnv* env, Handle name, jmmVMGlobal *global, Flag *flag, TRAPS) {
1670   Handle flag_name;
1671   if (name() == NULL) {
1672     flag_name = java_lang_String::create_from_str(flag->name, CHECK_false);
1673   } else {
1674     flag_name = name;
1675   }
1676   global->name = (jstring)JNIHandles::make_local(env, flag_name());
1677 
1678   if (flag->is_bool()) {
1679     global->value.z = flag->get_bool() ? JNI_TRUE : JNI_FALSE;
1680     global->type = JMM_VMGLOBAL_TYPE_JBOOLEAN;
1681   } else if (flag->is_intx()) {
1682     global->value.j = (jlong)flag->get_intx();
1683     global->type = JMM_VMGLOBAL_TYPE_JLONG;
1684   } else if (flag->is_uintx()) {
1685     global->value.j = (jlong)flag->get_uintx();
1686     global->type = JMM_VMGLOBAL_TYPE_JLONG;
1687   } else if (flag->is_uint64_t()) {
1688     global->value.j = (jlong)flag->get_uint64_t();
1689     global->type = JMM_VMGLOBAL_TYPE_JLONG;
1690   } else if (flag->is_ccstr()) {
1691     Handle str = java_lang_String::create_from_str(flag->get_ccstr(), CHECK_false);
1692     global->value.l = (jobject)JNIHandles::make_local(env, str());
1693     global->type = JMM_VMGLOBAL_TYPE_JSTRING;
1694   } else {
1695     global->type = JMM_VMGLOBAL_TYPE_UNKNOWN;
1696     return false;
1697   }
1698 
1699   global->writeable = flag->is_writeable();
1700   global->external = flag->is_external();
1701   switch (flag->origin) {
1702     case DEFAULT:
1703       global->origin = JMM_VMGLOBAL_ORIGIN_DEFAULT;
1704       break;
1705     case COMMAND_LINE:
1706       global->origin = JMM_VMGLOBAL_ORIGIN_COMMAND_LINE;
1707       break;
1708     case ENVIRON_VAR:
1709       global->origin = JMM_VMGLOBAL_ORIGIN_ENVIRON_VAR;
1710       break;
1711     case CONFIG_FILE:
1712       global->origin = JMM_VMGLOBAL_ORIGIN_CONFIG_FILE;
1713       break;
1714     case MANAGEMENT:
1715       global->origin = JMM_VMGLOBAL_ORIGIN_MANAGEMENT;
1716       break;
1717     case ERGONOMIC:
1718       global->origin = JMM_VMGLOBAL_ORIGIN_ERGONOMIC;
1719       break;
1720     default:
1721       global->origin = JMM_VMGLOBAL_ORIGIN_OTHER;
1722   }
1723 
1724   return true;
1725 }
1726 
1727 // Fill globals array of count length with jmmVMGlobal entries
1728 // specified by names. If names == NULL, fill globals array
1729 // with all Flags. Return value is number of entries
1730 // created in globals.
1731 // If a Flag with a given name in an array element does not
1732 // exist, globals[i].name will be set to NULL.
1733 JVM_ENTRY(jint, jmm_GetVMGlobals(JNIEnv *env,
1734                                  jobjectArray names,
1735                                  jmmVMGlobal *globals,
1736                                  jint count))
1737 


1764       Handle sh(THREAD, s);
1765       char* str = java_lang_String::as_utf8_string(s);
1766       Flag* flag = Flag::find_flag(str, strlen(str));
1767       if (flag != NULL &&
1768           add_global_entry(env, sh, &globals[i], flag, THREAD)) {
1769         num_entries++;
1770       } else {
1771         globals[i].name = NULL;
1772       }
1773     }
1774     return num_entries;
1775   } else {
1776     // return all globals if names == NULL
1777 
1778     // last flag entry is always NULL, so subtract 1
1779     int nFlags = (int) Flag::numFlags - 1;
1780     Handle null_h;
1781     int num_entries = 0;
1782     for (int i = 0; i < nFlags && num_entries < count;  i++) {
1783       Flag* flag = &Flag::flags[i];




1784       // Exclude the locked (diagnostic, experimental) flags
1785       if ((flag->is_unlocked() || flag->is_unlocker()) &&
1786           add_global_entry(env, null_h, &globals[num_entries], flag, THREAD)) {
1787         num_entries++;
1788       }
1789     }
1790     return num_entries;
1791   }
1792 JVM_END
1793 
1794 JVM_ENTRY(void, jmm_SetVMGlobal(JNIEnv *env, jstring flag_name, jvalue new_value))
1795   ResourceMark rm(THREAD);
1796 
1797   oop fn = JNIHandles::resolve_external_guard(flag_name);
1798   if (fn == NULL) {
1799     THROW_MSG(vmSymbols::java_lang_NullPointerException(),
1800               "The flag name cannot be null.");
1801   }
1802   char* name = java_lang_String::as_utf8_string(fn);
1803   Flag* flag = Flag::find_flag(name, strlen(name));
1804   if (flag == NULL) {
1805     THROW_MSG(vmSymbols::java_lang_IllegalArgumentException(),
1806               "Flag does not exist.");
1807   }
1808   if (!flag->is_writeable()) {
1809     THROW_MSG(vmSymbols::java_lang_IllegalArgumentException(),
1810               "This flag is not writeable.");
1811   }
1812 
1813   bool succeed;
1814   if (flag->is_bool()) {
1815     bool bvalue = (new_value.z == JNI_TRUE ? true : false);
1816     succeed = CommandLineFlags::boolAtPut(name, &bvalue, MANAGEMENT);
1817   } else if (flag->is_intx()) {
1818     intx ivalue = (intx)new_value.j;
1819     succeed = CommandLineFlags::intxAtPut(name, &ivalue, MANAGEMENT);
1820   } else if (flag->is_uintx()) {
1821     uintx uvalue = (uintx)new_value.j;
1822     succeed = CommandLineFlags::uintxAtPut(name, &uvalue, MANAGEMENT);
1823   } else if (flag->is_uint64_t()) {
1824     uint64_t uvalue = (uint64_t)new_value.j;
1825     succeed = CommandLineFlags::uint64_tAtPut(name, &uvalue, MANAGEMENT);
1826   } else if (flag->is_ccstr()) {
1827     oop str = JNIHandles::resolve_external_guard(new_value.l);
1828     if (str == NULL) {
1829       THROW(vmSymbols::java_lang_NullPointerException());
1830     }
1831     ccstr svalue = java_lang_String::as_utf8_string(str);
1832     succeed = CommandLineFlags::ccstrAtPut(name, &svalue, MANAGEMENT);
1833   }
1834   assert(succeed, "Setting flag should succeed");
1835 JVM_END
1836 
1837 class ThreadTimesClosure: public ThreadClosure {
1838  private:
1839   objArrayHandle _names_strings;
1840   char **_names_chars;
1841   typeArrayHandle _times;
1842   int _names_len;
1843   int _times_len;
1844   int _count;
1845 
1846  public:
1847   ThreadTimesClosure(objArrayHandle names, typeArrayHandle times);
1848   ~ThreadTimesClosure();
1849   virtual void do_thread(Thread* thread);
1850   void do_unlocked();
1851   int count() { return _count; }
1852 };




1626   for (int i = 0; i < num_threads; i++) {
1627     JavaThread* java_thread = find_java_thread_from_id(ids_ah->long_at(i));
1628     if (java_thread != NULL) {
1629       timeArray_h->long_at_put(i, os::thread_cpu_time((Thread*)java_thread,
1630                                                       user_sys_cpu_time != 0));
1631     }
1632   }
1633 JVM_END
1634 
1635 // Returns a String array of all VM global flag names
1636 JVM_ENTRY(jobjectArray, jmm_GetVMGlobalNames(JNIEnv *env))
1637   // last flag entry is always NULL, so subtract 1
1638   int nFlags = (int) Flag::numFlags - 1;
1639   // allocate a temp array
1640   objArrayOop r = oopFactory::new_objArray(SystemDictionary::String_klass(),
1641                                            nFlags, CHECK_0);
1642   objArrayHandle flags_ah(THREAD, r);
1643   int num_entries = 0;
1644   for (int i = 0; i < nFlags; i++) {
1645     Flag* flag = &Flag::flags[i];
1646     // Exclude notproduct and develop flags in product builds.
1647     if (flag->is_constant_in_binary()) {
1648       continue;
1649     }
1650     // Exclude the locked (experimental, diagnostic) flags
1651     if (flag->is_unlocked() || flag->is_unlocker()) {
1652       Handle s = java_lang_String::create_from_str(flag->_name, CHECK_0);
1653       flags_ah->obj_at_put(num_entries, s());
1654       num_entries++;
1655     }
1656   }
1657 
1658   if (num_entries < nFlags) {
1659     // Return array of right length
1660     objArrayOop res = oopFactory::new_objArray(SystemDictionary::String_klass(), num_entries, CHECK_0);
1661     for(int i = 0; i < num_entries; i++) {
1662       res->obj_at_put(i, flags_ah->obj_at(i));
1663     }
1664     return (jobjectArray)JNIHandles::make_local(env, res);
1665   }
1666 
1667   return (jobjectArray)JNIHandles::make_local(env, flags_ah());
1668 JVM_END
1669 
1670 // Utility function used by jmm_GetVMGlobals.  Returns false if flag type
1671 // can't be determined, true otherwise.  If false is returned, then *global
1672 // will be incomplete and invalid.
1673 bool add_global_entry(JNIEnv* env, Handle name, jmmVMGlobal *global, Flag *flag, TRAPS) {
1674   Handle flag_name;
1675   if (name() == NULL) {
1676     flag_name = java_lang_String::create_from_str(flag->_name, CHECK_false);
1677   } else {
1678     flag_name = name;
1679   }
1680   global->name = (jstring)JNIHandles::make_local(env, flag_name());
1681 
1682   if (flag->is_bool()) {
1683     global->value.z = flag->get_bool() ? JNI_TRUE : JNI_FALSE;
1684     global->type = JMM_VMGLOBAL_TYPE_JBOOLEAN;
1685   } else if (flag->is_intx()) {
1686     global->value.j = (jlong)flag->get_intx();
1687     global->type = JMM_VMGLOBAL_TYPE_JLONG;
1688   } else if (flag->is_uintx()) {
1689     global->value.j = (jlong)flag->get_uintx();
1690     global->type = JMM_VMGLOBAL_TYPE_JLONG;
1691   } else if (flag->is_uint64_t()) {
1692     global->value.j = (jlong)flag->get_uint64_t();
1693     global->type = JMM_VMGLOBAL_TYPE_JLONG;
1694   } else if (flag->is_ccstr()) {
1695     Handle str = java_lang_String::create_from_str(flag->get_ccstr(), CHECK_false);
1696     global->value.l = (jobject)JNIHandles::make_local(env, str());
1697     global->type = JMM_VMGLOBAL_TYPE_JSTRING;
1698   } else {
1699     global->type = JMM_VMGLOBAL_TYPE_UNKNOWN;
1700     return false;
1701   }
1702 
1703   global->writeable = flag->is_writeable();
1704   global->external = flag->is_external();
1705   switch (flag->get_origin()) {
1706     case Flag::DEFAULT:
1707       global->origin = JMM_VMGLOBAL_ORIGIN_DEFAULT;
1708       break;
1709     case Flag::COMMAND_LINE:
1710       global->origin = JMM_VMGLOBAL_ORIGIN_COMMAND_LINE;
1711       break;
1712     case Flag::ENVIRON_VAR:
1713       global->origin = JMM_VMGLOBAL_ORIGIN_ENVIRON_VAR;
1714       break;
1715     case Flag::CONFIG_FILE:
1716       global->origin = JMM_VMGLOBAL_ORIGIN_CONFIG_FILE;
1717       break;
1718     case Flag::MANAGEMENT:
1719       global->origin = JMM_VMGLOBAL_ORIGIN_MANAGEMENT;
1720       break;
1721     case Flag::ERGONOMIC:
1722       global->origin = JMM_VMGLOBAL_ORIGIN_ERGONOMIC;
1723       break;
1724     default:
1725       global->origin = JMM_VMGLOBAL_ORIGIN_OTHER;
1726   }
1727 
1728   return true;
1729 }
1730 
1731 // Fill globals array of count length with jmmVMGlobal entries
1732 // specified by names. If names == NULL, fill globals array
1733 // with all Flags. Return value is number of entries
1734 // created in globals.
1735 // If a Flag with a given name in an array element does not
1736 // exist, globals[i].name will be set to NULL.
1737 JVM_ENTRY(jint, jmm_GetVMGlobals(JNIEnv *env,
1738                                  jobjectArray names,
1739                                  jmmVMGlobal *globals,
1740                                  jint count))
1741 


1768       Handle sh(THREAD, s);
1769       char* str = java_lang_String::as_utf8_string(s);
1770       Flag* flag = Flag::find_flag(str, strlen(str));
1771       if (flag != NULL &&
1772           add_global_entry(env, sh, &globals[i], flag, THREAD)) {
1773         num_entries++;
1774       } else {
1775         globals[i].name = NULL;
1776       }
1777     }
1778     return num_entries;
1779   } else {
1780     // return all globals if names == NULL
1781 
1782     // last flag entry is always NULL, so subtract 1
1783     int nFlags = (int) Flag::numFlags - 1;
1784     Handle null_h;
1785     int num_entries = 0;
1786     for (int i = 0; i < nFlags && num_entries < count;  i++) {
1787       Flag* flag = &Flag::flags[i];
1788       // Exclude notproduct and develop flags in product builds.
1789       if (flag->is_constant_in_binary()) {
1790         continue;
1791       }
1792       // Exclude the locked (diagnostic, experimental) flags
1793       if ((flag->is_unlocked() || flag->is_unlocker()) &&
1794           add_global_entry(env, null_h, &globals[num_entries], flag, THREAD)) {
1795         num_entries++;
1796       }
1797     }
1798     return num_entries;
1799   }
1800 JVM_END
1801 
1802 JVM_ENTRY(void, jmm_SetVMGlobal(JNIEnv *env, jstring flag_name, jvalue new_value))
1803   ResourceMark rm(THREAD);
1804 
1805   oop fn = JNIHandles::resolve_external_guard(flag_name);
1806   if (fn == NULL) {
1807     THROW_MSG(vmSymbols::java_lang_NullPointerException(),
1808               "The flag name cannot be null.");
1809   }
1810   char* name = java_lang_String::as_utf8_string(fn);
1811   Flag* flag = Flag::find_flag(name, strlen(name));
1812   if (flag == NULL) {
1813     THROW_MSG(vmSymbols::java_lang_IllegalArgumentException(),
1814               "Flag does not exist.");
1815   }
1816   if (!flag->is_writeable()) {
1817     THROW_MSG(vmSymbols::java_lang_IllegalArgumentException(),
1818               "This flag is not writeable.");
1819   }
1820 
1821   bool succeed;
1822   if (flag->is_bool()) {
1823     bool bvalue = (new_value.z == JNI_TRUE ? true : false);
1824     succeed = CommandLineFlags::boolAtPut(name, &bvalue, Flag::MANAGEMENT);
1825   } else if (flag->is_intx()) {
1826     intx ivalue = (intx)new_value.j;
1827     succeed = CommandLineFlags::intxAtPut(name, &ivalue, Flag::MANAGEMENT);
1828   } else if (flag->is_uintx()) {
1829     uintx uvalue = (uintx)new_value.j;
1830     succeed = CommandLineFlags::uintxAtPut(name, &uvalue, Flag::MANAGEMENT);
1831   } else if (flag->is_uint64_t()) {
1832     uint64_t uvalue = (uint64_t)new_value.j;
1833     succeed = CommandLineFlags::uint64_tAtPut(name, &uvalue, Flag::MANAGEMENT);
1834   } else if (flag->is_ccstr()) {
1835     oop str = JNIHandles::resolve_external_guard(new_value.l);
1836     if (str == NULL) {
1837       THROW(vmSymbols::java_lang_NullPointerException());
1838     }
1839     ccstr svalue = java_lang_String::as_utf8_string(str);
1840     succeed = CommandLineFlags::ccstrAtPut(name, &svalue, Flag::MANAGEMENT);
1841   }
1842   assert(succeed, "Setting flag should succeed");
1843 JVM_END
1844 
1845 class ThreadTimesClosure: public ThreadClosure {
1846  private:
1847   objArrayHandle _names_strings;
1848   char **_names_chars;
1849   typeArrayHandle _times;
1850   int _names_len;
1851   int _times_len;
1852   int _count;
1853 
1854  public:
1855   ThreadTimesClosure(objArrayHandle names, typeArrayHandle times);
1856   ~ThreadTimesClosure();
1857   virtual void do_thread(Thread* thread);
1858   void do_unlocked();
1859   int count() { return _count; }
1860 };


src/share/vm/services/management.cpp
Index Unified diffs Context diffs Sdiffs Patch New Old Previous File Next File