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