comparison 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
comparison
equal deleted inserted replaced
4131:e9b91fd07263 4133:3b688d6ff3d0
38 #include "runtime/javaCalls.hpp" 38 #include "runtime/javaCalls.hpp"
39 #include "runtime/jniHandles.hpp" 39 #include "runtime/jniHandles.hpp"
40 #include "runtime/os.hpp" 40 #include "runtime/os.hpp"
41 #include "runtime/serviceThread.hpp" 41 #include "runtime/serviceThread.hpp"
42 #include "services/classLoadingService.hpp" 42 #include "services/classLoadingService.hpp"
43 #include "services/diagnosticCommand.hpp"
44 #include "services/diagnosticFramework.hpp"
43 #include "services/heapDumper.hpp" 45 #include "services/heapDumper.hpp"
46 #include "services/jmm.h"
44 #include "services/lowMemoryDetector.hpp" 47 #include "services/lowMemoryDetector.hpp"
45 #include "services/gcNotifier.hpp" 48 #include "services/gcNotifier.hpp"
46 #include "services/management.hpp" 49 #include "services/management.hpp"
47 #include "services/memoryManager.hpp" 50 #include "services/memoryManager.hpp"
48 #include "services/memoryPool.hpp" 51 #include "services/memoryPool.hpp"
111 #ifndef SERVICES_KERNEL 114 #ifndef SERVICES_KERNEL
112 // This depends on the heap inspector 115 // This depends on the heap inspector
113 _optional_support.isSynchronizerUsageSupported = 1; 116 _optional_support.isSynchronizerUsageSupported = 1;
114 #endif // SERVICES_KERNEL 117 #endif // SERVICES_KERNEL
115 _optional_support.isThreadAllocatedMemorySupported = 1; 118 _optional_support.isThreadAllocatedMemorySupported = 1;
119
120 DCmdFactory::register_DCmdFactory(new DCmdFactoryImpl<HelpDCmd>(true, false));
121 DCmdFactory::register_DCmdFactory(new DCmdFactoryImpl<VersionDCmd>(true, false));
116 } 122 }
117 123
118 void Management::initialize(TRAPS) { 124 void Management::initialize(TRAPS) {
119 // Start the service thread 125 // Start the service thread
120 ServiceThread::initialize(); 126 ServiceThread::initialize();
2103 } 2109 }
2104 return 0; 2110 return 0;
2105 #else // SERVICES_KERNEL 2111 #else // SERVICES_KERNEL
2106 return -1; 2112 return -1;
2107 #endif // SERVICES_KERNEL 2113 #endif // SERVICES_KERNEL
2114 JVM_END
2115
2116 JVM_ENTRY(jobjectArray, jmm_GetDiagnosticCommands(JNIEnv *env))
2117 ResourceMark rm(THREAD);
2118 GrowableArray<const char *>* dcmd_list = DCmdFactory::DCmd_list();
2119 objArrayOop cmd_array_oop = oopFactory::new_objArray(SystemDictionary::String_klass(),
2120 dcmd_list->length(), CHECK_NULL);
2121 objArrayHandle cmd_array(THREAD, cmd_array_oop);
2122 for (int i = 0; i < dcmd_list->length(); i++) {
2123 oop cmd_name = java_lang_String::create_oop_from_str(dcmd_list->at(i), CHECK_NULL);
2124 cmd_array->obj_at_put(i, cmd_name);
2125 }
2126 return (jobjectArray) JNIHandles::make_local(env, cmd_array());
2127 JVM_END
2128
2129 JVM_ENTRY(void, jmm_GetDiagnosticCommandInfo(JNIEnv *env, jobjectArray cmds,
2130 dcmdInfo* infoArray))
2131 if (cmds == NULL || infoArray == NULL) {
2132 THROW(vmSymbols::java_lang_NullPointerException());
2133 }
2134
2135 ResourceMark rm(THREAD);
2136
2137 objArrayOop ca = objArrayOop(JNIHandles::resolve_non_null(cmds));
2138 objArrayHandle cmds_ah(THREAD, ca);
2139
2140 // Make sure we have a String array
2141 klassOop element_klass = objArrayKlass::cast(cmds_ah->klass())->element_klass();
2142 if (element_klass != SystemDictionary::String_klass()) {
2143 THROW_MSG(vmSymbols::java_lang_IllegalArgumentException(),
2144 "Array element type is not String class");
2145 }
2146
2147 GrowableArray<DCmdInfo *>* info_list = DCmdFactory::DCmdInfo_list();
2148
2149 int num_cmds = cmds_ah->length();
2150 for (int i = 0; i < num_cmds; i++) {
2151 oop cmd = cmds_ah->obj_at(i);
2152 if (cmd == NULL) {
2153 THROW_MSG(vmSymbols::java_lang_NullPointerException(),
2154 "Command name cannot be null.");
2155 }
2156 char* cmd_name = java_lang_String::as_utf8_string(cmd);
2157 if (cmd_name == NULL) {
2158 THROW_MSG(vmSymbols::java_lang_NullPointerException(),
2159 "Command name cannot be null.");
2160 }
2161 int pos = info_list->find((void*)cmd_name,DCmdInfo::by_name);
2162 if (pos == -1) {
2163 THROW_MSG(vmSymbols::java_lang_IllegalArgumentException(),
2164 "Unknown diagnostic command");
2165 }
2166 DCmdInfo* info = info_list->at(pos);
2167 infoArray[i].name = info->name();
2168 infoArray[i].description = info->description();
2169 infoArray[i].impact = info->impact();
2170 infoArray[i].num_arguments = info->num_arguments();
2171 infoArray[i].enabled = info->is_enabled();
2172 }
2173 JVM_END
2174
2175 JVM_ENTRY(void, jmm_GetDiagnosticCommandArgumentsInfo(JNIEnv *env,
2176 jstring command, dcmdArgInfo* infoArray))
2177 ResourceMark rm(THREAD);
2178 oop cmd = JNIHandles::resolve_external_guard(command);
2179 if (cmd == NULL) {
2180 THROW_MSG(vmSymbols::java_lang_NullPointerException(),
2181 "Command line cannot be null.");
2182 }
2183 char* cmd_name = java_lang_String::as_utf8_string(cmd);
2184 if (cmd_name == NULL) {
2185 THROW_MSG(vmSymbols::java_lang_NullPointerException(),
2186 "Command line content cannot be null.");
2187 }
2188 DCmd* dcmd = NULL;
2189 DCmdFactory*factory = DCmdFactory::factory(cmd_name, strlen(cmd_name));
2190 if (factory != NULL) {
2191 dcmd = factory->create_resource_instance(NULL);
2192 }
2193 if (dcmd == NULL) {
2194 THROW_MSG(vmSymbols::java_lang_IllegalArgumentException(),
2195 "Unknown diagnostic command");
2196 }
2197 DCmdMark mark(dcmd);
2198 GrowableArray<DCmdArgumentInfo*>* array = dcmd->argument_info_array();
2199 if (array->length() == 0) {
2200 return;
2201 }
2202 for (int i = 0; i < array->length(); i++) {
2203 infoArray[i].name = array->at(i)->name();
2204 infoArray[i].description = array->at(i)->description();
2205 infoArray[i].type = array->at(i)->type();
2206 infoArray[i].default_string = array->at(i)->default_string();
2207 infoArray[i].mandatory = array->at(i)->is_mandatory();
2208 infoArray[i].option = array->at(i)->is_option();
2209 infoArray[i].position = array->at(i)->position();
2210 }
2211 return;
2212 JVM_END
2213
2214 JVM_ENTRY(jstring, jmm_ExecuteDiagnosticCommand(JNIEnv *env, jstring commandline))
2215 ResourceMark rm(THREAD);
2216 oop cmd = JNIHandles::resolve_external_guard(commandline);
2217 if (cmd == NULL) {
2218 THROW_MSG_NULL(vmSymbols::java_lang_NullPointerException(),
2219 "Command line cannot be null.");
2220 }
2221 char* cmdline = java_lang_String::as_utf8_string(cmd);
2222 if (cmdline == NULL) {
2223 THROW_MSG_NULL(vmSymbols::java_lang_NullPointerException(),
2224 "Command line content cannot be null.");
2225 }
2226 bufferedStream output;
2227 DCmd::parse_and_execute(&output, cmdline, ' ', CHECK_NULL);
2228 oop result = java_lang_String::create_oop_from_str(output.as_string(), CHECK_NULL);
2229 return (jstring) JNIHandles::make_local(env, result);
2108 JVM_END 2230 JVM_END
2109 2231
2110 jlong Management::ticks_to_ms(jlong ticks) { 2232 jlong Management::ticks_to_ms(jlong ticks) {
2111 assert(os::elapsed_frequency() > 0, "Must be non-zero"); 2233 assert(os::elapsed_frequency() > 0, "Must be non-zero");
2112 return (jlong)(((double)ticks / (double)os::elapsed_frequency()) 2234 return (jlong)(((double)ticks / (double)os::elapsed_frequency())
2147 jmm_DumpHeap0, 2269 jmm_DumpHeap0,
2148 jmm_FindDeadlockedThreads, 2270 jmm_FindDeadlockedThreads,
2149 jmm_SetVMGlobal, 2271 jmm_SetVMGlobal,
2150 NULL, 2272 NULL,
2151 jmm_DumpThreads, 2273 jmm_DumpThreads,
2152 jmm_SetGCNotificationEnabled 2274 jmm_SetGCNotificationEnabled,
2275 jmm_GetDiagnosticCommands,
2276 jmm_GetDiagnosticCommandInfo,
2277 jmm_GetDiagnosticCommandArgumentsInfo,
2278 jmm_ExecuteDiagnosticCommand
2153 }; 2279 };
2154 2280
2155 void* Management::get_jmm_interface(int version) { 2281 void* Management::get_jmm_interface(int version) {
2156 if (version == JMM_VERSION_1_0) { 2282 if (version == JMM_VERSION_1_0) {
2157 return (void*) &jmm_interface; 2283 return (void*) &jmm_interface;