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