Mercurial > hg > graal-jvmci-8
diff src/share/vm/services/management.cpp @ 4133:3b688d6ff3d0
7104647: Adding a diagnostic command framework
Reviewed-by: phh, dcubed
author | fparain |
---|---|
date | Wed, 14 Dec 2011 04:30:57 -0800 |
parents | 78542e2b5e35 |
children | 6c995c08526c |
line wrap: on
line diff
--- a/src/share/vm/services/management.cpp Fri Dec 09 06:46:57 2011 -0800 +++ b/src/share/vm/services/management.cpp Wed Dec 14 04:30:57 2011 -0800 @@ -40,7 +40,10 @@ #include "runtime/os.hpp" #include "runtime/serviceThread.hpp" #include "services/classLoadingService.hpp" +#include "services/diagnosticCommand.hpp" +#include "services/diagnosticFramework.hpp" #include "services/heapDumper.hpp" +#include "services/jmm.h" #include "services/lowMemoryDetector.hpp" #include "services/gcNotifier.hpp" #include "services/management.hpp" @@ -113,6 +116,9 @@ _optional_support.isSynchronizerUsageSupported = 1; #endif // SERVICES_KERNEL _optional_support.isThreadAllocatedMemorySupported = 1; + + DCmdFactory::register_DCmdFactory(new DCmdFactoryImpl<HelpDCmd>(true, false)); + DCmdFactory::register_DCmdFactory(new DCmdFactoryImpl<VersionDCmd>(true, false)); } void Management::initialize(TRAPS) { @@ -2107,6 +2113,122 @@ #endif // SERVICES_KERNEL JVM_END +JVM_ENTRY(jobjectArray, jmm_GetDiagnosticCommands(JNIEnv *env)) + ResourceMark rm(THREAD); + GrowableArray<const char *>* dcmd_list = DCmdFactory::DCmd_list(); + objArrayOop cmd_array_oop = oopFactory::new_objArray(SystemDictionary::String_klass(), + dcmd_list->length(), CHECK_NULL); + objArrayHandle cmd_array(THREAD, cmd_array_oop); + for (int i = 0; i < dcmd_list->length(); i++) { + oop cmd_name = java_lang_String::create_oop_from_str(dcmd_list->at(i), CHECK_NULL); + cmd_array->obj_at_put(i, cmd_name); + } + return (jobjectArray) JNIHandles::make_local(env, cmd_array()); +JVM_END + +JVM_ENTRY(void, jmm_GetDiagnosticCommandInfo(JNIEnv *env, jobjectArray cmds, + dcmdInfo* infoArray)) + if (cmds == NULL || infoArray == NULL) { + THROW(vmSymbols::java_lang_NullPointerException()); + } + + ResourceMark rm(THREAD); + + objArrayOop ca = objArrayOop(JNIHandles::resolve_non_null(cmds)); + objArrayHandle cmds_ah(THREAD, ca); + + // Make sure we have a String array + klassOop element_klass = objArrayKlass::cast(cmds_ah->klass())->element_klass(); + if (element_klass != SystemDictionary::String_klass()) { + THROW_MSG(vmSymbols::java_lang_IllegalArgumentException(), + "Array element type is not String class"); + } + + GrowableArray<DCmdInfo *>* info_list = DCmdFactory::DCmdInfo_list(); + + int num_cmds = cmds_ah->length(); + for (int i = 0; i < num_cmds; i++) { + oop cmd = cmds_ah->obj_at(i); + if (cmd == NULL) { + THROW_MSG(vmSymbols::java_lang_NullPointerException(), + "Command name cannot be null."); + } + char* cmd_name = java_lang_String::as_utf8_string(cmd); + if (cmd_name == NULL) { + THROW_MSG(vmSymbols::java_lang_NullPointerException(), + "Command name cannot be null."); + } + int pos = info_list->find((void*)cmd_name,DCmdInfo::by_name); + if (pos == -1) { + THROW_MSG(vmSymbols::java_lang_IllegalArgumentException(), + "Unknown diagnostic command"); + } + DCmdInfo* info = info_list->at(pos); + infoArray[i].name = info->name(); + infoArray[i].description = info->description(); + infoArray[i].impact = info->impact(); + infoArray[i].num_arguments = info->num_arguments(); + infoArray[i].enabled = info->is_enabled(); + } +JVM_END + +JVM_ENTRY(void, jmm_GetDiagnosticCommandArgumentsInfo(JNIEnv *env, + jstring command, dcmdArgInfo* infoArray)) + ResourceMark rm(THREAD); + oop cmd = JNIHandles::resolve_external_guard(command); + if (cmd == NULL) { + THROW_MSG(vmSymbols::java_lang_NullPointerException(), + "Command line cannot be null."); + } + char* cmd_name = java_lang_String::as_utf8_string(cmd); + if (cmd_name == NULL) { + THROW_MSG(vmSymbols::java_lang_NullPointerException(), + "Command line content cannot be null."); + } + DCmd* dcmd = NULL; + DCmdFactory*factory = DCmdFactory::factory(cmd_name, strlen(cmd_name)); + if (factory != NULL) { + dcmd = factory->create_resource_instance(NULL); + } + if (dcmd == NULL) { + THROW_MSG(vmSymbols::java_lang_IllegalArgumentException(), + "Unknown diagnostic command"); + } + DCmdMark mark(dcmd); + GrowableArray<DCmdArgumentInfo*>* array = dcmd->argument_info_array(); + if (array->length() == 0) { + return; + } + for (int i = 0; i < array->length(); i++) { + infoArray[i].name = array->at(i)->name(); + infoArray[i].description = array->at(i)->description(); + infoArray[i].type = array->at(i)->type(); + infoArray[i].default_string = array->at(i)->default_string(); + infoArray[i].mandatory = array->at(i)->is_mandatory(); + infoArray[i].option = array->at(i)->is_option(); + infoArray[i].position = array->at(i)->position(); + } + return; +JVM_END + +JVM_ENTRY(jstring, jmm_ExecuteDiagnosticCommand(JNIEnv *env, jstring commandline)) + ResourceMark rm(THREAD); + oop cmd = JNIHandles::resolve_external_guard(commandline); + if (cmd == NULL) { + THROW_MSG_NULL(vmSymbols::java_lang_NullPointerException(), + "Command line cannot be null."); + } + char* cmdline = java_lang_String::as_utf8_string(cmd); + if (cmdline == NULL) { + THROW_MSG_NULL(vmSymbols::java_lang_NullPointerException(), + "Command line content cannot be null."); + } + bufferedStream output; + DCmd::parse_and_execute(&output, cmdline, ' ', CHECK_NULL); + oop result = java_lang_String::create_oop_from_str(output.as_string(), CHECK_NULL); + return (jstring) JNIHandles::make_local(env, result); +JVM_END + jlong Management::ticks_to_ms(jlong ticks) { assert(os::elapsed_frequency() > 0, "Must be non-zero"); return (jlong)(((double)ticks / (double)os::elapsed_frequency()) @@ -2149,7 +2271,11 @@ jmm_SetVMGlobal, NULL, jmm_DumpThreads, - jmm_SetGCNotificationEnabled + jmm_SetGCNotificationEnabled, + jmm_GetDiagnosticCommands, + jmm_GetDiagnosticCommandInfo, + jmm_GetDiagnosticCommandArgumentsInfo, + jmm_ExecuteDiagnosticCommand }; void* Management::get_jmm_interface(int version) {