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