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