comparison src/share/vm/services/management.cpp @ 10215:31a4e55f8c9d

8004095: Add support for JMX interface to Diagnostic Framework and Commands Reviewed-by: acorn, sla
author fparain
date Fri, 03 May 2013 05:05:31 -0700
parents a527ddd44e07
children 71963b3f802a
comparison
equal deleted inserted replaced
10167:8fe2542bdc8d 10215:31a4e55f8c9d
1 /* 1 /*
2 * Copyright (c) 2003, 2012, Oracle and/or its affiliates. All rights reserved. 2 * Copyright (c) 2003, 2013, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 * 4 *
5 * This code is free software; you can redistribute it and/or modify it 5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as 6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. 7 * published by the Free Software Foundation.
66 Klass* Management::_memoryManagerMXBean_klass = NULL; 66 Klass* Management::_memoryManagerMXBean_klass = NULL;
67 Klass* Management::_garbageCollectorMXBean_klass = NULL; 67 Klass* Management::_garbageCollectorMXBean_klass = NULL;
68 Klass* Management::_managementFactory_klass = NULL; 68 Klass* Management::_managementFactory_klass = NULL;
69 Klass* Management::_garbageCollectorImpl_klass = NULL; 69 Klass* Management::_garbageCollectorImpl_klass = NULL;
70 Klass* Management::_gcInfo_klass = NULL; 70 Klass* Management::_gcInfo_klass = NULL;
71 Klass* Management::_diagnosticCommandImpl_klass = NULL;
72 Klass* Management::_managementFactoryHelper_klass = NULL;
73
71 74
72 jmmOptionalSupport Management::_optional_support = {0}; 75 jmmOptionalSupport Management::_optional_support = {0};
73 TimeStamp Management::_stamp; 76 TimeStamp Management::_stamp;
74 77
75 void management_init() { 78 void management_init() {
126 #if INCLUDE_SERVICES 129 #if INCLUDE_SERVICES
127 // This depends on the heap inspector 130 // This depends on the heap inspector
128 _optional_support.isSynchronizerUsageSupported = 1; 131 _optional_support.isSynchronizerUsageSupported = 1;
129 #endif // INCLUDE_SERVICES 132 #endif // INCLUDE_SERVICES
130 _optional_support.isThreadAllocatedMemorySupported = 1; 133 _optional_support.isThreadAllocatedMemorySupported = 1;
134 _optional_support.isRemoteDiagnosticCommandsSupported = 1;
131 135
132 // Registration of the diagnostic commands 136 // Registration of the diagnostic commands
133 DCmdRegistrant::register_dcmds(); 137 DCmdRegistrant::register_dcmds();
134 DCmdRegistrant::register_dcmds_ext(); 138 DCmdRegistrant::register_dcmds_ext();
135 DCmdFactory::register_DCmdFactory(new DCmdFactoryImpl<NMTDCmd>(true, false)); 139 uint32_t full_export = DCmd_Source_Internal | DCmd_Source_AttachAPI
140 | DCmd_Source_MBean;
141 DCmdFactory::register_DCmdFactory(new DCmdFactoryImpl<NMTDCmd>(full_export, true, false));
136 } 142 }
137 143
138 void Management::initialize(TRAPS) { 144 void Management::initialize(TRAPS) {
139 // Start the service thread 145 // Start the service thread
140 ServiceThread::initialize(); 146 ServiceThread::initialize();
258 Klass* Management::com_sun_management_GcInfo_klass(TRAPS) { 264 Klass* Management::com_sun_management_GcInfo_klass(TRAPS) {
259 if (_gcInfo_klass == NULL) { 265 if (_gcInfo_klass == NULL) {
260 _gcInfo_klass = load_and_initialize_klass(vmSymbols::com_sun_management_GcInfo(), CHECK_NULL); 266 _gcInfo_klass = load_and_initialize_klass(vmSymbols::com_sun_management_GcInfo(), CHECK_NULL);
261 } 267 }
262 return _gcInfo_klass; 268 return _gcInfo_klass;
269 }
270
271 Klass* Management::sun_management_DiagnosticCommandImpl_klass(TRAPS) {
272 if (_diagnosticCommandImpl_klass == NULL) {
273 _diagnosticCommandImpl_klass = load_and_initialize_klass(vmSymbols::sun_management_DiagnosticCommandImpl(), CHECK_NULL);
274 }
275 return _diagnosticCommandImpl_klass;
276 }
277
278 Klass* Management::sun_management_ManagementFactoryHelper_klass(TRAPS) {
279 if (_managementFactoryHelper_klass == NULL) {
280 _managementFactoryHelper_klass = load_and_initialize_klass(vmSymbols::sun_management_ManagementFactoryHelper(), CHECK_NULL);
281 }
282 return _managementFactoryHelper_klass;
263 } 283 }
264 284
265 static void initialize_ThreadInfo_constructor_arguments(JavaCallArguments* args, ThreadSnapshot* snapshot, TRAPS) { 285 static void initialize_ThreadInfo_constructor_arguments(JavaCallArguments* args, ThreadSnapshot* snapshot, TRAPS) {
266 Handle snapshot_thread(THREAD, snapshot->threadObj()); 286 Handle snapshot_thread(THREAD, snapshot->threadObj());
267 287
2142 #endif // INCLUDE_SERVICES 2162 #endif // INCLUDE_SERVICES
2143 JVM_END 2163 JVM_END
2144 2164
2145 JVM_ENTRY(jobjectArray, jmm_GetDiagnosticCommands(JNIEnv *env)) 2165 JVM_ENTRY(jobjectArray, jmm_GetDiagnosticCommands(JNIEnv *env))
2146 ResourceMark rm(THREAD); 2166 ResourceMark rm(THREAD);
2147 GrowableArray<const char *>* dcmd_list = DCmdFactory::DCmd_list(); 2167 GrowableArray<const char *>* dcmd_list = DCmdFactory::DCmd_list(DCmd_Source_MBean);
2148 objArrayOop cmd_array_oop = oopFactory::new_objArray(SystemDictionary::String_klass(), 2168 objArrayOop cmd_array_oop = oopFactory::new_objArray(SystemDictionary::String_klass(),
2149 dcmd_list->length(), CHECK_NULL); 2169 dcmd_list->length(), CHECK_NULL);
2150 objArrayHandle cmd_array(THREAD, cmd_array_oop); 2170 objArrayHandle cmd_array(THREAD, cmd_array_oop);
2151 for (int i = 0; i < dcmd_list->length(); i++) { 2171 for (int i = 0; i < dcmd_list->length(); i++) {
2152 oop cmd_name = java_lang_String::create_oop_from_str(dcmd_list->at(i), CHECK_NULL); 2172 oop cmd_name = java_lang_String::create_oop_from_str(dcmd_list->at(i), CHECK_NULL);
2171 if (element_klass != SystemDictionary::String_klass()) { 2191 if (element_klass != SystemDictionary::String_klass()) {
2172 THROW_MSG(vmSymbols::java_lang_IllegalArgumentException(), 2192 THROW_MSG(vmSymbols::java_lang_IllegalArgumentException(),
2173 "Array element type is not String class"); 2193 "Array element type is not String class");
2174 } 2194 }
2175 2195
2176 GrowableArray<DCmdInfo *>* info_list = DCmdFactory::DCmdInfo_list(); 2196 GrowableArray<DCmdInfo *>* info_list = DCmdFactory::DCmdInfo_list(DCmd_Source_MBean);
2177 2197
2178 int num_cmds = cmds_ah->length(); 2198 int num_cmds = cmds_ah->length();
2179 for (int i = 0; i < num_cmds; i++) { 2199 for (int i = 0; i < num_cmds; i++) {
2180 oop cmd = cmds_ah->obj_at(i); 2200 oop cmd = cmds_ah->obj_at(i);
2181 if (cmd == NULL) { 2201 if (cmd == NULL) {
2194 } 2214 }
2195 DCmdInfo* info = info_list->at(pos); 2215 DCmdInfo* info = info_list->at(pos);
2196 infoArray[i].name = info->name(); 2216 infoArray[i].name = info->name();
2197 infoArray[i].description = info->description(); 2217 infoArray[i].description = info->description();
2198 infoArray[i].impact = info->impact(); 2218 infoArray[i].impact = info->impact();
2219 JavaPermission p = info->permission();
2220 infoArray[i].permission_class = p._class;
2221 infoArray[i].permission_name = p._name;
2222 infoArray[i].permission_action = p._action;
2199 infoArray[i].num_arguments = info->num_arguments(); 2223 infoArray[i].num_arguments = info->num_arguments();
2200 infoArray[i].enabled = info->is_enabled(); 2224 infoArray[i].enabled = info->is_enabled();
2201 } 2225 }
2202 JVM_END 2226 JVM_END
2203 2227
2213 if (cmd_name == NULL) { 2237 if (cmd_name == NULL) {
2214 THROW_MSG(vmSymbols::java_lang_NullPointerException(), 2238 THROW_MSG(vmSymbols::java_lang_NullPointerException(),
2215 "Command line content cannot be null."); 2239 "Command line content cannot be null.");
2216 } 2240 }
2217 DCmd* dcmd = NULL; 2241 DCmd* dcmd = NULL;
2218 DCmdFactory*factory = DCmdFactory::factory(cmd_name, strlen(cmd_name)); 2242 DCmdFactory*factory = DCmdFactory::factory(DCmd_Source_MBean, cmd_name,
2243 strlen(cmd_name));
2219 if (factory != NULL) { 2244 if (factory != NULL) {
2220 dcmd = factory->create_resource_instance(NULL); 2245 dcmd = factory->create_resource_instance(NULL);
2221 } 2246 }
2222 if (dcmd == NULL) { 2247 if (dcmd == NULL) {
2223 THROW_MSG(vmSymbols::java_lang_IllegalArgumentException(), 2248 THROW_MSG(vmSymbols::java_lang_IllegalArgumentException(),
2233 infoArray[i].description = array->at(i)->description(); 2258 infoArray[i].description = array->at(i)->description();
2234 infoArray[i].type = array->at(i)->type(); 2259 infoArray[i].type = array->at(i)->type();
2235 infoArray[i].default_string = array->at(i)->default_string(); 2260 infoArray[i].default_string = array->at(i)->default_string();
2236 infoArray[i].mandatory = array->at(i)->is_mandatory(); 2261 infoArray[i].mandatory = array->at(i)->is_mandatory();
2237 infoArray[i].option = array->at(i)->is_option(); 2262 infoArray[i].option = array->at(i)->is_option();
2263 infoArray[i].multiple = array->at(i)->is_multiple();
2238 infoArray[i].position = array->at(i)->position(); 2264 infoArray[i].position = array->at(i)->position();
2239 } 2265 }
2240 return; 2266 return;
2241 JVM_END 2267 JVM_END
2242 2268
2251 if (cmdline == NULL) { 2277 if (cmdline == NULL) {
2252 THROW_MSG_NULL(vmSymbols::java_lang_NullPointerException(), 2278 THROW_MSG_NULL(vmSymbols::java_lang_NullPointerException(),
2253 "Command line content cannot be null."); 2279 "Command line content cannot be null.");
2254 } 2280 }
2255 bufferedStream output; 2281 bufferedStream output;
2256 DCmd::parse_and_execute(&output, cmdline, ' ', CHECK_NULL); 2282 DCmd::parse_and_execute(DCmd_Source_MBean, &output, cmdline, ' ', CHECK_NULL);
2257 oop result = java_lang_String::create_oop_from_str(output.as_string(), CHECK_NULL); 2283 oop result = java_lang_String::create_oop_from_str(output.as_string(), CHECK_NULL);
2258 return (jstring) JNIHandles::make_local(env, result); 2284 return (jstring) JNIHandles::make_local(env, result);
2285 JVM_END
2286
2287 JVM_ENTRY(void, jmm_SetDiagnosticFrameworkNotificationEnabled(JNIEnv *env, jboolean enabled))
2288 DCmdFactory::set_jmx_notification_enabled(enabled?true:false);
2259 JVM_END 2289 JVM_END
2260 2290
2261 jlong Management::ticks_to_ms(jlong ticks) { 2291 jlong Management::ticks_to_ms(jlong ticks) {
2262 assert(os::elapsed_frequency() > 0, "Must be non-zero"); 2292 assert(os::elapsed_frequency() > 0, "Must be non-zero");
2263 return (jlong)(((double)ticks / (double)os::elapsed_frequency()) 2293 return (jlong)(((double)ticks / (double)os::elapsed_frequency())
2302 jmm_DumpThreads, 2332 jmm_DumpThreads,
2303 jmm_SetGCNotificationEnabled, 2333 jmm_SetGCNotificationEnabled,
2304 jmm_GetDiagnosticCommands, 2334 jmm_GetDiagnosticCommands,
2305 jmm_GetDiagnosticCommandInfo, 2335 jmm_GetDiagnosticCommandInfo,
2306 jmm_GetDiagnosticCommandArgumentsInfo, 2336 jmm_GetDiagnosticCommandArgumentsInfo,
2307 jmm_ExecuteDiagnosticCommand 2337 jmm_ExecuteDiagnosticCommand,
2338 jmm_SetDiagnosticFrameworkNotificationEnabled
2308 }; 2339 };
2309 #endif // INCLUDE_MANAGEMENT 2340 #endif // INCLUDE_MANAGEMENT
2310 2341
2311 void* Management::get_jmm_interface(int version) { 2342 void* Management::get_jmm_interface(int version) {
2312 #if INCLUDE_MANAGEMENT 2343 #if INCLUDE_MANAGEMENT