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