* src/native/vm/openjdk/management.cpp: New file.
authorChristian Thalinger <twisti@complang.tuwien.ac.at>
Fri, 5 Sep 2008 11:55:01 +0000 (13:55 +0200)
committerChristian Thalinger <twisti@complang.tuwien.ac.at>
Fri, 5 Sep 2008 11:55:01 +0000 (13:55 +0200)
* src/native/vm/openjdk/management.hpp: Likewise.
* m4/jmm.m4: Likewise.
* configure.ac (AC_CHECK_WITH_JMM_H): Call for OpenJDK.
* src/native/vm/openjdk/Makefile.am (libnativevmcore_la_SOURCES):
Added new files.
* src/native/vm/openjdk/jvm.cpp (JVM_GetManagement): Implemented.
* src/vm/vm.hpp (VM) [WITH_JAVA_RUNTIME_LIBRARY_OPENJDK]: Added
Management, and get_management().

configure.ac
m4/jmm.m4 [new file with mode: 0644]
src/native/vm/openjdk/Makefile.am
src/native/vm/openjdk/jvm.cpp
src/native/vm/openjdk/management.cpp [new file with mode: 0644]
src/native/vm/openjdk/management.hpp [new file with mode: 0644]
src/vm/vm.hpp

index 95840e0d810a6ecff431266b12884107adaf9007..1d100c667b4f05930bfe2fba768030946ae51aa5 100644 (file)
@@ -589,6 +589,7 @@ case "${WITH_JAVA_RUNTIME_LIBRARY}" in
     openjdk)
         AC_CHECK_WITH_HPI_MD_H
         AC_CHECK_WITH_HPI_H
+        AC_CHECK_WITH_JMM_H
         ;;
     *)
         ;;
diff --git a/m4/jmm.m4 b/m4/jmm.m4
new file mode 100644 (file)
index 0000000..c9b62fb
--- /dev/null
+++ b/m4/jmm.m4
@@ -0,0 +1,45 @@
+dnl m4/jmm.m4
+dnl
+dnl Copyright (C) 2008 Theobroma Systems Ltd.
+dnl
+dnl This file is part of CACAO.
+dnl
+dnl This program is free software; you can redistribute it and/or
+dnl modify it under the terms of the GNU General Public License as
+dnl published by the Free Software Foundation; either version 2, or (at
+dnl your option) any later version.
+dnl
+dnl This program is distributed in the hope that it will be useful, but
+dnl WITHOUT ANY WARRANTY; without even the implied warranty of
+dnl MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+dnl General Public License for more details.
+dnl
+dnl You should have received a copy of the GNU General Public License
+dnl along with this program; if not, write to the Free Software
+dnl Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+dnl 02110-1301, USA.
+
+
+dnl Check for jmm.h
+
+AC_DEFUN([AC_CHECK_WITH_JMM_H],[
+AC_MSG_CHECKING(where jmm.h is installed)
+AC_ARG_WITH([jmm_h],
+            [AS_HELP_STRING(--with-jmm_h=<dir>,path to jmm.h (only with --with-java-runtime-library=openjdk) [[default=${JAVA_RUNTIME_LIBRARY_PREFIX}/jdk/src/share/javavm/export]])],
+            [WITH_JMM_H=${withval}],
+            [case "${WITH_JAVA_RUNTIME_LIBRARY}" in
+                 openjdk)
+                     WITH_JMM_H=${JAVA_RUNTIME_LIBRARY_PREFIX}/jdk/src/share/javavm/export
+                     ;;
+                 *)
+                     ;;
+            esac])
+AC_MSG_RESULT(${WITH_JMM_H})
+
+dnl Added that path to the CPPFLAGS.
+CPPFLAGS="${CPPFLAGS} -I${WITH_JMM_H}"
+
+AC_CHECK_HEADER([${WITH_JMM_H}/jmm.h],
+                [AC_DEFINE_UNQUOTED([INCLUDE_JMM_H], "${WITH_JMM_H}/jmm.h", [Java runtime library jmm.h header])],
+                [AC_MSG_ERROR(cannot find jmm.h)])
+])
index 49677897a94bc12b82aeef1f2bced9f6ebb84264..97f30a7bb931e4df2cc44b445af25882bd1fe81c 100644 (file)
@@ -31,7 +31,9 @@ noinst_LTLIBRARIES = \
 libnativevmcore_la_SOURCES = \
        hpi.c \
        hpi.h \
