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