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