23 */
24
25 #include "precompiled.hpp"
26 #include "classfile/systemDictionary.hpp"
27 #include "compiler/compileBroker.hpp"
28 #include "memory/iterator.hpp"
29 #include "memory/oopFactory.hpp"
30 #include "memory/resourceArea.hpp"
31 #include "oops/klass.hpp"
32 #include "oops/klassOop.hpp"
33 #include "oops/objArrayKlass.hpp"
34 #include "oops/oop.inline.hpp"
35 #include "runtime/arguments.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/heapDumper.hpp"
44 #include "services/lowMemoryDetector.hpp"
45 #include "services/gcNotifier.hpp"
46 #include "services/management.hpp"
47 #include "services/memoryManager.hpp"
48 #include "services/memoryPool.hpp"
49 #include "services/memoryService.hpp"
50 #include "services/runtimeService.hpp"
51 #include "services/threadService.hpp"
52
53 PerfVariable* Management::_begin_vm_creation_time = NULL;
54 PerfVariable* Management::_end_vm_creation_time = NULL;
55 PerfVariable* Management::_vm_init_done_time = NULL;
56
57 klassOop Management::_sensor_klass = NULL;
58 klassOop Management::_threadInfo_klass = NULL;
59 klassOop Management::_memoryUsage_klass = NULL;
60 klassOop Management::_memoryPoolMXBean_klass = NULL;
61 klassOop Management::_memoryManagerMXBean_klass = NULL;
62 klassOop Management::_garbageCollectorMXBean_klass = NULL;
63 klassOop Management::_managementFactory_klass = NULL;
96 // Initialize optional support
97 _optional_support.isLowMemoryDetectionSupported = 1;
98 _optional_support.isCompilationTimeMonitoringSupported = 1;
99 _optional_support.isThreadContentionMonitoringSupported = 1;
100
101 if (os::is_thread_cpu_time_supported()) {
102 _optional_support.isCurrentThreadCpuTimeSupported = 1;
103 _optional_support.isOtherThreadCpuTimeSupported = 1;
104 } else {
105 _optional_support.isCurrentThreadCpuTimeSupported = 0;
106 _optional_support.isOtherThreadCpuTimeSupported = 0;
107 }
108
109 _optional_support.isBootClassPathSupported = 1;
110 _optional_support.isObjectMonitorUsageSupported = 1;
111 #ifndef SERVICES_KERNEL
112 // This depends on the heap inspector
113 _optional_support.isSynchronizerUsageSupported = 1;
114 #endif // SERVICES_KERNEL
115 _optional_support.isThreadAllocatedMemorySupported = 1;
116 }
117
118 void Management::initialize(TRAPS) {
119 // Start the service thread
120 ServiceThread::initialize();
121
122 if (ManagementServer) {
123 ResourceMark rm(THREAD);
124 HandleMark hm(THREAD);
125
126 // Load and initialize the sun.management.Agent class
127 // invoke startAgent method to start the management server
128 Handle loader = Handle(THREAD, SystemDictionary::java_system_loader());
129 klassOop k = SystemDictionary::resolve_or_fail(vmSymbols::sun_management_Agent(),
130 loader,
131 Handle(),
132 true,
133 CHECK);
134 instanceKlassHandle ik (THREAD, k);
135
2090 if (on == NULL) {
2091 THROW_MSG_(vmSymbols::java_lang_NullPointerException(),
2092 "Output file name cannot be null.", -1);
2093 }
2094 char* name = java_lang_String::as_utf8_string(on);
2095 if (name == NULL) {
2096 THROW_MSG_(vmSymbols::java_lang_NullPointerException(),
2097 "Output file name cannot be null.", -1);
2098 }
2099 HeapDumper dumper(live ? true : false);
2100 if (dumper.dump(name) != 0) {
2101 const char* errmsg = dumper.error_as_C_string();
2102 THROW_MSG_(vmSymbols::java_io_IOException(), errmsg, -1);
2103 }
2104 return 0;
2105 #else // SERVICES_KERNEL
2106 return -1;
2107 #endif // SERVICES_KERNEL
2108 JVM_END
2109
2110 jlong Management::ticks_to_ms(jlong ticks) {
2111 assert(os::elapsed_frequency() > 0, "Must be non-zero");
2112 return (jlong)(((double)ticks / (double)os::elapsed_frequency())
2113 * (double)1000.0);
2114 }
2115
2116 const struct jmmInterface_1_ jmm_interface = {
2117 NULL,
2118 NULL,
2119 jmm_GetVersion,
2120 jmm_GetOptionalSupport,
2121 jmm_GetInputArguments,
2122 jmm_GetThreadInfo,
2123 jmm_GetInputArgumentArray,
2124 jmm_GetMemoryPools,
2125 jmm_GetMemoryManagers,
2126 jmm_GetMemoryPoolUsage,
2127 jmm_GetPeakMemoryPoolUsage,
2128 jmm_GetThreadAllocatedMemory,
2129 jmm_GetMemoryUsage,
2132 jmm_SetBoolAttribute,
2133 jmm_GetLongAttributes,
2134 jmm_FindMonitorDeadlockedThreads,
2135 jmm_GetThreadCpuTime,
2136 jmm_GetVMGlobalNames,
2137 jmm_GetVMGlobals,
2138 jmm_GetInternalThreadTimes,
2139 jmm_ResetStatistic,
2140 jmm_SetPoolSensor,
2141 jmm_SetPoolThreshold,
2142 jmm_GetPoolCollectionUsage,
2143 jmm_GetGCExtAttributeInfo,
2144 jmm_GetLastGCStat,
2145 jmm_GetThreadCpuTimeWithKind,
2146 jmm_GetThreadCpuTimesWithKind,
2147 jmm_DumpHeap0,
2148 jmm_FindDeadlockedThreads,
2149 jmm_SetVMGlobal,
2150 NULL,
2151 jmm_DumpThreads,
2152 jmm_SetGCNotificationEnabled
2153 };
2154
2155 void* Management::get_jmm_interface(int version) {
2156 if (version == JMM_VERSION_1_0) {
2157 return (void*) &jmm_interface;
2158 }
2159 return NULL;
2160 }
|
23 */
24
25 #include "precompiled.hpp"
26 #include "classfile/systemDictionary.hpp"
27 #include "compiler/compileBroker.hpp"
28 #include "memory/iterator.hpp"
29 #include "memory/oopFactory.hpp"
30 #include "memory/resourceArea.hpp"
31 #include "oops/klass.hpp"
32 #include "oops/klassOop.hpp"
33 #include "oops/objArrayKlass.hpp"
34 #include "oops/oop.inline.hpp"
35 #include "runtime/arguments.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 klassOop Management::_sensor_klass = NULL;
61 klassOop Management::_threadInfo_klass = NULL;
62 klassOop Management::_memoryUsage_klass = NULL;
63 klassOop Management::_memoryPoolMXBean_klass = NULL;
64 klassOop Management::_memoryManagerMXBean_klass = NULL;
65 klassOop Management::_garbageCollectorMXBean_klass = NULL;
66 klassOop Management::_managementFactory_klass = NULL;
99 // Initialize optional support
100 _optional_support.isLowMemoryDetectionSupported = 1;
101 _optional_support.isCompilationTimeMonitoringSupported = 1;
102 _optional_support.isThreadContentionMonitoringSupported = 1;
103
104 if (os::is_thread_cpu_time_supported()) {
105 _optional_support.isCurrentThreadCpuTimeSupported = 1;
106 _optional_support.isOtherThreadCpuTimeSupported = 1;
107 } else {
108 _optional_support.isCurrentThreadCpuTimeSupported = 0;
109 _optional_support.isOtherThreadCpuTimeSupported = 0;
110 }
111
112 _optional_support.isBootClassPathSupported = 1;
113 _optional_support.isObjectMonitorUsageSupported = 1;
114 #ifndef SERVICES_KERNEL
115 // This depends on the heap inspector
116 _optional_support.isSynchronizerUsageSupported = 1;
117 #endif // SERVICES_KERNEL
118 _optional_support.isThreadAllocatedMemorySupported = 1;
119
120 DCmdFactory::register_DCmdFactory(new DCmdFactoryImpl<HelpDCmd>());
121 DCmdFactory::register_DCmdFactory(new DCmdFactoryImpl<VersionDCmd>());
122 }
123
124 void Management::initialize(TRAPS) {
125 // Start the service thread
126 ServiceThread::initialize();
127
128 if (ManagementServer) {
129 ResourceMark rm(THREAD);
130 HandleMark hm(THREAD);
131
132 // Load and initialize the sun.management.Agent class
133 // invoke startAgent method to start the management server
134 Handle loader = Handle(THREAD, SystemDictionary::java_system_loader());
135 klassOop k = SystemDictionary::resolve_or_fail(vmSymbols::sun_management_Agent(),
136 loader,
137 Handle(),
138 true,
139 CHECK);
140 instanceKlassHandle ik (THREAD, k);
141
2096 if (on == NULL) {
2097 THROW_MSG_(vmSymbols::java_lang_NullPointerException(),
2098 "Output file name cannot be null.", -1);
2099 }
2100 char* name = java_lang_String::as_utf8_string(on);
2101 if (name == NULL) {
2102 THROW_MSG_(vmSymbols::java_lang_NullPointerException(),
2103 "Output file name cannot be null.", -1);
2104 }
2105 HeapDumper dumper(live ? true : false);
2106 if (dumper.dump(name) != 0) {
2107 const char* errmsg = dumper.error_as_C_string();
2108 THROW_MSG_(vmSymbols::java_io_IOException(), errmsg, -1);
2109 }
2110 return 0;
2111 #else // SERVICES_KERNEL
2112 return -1;
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::get_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::get_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->get_name();
2168 infoArray[i].description = info->get_description();
2169 infoArray[i].impact = info->get_impact();
2170 infoArray[i].num_arguments = info->get_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 cannot be null.");
2187 }
2188 DCmd* dcmd = NULL;
2189 {
2190 DCmdFactory*factory = DCmdFactory::get_factory(cmd_name, strlen(cmd_name));
2191 if (factory != NULL) {
2192 dcmd = factory->get_cheap_instance(NULL);
2193 }
2194 }
2195 if(dcmd == NULL) {
2196 THROW_MSG(vmSymbols::java_lang_IllegalArgumentException(),
2197 "Unknown diagnostic command");
2198 }
2199 DCmdMark mark(dcmd);
2200 GrowableArray<DCmdArgumentInfo*>* array = dcmd->get_argument_info_array();
2201 if(array->length() == 0) {
2202 return;
2203 }
2204 for(int i=0; i<array->length(); i++) {
2205 infoArray[i].name = array->at(i)->get_name();
2206 infoArray[i].description = array->at(i)->get_description();
2207 infoArray[i].type = array->at(i)->get_type();
2208 infoArray[i].default_string = array->at(i)->get_default();
2209 infoArray[i].mandatory = array->at(i)->is_mandatory();
2210 infoArray[i].option = array->at(i)->is_option();
2211 infoArray[i].position = array->at(i)->get_position();
2212 }
2213 return;
2214 JVM_END
2215
2216 JVM_ENTRY(jstring, jmm_ExecuteDiagnosticCommand(JNIEnv *env, jstring commandline))
2217 ResourceMark rm(THREAD);
2218 oop cmd = JNIHandles::resolve_external_guard(commandline);
2219 if (cmd == NULL) {
2220 THROW_MSG_NULL(vmSymbols::java_lang_NullPointerException(),
2221 "Command line cannot be null.");
2222 }
2223 char* cmdline = java_lang_String::as_utf8_string(cmd);
2224 if (cmdline == NULL) {
2225 THROW_MSG_NULL(vmSymbols::java_lang_NullPointerException(),
2226 "Command line cannot be null.");
2227 }
2228 bufferedStream output;
2229 DCmd::parse_and_execute(&output, cmdline, ' ', CHECK_NULL);
2230 oop result = java_lang_String::create_oop_from_str(output.as_string(), CHECK_NULL);
2231 return (jstring) JNIHandles::make_local(env, result);
2232 JVM_END
2233
2234 jlong Management::ticks_to_ms(jlong ticks) {
2235 assert(os::elapsed_frequency() > 0, "Must be non-zero");
2236 return (jlong)(((double)ticks / (double)os::elapsed_frequency())
2237 * (double)1000.0);
2238 }
2239
2240 const struct jmmInterface_1_ jmm_interface = {
2241 NULL,
2242 NULL,
2243 jmm_GetVersion,
2244 jmm_GetOptionalSupport,
2245 jmm_GetInputArguments,
2246 jmm_GetThreadInfo,
2247 jmm_GetInputArgumentArray,
2248 jmm_GetMemoryPools,
2249 jmm_GetMemoryManagers,
2250 jmm_GetMemoryPoolUsage,
2251 jmm_GetPeakMemoryPoolUsage,
2252 jmm_GetThreadAllocatedMemory,
2253 jmm_GetMemoryUsage,
2256 jmm_SetBoolAttribute,
2257 jmm_GetLongAttributes,
2258 jmm_FindMonitorDeadlockedThreads,
2259 jmm_GetThreadCpuTime,
2260 jmm_GetVMGlobalNames,
2261 jmm_GetVMGlobals,
2262 jmm_GetInternalThreadTimes,
2263 jmm_ResetStatistic,
2264 jmm_SetPoolSensor,
2265 jmm_SetPoolThreshold,
2266 jmm_GetPoolCollectionUsage,
2267 jmm_GetGCExtAttributeInfo,
2268 jmm_GetLastGCStat,
2269 jmm_GetThreadCpuTimeWithKind,
2270 jmm_GetThreadCpuTimesWithKind,
2271 jmm_DumpHeap0,
2272 jmm_FindDeadlockedThreads,
2273 jmm_SetVMGlobal,
2274 NULL,
2275 jmm_DumpThreads,
2276 jmm_SetGCNotificationEnabled,
2277 jmm_GetDiagnosticCommands,
2278 jmm_GetDiagnosticCommandInfo,
2279 jmm_GetDiagnosticCommandArgumentsInfo,
2280 jmm_ExecuteDiagnosticCommand
2281 };
2282
2283 void* Management::get_jmm_interface(int version) {
2284 if (version == JMM_VERSION_1_0) {
2285 return (void*) &jmm_interface;
2286 }
2287 return NULL;
2288 }
|