src/share/vm/services/management.cpp

Print this page




  29 #include "memory/oopFactory.hpp"
  30 #include "memory/resourceArea.hpp"
  31 #include "oops/klass.hpp"
  32 #include "oops/objArrayKlass.hpp"
  33 #include "oops/oop.inline.hpp"
  34 #include "runtime/arguments.hpp"
  35 #include "runtime/globals.hpp"
  36 #include "runtime/handles.inline.hpp"
  37 #include "runtime/interfaceSupport.hpp"
  38 #include "runtime/javaCalls.hpp"
  39 #include "runtime/jniHandles.hpp"
  40 #include "runtime/os.hpp"
  41 #include "runtime/serviceThread.hpp"
  42 #include "services/classLoadingService.hpp"
  43 #include "services/diagnosticCommand.hpp"
  44 #include "services/diagnosticFramework.hpp"
  45 #include "services/heapDumper.hpp"
  46 #include "services/jmm.h"
  47 #include "services/lowMemoryDetector.hpp"
  48 #include "services/gcNotifier.hpp"
  49 #include "services/nmtDCmd.hpp"
  50 #include "services/management.hpp"
  51 #include "services/memoryManager.hpp"
  52 #include "services/memoryPool.hpp"
  53 #include "services/memoryService.hpp"
  54 #include "services/runtimeService.hpp"
  55 #include "services/threadService.hpp"
  56 
  57 PerfVariable* Management::_begin_vm_creation_time = NULL;
  58 PerfVariable* Management::_end_vm_creation_time = NULL;
  59 PerfVariable* Management::_vm_init_done_time = NULL;
  60 
  61 Klass* Management::_sensor_klass = NULL;
  62 Klass* Management::_threadInfo_klass = NULL;
  63 Klass* Management::_memoryUsage_klass = NULL;
  64 Klass* Management::_memoryPoolMXBean_klass = NULL;
  65 Klass* Management::_memoryManagerMXBean_klass = NULL;
  66 Klass* Management::_garbageCollectorMXBean_klass = NULL;
  67 Klass* Management::_managementFactory_klass = NULL;
  68 Klass* Management::_garbageCollectorImpl_klass = NULL;
  69 Klass* Management::_gcInfo_klass = NULL;


  70 

  71 jmmOptionalSupport Management::_optional_support = {0};
  72 TimeStamp Management::_stamp;
  73 
  74 void management_init() {
  75 #if INCLUDE_MANAGEMENT
  76   Management::init();
  77   ThreadService::init();
  78   RuntimeService::init();
  79   ClassLoadingService::init();
  80 #else
  81   ThreadService::init();
  82   // Make sure the VM version is initialized
  83   // This is normally called by RuntimeService::init().
  84   // Since that is conditionalized out, we need to call it here.
  85   Abstract_VM_Version::initialize();
  86 #endif // INCLUDE_MANAGEMENT
  87 }
  88 
  89 #if INCLUDE_MANAGEMENT
  90 


 110   // Initialize optional support
 111   _optional_support.isLowMemoryDetectionSupported = 1;
 112   _optional_support.isCompilationTimeMonitoringSupported = 1;
 113   _optional_support.isThreadContentionMonitoringSupported = 1;
 114 
 115   if (os::is_thread_cpu_time_supported()) {
 116     _optional_support.isCurrentThreadCpuTimeSupported = 1;
 117     _optional_support.isOtherThreadCpuTimeSupported = 1;
 118   } else {
 119     _optional_support.isCurrentThreadCpuTimeSupported = 0;
 120     _optional_support.isOtherThreadCpuTimeSupported = 0;
 121   }
 122 
 123   _optional_support.isBootClassPathSupported = 1;
 124   _optional_support.isObjectMonitorUsageSupported = 1;
 125 #if INCLUDE_SERVICES
 126   // This depends on the heap inspector
 127   _optional_support.isSynchronizerUsageSupported = 1;
 128 #endif // INCLUDE_SERVICES
 129   _optional_support.isThreadAllocatedMemorySupported = 1;

 130 
 131   // Registration of the diagnostic commands
 132   DCmdRegistrant::register_dcmds();
 133   DCmdRegistrant::register_dcmds_ext();
 134   DCmdFactory::register_DCmdFactory(new DCmdFactoryImpl<NMTDCmd>(true, false));
 135 }
 136 
 137 void Management::initialize(TRAPS) {
 138   // Start the service thread
 139   ServiceThread::initialize();
 140 
 141   if (ManagementServer) {
 142     ResourceMark rm(THREAD);
 143     HandleMark hm(THREAD);
 144 
 145     // Load and initialize the sun.management.Agent class
 146     // invoke startAgent method to start the management server
 147     Handle loader = Handle(THREAD, SystemDictionary::java_system_loader());
 148     Klass* k = SystemDictionary::resolve_or_fail(vmSymbols::sun_management_Agent(),
 149                                                    loader,
 150                                                    Handle(),
 151                                                    true,
 152                                                    CHECK);
 153     instanceKlassHandle ik (THREAD, k);
 154 


 244   if (_managementFactory_klass == NULL) {
 245     _managementFactory_klass = load_and_initialize_klass(vmSymbols::sun_management_ManagementFactory(), CHECK_NULL);
 246   }
 247   return _managementFactory_klass;
 248 }
 249 
 250 Klass* Management::sun_management_GarbageCollectorImpl_klass(TRAPS) {
 251   if (_garbageCollectorImpl_klass == NULL) {
 252     _garbageCollectorImpl_klass = load_and_initialize_klass(vmSymbols::sun_management_GarbageCollectorImpl(), CHECK_NULL);
 253   }
 254   return _garbageCollectorImpl_klass;
 255 }
 256 
 257 Klass* Management::com_sun_management_GcInfo_klass(TRAPS) {
 258   if (_gcInfo_klass == NULL) {
 259     _gcInfo_klass = load_and_initialize_klass(vmSymbols::com_sun_management_GcInfo(), CHECK_NULL);
 260   }
 261   return _gcInfo_klass;
 262 }
 263 














 264 static void initialize_ThreadInfo_constructor_arguments(JavaCallArguments* args, ThreadSnapshot* snapshot, TRAPS) {
 265   Handle snapshot_thread(THREAD, snapshot->threadObj());
 266 
 267   jlong contended_time;
 268   jlong waited_time;
 269   if (ThreadService::is_thread_monitoring_contention()) {
 270     contended_time = Management::ticks_to_ms(snapshot->contended_enter_ticks());
 271     waited_time = Management::ticks_to_ms(snapshot->monitor_wait_ticks() + snapshot->sleep_ticks());
 272   } else {
 273     // set them to -1 if thread contention monitoring is disabled.
 274     contended_time = max_julong;
 275     waited_time = max_julong;
 276   }
 277 
 278   int thread_status = snapshot->thread_status();
 279   assert((thread_status & JMM_THREAD_STATE_FLAG_MASK) == 0, "Flags already set in thread_status in Thread object");
 280   if (snapshot->is_ext_suspended()) {
 281     thread_status |= JMM_THREAD_STATE_FLAG_SUSPENDED;
 282   }
 283   if (snapshot->is_in_native()) {


2126                "Output file name cannot be null.", -1);
2127   }
2128   char* name = java_lang_String::as_utf8_string(on);
2129   if (name == NULL) {
2130     THROW_MSG_(vmSymbols::java_lang_NullPointerException(),
2131                "Output file name cannot be null.", -1);
2132   }
2133   HeapDumper dumper(live ? true : false);
2134   if (dumper.dump(name) != 0) {
2135     const char* errmsg = dumper.error_as_C_string();
2136     THROW_MSG_(vmSymbols::java_io_IOException(), errmsg, -1);
2137   }
2138   return 0;
2139 #else  // INCLUDE_SERVICES
2140   return -1;
2141 #endif // INCLUDE_SERVICES
2142 JVM_END
2143 
2144 JVM_ENTRY(jobjectArray, jmm_GetDiagnosticCommands(JNIEnv *env))
2145   ResourceMark rm(THREAD);
2146   GrowableArray<const char *>* dcmd_list = DCmdFactory::DCmd_list();
2147   objArrayOop cmd_array_oop = oopFactory::new_objArray(SystemDictionary::String_klass(),
2148           dcmd_list->length(), CHECK_NULL);
2149   objArrayHandle cmd_array(THREAD, cmd_array_oop);
2150   for (int i = 0; i < dcmd_list->length(); i++) {
2151     oop cmd_name = java_lang_String::create_oop_from_str(dcmd_list->at(i), CHECK_NULL);
2152     cmd_array->obj_at_put(i, cmd_name);
2153   }
2154   return (jobjectArray) JNIHandles::make_local(env, cmd_array());
2155 JVM_END
2156 
2157 JVM_ENTRY(void, jmm_GetDiagnosticCommandInfo(JNIEnv *env, jobjectArray cmds,
2158           dcmdInfo* infoArray))
2159   if (cmds == NULL || infoArray == NULL) {
2160     THROW(vmSymbols::java_lang_NullPointerException());
2161   }
2162 
2163   ResourceMark rm(THREAD);
2164 
2165   objArrayOop ca = objArrayOop(JNIHandles::resolve_non_null(cmds));
2166   objArrayHandle cmds_ah(THREAD, ca);
2167 
2168   // Make sure we have a String array
2169   Klass* element_klass = ObjArrayKlass::cast(cmds_ah->klass())->element_klass();
2170   if (element_klass != SystemDictionary::String_klass()) {
2171     THROW_MSG(vmSymbols::java_lang_IllegalArgumentException(),
2172                "Array element type is not String class");
2173   }
2174 
2175   GrowableArray<DCmdInfo *>* info_list = DCmdFactory::DCmdInfo_list();
2176 
2177   int num_cmds = cmds_ah->length();
2178   for (int i = 0; i < num_cmds; i++) {
2179     oop cmd = cmds_ah->obj_at(i);
2180     if (cmd == NULL) {
2181         THROW_MSG(vmSymbols::java_lang_NullPointerException(),
2182                 "Command name cannot be null.");
2183     }
2184     char* cmd_name = java_lang_String::as_utf8_string(cmd);
2185     if (cmd_name == NULL) {
2186         THROW_MSG(vmSymbols::java_lang_NullPointerException(),
2187                 "Command name cannot be null.");
2188     }
2189     int pos = info_list->find((void*)cmd_name,DCmdInfo::by_name);
2190     if (pos == -1) {
2191         THROW_MSG(vmSymbols::java_lang_IllegalArgumentException(),
2192              "Unknown diagnostic command");
2193     }
2194     DCmdInfo* info = info_list->at(pos);
2195     infoArray[i].name = info->name();
2196     infoArray[i].description = info->description();
2197     infoArray[i].impact = info->impact();




2198     infoArray[i].num_arguments = info->num_arguments();
2199     infoArray[i].enabled = info->is_enabled();
2200   }
2201 JVM_END
2202 
2203 JVM_ENTRY(void, jmm_GetDiagnosticCommandArgumentsInfo(JNIEnv *env,
2204           jstring command, dcmdArgInfo* infoArray))
2205   ResourceMark rm(THREAD);
2206   oop cmd = JNIHandles::resolve_external_guard(command);
2207   if (cmd == NULL) {
2208     THROW_MSG(vmSymbols::java_lang_NullPointerException(),
2209               "Command line cannot be null.");
2210   }
2211   char* cmd_name = java_lang_String::as_utf8_string(cmd);
2212   if (cmd_name == NULL) {
2213     THROW_MSG(vmSymbols::java_lang_NullPointerException(),
2214               "Command line content cannot be null.");
2215   }
2216   DCmd* dcmd = NULL;
2217   DCmdFactory*factory = DCmdFactory::factory(cmd_name, strlen(cmd_name));

2218   if (factory != NULL) {
2219     dcmd = factory->create_resource_instance(NULL);
2220   }
2221   if (dcmd == NULL) {
2222     THROW_MSG(vmSymbols::java_lang_IllegalArgumentException(),
2223               "Unknown diagnostic command");
2224   }
2225   DCmdMark mark(dcmd);
2226   GrowableArray<DCmdArgumentInfo*>* array = dcmd->argument_info_array();
2227   if (array->length() == 0) {
2228     return;
2229   }
2230   for (int i = 0; i < array->length(); i++) {
2231     infoArray[i].name = array->at(i)->name();
2232     infoArray[i].description = array->at(i)->description();
2233     infoArray[i].type = array->at(i)->type();
2234     infoArray[i].default_string = array->at(i)->default_string();
2235     infoArray[i].mandatory = array->at(i)->is_mandatory();
2236     infoArray[i].option = array->at(i)->is_option();

2237     infoArray[i].position = array->at(i)->position();
2238   }
2239   return;
2240 JVM_END
2241 
2242 JVM_ENTRY(jstring, jmm_ExecuteDiagnosticCommand(JNIEnv *env, jstring commandline))
2243   ResourceMark rm(THREAD);
2244   oop cmd = JNIHandles::resolve_external_guard(commandline);
2245   if (cmd == NULL) {
2246     THROW_MSG_NULL(vmSymbols::java_lang_NullPointerException(),
2247                    "Command line cannot be null.");
2248   }
2249   char* cmdline = java_lang_String::as_utf8_string(cmd);
2250   if (cmdline == NULL) {
2251     THROW_MSG_NULL(vmSymbols::java_lang_NullPointerException(),
2252                    "Command line content cannot be null.");
2253   }
2254   bufferedStream output;
2255   DCmd::parse_and_execute(&output, cmdline, ' ', CHECK_NULL);
2256   oop result = java_lang_String::create_oop_from_str(output.as_string(), CHECK_NULL);
2257   return (jstring) JNIHandles::make_local(env, result);
2258 JVM_END
2259 




2260 jlong Management::ticks_to_ms(jlong ticks) {
2261   assert(os::elapsed_frequency() > 0, "Must be non-zero");
2262   return (jlong)(((double)ticks / (double)os::elapsed_frequency())
2263                  * (double)1000.0);
2264 }
2265 
2266 const struct jmmInterface_1_ jmm_interface = {
2267   NULL,
2268   NULL,
2269   jmm_GetVersion,
2270   jmm_GetOptionalSupport,
2271   jmm_GetInputArguments,
2272   jmm_GetThreadInfo,
2273   jmm_GetInputArgumentArray,
2274   jmm_GetMemoryPools,
2275   jmm_GetMemoryManagers,
2276   jmm_GetMemoryPoolUsage,
2277   jmm_GetPeakMemoryPoolUsage,
2278   jmm_GetThreadAllocatedMemory,
2279   jmm_GetMemoryUsage,


2286   jmm_GetVMGlobalNames,
2287   jmm_GetVMGlobals,
2288   jmm_GetInternalThreadTimes,
2289   jmm_ResetStatistic,
2290   jmm_SetPoolSensor,
2291   jmm_SetPoolThreshold,
2292   jmm_GetPoolCollectionUsage,
2293   jmm_GetGCExtAttributeInfo,
2294   jmm_GetLastGCStat,
2295   jmm_GetThreadCpuTimeWithKind,
2296   jmm_GetThreadCpuTimesWithKind,
2297   jmm_DumpHeap0,
2298   jmm_FindDeadlockedThreads,
2299   jmm_SetVMGlobal,
2300   NULL,
2301   jmm_DumpThreads,
2302   jmm_SetGCNotificationEnabled,
2303   jmm_GetDiagnosticCommands,
2304   jmm_GetDiagnosticCommandInfo,
2305   jmm_GetDiagnosticCommandArgumentsInfo,
2306   jmm_ExecuteDiagnosticCommand

2307 };
2308 #endif // INCLUDE_MANAGEMENT
2309 
2310 void* Management::get_jmm_interface(int version) {
2311 #if INCLUDE_MANAGEMENT
2312   if (version == JMM_VERSION_1_0) {
2313     return (void*) &jmm_interface;
2314   }
2315 #endif // INCLUDE_MANAGEMENT
2316   return NULL;
2317 }


  29 #include "memory/oopFactory.hpp"
  30 #include "memory/resourceArea.hpp"
  31 #include "oops/klass.hpp"
  32 #include "oops/objArrayKlass.hpp"
  33 #include "oops/oop.inline.hpp"
  34 #include "runtime/arguments.hpp"
  35 #include "runtime/globals.hpp"
  36 #include "runtime/handles.inline.hpp"
  37 #include "runtime/interfaceSupport.hpp"
  38 #include "runtime/javaCalls.hpp"
  39 #include "runtime/jniHandles.hpp"
  40 #include "runtime/os.hpp"
  41 #include "runtime/serviceThread.hpp"
  42 #include "services/classLoadingService.hpp"
  43 #include "services/diagnosticCommand.hpp"
  44 #include "services/diagnosticFramework.hpp"
  45 #include "services/heapDumper.hpp"
  46 #include "services/jmm.h"
  47 #include "services/lowMemoryDetector.hpp"
  48 #include "services/gcNotifier.hpp"

  49 #include "services/management.hpp"
  50 #include "services/memoryManager.hpp"
  51 #include "services/memoryPool.hpp"
  52 #include "services/memoryService.hpp"
  53 #include "services/runtimeService.hpp"
  54 #include "services/threadService.hpp"
  55 
  56 PerfVariable* Management::_begin_vm_creation_time = NULL;
  57 PerfVariable* Management::_end_vm_creation_time = NULL;
  58 PerfVariable* Management::_vm_init_done_time = NULL;
  59 
  60 Klass* Management::_sensor_klass = NULL;
  61 Klass* Management::_threadInfo_klass = NULL;
  62 Klass* Management::_memoryUsage_klass = NULL;
  63 Klass* Management::_memoryPoolMXBean_klass = NULL;
  64 Klass* Management::_memoryManagerMXBean_klass = NULL;
  65 Klass* Management::_garbageCollectorMXBean_klass = NULL;
  66 Klass* Management::_managementFactory_klass = NULL;
  67 Klass* Management::_garbageCollectorImpl_klass = NULL;
  68 Klass* Management::_gcInfo_klass = NULL;
  69 Klass* Management::_diagnosticCommandImpl_klass = NULL;
  70 Klass* Management::_managementFactoryHelper_klass = NULL;
  71 
  72 
  73 jmmOptionalSupport Management::_optional_support = {0};
  74 TimeStamp Management::_stamp;
  75 
  76 void management_init() {
  77 #if INCLUDE_MANAGEMENT
  78   Management::init();
  79   ThreadService::init();
  80   RuntimeService::init();
  81   ClassLoadingService::init();
  82 #else
  83   ThreadService::init();
  84   // Make sure the VM version is initialized
  85   // This is normally called by RuntimeService::init().
  86   // Since that is conditionalized out, we need to call it here.
  87   Abstract_VM_Version::initialize();
  88 #endif // INCLUDE_MANAGEMENT
  89 }
  90 
  91 #if INCLUDE_MANAGEMENT
  92 


 112   // Initialize optional support
 113   _optional_support.isLowMemoryDetectionSupported = 1;
 114   _optional_support.isCompilationTimeMonitoringSupported = 1;
 115   _optional_support.isThreadContentionMonitoringSupported = 1;
 116 
 117   if (os::is_thread_cpu_time_supported()) {
 118     _optional_support.isCurrentThreadCpuTimeSupported = 1;
 119     _optional_support.isOtherThreadCpuTimeSupported = 1;
 120   } else {
 121     _optional_support.isCurrentThreadCpuTimeSupported = 0;
 122     _optional_support.isOtherThreadCpuTimeSupported = 0;
 123   }
 124 
 125   _optional_support.isBootClassPathSupported = 1;
 126   _optional_support.isObjectMonitorUsageSupported = 1;
 127 #if INCLUDE_SERVICES
 128   // This depends on the heap inspector
 129   _optional_support.isSynchronizerUsageSupported = 1;
 130 #endif // INCLUDE_SERVICES
 131   _optional_support.isThreadAllocatedMemorySupported = 1;
 132   _optional_support.isRemoteDiagnosticCommandsSupported = 1;
 133 
 134   // Registration of the diagnostic commands
 135   DCmdRegistrant::register_dcmds();
 136   DCmdRegistrant::register_dcmds_ext();

 137 }
 138 
 139 void Management::initialize(TRAPS) {
 140   // Start the service thread
 141   ServiceThread::initialize();
 142 
 143   if (ManagementServer) {
 144     ResourceMark rm(THREAD);
 145     HandleMark hm(THREAD);
 146 
 147     // Load and initialize the sun.management.Agent class
 148     // invoke startAgent method to start the management server
 149     Handle loader = Handle(THREAD, SystemDictionary::java_system_loader());
 150     Klass* k = SystemDictionary::resolve_or_fail(vmSymbols::sun_management_Agent(),
 151                                                    loader,
 152                                                    Handle(),
 153                                                    true,
 154                                                    CHECK);
 155     instanceKlassHandle ik (THREAD, k);
 156 


 246   if (_managementFactory_klass == NULL) {
 247     _managementFactory_klass = load_and_initialize_klass(vmSymbols::sun_management_ManagementFactory(), CHECK_NULL);
 248   }
 249   return _managementFactory_klass;
 250 }
 251 
 252 Klass* Management::sun_management_GarbageCollectorImpl_klass(TRAPS) {
 253   if (_garbageCollectorImpl_klass == NULL) {
 254     _garbageCollectorImpl_klass = load_and_initialize_klass(vmSymbols::sun_management_GarbageCollectorImpl(), CHECK_NULL);
 255   }
 256   return _garbageCollectorImpl_klass;
 257 }
 258 
 259 Klass* Management::com_sun_management_GcInfo_klass(TRAPS) {
 260   if (_gcInfo_klass == NULL) {
 261     _gcInfo_klass = load_and_initialize_klass(vmSymbols::com_sun_management_GcInfo(), CHECK_NULL);
 262   }
 263   return _gcInfo_klass;
 264 }
 265 
 266 Klass* Management::sun_management_DiagnosticCommandImpl_klass(TRAPS) {
 267   if (_diagnosticCommandImpl_klass == NULL) {
 268     _diagnosticCommandImpl_klass = load_and_initialize_klass(vmSymbols::sun_management_DiagnosticCommandImpl(), CHECK_NULL);
 269   }
 270   return _diagnosticCommandImpl_klass;
 271 }
 272 
 273 Klass* Management::sun_management_ManagementFactoryHelper_klass(TRAPS) {
 274   if (_managementFactoryHelper_klass == NULL) {
 275     _managementFactoryHelper_klass = load_and_initialize_klass(vmSymbols::sun_management_ManagementFactoryHelper(), CHECK_NULL);
 276   }
 277   return _managementFactoryHelper_klass;
 278 }
 279 
 280 static void initialize_ThreadInfo_constructor_arguments(JavaCallArguments* args, ThreadSnapshot* snapshot, TRAPS) {
 281   Handle snapshot_thread(THREAD, snapshot->threadObj());
 282 
 283   jlong contended_time;
 284   jlong waited_time;
 285   if (ThreadService::is_thread_monitoring_contention()) {
 286     contended_time = Management::ticks_to_ms(snapshot->contended_enter_ticks());
 287     waited_time = Management::ticks_to_ms(snapshot->monitor_wait_ticks() + snapshot->sleep_ticks());
 288   } else {
 289     // set them to -1 if thread contention monitoring is disabled.
 290     contended_time = max_julong;
 291     waited_time = max_julong;
 292   }
 293 
 294   int thread_status = snapshot->thread_status();
 295   assert((thread_status & JMM_THREAD_STATE_FLAG_MASK) == 0, "Flags already set in thread_status in Thread object");
 296   if (snapshot->is_ext_suspended()) {
 297     thread_status |= JMM_THREAD_STATE_FLAG_SUSPENDED;
 298   }
 299   if (snapshot->is_in_native()) {


2142                "Output file name cannot be null.", -1);
2143   }
2144   char* name = java_lang_String::as_utf8_string(on);
2145   if (name == NULL) {
2146     THROW_MSG_(vmSymbols::java_lang_NullPointerException(),
2147                "Output file name cannot be null.", -1);
2148   }
2149   HeapDumper dumper(live ? true : false);
2150   if (dumper.dump(name) != 0) {
2151     const char* errmsg = dumper.error_as_C_string();
2152     THROW_MSG_(vmSymbols::java_io_IOException(), errmsg, -1);
2153   }
2154   return 0;
2155 #else  // INCLUDE_SERVICES
2156   return -1;
2157 #endif // INCLUDE_SERVICES
2158 JVM_END
2159 
2160 JVM_ENTRY(jobjectArray, jmm_GetDiagnosticCommands(JNIEnv *env))
2161   ResourceMark rm(THREAD);
2162   GrowableArray<const char *>* dcmd_list = DCmdFactory::DCmd_list(DCmd_Source_MBean);
2163   objArrayOop cmd_array_oop = oopFactory::new_objArray(SystemDictionary::String_klass(),
2164           dcmd_list->length(), CHECK_NULL);
2165   objArrayHandle cmd_array(THREAD, cmd_array_oop);
2166   for (int i = 0; i < dcmd_list->length(); i++) {
2167     oop cmd_name = java_lang_String::create_oop_from_str(dcmd_list->at(i), CHECK_NULL);
2168     cmd_array->obj_at_put(i, cmd_name);
2169   }
2170   return (jobjectArray) JNIHandles::make_local(env, cmd_array());
2171 JVM_END
2172 
2173 JVM_ENTRY(void, jmm_GetDiagnosticCommandInfo(JNIEnv *env, jobjectArray cmds,
2174           dcmdInfo* infoArray))
2175   if (cmds == NULL || infoArray == NULL) {
2176     THROW(vmSymbols::java_lang_NullPointerException());
2177   }
2178 
2179   ResourceMark rm(THREAD);
2180 
2181   objArrayOop ca = objArrayOop(JNIHandles::resolve_non_null(cmds));
2182   objArrayHandle cmds_ah(THREAD, ca);
2183 
2184   // Make sure we have a String array
2185   Klass* element_klass = ObjArrayKlass::cast(cmds_ah->klass())->element_klass();
2186   if (element_klass != SystemDictionary::String_klass()) {
2187     THROW_MSG(vmSymbols::java_lang_IllegalArgumentException(),
2188                "Array element type is not String class");
2189   }
2190 
2191   GrowableArray<DCmdInfo *>* info_list = DCmdFactory::DCmdInfo_list(DCmd_Source_MBean);
2192 
2193   int num_cmds = cmds_ah->length();
2194   for (int i = 0; i < num_cmds; i++) {
2195     oop cmd = cmds_ah->obj_at(i);
2196     if (cmd == NULL) {
2197         THROW_MSG(vmSymbols::java_lang_NullPointerException(),
2198                 "Command name cannot be null.");
2199     }
2200     char* cmd_name = java_lang_String::as_utf8_string(cmd);
2201     if (cmd_name == NULL) {
2202         THROW_MSG(vmSymbols::java_lang_NullPointerException(),
2203                 "Command name cannot be null.");
2204     }
2205     int pos = info_list->find((void*)cmd_name,DCmdInfo::by_name);
2206     if (pos == -1) {
2207         THROW_MSG(vmSymbols::java_lang_IllegalArgumentException(),
2208              "Unknown diagnostic command");
2209     }
2210     DCmdInfo* info = info_list->at(pos);
2211     infoArray[i].name = info->name();
2212     infoArray[i].description = info->description();
2213     infoArray[i].impact = info->impact();
2214     JavaPermission p = info->permission();
2215     infoArray[i].permission_class = p._class;
2216     infoArray[i].permission_name = p._name;
2217     infoArray[i].permission_action = p._action;
2218     infoArray[i].num_arguments = info->num_arguments();
2219     infoArray[i].enabled = info->is_enabled();
2220   }
2221 JVM_END
2222 
2223 JVM_ENTRY(void, jmm_GetDiagnosticCommandArgumentsInfo(JNIEnv *env,
2224           jstring command, dcmdArgInfo* infoArray))
2225   ResourceMark rm(THREAD);
2226   oop cmd = JNIHandles::resolve_external_guard(command);
2227   if (cmd == NULL) {
2228     THROW_MSG(vmSymbols::java_lang_NullPointerException(),
2229               "Command line cannot be null.");
2230   }
2231   char* cmd_name = java_lang_String::as_utf8_string(cmd);
2232   if (cmd_name == NULL) {
2233     THROW_MSG(vmSymbols::java_lang_NullPointerException(),
2234               "Command line content cannot be null.");
2235   }
2236   DCmd* dcmd = NULL;
2237   DCmdFactory*factory = DCmdFactory::factory(DCmd_Source_MBean, cmd_name,
2238                                              strlen(cmd_name));
2239   if (factory != NULL) {
2240     dcmd = factory->create_resource_instance(NULL);
2241   }
2242   if (dcmd == NULL) {
2243     THROW_MSG(vmSymbols::java_lang_IllegalArgumentException(),
2244               "Unknown diagnostic command");
2245   }
2246   DCmdMark mark(dcmd);
2247   GrowableArray<DCmdArgumentInfo*>* array = dcmd->argument_info_array();
2248   if (array->length() == 0) {
2249     return;
2250   }
2251   for (int i = 0; i < array->length(); i++) {
2252     infoArray[i].name = array->at(i)->name();
2253     infoArray[i].description = array->at(i)->description();
2254     infoArray[i].type = array->at(i)->type();
2255     infoArray[i].default_string = array->at(i)->default_string();
2256     infoArray[i].mandatory = array->at(i)->is_mandatory();
2257     infoArray[i].option = array->at(i)->is_option();
2258     infoArray[i].multiple = array->at(i)->is_multiple();
2259     infoArray[i].position = array->at(i)->position();
2260   }
2261   return;
2262 JVM_END
2263 
2264 JVM_ENTRY(jstring, jmm_ExecuteDiagnosticCommand(JNIEnv *env, jstring commandline))
2265   ResourceMark rm(THREAD);
2266   oop cmd = JNIHandles::resolve_external_guard(commandline);
2267   if (cmd == NULL) {
2268     THROW_MSG_NULL(vmSymbols::java_lang_NullPointerException(),
2269                    "Command line cannot be null.");
2270   }
2271   char* cmdline = java_lang_String::as_utf8_string(cmd);
2272   if (cmdline == NULL) {
2273     THROW_MSG_NULL(vmSymbols::java_lang_NullPointerException(),
2274                    "Command line content cannot be null.");
2275   }
2276   bufferedStream output;
2277   DCmd::parse_and_execute(DCmd_Source_MBean, &output, cmdline, ' ', CHECK_NULL);
2278   oop result = java_lang_String::create_oop_from_str(output.as_string(), CHECK_NULL);
2279   return (jstring) JNIHandles::make_local(env, result);
2280 JVM_END
2281 
2282 JVM_ENTRY(void, jmm_SetDiagnosticFrameworkNotificationEnabled(JNIEnv *env, jboolean enabled))
2283   DCmdFactory::set_jmx_notification_enabled(enabled?true:false);
2284 JVM_END
2285 
2286 jlong Management::ticks_to_ms(jlong ticks) {
2287   assert(os::elapsed_frequency() > 0, "Must be non-zero");
2288   return (jlong)(((double)ticks / (double)os::elapsed_frequency())
2289                  * (double)1000.0);
2290 }
2291 
2292 const struct jmmInterface_1_ jmm_interface = {
2293   NULL,
2294   NULL,
2295   jmm_GetVersion,
2296   jmm_GetOptionalSupport,
2297   jmm_GetInputArguments,
2298   jmm_GetThreadInfo,
2299   jmm_GetInputArgumentArray,
2300   jmm_GetMemoryPools,
2301   jmm_GetMemoryManagers,
2302   jmm_GetMemoryPoolUsage,
2303   jmm_GetPeakMemoryPoolUsage,
2304   jmm_GetThreadAllocatedMemory,
2305   jmm_GetMemoryUsage,


2312   jmm_GetVMGlobalNames,
2313   jmm_GetVMGlobals,
2314   jmm_GetInternalThreadTimes,
2315   jmm_ResetStatistic,
2316   jmm_SetPoolSensor,
2317   jmm_SetPoolThreshold,
2318   jmm_GetPoolCollectionUsage,
2319   jmm_GetGCExtAttributeInfo,
2320   jmm_GetLastGCStat,
2321   jmm_GetThreadCpuTimeWithKind,
2322   jmm_GetThreadCpuTimesWithKind,
2323   jmm_DumpHeap0,
2324   jmm_FindDeadlockedThreads,
2325   jmm_SetVMGlobal,
2326   NULL,
2327   jmm_DumpThreads,
2328   jmm_SetGCNotificationEnabled,
2329   jmm_GetDiagnosticCommands,
2330   jmm_GetDiagnosticCommandInfo,
2331   jmm_GetDiagnosticCommandArgumentsInfo,
2332   jmm_ExecuteDiagnosticCommand,
2333   jmm_SetDiagnosticFrameworkNotificationEnabled
2334 };
2335 #endif // INCLUDE_MANAGEMENT
2336 
2337 void* Management::get_jmm_interface(int version) {
2338 #if INCLUDE_MANAGEMENT
2339   if (version == JMM_VERSION_1_0) {
2340     return (void*) &jmm_interface;
2341   }
2342 #endif // INCLUDE_MANAGEMENT
2343   return NULL;
2344 }