5b63de218bf63aaa2c61dcf7a19b1dc695a571ff
[cacao.git] / src / native / vm / gnuclasspath / java_lang_VMObject.cpp
1 /* src/native/vm/gnuclasspath/java_lang_VMObject.cpp - java/lang/VMObject
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 "native/jni.h"
31 #include "native/llni.h"
32 #include "native/native.h"
33
34 #if defined(ENABLE_JNI_HEADERS)
35 # include "native/vm/include/java_lang_VMObject.h"
36 #endif
37
38 #include "threads/lock-common.h"
39
40 #include "vm/builtin.h"
41 #include "vm/exceptions.hpp"
42 #include "vm/utf8.h"
43
44
45 // Native functions are exported as C functions.
46 extern "C" {
47
48 /*
49  * Class:     java/lang/VMObject
50  * Method:    getClass
51  * Signature: (Ljava/lang/Object;)Ljava/lang/Class;
52  */
53 JNIEXPORT jclass JNICALL Java_java_lang_VMObject_getClass(JNIEnv *env, jclass clazz, jobject obj)
54 {
55         classinfo *c;
56
57         if (obj == NULL) {
58                 exceptions_throw_nullpointerexception();
59                 return NULL;
60         }
61
62         LLNI_class_get(obj, c);
63
64         return (jclass) LLNI_classinfo_wrap(c);
65 }
66
67
68 /*
69  * Class:     java/lang/VMObject
70  * Method:    clone
71  * Signature: (Ljava/lang/Cloneable;)Ljava/lang/Object;
72  */
73 JNIEXPORT jobject JNICALL Java_java_lang_VMObject_clone(JNIEnv *env, jclass clazz, jobject _this)
74 {
75         java_handle_t *o;
76         java_handle_t *co;
77
78         o = (java_handle_t *) _this;
79
80         co = builtin_clone(NULL, o);
81
82         return (jobject) co;
83 }
84
85
86 /*
87  * Class:     java/lang/VMObject
88  * Method:    notify
89  * Signature: (Ljava/lang/Object;)V
90  */
91 JNIEXPORT void JNICALL Java_java_lang_VMObject_notify(JNIEnv *env, jclass clazz, jobject _this)
92 {
93 #if defined(ENABLE_THREADS)
94         lock_notify_object((java_handle_t *) _this);
95 #endif
96 }
97
98
99 /*
100  * Class:     java/lang/VMObject
101  * Method:    notifyAll
102  * Signature: (Ljava/lang/Object;)V
103  */
104 JNIEXPORT void JNICALL Java_java_lang_VMObject_notifyAll(JNIEnv *env, jclass clazz, jobject _this)
105 {
106 #if defined(ENABLE_THREADS)
107         lock_notify_all_object((java_handle_t *) _this);
108 #endif
109 }
110
111
112 /*
113  * Class:     java/lang/VMObject
114  * Method:    wait
115  * Signature: (Ljava/lang/Object;JI)V
116  */
117 JNIEXPORT void JNICALL Java_java_lang_VMObject_wait(JNIEnv *env, jclass clazz, jobject o, jlong ms, jint ns)
118 {
119 #if defined(ENABLE_JVMTI)
120         /* Monitor Wait */
121         if (jvmti) jvmti_MonitorWaiting(true, o, ms);
122 #endif
123
124 #if defined(ENABLE_THREADS)
125         lock_wait_for_object((java_handle_t *) o, ms, ns);
126 #endif
127
128 #if defined(ENABLE_JVMTI)
129         /* Monitor Waited */
130         /* XXX: How do you know if wait timed out ?*/
131         if (jvmti) jvmti_MonitorWaiting(false, o, 0);
132 #endif
133 }
134
135 } // extern "C"
136
137
138 /* native methods implemented by this file ************************************/
139
140 static JNINativeMethod methods[] = {
141         { (char*) "getClass",  (char*) "(Ljava/lang/Object;)Ljava/lang/Class;",     (void*) (uintptr_t) &Java_java_lang_VMObject_getClass  },
142         { (char*) "clone",     (char*) "(Ljava/lang/Cloneable;)Ljava/lang/Object;", (void*) (uintptr_t) &Java_java_lang_VMObject_clone     },
143         { (char*) "notify",    (char*) "(Ljava/lang/Object;)V",                     (void*) (uintptr_t) &Java_java_lang_VMObject_notify    },
144         { (char*) "notifyAll", (char*) "(Ljava/lang/Object;)V",                     (void*) (uintptr_t) &Java_java_lang_VMObject_notifyAll },
145         { (char*) "wait",      (char*) "(Ljava/lang/Object;JI)V",                   (void*) (uintptr_t) &Java_java_lang_VMObject_wait      },
146 };
147
148
149 /* _Jv_java_lang_VMObject_init *************************************************
150
151    Register native functions.
152
153 *******************************************************************************/
154
155 // FIXME
156 extern "C" {
157 void _Jv_java_lang_VMObject_init(void)
158 {
159         utf *u;
160
161         u = utf_new_char("java/lang/VMObject");
162
163         native_method_register(u, methods, NATIVE_METHODS_COUNT);
164 }
165 }
166
167
168 /*
169  * These are local overrides for various environment variables in Emacs.
170  * Please do not remove this and leave it at the end of the file, where
171  * Emacs will automagically detect them.
172  * ---------------------------------------------------------------------
173  * Local variables:
174  * mode: c++
175  * indent-tabs-mode: t
176  * c-basic-offset: 4
177  * tab-width: 4
178  * End:
179  */