* src/native/vm/cldc1.1/com_sun_cldc_io_ResourceInputStream.c,
[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.h"
32 #include "native/llni.h"
33 #include "native/native.h"
34
35 #include "native/include/java_lang_String.h"             /* required by j.l.C */
36 #include "native/include/java_lang_Class.h"
37
38 // FIXME
39 extern "C" {
40 #include "native/include/java_lang_Object.h"
41 }
42
43 #include "threads/lock-common.h"
44
45 #include "vm/exceptions.hpp"
46
47
48 /* native methods implemented by this file ************************************/
49  
50 static JNINativeMethod methods[] = {
51         { (char*) "getClass",  (char*) "()Ljava/lang/Class;", (void*) (uintptr_t) &Java_java_lang_Object_getClass  },
52         { (char*) "hashCode",  (char*) "()I",                 (void*) (uintptr_t) &Java_java_lang_Object_hashCode  },
53         { (char*) "notify",    (char*) "()V",                 (void*) (uintptr_t) &Java_java_lang_Object_notify    },
54         { (char*) "notifyAll", (char*) "()V",                 (void*) (uintptr_t) &Java_java_lang_Object_notifyAll },
55         { (char*) "wait",      (char*) "(J)V",                (void*) (uintptr_t) &Java_java_lang_Object_wait      },
56 };
57  
58  
59 /* _Jv_java_lang_Object_init ***************************************************
60  
61    Register native functions.
62  
63 *******************************************************************************/
64  
65 // FIXME
66 extern "C" {
67 void _Jv_java_lang_Object_init(void)
68 {
69         utf *u;
70  
71         u = utf_new_char("java/lang/Object");
72  
73         native_method_register(u, methods, NATIVE_METHODS_COUNT);
74 }
75 }
76
77
78 // Native functions are exported as C functions.
79 extern "C" {
80
81 /*
82  * Class:     java/lang/Object
83  * Method:    getClass
84  * Signature: ()Ljava/lang/Class;
85  */
86 JNIEXPORT java_lang_Class* JNICALL Java_java_lang_Object_getClass(JNIEnv *env, java_lang_Object *obj)
87 {
88         classinfo *c;
89
90         if (obj == NULL) {
91                 exceptions_throw_nullpointerexception();
92                 return NULL;
93         }
94
95         LLNI_class_get(obj, c);
96
97         return LLNI_classinfo_wrap(c);
98 }
99
100
101 /*
102  * Class:     java/lang/Object
103  * Method:    hashCode
104  * Signature: ()I
105  */
106 JNIEXPORT int32_t JNICALL Java_java_lang_Object_hashCode(JNIEnv *env, java_lang_Object *_this)
107 {
108 #if defined(ENABLE_GC_CACAO)
109         assert(0);
110 #else
111         return (int32_t) ((intptr_t) _this);
112 #endif
113 }
114
115
116 /*
117  * Class:     java/lang/Object
118  * Method:    notify
119  * Signature: ()V
120  */
121 JNIEXPORT void JNICALL Java_java_lang_Object_notify(JNIEnv *env, java_lang_Object *_this)
122 {
123 #if defined(ENABLE_THREADS)
124         lock_notify_object((java_handle_t *) _this);
125 #endif
126 }
127
128
129 /*
130  * Class:     java/lang/Object
131  * Method:    notifyAll
132  * Signature: ()V
133  */
134 JNIEXPORT void JNICALL Java_java_lang_Object_notifyAll(JNIEnv *env, java_lang_Object *_this)
135 {
136 #if defined(ENABLE_THREADS)
137         lock_notify_all_object((java_handle_t *) _this);
138 #endif
139 }
140
141
142 /*
143  * Class:     java/lang/Object
144  * Method:    wait
145  * Signature: (J)V
146  */
147 JNIEXPORT void JNICALL Java_java_lang_Object_wait(JNIEnv *env, java_lang_Object *_this, s8 timeout)
148 {
149 #if defined(ENABLE_JVMTI)
150         /* Monitor Wait */
151         if (jvmti) jvmti_MonitorWaiting(true, _this, timeout);
152 #endif
153
154 #if defined(ENABLE_THREADS)
155         lock_wait_for_object((java_handle_t *) _this, timeout, 0);
156 #endif
157
158 #if defined(ENABLE_JVMTI)
159         /* Monitor Waited */
160         /* XXX: How do you know if wait timed out ?*/
161         if (jvmti) jvmti_MonitorWaiting(false, _this, 0);
162 #endif
163 }
164
165 } // extern "C"
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  * vim:noexpandtab:sw=4:ts=4:
180  */