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