37741ec71cf76ef92b7972183662a7a17a4a4e40
[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    $Id: VMFrame.c 4996 2006-05-31 13:53:16Z motse $
26
27 */
28
29
30 #include "config.h"
31 #include "vm/types.h"
32
33 #include "mm/gc-common.h"
34
35 #include "native/jni.h"
36 #include "native/include/java_lang_management_MemoryUsage.h"
37
38 #include "vm/builtin.h"
39 #include "vm/global.h"
40 #include "vm/vm.h"
41
42 #include "vmcore/class.h"
43 #include "vmcore/loader.h"               /* XXX only for load_class_bootstrap */
44 #include "vmcore/options.h"
45
46
47 /*
48  * Class:     gnu/java/lang/management/VMMemoryMXBeanImpl
49  * Method:    getHeapMemoryUsage
50  * Signature: ()Ljava/lang/management/MemoryUsage;
51  */
52 JNIEXPORT java_lang_management_MemoryUsage* JNICALL Java_gnu_java_lang_management_VMMemoryMXBeanImpl_getHeapMemoryUsage(JNIEnv *env, jclass clazz)
53 {
54         classinfo                        *class_java_lang_management_MemoryUsage;
55         java_objectheader                *o;
56         java_lang_management_MemoryUsage *mu;
57         methodinfo                       *m;
58         s8                                init;
59         s8                                used;
60         s8                                commited;
61         s8                                maximum;
62
63         /* get the class */
64         /* XXX optimize me! sometime... */
65
66         if (!(class_java_lang_management_MemoryUsage = load_class_bootstrap(utf_new_char("java/lang/management/MemoryUsage"))))
67                 return false;
68
69         /* create the object */
70
71         o = builtin_new(class_java_lang_management_MemoryUsage);
72         
73         if (o == NULL)
74                 return NULL;
75
76         /* cast the object to a MemoryUsage object (for debugability) */
77
78         mu = (java_lang_management_MemoryUsage *) o;
79
80         /* find initializer */
81
82         m = class_findmethod(class_java_lang_management_MemoryUsage,
83                                                  utf_init, utf_new_char("(JJJJ)V"));
84                                                       
85         /* initializer not found */
86
87         if (m == NULL)
88                 return NULL;
89
90         /* get values from the VM */
91         /* XXX if we ever support more than one VM, change this */
92
93         init     = opt_heapstartsize;
94         used     = gc_get_total_bytes();
95         commited = gc_get_heap_size();
96         maximum  = gc_get_max_heap_size();
97
98         /* call initializer */
99
100         (void) vm_call_method(m, o, init, used, commited, maximum);
101
102         return mu;
103 }
104
105
106 /*
107  * Class:     gnu/java/lang/management/VMMemoryMXBeanImpl
108  * Method:    getNonHeapMemoryUsage
109  * Signature: ()Ljava/lang/management/MemoryUsage;
110  */
111 JNIEXPORT java_lang_management_MemoryUsage* JNICALL Java_gnu_java_lang_management_VMMemoryMXBeanImpl_getNonHeapMemoryUsage(JNIEnv *env, jclass clazz)
112 {
113         log_println("Java_gnu_java_lang_management_VMMemoryMXBeanImpl_getNonHeapMemoryUsage: IMPLEMENT ME!");
114
115         return NULL;
116 }
117
118
119 /*
120  * Class:     gnu/java/lang/management/VMMemoryMXBeanImpl
121  * Method:    getObjectPendingFinalizationCount
122  * Signature: ()I
123  */
124 JNIEXPORT s4 JNICALL Java_gnu_java_lang_management_VMMemoryMXBeanImpl_getObjectPendingFinalizationCount(JNIEnv *env, jclass clazz)
125 {
126         log_println("Java_gnu_java_lang_management_VMMemoryMXBeanImpl_getObjectPendingFinalizationCount: IMPLEMENT ME!");
127
128         return 0;
129 }
130
131
132 /*
133  * Class:     gnu/java/lang/management/VMMemoryMXBeanImpl
134  * Method:    isVerbose
135  * Signature: ()Z
136  */
137 JNIEXPORT s4 JNICALL Java_gnu_java_lang_management_VMMemoryMXBeanImpl_isVerbose(JNIEnv *env, jclass clazz)
138 {
139         return _Jv_jvm->Java_gnu_java_lang_management_VMMemoryMXBeanImpl_verbose;
140 }
141
142
143 /*
144  * Class:     gnu/java/lang/management/VMMemoryMXBeanImpl
145  * Method:    setVerbose
146  * Signature: (Z)V
147  */
148 JNIEXPORT void JNICALL Java_gnu_java_lang_management_VMMemoryMXBeanImpl_setVerbose(JNIEnv *env, jclass clazz, s4 verbose)
149 {
150         _Jv_jvm->Java_gnu_java_lang_management_VMMemoryMXBeanImpl_verbose = verbose;
151 }
152
153
154 /*
155  * These are local overrides for various environment variables in Emacs.
156  * Please do not remove this and leave it at the end of the file, where
157  * Emacs will automagically detect them.
158  * ---------------------------------------------------------------------
159  * Local variables:
160  * mode: c
161  * indent-tabs-mode: t
162  * c-basic-offset: 4
163  * tab-width: 4
164  * End:
165  * vim:noexpandtab:sw=4:ts=4:
166  */