merged volatile memory barriers
[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.hpp"
33 #include "native/native.hpp"
34
35 #if defined(ENABLE_JNI_HEADERS)
36 # include "native/vm/include/gnu_java_lang_management_VMMemoryMXBeanImpl.h"
37 #endif
38
39 #include "vm/class.hpp"
40 #include "vm/global.h"
41 #include "vm/javaobjects.hpp"
42 #include "vm/options.h"
43 #include "vm/vm.hpp"
44
45
46 // Native functions are exported as C functions.
47 extern "C" {
48
49 /*
50  * Class:     gnu/java/lang/management/VMMemoryMXBeanImpl
51  * Method:    getHeapMemoryUsage
52  * Signature: ()Ljava/lang/management/MemoryUsage;
53  */
54 JNIEXPORT jobject JNICALL Java_gnu_java_lang_management_VMMemoryMXBeanImpl_getHeapMemoryUsage(JNIEnv *env, jclass clazz)
55 {
56         // Get values from the VM.
57         // XXX If we ever support more than one VM, change this.
58         int64_t init     = opt_heapstartsize;
59         int64_t used     = gc_get_total_bytes();
60         int64_t commited = gc_get_heap_size();
61         int64_t maximum  = gc_get_max_heap_size();
62
63         // Construct a new java.lang.management.MemoryUsage object.
64         java_lang_management_MemoryUsage jlmmu(init, used, commited, maximum);
65
66         return jlmmu.get_handle();
67 }
68
69
70 /*
71  * Class:     gnu/java/lang/management/VMMemoryMXBeanImpl
72  * Method:    getNonHeapMemoryUsage
73  * Signature: ()Ljava/lang/management/MemoryUsage;
74  */
75 JNIEXPORT jobject JNICALL Java_gnu_java_lang_management_VMMemoryMXBeanImpl_getNonHeapMemoryUsage(JNIEnv *env, jclass clazz)
76 {
77         log_println("Java_gnu_java_lang_management_VMMemoryMXBeanImpl_getNonHeapMemoryUsage: IMPLEMENT ME!");
78
79         return NULL;
80 }
81
82
83 /*
84  * Class:     gnu/java/lang/management/VMMemoryMXBeanImpl
85  * Method:    getObjectPendingFinalizationCount
86  * Signature: ()I
87  */
88 JNIEXPORT jint JNICALL Java_gnu_java_lang_management_VMMemoryMXBeanImpl_getObjectPendingFinalizationCount(JNIEnv *env, jclass clazz)
89 {
90         log_println("Java_gnu_java_lang_management_VMMemoryMXBeanImpl_getObjectPendingFinalizationCount: IMPLEMENT ME!");
91
92         return 0;
93 }
94
95
96 /*
97  * Class:     gnu/java/lang/management/VMMemoryMXBeanImpl
98  * Method:    isVerbose
99  * Signature: ()Z
100  */
101 JNIEXPORT jboolean JNICALL Java_gnu_java_lang_management_VMMemoryMXBeanImpl_isVerbose(JNIEnv *env, jclass clazz)
102 {
103         return opt_verbosegc;
104 }
105
106
107 /*
108  * Class:     gnu/java/lang/management/VMMemoryMXBeanImpl
109  * Method:    setVerbose
110  * Signature: (Z)V
111  */
112 JNIEXPORT void JNICALL Java_gnu_java_lang_management_VMMemoryMXBeanImpl_setVerbose(JNIEnv *env, jclass clazz, jboolean verbose)
113 {
114         opt_verbosegc = verbose;
115 }
116
117 } // extern "C"
118
119
120 /* native methods implemented by this file ************************************/
121
122 static JNINativeMethod methods[] = {
123         { (char*) "getHeapMemoryUsage",                (char*) "()Ljava/lang/management/MemoryUsage;", (void*) (uintptr_t) &Java_gnu_java_lang_management_VMMemoryMXBeanImpl_getHeapMemoryUsage                },
124         { (char*) "getNonHeapMemoryUsage",             (char*) "()Ljava/lang/management/MemoryUsage;", (void*) (uintptr_t) &Java_gnu_java_lang_management_VMMemoryMXBeanImpl_getNonHeapMemoryUsage             },
125         { (char*) "getObjectPendingFinalizationCount", (char*) "()I",                                  (void*) (uintptr_t) &Java_gnu_java_lang_management_VMMemoryMXBeanImpl_getObjectPendingFinalizationCount },
126         { (char*) "isVerbose",                         (char*) "()Z",                                  (void*) (uintptr_t) &Java_gnu_java_lang_management_VMMemoryMXBeanImpl_isVerbose                         },
127         { (char*) "setVerbose",                        (char*) "(Z)V",                                 (void*) (uintptr_t) &Java_gnu_java_lang_management_VMMemoryMXBeanImpl_setVerbose                        },
128 };
129
130
131 /* _Jv_gnu_java_lang_management_VMMemoryMXBeanImpl_init ************************
132
133    Register native functions.
134
135 *******************************************************************************/
136
137 void _Jv_gnu_java_lang_management_VMMemoryMXBeanImpl_init(void)
138 {
139         utf* u = utf_new_char("gnu/java/lang/management/VMMemoryMXBeanImpl");
140
141         NativeMethods& nm = VM::get_current()->get_nativemethods();
142         nm.register_methods(u, methods, NATIVE_METHODS_COUNT);
143 }
144
145
146 /*
147  * These are local overrides for various environment variables in Emacs.
148  * Please do not remove this and leave it at the end of the file, where
149  * Emacs will automagically detect them.
150  * ---------------------------------------------------------------------
151  * Local variables:
152  * mode: c++
153  * indent-tabs-mode: t
154  * c-basic-offset: 4
155  * tab-width: 4
156  * End:
157  * vim:noexpandtab:sw=4:ts=4:
158  */