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 log_println("jmm_GetBoolAttribute: Unknown attribute %d", att);
225 jboolean jmm_SetBoolAttribute(JNIEnv* env, jmmBoolAttribute att, jboolean flag)
227 TRACEJMMCALLS(("jmm_SetBoolAttribute(env=%p, att=%d, flag=%d)", env, att, flag));
231 log_println("jmm_SetBoolAttribute: Unknown attribute %d", att);
239 jlong jmm_GetLongAttribute(JNIEnv* env, jobject obj, jmmLongAttribute att)
241 TRACEJMMCALLS(("jmm_GetLongAttribute(env=%p, obj=%p, att=%d)", env, obj, att));
246 case JMM_CLASS_LOADED_COUNT:
247 result = classcache_get_loaded_class_count();
249 case JMM_CLASS_UNLOADED_COUNT:
250 // XXX Fix this once we support class unloading!
253 case JMM_THREAD_TOTAL_COUNT:
254 result = ThreadList::get_number_of_started_java_threads();
256 case JMM_THREAD_LIVE_COUNT:
257 result = ThreadList::get_number_of_active_java_threads();
259 case JMM_THREAD_PEAK_COUNT:
260 result = ThreadList::get_peak_of_active_java_threads();
262 case JMM_THREAD_DAEMON_COUNT:
263 result = ThreadList::get_number_of_daemon_java_threads();
265 case JMM_JVM_INIT_DONE_TIME_MS:
266 result = VM::get_current()->get_inittime();
269 log_println("jmm_GetLongAttribute: Unknown attribute %d", att);
277 jint jmm_GetLongAttributes(JNIEnv* env, jobject obj, jmmLongAttribute* atts, jint count, jlong* result)
279 log_println("jmm_GetLongAttributes: IMPLEMENT ME!");
284 jint jmm_GetThreadInfo(JNIEnv* env, jlongArray ids, jint maxDepth, jobjectArray infoArray)
286 log_println("jmm_GetThreadInfo: IMPLEMENT ME!");
291 jobjectArray jmm_DumpThreads(JNIEnv* env, jlongArray thread_ids, jboolean locked_monitors, jboolean locked_synchronizers)
293 log_println("jmm_DumpThreads: IMPLEMENT ME!");
298 jobjectArray jmm_GetLoadedClasses(JNIEnv* env)
300 log_println("jmm_GetLoadedClasses: IMPLEMENT ME!");
305 jboolean jmm_ResetStatistic(JNIEnv* env, jvalue obj, jmmStatisticType type)
307 TRACEJMMCALLS(("jmm_ResetStatistic(env=%p, obj=%p, type=%d)", env, obj, type));
310 case JMM_STAT_PEAK_THREAD_COUNT:
311 ThreadList::reset_peak_of_active_java_threads();
314 log_println("jmm_ResetStatistic: Unknown statistic type %d", type);
322 jlong jmm_GetThreadCpuTime(JNIEnv* env, jlong thread_id)
324 log_println("jmm_GetThreadCpuTime: IMPLEMENT ME!");
329 jlong jmm_GetThreadCpuTimeWithKind(JNIEnv* env, jlong thread_id, jboolean user_sys_cpu_time)
331 log_println("jmm_GetThreadCpuTimeWithKind: IMPLEMENT ME!");
336 jobjectArray jmm_GetVMGlobalNames(JNIEnv* env)
338 log_println("jmm_GetVMGlobalNames: IMPLEMENT ME!");
343 jint jmm_GetVMGlobals(JNIEnv* env, jobjectArray names, jmmVMGlobal* globals, jint count)
345 log_println("jmm_GetVMGlobals: IMPLEMENT ME!");
350 void jmm_SetVMGlobal(JNIEnv* env, jstring flag_name, jvalue new_value)
352 log_println("jmm_SetVMGlobal: IMPLEMENT ME!");
356 jint jmm_GetInternalThreadTimes(JNIEnv* env, jobjectArray names, jlongArray times)
358 log_println("jmm_GetInternalThreadTimes: IMPLEMENT ME!");
363 jobjectArray jmm_FindDeadlockedThreads(JNIEnv* env, jboolean object_monitors_only)
365 log_println("jmm_FindDeadlockedThreads: IMPLEMENT ME!");
370 jobjectArray jmm_FindMonitorDeadlockedThreads(JNIEnv* env)
372 log_println("jmm_FindMonitorDeadlockedThreads: IMPLEMENT ME!");
377 jint jmm_GetGCExtAttributeInfo(JNIEnv* env, jobject mgr, jmmExtAttributeInfo* info, jint count)
379 log_println("jmm_GetGCExtAttributeInfo: IMPLEMENT ME!");
384 void jmm_GetLastGCStat(JNIEnv* env, jobject obj, jmmGCStat* gc_stat)
386 log_println("jmm_GetLastGCStat: IMPLEMENT ME!");
390 jint jmm_DumpHeap0(JNIEnv* env, jstring outputfile, jboolean live)
392 log_println("jmm_DumpHeap0: IMPLEMENT ME!");
399 const struct jmmInterface_1_ jmm_interface = {
403 jmm_GetOptionalSupport,
404 jmm_GetInputArguments,
406 jmm_GetInputArgumentArray,
408 jmm_GetMemoryManagers,
409 jmm_GetMemoryPoolUsage,
410 jmm_GetPeakMemoryPoolUsage,
413 jmm_GetLongAttribute,
414 jmm_GetBoolAttribute,
415 jmm_SetBoolAttribute,
416 jmm_GetLongAttributes,
417 jmm_FindMonitorDeadlockedThreads,
418 jmm_GetThreadCpuTime,
419 jmm_GetVMGlobalNames,
421 jmm_GetInternalThreadTimes,
424 jmm_SetPoolThreshold,
425 jmm_GetPoolCollectionUsage,
426 jmm_GetGCExtAttributeInfo,
428 jmm_GetThreadCpuTimeWithKind,
431 jmm_FindDeadlockedThreads,
439 * Return the requested management interface.
441 * @param version Requested management interface version.
443 * @return Pointer to management interface structure.
445 void* Management::get_jmm_interface(int version)
447 if (version == JMM_VERSION_1_0) {
448 return (void*) &jmm_interface;
455 * These are local overrides for various environment variables in Emacs.
456 * Please do not remove this and leave it at the end of the file, where
457 * Emacs will automagically detect them.
458 * ---------------------------------------------------------------------
461 * indent-tabs-mode: t
465 * vim:noexpandtab:sw=4:ts=4: