merged volatile memory barriers
[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_THREADS)
113         lock_wait_for_object((java_handle_t *) _this, timeout, 0);
114 #endif
115 }
116
117 } // extern "C"
118
119
120 /* native methods implemented by this file ************************************/
121  
122 static JNINativeMethod methods[] = {
123         { (char*) "getClass",  (char*) "()Ljava/lang/Class;", (void*) (uintptr_t) &Java_java_lang_Object_getClass  },
124         { (char*) "hashCode",  (char*) "()I",                 (void*) (uintptr_t) &Java_java_lang_Object_hashCode  },
125         { (char*) "notify",    (char*) "()V",                 (void*) (uintptr_t) &Java_java_lang_Object_notify    },
126         { (char*) "notifyAll", (char*) "()V",                 (void*) (uintptr_t) &Java_java_lang_Object_notifyAll },
127         { (char*) "wait",      (char*) "(J)V",                (void*) (uintptr_t) &Java_java_lang_Object_wait      },
128 };
129  
130  
131 /* _Jv_java_lang_Object_init ***************************************************
132  
133    Register native functions.
134  
135 *******************************************************************************/
136  
137 void _Jv_java_lang_Object_init(void)
138 {
139         utf* u = utf_new_char("java/lang/Object");
140  
141         NativeMethods& nm = VM::get_current()->get_nativemethods();
142         nm.register_methods(u, methods, NATIVE_METHODS_COUNT);
143 }
144
145
146 /*
147  * These are local overrides for various environment variables in Emacs.
148  * Please do not remove this and leave it at the end of the file, where
149  * Emacs will automagically detect them.
150  * ---------------------------------------------------------------------
151  * Local variables:
152  * mode: c++
153  * indent-tabs-mode: t
154  * c-basic-offset: 4
155  * tab-width: 4
156  * End:
157  * vim:noexpandtab:sw=4:ts=4:
158  */