adadd0d0be95e9de84fa6abe5b779cc40170a863
[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
38 #if defined(ENABLE_JAVAME_CLDC1_1)
39 # include "native/include/java_lang_String.h"/* required by java_lang_Class.h */
40 #endif
41
42 #include "native/include/java_lang_Class.h"
43
44 #if defined(ENABLE_JAVASE)
45 # include "native/include/java_lang_Cloneable.h"
46 #endif
47
48 #include "native/include/java_lang_Object.h"
49
50 #include "threads/lock-common.h"
51
52 #include "vm/builtin.h"
53
54 #include "vmcore/options.h"
55
56 #if defined(ENABLE_JVMTI)
57 #include "native/jvmti/cacaodbg.h"
58 #endif
59
60
61 /*
62  * Class:     java/lang/Object
63  * Method:    getClass
64  * Signature: (Ljava/lang/Object;)Ljava/lang/Class;
65  */
66 java_lang_Class *_Jv_java_lang_Object_getClass(java_lang_Object *obj)
67 {
68         classinfo *c;
69
70         if (obj == NULL)
71                 return NULL;
72
73         c = ((java_objectheader *) obj)->vftbl->class;
74
75         return (java_lang_Class *) c;
76 }
77
78
79 /*
80  * Class:     java/lang/Object
81  * Method:    notify
82  * Signature: ()V
83  */
84 void _Jv_java_lang_Object_notify(java_lang_Object *this)
85 {
86 #if defined(ENABLE_THREADS)
87         lock_notify_object(&this->header);
88 #endif
89 }
90
91
92 /*
93  * Class:     java/lang/Object
94  * Method:    notifyAll
95  * Signature: ()V
96  */
97 void _Jv_java_lang_Object_notifyAll(java_lang_Object *this)
98 {
99 #if defined(ENABLE_THREADS)
100         lock_notify_all_object(&this->header);
101 #endif
102 }
103
104
105 /*
106  * Class:     java/lang/Object
107  * Method:    wait
108  * Signature: (Ljava/lang/Object;JI)V
109  */
110 void _Jv_java_lang_Object_wait(java_lang_Object *o, s8 ms, s4 ns)
111 {
112 #if defined(ENABLE_JVMTI)
113         /* Monitor Wait */
114         if (jvmti) jvmti_MonitorWaiting(true, o, ms);
115 #endif
116
117 #if defined(ENABLE_THREADS)
118         lock_wait_for_object(&o->header, ms, ns);
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, o, 0);
125 #endif
126 }
127
128
129 #if defined(ENABLE_JAVASE)
130
131 /*
132  * Class:     java/lang/Object
133  * Method:    clone
134  * Signature: (Ljava/lang/Cloneable;)Ljava/lang/Object;
135  */
136 java_lang_Object *_Jv_java_lang_Object_clone(java_lang_Cloneable *this)
137 {
138         java_objectheader *o;
139         java_objectheader *co;
140
141         o = (java_objectheader *) this;
142
143         co = builtin_clone(NULL, o);
144
145         return (java_lang_Object *) co;
146 }
147
148 #endif /* ENABLE_JAVASE */
149
150
151 /*
152  * These are local overrides for various environment variables in Emacs.
153  * Please do not remove this and leave it at the end of the file, where
154  * Emacs will automagically detect them.
155  * ---------------------------------------------------------------------
156  * Local variables:
157  * mode: c
158  * indent-tabs-mode: t
159  * c-basic-offset: 4
160  * tab-width: 4
161  * End:
162  */