-       jvm.cpp
+       jvm.cpp \
+       management.cpp \
+       management.hpp
 
 
 ## Local variables:
index 301d4f23ed2f0b2857abaf707df3e7f8599879ec..b62ae3fe5f0b7b01b59242afb97cbfdcdc20eea1 100644 (file)
@@ -52,6 +52,7 @@
 #include "native/vm/reflection.hpp"
 
 #include "native/vm/openjdk/hpi.h"
+#include "native/vm/openjdk/management.hpp"
 
 #include "threads/lock.hpp"
 #include "threads/thread.hpp"
@@ -3259,9 +3260,7 @@ void *JVM_GetManagement(jint version)
 {
        TRACEJVMCALLS(("JVM_GetManagement(version=%d)", version));
 
-       /* TODO We current don't support the management interface. */
-
-       return NULL;
+       return Management::get_jmm_interface(version);
 }
 
 
diff --git a/src/native/vm/openjdk/management.cpp b/src/native/vm/openjdk/management.cpp
new file mode 100644 (file)
index 0000000..3884893
--- /dev/null
@@ -0,0 +1,377 @@
+ /* src/native/vm/openjdk/management.cpp - HotSpot management interface functions
+
+   Copyright (C) 2008 Theobroma Systems Ltd.
+
+   This file is part of CACAO.
+
+   This program is free software; you can redistribute it and/or
+   modify it under the terms of the GNU General Public License as
+   published by the Free Software Foundation; either version 2, or (at
+   your option) any later version.
+
+   This program is distributed in the hope that it will be useful, but
+   WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with this program; if not, write to the Free Software
+   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+   02110-1301, USA.
+
+*/
+
+
+#include "config.h"
+
+#include <stdint.h>
+
+// Include our JNI header before the JMM header, because the JMM
+// header include jni.h and we want to override the typedefs in jni.h.
+#include "native/jni.hpp"
+
+#include INCLUDE_JMM_H
+
+#include "native/vm/openjdk/management.hpp"
+
+#include "toolbox/logging.h"
+
+#include "vm/os.hpp"
+#include "vm/vm.hpp"
+
+
+/**
+ * Initialize the Management subsystem.
+ */
+Management::Management()
+{
+       // Initialize optional support
+       _optional_support.isLowMemoryDetectionSupported = 1;
+       _optional_support.isCompilationTimeMonitoringSupported = 1;
+       _optional_support.isThreadContentionMonitoringSupported = 1;
+
+//     if (os::is_thread_cpu_time_supported()) {
+       if (false) {
+               _optional_support.isCurrentThreadCpuTimeSupported = 1;
+               _optional_support.isOtherThreadCpuTimeSupported = 1;
+       }
+       else {
+               _optional_support.isCurrentThreadCpuTimeSupported = 0;
+               _optional_support.isOtherThreadCpuTimeSupported = 0;
+       }
+
+       _optional_support.isBootClassPathSupported = 1;
+       _optional_support.isObjectMonitorUsageSupported = 1;
+       _optional_support.isSynchronizerUsageSupported = 1;
+}
+
+
+/**
+ * Return a pointer to the optional support structure.
+ *
+ * @param Pointer to optional support structure.
+ */
+const jmmOptionalSupport& Management::get_optional_support() const
+{
+       return _optional_support;
+}
+
+
+// Interface functions are exported as C functions.
+extern "C" {
+
+// Returns a version string and sets major and minor version if the
+// input parameters are non-null.
+jint jmm_GetVersion(JNIEnv* env)
+{
+       return JMM_VERSION;
+}
+
+
+// Gets the list of VM monitoring and management optional supports
+// Returns 0 if succeeded; otherwise returns non-zero.
+jint jmm_GetOptionalSupport(JNIEnv* env, jmmOptionalSupport* support)
+{
+       if (support == NULL) {
+               return -1;
+       }
+
+       Management& mm = VM::get_current()->get_management();
+
+       // memcpy the structure.
+       os::memcpy(support, &mm.get_optional_support(), sizeof(jmmOptionalSupport));
+
+       return 0;
+}
+
+
+jobject jmm_GetInputArguments(JNIEnv* env)
+{
+       log_println("jmm_GetInputArguments: IMPLEMENT ME!");
+       return NULL;
+}
+
+
+jobjectArray jmm_GetInputArgumentArray(JNIEnv* env)
+{
+       log_println("jmm_GetInputArgumentArray: IMPLEMENT ME!");
+       return NULL;
+}
+
+
+jobjectArray jmm_GetMemoryPools(JNIEnv* env, jobject obj)
+{
+       log_println("jmm_GetMemoryPools: IMPLEMENT ME!");
+       return NULL;
+}
+
+
+jobjectArray jmm_GetMemoryManagers(JNIEnv* env, jobject obj)
+{
+       log_println("jmm_GetMemoryManagers: IMPLEMENT ME!");
+       return NULL;
+}
+
+
+jobject jmm_GetMemoryPoolUsage(JNIEnv* env, jobject obj)
+{
+       log_println("jmm_GetMemoryPoolUsage: IMPLEMENT ME!");
+       return NULL;
+}
+
+
+jobject jmm_GetPeakMemoryPoolUsage(JNIEnv* env, jobject obj)
+{
+       log_println("jmm_GetPeakMemoryPoolUsage: IMPLEMENT ME!");
+       return NULL;
+}
+
+
+jobject jmm_GetPoolCollectionUsage(JNIEnv* env, jobject obj)
+{
+       log_println("jmm_GetPoolCollectionUsage: IMPLEMENT ME!");
+       return NULL;
+}
+
+
+void jmm_SetPoolSensor(JNIEnv* env, jobject obj, jmmThresholdType type, jobject sensorObj)
+{
+       log_println("jmm_SetPoolSensor: IMPLEMENT ME!");
+}
+
+
+jlong jmm_SetPoolThreshold(JNIEnv* env, jobject obj, jmmThresholdType type, jlong threshold)
+{
+       log_println("jmm_SetPoolThreshold: IMPLEMENT ME!");
+       return 0;
+}
+
+
+jobject jmm_GetMemoryUsage(JNIEnv* env, jboolean heap)
+{
+       log_println("jmm_GetMemoryUsage: IMPLEMENT ME!");
+       return NULL;
+}
+
+
+jboolean jmm_GetBoolAttribute(JNIEnv* env, jmmBoolAttribute att)
+{
+       log_println("jmm_GetBoolAttribute: IMPLEMENT ME!");
+       return 0;
+}
+
+
+jboolean jmm_SetBoolAttribute(JNIEnv* env, jmmBoolAttribute att, jboolean flag)
+{
+       log_println("jmm_SetBoolAttribute: IMPLEMENT ME!");
+       return 0;
+}
+
+
+jlong jmm_GetLongAttribute(JNIEnv* env, jobject obj, jmmLongAttribute att)
+{
+       log_println("jmm_GetLongAttribute: IMPLEMENT ME!");
+       return 0;
+}
+
+
+jint jmm_GetLongAttributes(JNIEnv* env, jobject obj, jmmLongAttribute* atts, jint count, jlong* result)
+{
+       log_println("jmm_GetLongAttributes: IMPLEMENT ME!");
+       return 0;
+}
+
+
+jint jmm_GetThreadInfo(JNIEnv* env, jlongArray ids, jint maxDepth, jobjectArray infoArray)
+{
+       log_println("jmm_GetThreadInfo: IMPLEMENT ME!");
+       return 0;
+}
+
+
+jobjectArray jmm_DumpThreads(JNIEnv* env, jlongArray thread_ids, jboolean locked_monitors, jboolean locked_synchronizers)
+{
+       log_println("jmm_DumpThreads: IMPLEMENT ME!");
+       return NULL;
+}
+
+
+jobjectArray jmm_GetLoadedClasses(JNIEnv* env)
+{
+       log_println("jmm_GetLoadedClasses: IMPLEMENT ME!");
+       return NULL;
+}
+
+
+jboolean jmm_ResetStatistic(JNIEnv* env, jvalue obj, jmmStatisticType type)
+{
+       log_println("jmm_ResetStatistic: IMPLEMENT ME!");
+       return 0;
+}
+
+
+jlong jmm_GetThreadCpuTime(JNIEnv* env, jlong thread_id)
+{
+       log_println("jmm_GetThreadCpuTime: IMPLEMENT ME!");
+       return 0;
+}
+
+
+jlong jmm_GetThreadCpuTimeWithKind(JNIEnv* env, jlong thread_id, jboolean user_sys_cpu_time)
+{
+       log_println("jmm_GetThreadCpuTimeWithKind: IMPLEMENT ME!");
+       return 0;
+}
+
+
+jobjectArray jmm_GetVMGlobalNames(JNIEnv* env)
+{
+       log_println("jmm_GetVMGlobalNames: IMPLEMENT ME!");
+       return NULL;
+}
+
+
+jint jmm_GetVMGlobals(JNIEnv* env, jobjectArray names, jmmVMGlobal* globals, jint count)
+{
+       log_println("jmm_GetVMGlobals: IMPLEMENT ME!");
+       return 0;
+}
+
+
+void jmm_SetVMGlobal(JNIEnv* env, jstring flag_name, jvalue new_value)
+{
+       log_println("jmm_SetVMGlobal: IMPLEMENT ME!");
+}
+
+
+jint jmm_GetInternalThreadTimes(JNIEnv* env, jobjectArray names, jlongArray times)
+{
+       log_println("jmm_GetInternalThreadTimes: IMPLEMENT ME!");
+       return 0;
+}
+
+
+jobjectArray jmm_FindDeadlockedThreads(JNIEnv* env, jboolean object_monitors_only)
+{
+       log_println("jmm_FindDeadlockedThreads: IMPLEMENT ME!");
+       return NULL;
+}
+
+
+jobjectArray jmm_FindMonitorDeadlockedThreads(JNIEnv* env)
+{
+       log_println("jmm_FindMonitorDeadlockedThreads: IMPLEMENT ME!");
+       return NULL;
+}
+
+
+jint jmm_GetGCExtAttributeInfo(JNIEnv* env, jobject mgr, jmmExtAttributeInfo* info, jint count)
+{
+       log_println("jmm_GetGCExtAttributeInfo: IMPLEMENT ME!");
+       return 0;
+}
+
+
+void jmm_GetLastGCStat(JNIEnv* env, jobject obj, jmmGCStat* gc_stat)
+{
+       log_println("jmm_GetLastGCStat: IMPLEMENT ME!");
+}
+
+
+jint jmm_DumpHeap0(JNIEnv* env, jstring outputfile, jboolean live)
+{
+       log_println("jmm_DumpHeap0: IMPLEMENT ME!");
+       return 0;
+}
+
+} // extern "C"
+
+
+const struct jmmInterface_1_ jmm_interface = {
+       NULL,
+       NULL,
+       jmm_GetVersion,
+       jmm_GetOptionalSupport,
+       jmm_GetInputArguments,
+       jmm_GetThreadInfo,
+       jmm_GetInputArgumentArray,
+       jmm_GetMemoryPools,
+       jmm_GetMemoryManagers,
+       jmm_GetMemoryPoolUsage,
+       jmm_GetPeakMemoryPoolUsage,
+       NULL,
+       jmm_GetMemoryUsage,
+       jmm_GetLongAttribute,
+       jmm_GetBoolAttribute,
+       jmm_SetBoolAttribute,
+       jmm_GetLongAttributes,
+       jmm_FindMonitorDeadlockedThreads,
+       jmm_GetThreadCpuTime,
+       jmm_GetVMGlobalNames,
+       jmm_GetVMGlobals,
+       jmm_GetInternalThreadTimes,
+       jmm_ResetStatistic,
+       jmm_SetPoolSensor,
+       jmm_SetPoolThreshold,
+       jmm_GetPoolCollectionUsage,
+       jmm_GetGCExtAttributeInfo,
+       jmm_GetLastGCStat,
+       jmm_GetThreadCpuTimeWithKind,
+       NULL,
+       jmm_DumpHeap0,
+       jmm_FindDeadlockedThreads,
+       jmm_SetVMGlobal,
+       NULL,
+       jmm_DumpThreads
+};
+
+
+/**
+ * Return the requested management interface.
+ *
+ * @param version Requested management interface version.
+ *
+ * @return Pointer to management interface structure.
+ */
+void* Management::get_jmm_interface(int version)
+{
+       if (version == JMM_VERSION_1_0) {
+               return (void*) &jmm_interface;
+       }
+
+       return NULL;
+}
+
+/*
+ * These are local overrides for various environment variables in Emacs.
+ * Please do not remove this and leave it at the end of the file, where
+ * Emacs will automagically detect them.
+ * ---------------------------------------------------------------------
+ * Local variables:
+ * mode: c++
+ * indent-tabs-mode: t
+ * c-basic-offset: 4
+ * tab-width: 4
+ * End:
+ * vim:noexpandtab:sw=4:ts=4:
+ */
diff --git a/src/native/vm/openjdk/management.hpp b/src/native/vm/openjdk/management.hpp
new file mode 100644 (file)
index 0000000..4c83d88
--- /dev/null
@@ -0,0 +1,75 @@
+/* src/native/vm/openjdk/management.hpp - HotSpot management interface functions
+
+   Copyright (C) 2008 Theobroma Systems Ltd.
+
+   This file is part of CACAO.
+
+   This program is free software; you can redistribute it and/or
+   modify it under the terms of the GNU General Public License as
+   published by the Free Software Foundation; either version 2, or (at
+   your option) any later version.
+
+   This program is distributed in the hope that it will be useful, but
+   WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with this program; if not, write to the Free Software
+   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+   02110-1301, USA.
+
+*/
+
+
+#ifndef _MANAGEMENT_HPP
+#define _MANAGEMENT_HPP
+
+#include <stdint.h>
+
+// Include our JNI header before the JMM header, because the JMM
+// header include jni.h and we want to override the typedefs in jni.h.
+#include "native/jni.hpp"
+
+#include INCLUDE_JMM_H
+
+
+#ifdef __cplusplus
+
+/**
+ * Management support.
+ */
+class Management {
+private:
+       jmmOptionalSupport _optional_support;
+
+public:
+       Management();
+
+       static void* get_jmm_interface(int version);
+
+       const jmmOptionalSupport& get_optional_support() const;
+};
+
+#else
+
+typedef struct Management Management;
+
+#endif
+
+#endif // _MANAGEMENT_HPP
+
+
+/*
+ * These are local overrides for various environment variables in Emacs.
+ * Please do not remove this and leave it at the end of the file, where
+ * Emacs will automagically detect them.
+ * ---------------------------------------------------------------------
+ * Local variables:
+ * mode: c++
+ * indent-tabs-mode: t
+ * c-basic-offset: 4
+ * tab-width: 4
+ * End:
+ * vim:noexpandtab:sw=4:ts=4:
+ */
index 357884601a3d1ff45cc896d836a6e37ae3008c02..8446f3e3c33cfbcb87bafdedbf0453dccce1929d 100644 (file)
 // We need the JNI types for the VM class.
 #include "native/jni.hpp"
 
+#if defined(WITH_JAVA_RUNTIME_LIBRARY_OPENJDK)
+# include "native/vm/openjdk/management.hpp"
+#endif
+
 #include "vm/properties.hpp"
 
 #include "vm/jit/optimizing/recompiler.hpp"
@@ -64,6 +68,9 @@ private:
 #if defined(ENABLE_THREADS)
        Recompiler _recompiler; ///< JIT recompilation framework.
 #endif
+#if defined(WITH_JAVA_RUNTIME_LIBRARY_OPENJDK)
+       Management _management;
+#endif
 
 public:
        // Constructor, Destructor.
@@ -87,6 +94,9 @@ public:
 
        Properties& get_properties() { return _properties; }
        Recompiler& get_recompiler() { return _recompiler; } // REMOVEME
+#if defined(WITH_JAVA_RUNTIME_LIBRARY_OPENJDK)
+       Management& get_management() { return _management; }
+#endif
 };
 
 #else