83f5f7570552969bb057467804e64f31284d9fe6
[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 #if defined(ENABLE_THREADS)
51 # include "threads/native/lock.h"
52 #endif
53
54 #include "vm/builtin.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                 return NULL;
74
75         c = ((java_objectheader *) obj)->vftbl->class;
76
77         return (java_lang_Class *) c;
78 }
79
80
81 /*
82  * Class:     java/lang/Object
83  * Method:    notify
84  * Signature: ()V
85  */
86 void _Jv_java_lang_Object_notify(java_lang_Object *this)
87 {
88 #if defined(ENABLE_THREADS)
89         lock_notify_object(&this->header);
90 #endif
91 }
92
93
94 /*
95  * Class:     java/lang/Object
96  * Method:    notifyAll
97  * Signature: ()V
98  */
99 void _Jv_java_lang_Object_notifyAll(java_lang_Object *this)
100 {
101 #if defined(ENABLE_THREADS)
102         lock_notify_all_object(&this->header);
103 #endif
104 }
105
106
107 /*
108  * Class:     java/lang/Object
109  * Method:    wait
110  * Signature: (Ljava/lang/Object;JI)V
111  */
112 void _Jv_java_lang_Object_wait(java_lang_Object *o, s8 ms, s4 ns)
113 {
114 #if defined(ENABLE_JVMTI)
115         /* Monitor Wait */
116         if (jvmti) jvmti_MonitorWaiting(true, o, ms);
117 #endif
118
119 #if defined(ENABLE_THREADS)
120         lock_wait_for_object(&o->header, ms, ns);
121 #endif
122
123 #if defined(ENABLE_JVMTI)
124         /* Monitor Waited */
125         /* XXX: How do you know if wait timed out ?*/
126         if (jvmti) jvmti_MonitorWaiting(false, o, 0);
127 #endif
128 }
129
130
131 #if defined(ENABLE_JAVASE)
132
133 /*
134  * Class:     java/lang/Object
135  * Method:    clone
136  * Signature: (Ljava/lang/Cloneable;)Ljava/lang/Object;
137  */
138 java_lang_Object *_Jv_java_lang_Object_clone(java_lang_Cloneable *this)
139 {
140         java_objectheader *o;
141         java_objectheader *co;
142
143         o = (java_objectheader *) this;
144
145         co = builtin_clone(NULL, o);
146
147         return (java_lang_Object *) co;
148 }
149
150 #endif /* ENABLE_JAVASE */
151
152
153 /*
154  * These are local overrides for various environment variables in Emacs.
155  * Please do not remove this and leave it at the end of the file, where
156  * Emacs will automagically detect them.
157  * ---------------------------------------------------------------------
158  * Local variables:
159  * mode: c
160  * indent-tabs-mode: t
161  * c-basic-offset: 4
162  * tab-width: 4
163  * End:
164  */