* Removed all Id tags.
[cacao.git] / src / native / vm / java_lang_Object.c
1 /* src/native/vm/java_lang_Object.c - java/lang/Object functions
2
3    Copyright (C) 1996-2005, 2006, 2007 R. Grafl, A. Krall, C. Kruegel,
4    C. Oates, R. Obermaisser, M. Platter, M. Probst, S. Ring,
5    E. Steiner, C. Thalinger, D. Thuernbeck, P. Tomsich, C. Ullrich,
6    J. Wenninger, 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
37 #include "native/include/java_lang_Object.h"
38 #include "native/include/java_lang_String.h"            /* required by j.l.CL */
39
40 #if defined(ENABLE_JAVASE)
41 # if defined(WITH_CLASSPATH_SUN)
42 #  include "native/include/java_nio_ByteBuffer.h"       /* required by j.l.CL */
43 # endif
44
45 # include "native/include/java_lang_ClassLoader.h"       /* required by j.l.C */
46 # include "native/include/java_lang_Cloneable.h"
47 #endif
48
49 #include "native/include/java_lang_Class.h"
50
51 #include "threads/lock-common.h"
52
53 #include "vm/builtin.h"
54 #include "vm/exceptions.h"
55
56 #include "vmcore/options.h"
57
58 #if defined(ENABLE_JVMTI)
59 #include "native/jvmti/cacaodbg.h"
60 #endif
61
62
63 /*
64  * Class:     java/lang/Object
65  * Method:    getClass
66  * Signature: (Ljava/lang/Object;)Ljava/lang/Class;
67  */
68 java_lang_Class *_Jv_java_lang_Object_getClass(java_lang_Object *obj)
69 {
70         classinfo     *c;
71
72         if (obj == NULL) {
73                 exceptions_throw_nullpointerexception();
74                 return NULL;
75         }
76
77         LLNI_class_get(obj, c);
78
79         return LLNI_classinfo_wrap(c);
80 }
81
82
83 /*
84  * Class:     java/lang/Object
85  * Method:    notify
86  * Signature: ()V
87  */
88 void _Jv_java_lang_Object_notify(java_lang_Object *this)
89 {
90 #if defined(ENABLE_THREADS)
91         lock_notify_object(&LLNI_field_direct(this, header));
92 #endif
93 }
94
95
96 /*
97  * Class:     java/lang/Object
98  * Method:    notifyAll
99  * Signature: ()V
100  */
101 void _Jv_java_lang_Object_notifyAll(java_lang_Object *this)
102 {
103 #if defined(ENABLE_THREADS)
104         lock_notify_all_object(&LLNI_field_direct(this, header));
105 #endif
106 }
107
108
109 /*
110  * Class:     java/lang/Object
111  * Method:    wait
112  * Signature: (Ljava/lang/Object;JI)V
113  */
114 void _Jv_java_lang_Object_wait(java_lang_Object *o, s8 ms, s4 ns)
115 {
116 #if defined(ENABLE_JVMTI)
117         /* Monitor Wait */
118         if (jvmti) jvmti_MonitorWaiting(true, o, ms);
119 #endif
120
121     if (ms < 0) {
122 /*              exceptions_throw_illegalargumentexception("argument out of range"); */
123                 exceptions_throw_illegalargumentexception();
124                 return;
125         }
126
127 #if defined(ENABLE_THREADS)
128         lock_wait_for_object(&LLNI_field_direct(o, header), ms, ns);
129 #endif
130
131 #if defined(ENABLE_JVMTI)
132         /* Monitor Waited */
133         /* XXX: How do you know if wait timed out ?*/
134         if (jvmti) jvmti_MonitorWaiting(false, o, 0);
135 #endif
136 }
137
138
139 #if defined(ENABLE_JAVASE)
140
141 /*
142  * Class:     java/lang/Object
143  * Method:    clone
144  * Signature: (Ljava/lang/Cloneable;)Ljava/lang/Object;
145  */
146 java_lang_Object *_Jv_java_lang_Object_clone(java_lang_Cloneable *this)
147 {
148         java_handle_t *o;
149         java_handle_t *co;
150
151         o = (java_handle_t *) this;
152
153         co = builtin_clone(NULL, o);
154
155         return (java_lang_Object *) co;
156 }
157
158 #endif /* ENABLE_JAVASE */
159
160
161 /*
162  * These are local overrides for various environment variables in Emacs.
163  * Please do not remove this and leave it at the end of the file, where
164  * Emacs will automagically detect them.
165  * ---------------------------------------------------------------------
166  * Local variables:
167  * mode: c
168  * indent-tabs-mode: t
169  * c-basic-offset: 4
170  * tab-width: 4
171  * End:
172  */