CACAO
gnu_java_lang_management_VMMemoryMXBeanImpl.cpp
Go to the documentation of this file.
1 /* src/native/vm/gnuclasspath/gnu_java_lang_management_VMMemoryMXBeanImpl.cpp
2 
3  Copyright (C) 1996-2013
4  CACAOVM - Verein zur Foerderung der freien virtuellen Maschine CACAO
5 
6  This file is part of CACAO.
7 
8  This program is free software; you can redistribute it and/or
9  modify it under the terms of the GNU General Public License as
10  published by the Free Software Foundation; either version 2, or (at
11  your option) any later version.
12 
13  This program is distributed in the hope that it will be useful, but
14  WITHOUT ANY WARRANTY; without even the implied warranty of
15  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16  General Public License for more details.
17 
18  You should have received a copy of the GNU General Public License
19  along with this program; if not, write to the Free Software
20  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
21  02110-1301, USA.
22 
23 */
24 
25 
26 #include "config.h"
27 
28 #include <stdint.h>
29 
30 #include "mm/gc.hpp"
31 
32 #include "native/jni.hpp"
33 #include "native/native.hpp"
34 
35 #include "toolbox/logging.hpp"
36 
37 #if defined(ENABLE_JNI_HEADERS)
38 # include "native/vm/include/gnu_java_lang_management_VMMemoryMXBeanImpl.h"
39 #endif
40 
41 #include "vm/class.hpp"
42 #include "vm/global.hpp"
43 #include "vm/javaobjects.hpp"
44 #include "vm/options.hpp"
45 #include "vm/vm.hpp"
46 
47 
48 // Native functions are exported as C functions.
49 extern "C" {
50 
51 /*
52  * Class: gnu/java/lang/management/VMMemoryMXBeanImpl
53  * Method: getHeapMemoryUsage
54  * Signature: ()Ljava/lang/management/MemoryUsage;
55  */
57 {
58  // Get values from the VM.
59  // XXX If we ever support more than one VM, change this.
60  int64_t init = opt_heapstartsize;
61  int64_t used = gc_get_total_bytes();
62  int64_t commited = gc_get_heap_size();
63  int64_t maximum = gc_get_max_heap_size();
64 
65  // Construct a new java.lang.management.MemoryUsage object.
66  java_lang_management_MemoryUsage jlmmu(init, used, commited, maximum);
67 
68  return jlmmu.get_handle();
69 }
70 
71 
72 /*
73  * Class: gnu/java/lang/management/VMMemoryMXBeanImpl
74  * Method: getNonHeapMemoryUsage
75  * Signature: ()Ljava/lang/management/MemoryUsage;
76  */
78 {
79  log_println("Java_gnu_java_lang_management_VMMemoryMXBeanImpl_getNonHeapMemoryUsage: IMPLEMENT ME!");
80 
81  return NULL;
82 }
83 
84 
85 /*
86  * Class: gnu/java/lang/management/VMMemoryMXBeanImpl
87  * Method: getObjectPendingFinalizationCount
88  * Signature: ()I
89  */
91 {
92  log_println("Java_gnu_java_lang_management_VMMemoryMXBeanImpl_getObjectPendingFinalizationCount: IMPLEMENT ME!");
93 
94  return 0;
95 }
96 
97 
98 /*
99  * Class: gnu/java/lang/management/VMMemoryMXBeanImpl
100  * Method: isVerbose
101  * Signature: ()Z
102  */
104 {
105  return opt_verbosegc;
106 }
107 
108 
109 /*
110  * Class: gnu/java/lang/management/VMMemoryMXBeanImpl
111  * Method: setVerbose
112  * Signature: (Z)V
113  */
115 {
117 }
118 
119 } // extern "C"
120 
121 
122 /* native methods implemented by this file ************************************/
123 
124 static JNINativeMethod methods[] = {
125  { (char*) "getHeapMemoryUsage", (char*) "()Ljava/lang/management/MemoryUsage;", (void*) (uintptr_t) &Java_gnu_java_lang_management_VMMemoryMXBeanImpl_getHeapMemoryUsage },
126  { (char*) "getNonHeapMemoryUsage", (char*) "()Ljava/lang/management/MemoryUsage;", (void*) (uintptr_t) &Java_gnu_java_lang_management_VMMemoryMXBeanImpl_getNonHeapMemoryUsage },
127  { (char*) "getObjectPendingFinalizationCount", (char*) "()I", (void*) (uintptr_t) &Java_gnu_java_lang_management_VMMemoryMXBeanImpl_getObjectPendingFinalizationCount },
128  { (char*) "isVerbose", (char*) "()Z", (void*) (uintptr_t) &Java_gnu_java_lang_management_VMMemoryMXBeanImpl_isVerbose },
129  { (char*) "setVerbose", (char*) "(Z)V", (void*) (uintptr_t) &Java_gnu_java_lang_management_VMMemoryMXBeanImpl_setVerbose },
130 };
131 
132 
133 /* _Jv_gnu_java_lang_management_VMMemoryMXBeanImpl_init ************************
134 
135  Register native functions.
136 
137 *******************************************************************************/
138 
140 {
141  Utf8String u = Utf8String::from_utf8("gnu/java/lang/management/VMMemoryMXBeanImpl");
142 
145 }
146 
147 
148 /*
149  * These are local overrides for various environment variables in Emacs.
150  * Please do not remove this and leave it at the end of the file, where
151  * Emacs will automagically detect them.
152  * ---------------------------------------------------------------------
153  * Local variables:
154  * mode: c++
155  * indent-tabs-mode: t
156  * c-basic-offset: 4
157  * tab-width: 4
158  * End:
159  * vim:noexpandtab:sw=4:ts=4:
160  */
virtual java_handle_t * get_handle() const
Table containing all native methods registered with the VM.
Definition: native.hpp:132
NativeMethods & get_nativemethods()
Definition: vm.hpp:128
void register_methods(Utf8String classname, const JNINativeMethod *methods, size_t count)
Register native methods with the VM.
Definition: native.cpp:242
_Jv_JNIEnv JNIEnv
Definition: jni.hpp:112
#define NATIVE_METHODS_COUNT
Definition: native.hpp:45
JNIEXPORT jobject JNICALL Java_gnu_java_lang_management_VMMemoryMXBeanImpl_getNonHeapMemoryUsage(JNIEnv *env, jclass clazz)
s4 opt_heapstartsize
Definition: options.cpp:64
void log_println(const char *text,...)
Definition: logging.cpp:193
s8 gc_get_max_heap_size(void)
Definition: gc.c:555
java/lang/management/MemoryUsage
JNIEXPORT jint JNICALL Java_gnu_java_lang_management_VMMemoryMXBeanImpl_getObjectPendingFinalizationCount(JNIEnv *env, jclass clazz)
s8 gc_get_total_bytes(void)
Definition: gc.c:554
void _Jv_gnu_java_lang_management_VMMemoryMXBeanImpl_init(void)
static Utf8String from_utf8(const char *, size_t)
Definition: utf8.cpp:335
bool opt_verbosegc
Definition: options.cpp:74
bool verbose
s8 gc_get_heap_size(void)
Definition: gc.c:552
JNIEXPORT jobject JNICALL Java_gnu_java_lang_management_VMMemoryMXBeanImpl_getHeapMemoryUsage(JNIEnv *env, jclass clazz)
static JNINativeMethod methods[]
JNIEXPORT jboolean JNICALL Java_gnu_java_lang_management_VMMemoryMXBeanImpl_isVerbose(JNIEnv *env, jclass clazz)
JNIEXPORT void JNICALL Java_gnu_java_lang_management_VMMemoryMXBeanImpl_setVerbose(JNIEnv *env, jclass clazz, jboolean verbose)
static VM * get_current()
Definition: vm.hpp:99