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