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 Management::init(); 76 ThreadService::init(); 77 RuntimeService::init(); 78 ClassLoadingService::init(); 79 } 80 81 void Management::init() { 82 EXCEPTION_MARK; 83 84 // These counters are for java.lang.management API support. 85 // They are created even if -XX:-UsePerfData is set and in 86 // that case, they will be allocated on C heap. 87 88 _begin_vm_creation_time = 89 PerfDataManager::create_variable(SUN_RT, "createVmBeginTime", 90 PerfData::U_None, CHECK); 91 92 _end_vm_creation_time = 93 PerfDataManager::create_variable(SUN_RT, "createVmEndTime", 94 PerfData::U_None, CHECK); 95 96 _vm_init_done_time = 97 PerfDataManager::create_variable(SUN_RT, "vmInitDoneTime", 98 PerfData::U_None, CHECK); 99 100 // Initialize optional support 101 _optional_support.isLowMemoryDetectionSupported = 1; 102 _optional_support.isCompilationTimeMonitoringSupported = 1; 103 _optional_support.isThreadContentionMonitoringSupported = 1; 104 105 if (os::is_thread_cpu_time_supported()) { 106 _optional_support.isCurrentThreadCpuTimeSupported = 1; 107 _optional_support.isOtherThreadCpuTimeSupported = 1; 108 } else { 109 _optional_support.isCurrentThreadCpuTimeSupported = 0; 110 _optional_support.isOtherThreadCpuTimeSupported = 0; 111 } 112 113 _optional_support.isBootClassPathSupported = 1; 114 _optional_support.isObjectMonitorUsageSupported = 1; 115 #ifndef SERVICES_KERNEL 116 // This depends on the heap inspector 117 _optional_support.isSynchronizerUsageSupported = 1; 118 #endif // SERVICES_KERNEL 119 _optional_support.isThreadAllocatedMemorySupported = 1; 120 121 // Registration of the diagnostic commands 122 DCmdRegistrant::register_dcmds(); 123 DCmdRegistrant::register_dcmds_ext(); 124 DCmdFactory::register_DCmdFactory(new DCmdFactoryImpl<NMTDCmd>(true, false)); 125 } 126 127 void Management::initialize(TRAPS) { 128 // Start the service thread 129 ServiceThread::initialize(); 130 131 if (ManagementServer) { 132 ResourceMark rm(THREAD); 133 HandleMark hm(THREAD); 134 135 // Load and initialize the sun.management.Agent class 136 // invoke startAgent method to start the management server 137 Handle loader = Handle(THREAD, SystemDictionary::java_system_loader()); 138 Klass* k = SystemDictionary::resolve_or_fail(vmSymbols::sun_management_Agent(), 2069 usage_before_gc_ah->obj_at_put(i, before_usage()); 2070 usage_after_gc_ah->obj_at_put(i, after_usage()); 2071 } 2072 2073 if (gc_stat->gc_ext_attribute_values_size > 0) { 2074 // Current implementation only has 1 attribute (number of GC threads) 2075 // The type is 'I' 2076 gc_stat->gc_ext_attribute_values[0].i = mgr->num_gc_threads(); 2077 } 2078 JVM_END 2079 2080 JVM_ENTRY(void, jmm_SetGCNotificationEnabled(JNIEnv *env, jobject obj, jboolean enabled)) 2081 ResourceMark rm(THREAD); 2082 // Get the GCMemoryManager 2083 GCMemoryManager* mgr = get_gc_memory_manager_from_jobject(obj, CHECK); 2084 mgr->set_notification_enabled(enabled?true:false); 2085 JVM_END 2086 2087 // Dump heap - Returns 0 if succeeds. 2088 JVM_ENTRY(jint, jmm_DumpHeap0(JNIEnv *env, jstring outputfile, jboolean live)) 2089 #ifndef SERVICES_KERNEL 2090 ResourceMark rm(THREAD); 2091 oop on = JNIHandles::resolve_external_guard(outputfile); 2092 if (on == NULL) { 2093 THROW_MSG_(vmSymbols::java_lang_NullPointerException(), 2094 "Output file name cannot be null.", -1); 2095 } 2096 char* name = java_lang_String::as_utf8_string(on); 2097 if (name == NULL) { 2098 THROW_MSG_(vmSymbols::java_lang_NullPointerException(), 2099 "Output file name cannot be null.", -1); 2100 } 2101 HeapDumper dumper(live ? true : false); 2102 if (dumper.dump(name) != 0) { 2103 const char* errmsg = dumper.error_as_C_string(); 2104 THROW_MSG_(vmSymbols::java_io_IOException(), errmsg, -1); 2105 } 2106 return 0; 2107 #else // SERVICES_KERNEL 2108 return -1; 2109 #endif // SERVICES_KERNEL 2110 JVM_END 2111 2112 JVM_ENTRY(jobjectArray, jmm_GetDiagnosticCommands(JNIEnv *env)) 2113 ResourceMark rm(THREAD); 2114 GrowableArray<const char *>* dcmd_list = DCmdFactory::DCmd_list(); 2115 objArrayOop cmd_array_oop = oopFactory::new_objArray(SystemDictionary::String_klass(), 2116 dcmd_list->length(), CHECK_NULL); 2117 objArrayHandle cmd_array(THREAD, cmd_array_oop); 2118 for (int i = 0; i < dcmd_list->length(); i++) { 2119 oop cmd_name = java_lang_String::create_oop_from_str(dcmd_list->at(i), CHECK_NULL); 2120 cmd_array->obj_at_put(i, cmd_name); 2121 } 2122 return (jobjectArray) JNIHandles::make_local(env, cmd_array()); 2123 JVM_END 2124 2125 JVM_ENTRY(void, jmm_GetDiagnosticCommandInfo(JNIEnv *env, jobjectArray cmds, 2126 dcmdInfo* infoArray)) 2127 if (cmds == NULL || infoArray == NULL) { 2128 THROW(vmSymbols::java_lang_NullPointerException()); 2129 } 2256 jmm_GetInternalThreadTimes, 2257 jmm_ResetStatistic, 2258 jmm_SetPoolSensor, 2259 jmm_SetPoolThreshold, 2260 jmm_GetPoolCollectionUsage, 2261 jmm_GetGCExtAttributeInfo, 2262 jmm_GetLastGCStat, 2263 jmm_GetThreadCpuTimeWithKind, 2264 jmm_GetThreadCpuTimesWithKind, 2265 jmm_DumpHeap0, 2266 jmm_FindDeadlockedThreads, 2267 jmm_SetVMGlobal, 2268 NULL, 2269 jmm_DumpThreads, 2270 jmm_SetGCNotificationEnabled, 2271 jmm_GetDiagnosticCommands, 2272 jmm_GetDiagnosticCommandInfo, 2273 jmm_GetDiagnosticCommandArgumentsInfo, 2274 jmm_ExecuteDiagnosticCommand 2275 }; 2276 2277 void* Management::get_jmm_interface(int version) { 2278 if (version == JMM_VERSION_1_0) { 2279 return (void*) &jmm_interface; 2280 } 2281 return NULL; 2282 } | 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 91 void Management::init() { 92 EXCEPTION_MARK; 93 94 // These counters are for java.lang.management API support. 95 // They are created even if -XX:-UsePerfData is set and in 96 // that case, they will be allocated on C heap. 97 98 _begin_vm_creation_time = 99 PerfDataManager::create_variable(SUN_RT, "createVmBeginTime", 100 PerfData::U_None, CHECK); 101 102 _end_vm_creation_time = 103 PerfDataManager::create_variable(SUN_RT, "createVmEndTime", 104 PerfData::U_None, CHECK); 105 106 _vm_init_done_time = 107 PerfDataManager::create_variable(SUN_RT, "vmInitDoneTime", 108 PerfData::U_None, CHECK); 109 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(), 2079 usage_before_gc_ah->obj_at_put(i, before_usage()); 2080 usage_after_gc_ah->obj_at_put(i, after_usage()); 2081 } 2082 2083 if (gc_stat->gc_ext_attribute_values_size > 0) { 2084 // Current implementation only has 1 attribute (number of GC threads) 2085 // The type is 'I' 2086 gc_stat->gc_ext_attribute_values[0].i = mgr->num_gc_threads(); 2087 } 2088 JVM_END 2089 2090 JVM_ENTRY(void, jmm_SetGCNotificationEnabled(JNIEnv *env, jobject obj, jboolean enabled)) 2091 ResourceMark rm(THREAD); 2092 // Get the GCMemoryManager 2093 GCMemoryManager* mgr = get_gc_memory_manager_from_jobject(obj, CHECK); 2094 mgr->set_notification_enabled(enabled?true:false); 2095 JVM_END 2096 2097 // Dump heap - Returns 0 if succeeds. 2098 JVM_ENTRY(jint, jmm_DumpHeap0(JNIEnv *env, jstring outputfile, jboolean live)) 2099 #if INCLUDE_SERVICES 2100 ResourceMark rm(THREAD); 2101 oop on = JNIHandles::resolve_external_guard(outputfile); 2102 if (on == NULL) { 2103 THROW_MSG_(vmSymbols::java_lang_NullPointerException(), 2104 "Output file name cannot be null.", -1); 2105 } 2106 char* name = java_lang_String::as_utf8_string(on); 2107 if (name == NULL) { 2108 THROW_MSG_(vmSymbols::java_lang_NullPointerException(), 2109 "Output file name cannot be null.", -1); 2110 } 2111 HeapDumper dumper(live ? true : false); 2112 if (dumper.dump(name) != 0) { 2113 const char* errmsg = dumper.error_as_C_string(); 2114 THROW_MSG_(vmSymbols::java_io_IOException(), errmsg, -1); 2115 } 2116 return 0; 2117 #else // INCLUDE_SERVICES 2118 return -1; 2119 #endif // INCLUDE_SERVICES 2120 JVM_END 2121 2122 JVM_ENTRY(jobjectArray, jmm_GetDiagnosticCommands(JNIEnv *env)) 2123 ResourceMark rm(THREAD); 2124 GrowableArray<const char *>* dcmd_list = DCmdFactory::DCmd_list(); 2125 objArrayOop cmd_array_oop = oopFactory::new_objArray(SystemDictionary::String_klass(), 2126 dcmd_list->length(), CHECK_NULL); 2127 objArrayHandle cmd_array(THREAD, cmd_array_oop); 2128 for (int i = 0; i < dcmd_list->length(); i++) { 2129 oop cmd_name = java_lang_String::create_oop_from_str(dcmd_list->at(i), CHECK_NULL); 2130 cmd_array->obj_at_put(i, cmd_name); 2131 } 2132 return (jobjectArray) JNIHandles::make_local(env, cmd_array()); 2133 JVM_END 2134 2135 JVM_ENTRY(void, jmm_GetDiagnosticCommandInfo(JNIEnv *env, jobjectArray cmds, 2136 dcmdInfo* infoArray)) 2137 if (cmds == NULL || infoArray == NULL) { 2138 THROW(vmSymbols::java_lang_NullPointerException()); 2139 } 2266 jmm_GetInternalThreadTimes, 2267 jmm_ResetStatistic, 2268 jmm_SetPoolSensor, 2269 jmm_SetPoolThreshold, 2270 jmm_GetPoolCollectionUsage, 2271 jmm_GetGCExtAttributeInfo, 2272 jmm_GetLastGCStat, 2273 jmm_GetThreadCpuTimeWithKind, 2274 jmm_GetThreadCpuTimesWithKind, 2275 jmm_DumpHeap0, 2276 jmm_FindDeadlockedThreads, 2277 jmm_SetVMGlobal, 2278 NULL, 2279 jmm_DumpThreads, 2280 jmm_SetGCNotificationEnabled, 2281 jmm_GetDiagnosticCommands, 2282 jmm_GetDiagnosticCommandInfo, 2283 jmm_GetDiagnosticCommandArgumentsInfo, 2284 jmm_ExecuteDiagnosticCommand 2285 }; 2286 #endif // INCLUDE_MANAGEMENT 2287 2288 void* Management::get_jmm_interface(int version) { 2289 #if INCLUDE_MANAGEMENT 2290 if (version == JMM_VERSION_1_0) { 2291 return (void*) &jmm_interface; 2292 } 2293 #endif // INCLUDE_MANAGEMENT 2294 return NULL; 2295 } |