* Merged twisti branch to default. This merge introduces C++ wrapper
[cacao.git] / src / native / vm / gnuclasspath / gnu_java_lang_management_VMMemoryMXBeanImpl.cpp
1 /* src/native/vm/gnuclasspath/gnu_java_lang_management_VMMemoryMXBeanImpl.cpp
2
3    Copyright (C) 1996-2005, 2006, 2007, 2008
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.h"
33 #include "native/native.h"
34
35 #if defined(ENABLE_JNI_HEADERS)
36 # include "native/vm/include/gnu_java_lang_management_VMMemoryMXBeanImpl.h"
37 #endif
38
39 #include "vm/builtin.h"
40 #include "vm/global.h"
41 #include "vm/vm.hpp"
42
43 #include "vmcore/class.h"
44 #include "vmcore/loader.h"               /* XXX only for load_class_bootstrap */
45 #include "vmcore/options.h"
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  */
56 JNIEXPORT jobject JNICALL Java_gnu_java_lang_management_VMMemoryMXBeanImpl_getHeapMemoryUsage(JNIEnv *env, jclass clazz)
57 {
58         classinfo     *class_java_lang_management_MemoryUsage;
59         java_handle_t *o;
60         methodinfo    *m;
61         int64_t        init;
62         int64_t        used;
63         int64_t        commited;
64         int64_t        maximum;
65
66         /* get the class */
67         /* XXX optimize me! sometime... */
68
69         if (!(class_java_lang_management_MemoryUsage = load_class_bootstrap(utf_new_char("java/lang/management/MemoryUsage"))))
70                 return false;
71
72         /* create the object */
73
74         o = builtin_new(class_java_lang_management_MemoryUsage);
75         
76         if (o == NULL)
77                 return NULL;
78
79         /* find initializer */
80
81         m = class_findmethod(class_java_lang_management_MemoryUsage,
82                                                  utf_init, utf_new_char("(JJJJ)V"));
83                                                       
84         /* initializer not found */
85
86         if (m == NULL)
87                 return NULL;
88
89         /* get values from the VM */
90         /* XXX if we ever support more than one VM, change this */
91
92         init     = opt_heapstartsize;
93         used     = gc_get_total_bytes();
94         commited = gc_get_heap_size();
95         maximum  = gc_get_max_heap_size();
96
97         /* call initializer */
98
99         (void) vm_call_method(m, o, init, used, commited, maximum);
100
101         return (jobject) o;
102 }
103
104
105 /*
106  * Class:     gnu/java/lang/management/VMMemoryMXBeanImpl
107  * Method:    getNonHeapMemoryUsage
108  * Signature: ()Ljava/lang/management/MemoryUsage;
109  */
110 JNIEXPORT jobject JNICALL Java_gnu_java_lang_management_VMMemoryMXBeanImpl_getNonHeapMemoryUsage(JNIEnv *env, jclass clazz)
111 {
112         log_println("Java_gnu_java_lang_management_VMMemoryMXBeanImpl_getNonHeapMemoryUsage: IMPLEMENT ME!");
113
114         return NULL;
115 }
116
117
118 /*
119  * Class:     gnu/java/lang/management/VMMemoryMXBeanImpl
120  * Method:    getObjectPendingFinalizationCount
121  * Signature: ()I
122  */
123 JNIEXPORT jint JNICALL Java_gnu_java_lang_management_VMMemoryMXBeanImpl_getObjectPendingFinalizationCount(JNIEnv *env, jclass clazz)
124 {
125         log_println("Java_gnu_java_lang_management_VMMemoryMXBeanImpl_getObjectPendingFinalizationCount: IMPLEMENT ME!");
126
127         return 0;
128 }
129
130
131 /*
132  * Class:     gnu/java/lang/management/VMMemoryMXBeanImpl
133  * Method:    isVerbose
134  * Signature: ()Z
135  */
136 JNIEXPORT jboolean JNICALL Java_gnu_java_lang_management_VMMemoryMXBeanImpl_isVerbose(JNIEnv *env, jclass clazz)
137 {
138 /*      return _Jv_jvm->Java_gnu_java_lang_management_VMMemoryMXBeanImpl_verbose; */
139 #warning Move to C++
140         log_println("Java_gnu_java_lang_management_VMMemoryMXBeanImpl_isVerbose: MOVE TO C++!");
141         return 0;
142 }
143
144
145 /*
146  * Class:     gnu/java/lang/management/VMMemoryMXBeanImpl
147  * Method:    setVerbose
148  * Signature: (Z)V
149  */
150 JNIEXPORT void JNICALL Java_gnu_java_lang_management_VMMemoryMXBeanImpl_setVerbose(JNIEnv *env, jclass clazz, jboolean verbose)
151 {
152 /*      _Jv_jvm->Java_gnu_java_lang_management_VMMemoryMXBeanImpl_verbose = verbose; */
153 #warning Move to C++
154         log_println("Java_gnu_java_lang_management_VMMemoryMXBeanImpl_setVerbose: MOVE TO C++!");
155 }
156
157 } // extern "C"
158
159
160 /* native methods implemented by this file ************************************/
161
162 static JNINativeMethod methods[] = {
163         { (char*) "getHeapMemoryUsage",                (char*) "()Ljava/lang/management/MemoryUsage;", (void*) (uintptr_t) &Java_gnu_java_lang_management_VMMemoryMXBeanImpl_getHeapMemoryUsage                },
164         { (char*) "getNonHeapMemoryUsage",             (char*) "()Ljava/lang/management/MemoryUsage;", (void*) (uintptr_t) &Java_gnu_java_lang_management_VMMemoryMXBeanImpl_getNonHeapMemoryUsage             },
165         { (char*) "getObjectPendingFinalizationCount", (char*) "()I",                                  (void*) (uintptr_t) &Java_gnu_java_lang_management_VMMemoryMXBeanImpl_getObjectPendingFinalizationCount },
166         { (char*) "isVerbose",                         (char*) "()Z",                                  (void*) (uintptr_t) &Java_gnu_java_lang_management_VMMemoryMXBeanImpl_isVerbose                         },
167         { (char*) "setVerbose",                        (char*) "(Z)V",                                 (void*) (uintptr_t) &Java_gnu_java_lang_management_VMMemoryMXBeanImpl_setVerbose                        },
168 };
169
170
171 /* _Jv_gnu_java_lang_management_VMMemoryMXBeanImpl_init ************************
172
173    Register native functions.
174
175 *******************************************************************************/
176
177 // FIXME
178 extern "C" {
179 void _Jv_gnu_java_lang_management_VMMemoryMXBeanImpl_init(void)
180 {
181         utf *u;
182
183         u = utf_new_char("gnu/java/lang/management/VMMemoryMXBeanImpl");
184
185         native_method_register(u, methods, NATIVE_METHODS_COUNT);
186 }
187 }
188
189
190 /*
191  * These are local overrides for various environment variables in Emacs.
192  * Please do not remove this and leave it at the end of the file, where
193  * Emacs will automagically detect them.
194  * ---------------------------------------------------------------------
195  * Local variables:
196  * mode: c++
197  * indent-tabs-mode: t
198  * c-basic-offset: 4
199  * tab-width: 4
200  * End:
201  * vim:noexpandtab:sw=4:ts=4:
202  */