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