1 /* src/native/vm/openjdk/management.cpp - HotSpot management interface functions
4 CACAOVM - Verein zur Foerderung der freien virtuellen Maschine CACAO
5 Copyright (C) 2008, 2009 Theobroma Systems Ltd.
7 This file is part of CACAO.
9 This program is free software; you can redistribute it and/or
10 modify it under the terms of the GNU General Public License as
11 published by the Free Software Foundation; either version 2, or (at
12 your option) any later version.
14 This program is distributed in the hope that it will be useful, but
15 WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 General Public License for more details.
19 You should have received a copy of the GNU General Public License
20 along with this program; if not, write to the Free Software
21 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
31 // Include our JNI header before the JMM header, because the JMM
32 // header include jni.h and we want to override the typedefs in jni.h.
33 #include "native/jni.hpp"
35 #include INCLUDE_JMM_H
37 #include "native/vm/openjdk/management.hpp"
39 #include "threads/threadlist.hpp"
41 #include "toolbox/logging.hpp"
43 #include "vm/array.hpp"
44 #include "vm/classcache.hpp"
45 #include "vm/globals.hpp" // XXX Remove!!!
46 #include "vm/options.h"
51 /* debugging macros ***********************************************************/
55 # define TRACEJMMCALLS(x) \
57 if (opt_TraceJMMCalls) { \
64 # define TRACEJMMCALLS(x)
70 * Initialize the Management subsystem.
72 Management::Management()
74 // Initialize optional support
75 _optional_support.isLowMemoryDetectionSupported = 1;
76 _optional_support.isCompilationTimeMonitoringSupported = 1;
77 _optional_support.isThreadContentionMonitoringSupported = 1;
79 // if (os::is_thread_cpu_time_supported()) {
81 _optional_support.isCurrentThreadCpuTimeSupported = 1;
82 _optional_support.isOtherThreadCpuTimeSupported = 1;
85 _optional_support.isCurrentThreadCpuTimeSupported = 0;
86 _optional_support.isOtherThreadCpuTimeSupported = 0;
89 _optional_support.isBootClassPathSupported = 1;
90 _optional_support.isObjectMonitorUsageSupported = 1;
91 _optional_support.isSynchronizerUsageSupported = 1;
96 * Return a pointer to the optional support structure.
98 * @param Pointer to optional support structure.
100 const jmmOptionalSupport& Management::get_optional_support() const
102 return _optional_support;
106 // Interface functions are exported as C functions.
109 jint jmm_GetVersion(JNIEnv* env)
115 jint jmm_GetOptionalSupport(JNIEnv* env, jmmOptionalSupport* support)
117 if (support == NULL) {
121 Management& mm = VM::get_current()->get_management();
123 // memcpy the structure.
124 os::memcpy(support, &mm.get_optional_support(), sizeof(jmmOptionalSupport));
130 jobject jmm_GetInputArguments(JNIEnv* env)
132 log_println("jmm_GetInputArguments: IMPLEMENT ME!");
137 jobjectArray jmm_GetInputArgumentArray(JNIEnv* env)
139 log_println("jmm_GetInputArgumentArray: IMPLEMENT ME!");
144 jobjectArray jmm_GetMemoryPools(JNIEnv* env, jobject obj)
146 TRACEJMMCALLS(("jmm_GetMemoryPools(env=%p, obj=%p)", env, obj));
148 // XXX This should be an array of java/lang/management/MemoryPoolMXBean.
149 log_println("jmm_GetMemoryPools: FIX ME!");
150 ObjectArray oa(0, class_java_lang_String);
152 return oa.get_handle();
156 jobjectArray jmm_GetMemoryManagers(JNIEnv* env, jobject obj)
158 TRACEJMMCALLS(("jmm_GetMemoryManagers(env=%p, obj=%p)", env, obj));
160 // XXX This should be an array of java/lang/management/MemoryManagerMXBean.
161 log_println("jmm_GetMemoryManagers: FIX ME!");
162 ObjectArray oa(0, class_java_lang_String);
164 return oa.get_handle();
168 jobject jmm_GetMemoryPoolUsage(JNIEnv* env, jobject obj)
170 log_println("jmm_GetMemoryPoolUsage: IMPLEMENT ME!");
175 jobject jmm_GetPeakMemoryPoolUsage(JNIEnv* env, jobject obj)
177 log_println("jmm_GetPeakMemoryPoolUsage: IMPLEMENT ME!");
182 jobject jmm_GetPoolCollectionUsage(JNIEnv* env, jobject obj)
184 log_println("jmm_GetPoolCollectionUsage: IMPLEMENT ME!");
189 void jmm_SetPoolSensor(JNIEnv* env, jobject obj, jmmThresholdType type, jobject sensorObj)
191 log_println("jmm_SetPoolSensor: IMPLEMENT ME!");
195 jlong jmm_SetPoolThreshold(JNIEnv* env, jobject obj, jmmThresholdType type, jlong threshold)
197 log_println("jmm_SetPoolThreshold: IMPLEMENT ME!");
202 jobject jmm_GetMemoryUsage(JNIEnv* env, jboolean heap)
204 log_println("jmm_GetMemoryUsage: IMPLEMENT ME!");
209 jboolean jmm_GetBoolAttribute(JNIEnv* env, jmmBoolAttribute att)
211 TRACEJMMCALLS(("jmm_GetBoolAttribute(env=%p, att=%d)", env, att));
217 result = opt_verbosegc;
219 case JMM_VERBOSE_CLASS:
220 result = opt_verboseclass;
223 log_println("jmm_GetBoolAttribute: Unknown attribute %d", att);
231 jboolean jmm_SetBoolAttribute(JNIEnv* env, jmmBoolAttribute att, jboolean flag)
233 TRACEJMMCALLS(("jmm_SetBoolAttribute(env=%p, att=%d, flag=%d)", env, att, flag));
237 opt_verbosegc = flag;
239 case JMM_VERBOSE_CLASS:
240 opt_verboseclass = flag;
243 log_println("jmm_SetBoolAttribute: Unknown attribute %d", att);
251 jlong jmm_GetLongAttribute(JNIEnv* env, jobject obj, jmmLongAttribute att)
253 TRACEJMMCALLS(("jmm_GetLongAttribute(env=%p, obj=%p, att=%d)", env, obj, att));
258 case JMM_CLASS_LOADED_COUNT:
259 result = classcache_get_loaded_class_count();
261 case JMM_CLASS_UNLOADED_COUNT:
262 // XXX Fix this once we support class unloading!
265 case JMM_THREAD_TOTAL_COUNT:
266 result = ThreadList::get_number_of_started_java_threads();
268 case JMM_THREAD_LIVE_COUNT:
269 result = ThreadList::get_number_of_active_java_threads();
271 case JMM_THREAD_PEAK_COUNT:
272 result = ThreadList::get_peak_of_active_java_threads();
274 case JMM_THREAD_DAEMON_COUNT:
275 result = ThreadList::get_number_of_daemon_java_threads();
277 case JMM_JVM_INIT_DONE_TIME_MS:
278 result = VM::get_current()->get_inittime();
280 case JMM_OS_PROCESS_ID:
281 result = os::getpid();
284 log_println("jmm_GetLongAttribute: Unknown attribute %d", att);
292 jint jmm_GetLongAttributes(JNIEnv* env, jobject obj, jmmLongAttribute* atts, jint count, jlong* result)
294 log_println("jmm_GetLongAttributes: IMPLEMENT ME!");
299 jint jmm_GetThreadInfo(JNIEnv* env, jlongArray ids, jint maxDepth, jobjectArray infoArray)
301 log_println("jmm_GetThreadInfo: IMPLEMENT ME!");
306 jobjectArray jmm_DumpThreads(JNIEnv* env, jlongArray thread_ids, jboolean locked_monitors, jboolean locked_synchronizers)
308 log_println("jmm_DumpThreads: IMPLEMENT ME!");
313 jobjectArray jmm_GetLoadedClasses(JNIEnv* env)
315 log_println("jmm_GetLoadedClasses: IMPLEMENT ME!");
320 jboolean jmm_ResetStatistic(JNIEnv* env, jvalue obj, jmmStatisticType type)
322 TRACEJMMCALLS(("jmm_ResetStatistic(env=%p, obj=%p, type=%d)", env, obj, type));
325 case JMM_STAT_PEAK_THREAD_COUNT:
326 ThreadList::reset_peak_of_active_java_threads();
329 log_println("jmm_ResetStatistic: Unknown statistic type %d", type);
337 jlong jmm_GetThreadCpuTime(JNIEnv* env, jlong thread_id)
339 log_println("jmm_GetThreadCpuTime: IMPLEMENT ME!");
344 jlong jmm_GetThreadCpuTimeWithKind(JNIEnv* env, jlong thread_id, jboolean user_sys_cpu_time)
346 log_println("jmm_GetThreadCpuTimeWithKind: IMPLEMENT ME!");
351 jobjectArray jmm_GetVMGlobalNames(JNIEnv* env)
353 log_println("jmm_GetVMGlobalNames: IMPLEMENT ME!");
358 jint jmm_GetVMGlobals(JNIEnv* env, jobjectArray names, jmmVMGlobal* globals, jint count)
360 log_println("jmm_GetVMGlobals: IMPLEMENT ME!");
365 void jmm_SetVMGlobal(JNIEnv* env, jstring flag_name, jvalue new_value)
367 log_println("jmm_SetVMGlobal: IMPLEMENT ME!");
371 jint jmm_GetInternalThreadTimes(JNIEnv* env, jobjectArray names, jlongArray times)
373 log_println("jmm_GetInternalThreadTimes: IMPLEMENT ME!");
378 jobjectArray jmm_FindDeadlockedThreads(JNIEnv* env, jboolean object_monitors_only)
380 log_println("jmm_FindDeadlockedThreads: IMPLEMENT ME!");
385 jobjectArray jmm_FindMonitorDeadlockedThreads(JNIEnv* env)
387 log_println("jmm_FindMonitorDeadlockedThreads: IMPLEMENT ME!");
392 jint jmm_GetGCExtAttributeInfo(JNIEnv* env, jobject mgr, jmmExtAttributeInfo* info, jint count)
394 log_println("jmm_GetGCExtAttributeInfo: IMPLEMENT ME!");
399 void jmm_GetLastGCStat(JNIEnv* env, jobject obj, jmmGCStat* gc_stat)
401 log_println("jmm_GetLastGCStat: IMPLEMENT ME!");
405 jint jmm_DumpHeap0(JNIEnv* env, jstring outputfile, jboolean live)
407 log_println("jmm_DumpHeap0: IMPLEMENT ME!");
414 const struct jmmInterface_1_ jmm_interface = {
418 jmm_GetOptionalSupport,
419 jmm_GetInputArguments,
421 jmm_GetInputArgumentArray,
423 jmm_GetMemoryManagers,
424 jmm_GetMemoryPoolUsage,
425 jmm_GetPeakMemoryPoolUsage,
428 jmm_GetLongAttribute,
429 jmm_GetBoolAttribute,
430 jmm_SetBoolAttribute,
431 jmm_GetLongAttributes,
432 jmm_FindMonitorDeadlockedThreads,
433 jmm_GetThreadCpuTime,
434 jmm_GetVMGlobalNames,
436 jmm_GetInternalThreadTimes,
439 jmm_SetPoolThreshold,
440 jmm_GetPoolCollectionUsage,
441 jmm_GetGCExtAttributeInfo,
443 jmm_GetThreadCpuTimeWithKind,
446 jmm_FindDeadlockedThreads,
454 * Return the requested management interface.
456 * @param version Requested management interface version.
458 * @return Pointer to management interface structure.
460 void* Management::get_jmm_interface(int version)
462 if (version == JMM_VERSION_1_0) {
463 return (void*) &jmm_interface;
470 * These are local overrides for various environment variables in Emacs.
471 * Please do not remove this and leave it at the end of the file, where
472 * Emacs will automagically detect them.
473 * ---------------------------------------------------------------------
476 * indent-tabs-mode: t
480 * vim:noexpandtab:sw=4:ts=4: