* Removed all Id tags.
[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 R. Grafl, A. Krall, C. Kruegel,
4    C. Oates, R. Obermaisser, M. Platter, M. Probst, S. Ring,
5    E. Steiner, C. Thalinger, D. Thuernbeck, P. Tomsich, C. Ullrich,
6    J. Wenninger, Institut f. Computersprachen - TU Wien
7
8    This file is part of CACAO.
9
10    This program is free software; you can redistribute it and/or
11    modify it under the terms of the GNU General Public License as
12    published by the Free Software Foundation; either version 2, or (at
13    your option) any later version.
14
15    This program is distributed in the hope that it will be useful, but
16    WITHOUT ANY WARRANTY; without even the implied warranty of
17    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
18    General Public License for more details.
19
20    You should have received a copy of the GNU General Public License
21    along with this program; if not, write to the Free Software
22    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
23    02110-1301, USA.
24
25 */
26
27
28 #include "config.h"
29 #include "vm/types.h"
30
31 #include "mm/gc-common.h"
32
33 #include "native/jni.h"
34 #include "native/native.h"
35
36 #include "native/include/java_lang_management_MemoryUsage.h"
37
38 #include "native/include/gnu_java_lang_management_VMMemoryMXBeanImpl.h"
39
40 #include "vm/builtin.h"
41 #include "vm/global.h"
42 #include "vm/vm.h"
43
44 #include "vmcore/class.h"
45 #include "vmcore/loader.h"               /* XXX only for load_class_bootstrap */
46 #include "vmcore/options.h"
47
48
49 /* native methods implemented by this file ************************************/
50
51 static JNINativeMethod methods[] = {
52         { "getHeapMemoryUsage",                "()Ljava/lang/management/MemoryUsage;", (void *) (ptrint) &Java_gnu_java_lang_management_VMMemoryMXBeanImpl_getHeapMemoryUsage                },
53         { "getNonHeapMemoryUsage",             "()Ljava/lang/management/MemoryUsage;", (void *) (ptrint) &Java_gnu_java_lang_management_VMMemoryMXBeanImpl_getNonHeapMemoryUsage             },
54         { "getObjectPendingFinalizationCount", "()I",                                  (void *) (ptrint) &Java_gnu_java_lang_management_VMMemoryMXBeanImpl_getObjectPendingFinalizationCount },
55         { "isVerbose",                         "()Z",                                  (void *) (ptrint) &Java_gnu_java_lang_management_VMMemoryMXBeanImpl_isVerbose                         },
56         { "setVerbose",                        "(Z)V",                                 (void *) (ptrint) &Java_gnu_java_lang_management_VMMemoryMXBeanImpl_setVerbose                        },
57 };
58
59
60 /* _Jv_gnu_java_lang_management_VMMemoryMXBeanImpl_init ************************
61
62    Register native functions.
63
64 *******************************************************************************/
65
66 void _Jv_gnu_java_lang_management_VMMemoryMXBeanImpl_init(void)
67 {
68         utf *u;
69
70         u = utf_new_char("gnu/java/lang/management/VMMemoryMXBeanImpl");
71
72         native_method_register(u, methods, NATIVE_METHODS_COUNT);
73 }
74
75
76 /*
77  * Class:     gnu/java/lang/management/VMMemoryMXBeanImpl
78  * Method:    getHeapMemoryUsage
79  * Signature: ()Ljava/lang/management/MemoryUsage;
80  */
81 JNIEXPORT java_lang_management_MemoryUsage* JNICALL Java_gnu_java_lang_management_VMMemoryMXBeanImpl_getHeapMemoryUsage(JNIEnv *env, jclass clazz)
82 {
83         classinfo                        *class_java_lang_management_MemoryUsage;
84         java_handle_t                    *o;
85         java_lang_management_MemoryUsage *mu;
86         methodinfo                       *m;
87         s8                                init;
88         s8                                used;
89         s8                                commited;
90         s8                                maximum;
91
92         /* get the class */
93         /* XXX optimize me! sometime... */
94
95         if (!(class_java_lang_management_MemoryUsage = load_class_bootstrap(utf_new_char("java/lang/management/MemoryUsage"))))
96                 return false;
97
98         /* create the object */
99
100         o = builtin_new(class_java_lang_management_MemoryUsage);
101         
102         if (o == NULL)
103                 return NULL;
104
105         /* cast the object to a MemoryUsage object (for debugability) */
106
107         mu = (java_lang_management_MemoryUsage *) o;
108
109         /* find initializer */
110
111         m = class_findmethod(class_java_lang_management_MemoryUsage,
112                                                  utf_init, utf_new_char("(JJJJ)V"));
113                                                       
114         /* initializer not found */
115
116         if (m == NULL)
117                 return NULL;
118
119         /* get values from the VM */
120         /* XXX if we ever support more than one VM, change this */
121
122         init     = opt_heapstartsize;
123         used     = gc_get_total_bytes();
124         commited = gc_get_heap_size();
125         maximum  = gc_get_max_heap_size();
126
127         /* call initializer */
128
129         (void) vm_call_method(m, o, init, used, commited, maximum);
130
131         return mu;
132 }
133
134
135 /*
136  * Class:     gnu/java/lang/management/VMMemoryMXBeanImpl
137  * Method:    getNonHeapMemoryUsage
138  * Signature: ()Ljava/lang/management/MemoryUsage;
139  */
140 JNIEXPORT java_lang_management_MemoryUsage* JNICALL Java_gnu_java_lang_management_VMMemoryMXBeanImpl_getNonHeapMemoryUsage(JNIEnv *env, jclass clazz)
141 {
142         log_println("Java_gnu_java_lang_management_VMMemoryMXBeanImpl_getNonHeapMemoryUsage: IMPLEMENT ME!");
143
144         return NULL;
145 }
146
147
148 /*
149  * Class:     gnu/java/lang/management/VMMemoryMXBeanImpl
150  * Method:    getObjectPendingFinalizationCount
151  * Signature: ()I
152  */
153 JNIEXPORT s4 JNICALL Java_gnu_java_lang_management_VMMemoryMXBeanImpl_getObjectPendingFinalizationCount(JNIEnv *env, jclass clazz)
154 {
155         log_println("Java_gnu_java_lang_management_VMMemoryMXBeanImpl_getObjectPendingFinalizationCount: IMPLEMENT ME!");
156
157         return 0;
158 }
159
160
161 /*
162  * Class:     gnu/java/lang/management/VMMemoryMXBeanImpl
163  * Method:    isVerbose
164  * Signature: ()Z
165  */
166 JNIEXPORT s4 JNICALL Java_gnu_java_lang_management_VMMemoryMXBeanImpl_isVerbose(JNIEnv *env, jclass clazz)
167 {
168         return _Jv_jvm->Java_gnu_java_lang_management_VMMemoryMXBeanImpl_verbose;
169 }
170
171
172 /*
173  * Class:     gnu/java/lang/management/VMMemoryMXBeanImpl
174  * Method:    setVerbose
175  * Signature: (Z)V
176  */
177 JNIEXPORT void JNICALL Java_gnu_java_lang_management_VMMemoryMXBeanImpl_setVerbose(JNIEnv *env, jclass clazz, s4 verbose)
178 {
179         _Jv_jvm->Java_gnu_java_lang_management_VMMemoryMXBeanImpl_verbose = verbose;
180 }
181
182
183 /*
184  * These are local overrides for various environment variables in Emacs.
185  * Please do not remove this and leave it at the end of the file, where
186  * Emacs will automagically detect them.
187  * ---------------------------------------------------------------------
188  * Local variables:
189  * mode: c
190  * indent-tabs-mode: t
191  * c-basic-offset: 4
192  * tab-width: 4
193  * End:
194  * vim:noexpandtab:sw=4:ts=4:
195  */