6d419c0dce5dc64bbe1002b0e1e4ec31dfef6f44
[cacao.git] / src / native / vm / cldc1.1 / java_lang_Object.c
1 /* src/native/vm/cldc1.1/java_lang_Object.c
2
3    Copyright (C) 2006, 2007 R. Grafl, A. Krall, C. Kruegel, C. Oates,
4    R. Obermaisser, M. Platter, M. Probst, S. Ring, E. Steiner,
5    C. Thalinger, D. Thuernbeck, P. Tomsich, C. Ullrich, J. Wenninger,
6    Institut f. Computersprachen - TU Wien
7
8    This file is part of CACAO.
9
10    This program is free software; you can redistribute it and/or
11    modify it under the terms of the GNU General Public License as
12    published by the Free Software Foundation; either version 2, or (at
13    your option) any later version.
14
15    This program is distributed in the hope that it will be useful, but
16    WITHOUT ANY WARRANTY; without even the implied warranty of
17    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
18    General Public License for more details.
19
20    You should have received a copy of the GNU General Public License
21    along with this program; if not, write to the Free Software
22    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
23    02110-1301, USA.
24
25 */
26
27
28 #include "config.h"
29
30 #include <stdlib.h>
31
32 #include "vm/types.h"
33
34 #include "native/jni.h"
35 #include "native/llni.h"
36 #include "native/native.h"
37
38 #include "native/include/java_lang_String.h"             /* required by j.l.C */
39 #include "native/include/java_lang_Class.h"
40
41 #include "native/include/java_lang_Object.h"
42
43 #include "threads/lock-common.h"
44
45 #include "vm/exceptions.h"
46
47
48 /* native methods implemented by this file ************************************/
49  
50 static JNINativeMethod methods[] = {
51         { "getClass",  "()Ljava/lang/Class;",                   (void *) (ptrint) &Java_java_lang_Object_getClass  },
52         { "hashCode",  "()I",                                   (void *) (ptrint) &Java_java_lang_Object_hashCode  },
53         { "notify",    "()V",                                   (void *) (ptrint) &Java_java_lang_Object_notify    },
54         { "notifyAll", "()V",                                   (void *) (ptrint) &Java_java_lang_Object_notifyAll },
55         { "wait",      "(J)V",                                  (void *) (ptrint) &Java_java_lang_Object_wait      },
56 };
57  
58  
59 /* _Jv_java_lang_Object_init ***************************************************
60  
61    Register native functions.
62  
63 *******************************************************************************/
64  
65 void _Jv_java_lang_Object_init(void)
66 {
67         utf *u;
68  
69         u = utf_new_char("java/lang/Object");
70  
71         native_method_register(u, methods, NATIVE_METHODS_COUNT);
72 }
73
74
75 /*
76  * Class:     java/lang/Object
77  * Method:    getClass
78  * Signature: ()Ljava/lang/Class;
79  */
80 JNIEXPORT java_lang_Class* JNICALL Java_java_lang_Object_getClass(JNIEnv *env, java_lang_Object *obj)
81 {
82         classinfo *c;
83
84         if (obj == NULL) {
85                 exceptions_throw_nullpointerexception();
86                 return NULL;
87         }
88
89         LLNI_class_get(obj, c);
90
91         return LLNI_classinfo_wrap(c);
92 }
93
94
95 /*
96  * Class:     java/lang/Object
97  * Method:    hashCode
98  * Signature: ()I
99  */
100 JNIEXPORT int32_t JNICALL Java_java_lang_Object_hashCode(JNIEnv *env, java_lang_Object *this)
101 {
102 #if defined(ENABLE_GC_CACAO)
103         assert(0);
104 #else
105         return (int32_t) ((intptr_t) this);
106 #endif
107 }
108
109
110 /*
111  * Class:     java/lang/Object
112  * Method:    notify
113  * Signature: ()V
114  */
115 JNIEXPORT void JNICALL Java_java_lang_Object_notify(JNIEnv *env, java_lang_Object *this)
116 {
117 #if defined(ENABLE_THREADS)
118         LLNI_CRITICAL_START;
119         lock_notify_object((java_object_t *) LLNI_DIRECT(this));
120         LLNI_CRITICAL_END;
121 #endif
122 }
123
124
125 /*
126  * Class:     java/lang/Object
127  * Method:    notifyAll
128  * Signature: ()V
129  */
130 JNIEXPORT void JNICALL Java_java_lang_Object_notifyAll(JNIEnv *env, java_lang_Object *this)
131 {
132 #if defined(ENABLE_THREADS)
133         LLNI_CRITICAL_START;
134         lock_notify_all_object((java_object_t *) LLNI_DIRECT(this));
135         LLNI_CRITICAL_END;
136 #endif
137 }
138
139
140 /*
141  * Class:     java/lang/Object
142  * Method:    wait
143  * Signature: (J)V
144  */
145 JNIEXPORT void JNICALL Java_java_lang_Object_wait(JNIEnv *env, java_lang_Object *this, s8 timeout)
146 {
147 #if defined(ENABLE_JVMTI)
148         /* Monitor Wait */
149         if (jvmti) jvmti_MonitorWaiting(true, this, timeout);
150 #endif
151
152 #if defined(ENABLE_THREADS)
153         LLNI_CRITICAL_START;
154         lock_wait_for_object((java_object_t *) LLNI_DIRECT(this), timeout, 0);
155         LLNI_CRITICAL_END;
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
166 /*
167  * These are local overrides for various environment variables in Emacs.
168  * Please do not remove this and leave it at the end of the file, where
169  * Emacs will automagically detect them.
170  * ---------------------------------------------------------------------
171  * Local variables:
172  * mode: c
173  * indent-tabs-mode: t
174  * c-basic-offset: 4
175  * tab-width: 4
176  * End:
177  * vim:noexpandtab:sw=4:ts=4:
178  */