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